/** * Creates a utility instance. */ public PdoUtilities() { ServiceFinder finder = ServiceFactory.getServiceFinder(); singularMap = new HashMap<>(); for (Map.Entry<String,String> entry: finder.createNameMap(Singular.class.getName()).entrySet()) { String singleName = StringHelper.stripEnclosingDoubleQuotes(entry.getKey()); singularMap.put(entry.getValue(), singleName); } pluralMap = new HashMap<>(); for (Map.Entry<String,String> entry: finder.createNameMap(Plural.class.getName()).entrySet()) { String multiName = StringHelper.stripEnclosingDoubleQuotes(entry.getKey()); pluralMap.put(entry.getValue(), multiName); } }
/** * Creates a list of providers. * * @return the non-empty list of providers, null if no providers found */ protected List<ResourceBundleControlProvider> createProviders() { List<ResourceBundleControlProvider> providerList = null; try { for (Class<ResourceBundleControlProvider> clazz: ServiceFactory.getServiceFinder().findServiceProviders(ResourceBundleControlProvider.class)) { if (providerList == null) { providerList = new ArrayList<>(); } providerList.add(clazz.getDeclaredConstructor().newInstance()); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new TentackleRuntimeException("cannot load bundle control providers", ex); } return providerList; }
/** * Installs all Tentackle Look and Feels */ public void installTentackleLookAndFeels() { for (String plafName: ServiceFactory.getServiceFinder().findServiceConfigurations(TentackleLookAndFeel.class.getName()).keySet()) { installLookAndFeel(plafName); } }
controllerClasses = ServiceFactory.getServiceFinder().findServiceProviders(FxController.class); Map<String,String> serviceMap = ServiceFactory.getServiceFinder().createNameMap(Configurator.class.getName()); for (Map.Entry<String,String> entry: serviceMap.entrySet()) { try { for (Class<ImageProvider> clazz: ServiceFactory.getServiceFinder().findServiceProviders(ImageProvider.class)) { ImageProviderService svc = clazz.getAnnotation(ImageProviderService.class); if (svc != null) { for (Class<ValueTranslator> clazz: ServiceFactory.getServiceFinder().findServiceProviders(ValueTranslator.class)) { ValueTranslatorService svc = clazz.getAnnotation(ValueTranslatorService.class); if (svc != null) {
/** * Utility method to create a service instance.<br> * This is the standard way to instantiate singletons. * Finds the first service implementation along the classpath. * * @param <T> the service type * @param serviceClass the service class * @return an instance of the service */ public static <T> Class<T> createServiceClass(Class<T> serviceClass) { try { return INSTANCE.getServiceFinderImpl().findFirstServiceProvider(serviceClass); } catch (ClassNotFoundException ex) { throw new TentackleRuntimeException("cannot create service class for " + serviceClass, ex); } }
findFirstServiceConfiguration(interception.implementedByService()); implClass = (Class<? extends Interceptor>) Class.forName(entry.getKey()); findFirstServiceConfiguration(annotation.annotationType().getName()); implClass = (Class<? extends Interceptor>) Class.forName(entry.getKey());
/** * Creates the factory. */ public FxBuilderFactory() { defaultFactory = new JavaFXBuilderFactory(); // pickup class mapping for builders Map<String,String> serviceMap = ServiceFactory.getServiceFinder().createNameMap(Builder.class.getName()); builderMap = new HashMap<>(); for (Map.Entry<String,String> entry: serviceMap.entrySet()) { try { Class<?> nodeClass = Class.forName(entry.getKey()); Class<?> builderClass = Class.forName(entry.getValue()); builderMap.put(nodeClass, builderClass); } catch (ClassNotFoundException ex) { throw new FxRuntimeException(ex); } } }
@Override public synchronized Collection<ScriptingLanguage> getLanguages() { if (languages == null) { // load all languages via @Service // the abbreviations override previous ones in classpath // dto. for the default language // so it's easy to change the default or the meaning of an abbreviation languages = new HashMap<>(); try { for (Class<ScriptingLanguage> clazz: ServiceFactory.getServiceFinder().findServiceProviders(ScriptingLanguage.class)) { ScriptingLanguage language = clazz.getDeclaredConstructor().newInstance(); for (String abbrv: language.getAbbreviations()) { String abbrvLC = abbrv.toLowerCase(); languages.put(abbrvLC, language); LOGGER.info("added scripting language {0} as {1}", language, abbrvLC); } } } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException nfe) { throw new ScriptRuntimeException("supported scripting languages could not be determined", nfe); } } return languages.values(); }
/** * Creates a map of names to all mapped services.<p> * They key of the map is the service name. * The value is a list of names providing the service ordered by discovery along the classpath. * * @param serviceName the service class * @return the map */ @Override public synchronized Map<String, Set<String>> createNameMapToAll(String serviceName) { Map<String, Set<String>> nameMap = new HashMap<>(); for (Map.Entry<String, URL> entry : ServiceFactory.getServiceFinder(Constants.MAPPED_SERVICE_PATH).findServiceConfigurations(serviceName).entrySet()) { String configuration = entry.getKey(); List<String> parts = StringHelper.split(configuration, ":= "); if (parts.size() != 2) { throw new TentackleRuntimeException("invalid service configuration '" + configuration + "' in " + entry.getValue()); } String key = parts.get(1); Set<String> serviceList = nameMap.computeIfAbsent(key, k -> new HashSet<>()); serviceList.add(parts.get(0)); } return nameMap; }
/** * Creates a class mapper for a given mapped service name. * * @param name the mapper's name * @param mappedServiceName the mapped name */ public DefaultClassMapper(String name, String mappedServiceName) { this(name, ServiceFactory.getClassLoader(Constants.MAPPED_SERVICE_PATH, mappedServiceName), ServiceFactory.getServiceFinder().createNameMap(mappedServiceName), null); }
/** * Creates a map of classnames to mapped services. * <p> * They key of the map is the service name. * The value is the name providing the service which comes first in the classpath. * * @param serviceName the service class * @return the map */ @Override public synchronized Map<String, String> createNameMap(String serviceName) { Map<String, String> nameMap = new HashMap<>(); for (Map.Entry<String, URL> entry : ServiceFactory.getServiceFinder(Constants.MAPPED_SERVICE_PATH).findServiceConfigurations(serviceName).entrySet()) { String configuration = entry.getKey(); List<String> parts = StringHelper.split(configuration, ":= "); if (parts.size() != 2) { throw new TentackleRuntimeException("invalid service configuration '" + configuration + "' in " + entry.getValue()); } nameMap.putIfAbsent(parts.get(1), parts.get(0)); } return nameMap; }
scopesByIface = new HashMap<>(); try { Map<String,String> scopeMap = ServiceFactory.getServiceFinder().createNameMap(ValidationScopeService.class.getName()); for (Map.Entry<String,String> entry: scopeMap.entrySet()) { @SuppressWarnings("unchecked")
for (Map.Entry<String, URL> providerEntry : ServiceFactory.getServiceFinder(classLoader, Constants.DEFAULT_SERVICE_PATH). findServiceConfigurations(BundleSupport.BUNDLE_SERVICE).entrySet()) { findServiceConfigurations(serviceName).entrySet()) { ModuleInfo info = ModuleSorter.INSTANCE.getModuleInfo(entry.getValue()); List<String> parts = StringHelper.split(entry.getKey(), ":= ");
permissions = new ArrayList<>(); try { Map<String,String> permissionMap = ServiceFactory.getServiceFinder().createNameMap(PermissionService.class.getName()); for (Map.Entry<String,String> entry: permissionMap.entrySet()) { @SuppressWarnings("unchecked")