public void addFactory(Factory factory) { factories.put(factory.getId(), factory); }
public void scan(Configuration configuration) { List<ScannedItemHandler> handlers = new ArrayList<ScannedItemHandler>(); for (Factory factory : factories.values()) { try { Class<?> clazz = TypeUtil.forName(factory.getClassName()); Method method = clazz.getMethod("getScannedItemHandler"); if ((Modifier.STATIC & method.getModifiers()) != 0 && method.getParameterTypes().length == 0) { ScannedItemHandler handler = (ScannedItemHandler)method.invoke(null); handlers.add(handler); } else log.warn("Factory class %s contains an unexpected signature for method: %s", factory.getClassName(), method); } catch (NoSuchMethodException e) { // ignore } catch (ClassNotFoundException e) { log.error(e, "Could not load factory class: %s", factory.getClassName()); } catch (Exception e) { log.error(e, "Error while calling %s.getScannedItemHandler() method", factory.getClassName()); } } scanConfig(configuration != null ? configuration.getFlexServicesConfigProperties() : null, handlers); }
if (factories != null) { for (XMap factory : factories.getAll("factory")) { Factory fact = Factory.forElement(factory); this.factories.put(fact.getId(), fact);
private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = context.getServicesConfig().findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }
public static Factory forElement(XMap element) { String id = element.get("@id"); String className = element.get("@class"); XMap properties = new XMap(element.getOne("properties")); return new Factory(id, className, properties); } }
if (factories != null) { for (XMap factory : factories.getAll("factory")) { Factory fact = Factory.forElement(factory); this.factories.put(fact.getId(), fact);
private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = ((ServicesConfig)context.getServicesConfig()).findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }
public static Factory forElement(XMap element) { String id = element.get("@id"); String className = element.get("@class"); XMap properties = new XMap(element.getOne("properties")); return new Factory(id, className, properties); } }
public void addFactory(Factory factory) { factories.put(factory.getId(), factory); }
Factory factory = servicesConfig.findFactoryById("tide-" + type + "-factory"); if (factory == null) { factory = new Factory("tide-" + type + "-factory", factoryClass.getName(), factoryProperties); servicesConfig.addFactory(factory); Factory factory = new Factory(type + "-factory", factoryClass.getName(), factoryProperties); servicesConfig.addFactory(factory);
public void scan(Configuration configuration) { List<ScannedItemHandler> handlers = new ArrayList<ScannedItemHandler>(); for (Factory factory : factories.values()) { try { Class<?> clazz = TypeUtil.forName(factory.getClassName()); Method method = clazz.getMethod("getScannedItemHandler"); if ((Modifier.STATIC & method.getModifiers()) != 0 && method.getParameterTypes().length == 0) { ScannedItemHandler handler = (ScannedItemHandler)method.invoke(null); handlers.add(handler); } else log.warn("Factory class %s contains an unexpected signature for method: %s", factory.getClassName(), method); } catch (NoSuchMethodException e) { // ignore } catch (ClassNotFoundException e) { log.error(e, "Could not load factory class: %s", factory.getClassName()); } catch (Exception e) { log.error(e, "Error while calling %s.getScannedItemHandler() method", factory.getClassName()); } } scanConfig(configuration != null ? configuration.getFlexServicesConfigProperties() : null, handlers); }
@Override public String toString() { return "Destination{" + "id='" + id + '\'' + ", service='" + service.getId() + '\'' + ", factory='" + factory.getId() + '\'' + ", scope='" + properties.get("scope") + '\'' + '}'; } }
@Validate public void start() { log.debug("Start OSGiDestinationFactory: " + toString()); if (service.findDestinationById(id) == null) { this.properties.put("factory", factory.getId()); service.addDestination(this); started = true; } else { log.error("Destination \"" + id + "\" already registered"); } }