public AssetSourceImpl( ThreadLocale threadLocale, Map<String, AssetFactory> configuration, SymbolSource symbolSource, Logger logger, OperationTracker tracker, Request request) { this.configuration = configuration; this.threadLocale = threadLocale; this.symbolSource = symbolSource; this.logger = logger; this.tracker = tracker; this.request = request; Map<Class, AssetFactory> byResourceClass = CollectionFactory.newMap(); for (Map.Entry<String, AssetFactory> e : configuration.entrySet()) { String prefix = e.getKey(); AssetFactory factory = e.getValue(); Resource rootResource = factory.getRootResource(); byResourceClass.put(rootResource.getClass(), factory); prefixToRootResource.put(prefix, rootResource); } registry = StrategyRegistry.newInstance(AssetFactory.class, byResourceClass); }
private Asset createAssetFromResource(Resource resource) { // The class of the resource is derived from the class of the base resource. // So we can then use the class of the resource as a key to locate the correct asset // factory. try { upgradeReadLockToWriteLock(); // Check for competing thread beat us to it (not very likely!): Asset result = TapestryInternalUtils.getAndDeref(cache, resource); if (result != null) { return result; } Class resourceClass = resource.getClass(); AssetFactory factory = registry.get(resourceClass); return factory.createAsset(resource); } finally { downgradeWriteLockToReadLock(); } }
public CacheProcessorSourceImpl( Map<Class, CacheProcessor> configuration, PropertyAccess propertyAccess, TypeCoercer coercer, EntityService entityService) { registry = StrategyRegistry.newInstance(CacheProcessor.class, configuration, true); this.propertyAccess = propertyAccess; this.coercer = coercer; this.entityService = entityService; }
@Override public <T> CacheProcessor<T> getProcessor(final Class<T> clazz) { CacheProcessor processor = registry.get(clazz); if (processor != null) { return processor; } if (clazz.isAnnotationPresent(Entity.class)) { return new CacheProcessor() { @Override public Object fromCache(List cacheObject, Method method) { // fetch id property class Class<?> idClass = propertyAccess .getAdapter(clazz) .getPropertyAdapter(EntityConstants.ID_PROPERTY_NAME) .getType(); // convert id value Object obj = coercer.coerce(cacheObject, idClass); // find object obj = entityService.get(clazz, obj); return obj; } @Override public List toCache(Object value) { return convertAsListObject(value); } }; } else { return new CacheProcessor() { @Override public Object fromCache(List cacheObject, Method method) { return coercer.coerce(cacheObject, clazz); } @Override public List toCache(Object value) { return convertAsListObject(value); } }; } }
private MonitorNameGenerator getNameGenerator(Class owningClass) { MonitorNameGenerator nameGenerator = strategyRegistry.get(owningClass); if (nameGenerator == null) nameGenerator = defaultMonitorNameGenerator; return nameGenerator; }
public MonitorNameGeneratorImpl( Map<Class, MonitorNameGenerator> source, @Autobuild DefaultMonitorNameGenerator defaultMonitorNameGenerator) { this.defaultMonitorNameGenerator = defaultMonitorNameGenerator; strategyRegistry = StrategyRegistry.newInstance(MonitorNameGenerator.class, source, true); }
@Override public <S> S build(Class<S> adapterType, Map<Class, S> registrations) { StrategyRegistry<S> registry = StrategyRegistry.newInstance(adapterType, registrations); return build(registry); }
@Override public <S> S build(StrategyRegistry<S> registry) { return createProxy(registry.getAdapterType(), registry); }