package gw.rating.rtm.matchop uses gw.lang.reflect.TypeSystem uses gw.rating.rtm.query.RateQueryParam uses gw.rating.rtm.validation.MatchOpValidator uses java.lang.IllegalStateException uses java.lang.UnsupportedOperationException uses java.util.HashMap /** * Keeps a cache of {@link MatchOperationFactory} objects, and creates them by name. */ @ReadOnly abstract class MatchOperationFactory { static var factoryMap = new HashMap() construct() { } /** * Return the factory with the given name. Returns a cached value if it exists, otherwise creates a new one. */ static function getFactoryByName(factoryName : String) : MatchOperationFactory { var factoryClass = factoryMap.get(factoryName) if (factoryClass == null) { var type = TypeSystem.getByFullNameIfValid(factoryName) var constructor = type.TypeInfo.getCallableConstructor({}) factoryClass = constructor.Constructor.newInstance({}) as MatchOperationFactory factoryMap.put(factoryName, factoryClass) } return factoryClass } /** * For testing only: directly sets an implementation of a factory with the given name. */ static function setFactoryForTest(factoryName : String, factoryClass : MatchOperationFactory) { if (factoryMap == null) { throw new IllegalStateException("factory map is not initialized") } factoryMap.put(factoryName, factoryClass) } abstract function createStatelessMatchOperator(matchOp : RateTableMatchOp) : S /** * Returns a new instance of the MatchOperation. */ final function createMatchOperation(matchOp : RateTableMatchOp, param : RateQueryParam) : Object { throw new UnsupportedOperationException("createMatchOperation is no longer supported. Please use createStatelessMatchOperator") } /** * Returns a new instance of the MatchOpValidator. */ abstract function createValidator() : MatchOpValidator /** * Returns the type of class this implementation creates. */ property get CreatesType() : Type { return S } }