/** * Obtains the {@link ConfigModel} from the "global" element name. * * <p> * This method uses {@link #buildModel} to lazily build models if necessary. * * @return * Null if no configurable component is registered under the given global element name. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ConfigModel getModelByElementName(String elementName) { ActiveDescriptor<?> i = habitat.getBestDescriptor( BuilderHelper.createNameAndContractFilter(ConfigInjector.class.getName(), elementName)); if(i==null) return null; return buildModel((ActiveDescriptor<? extends ConfigInjector>) i); }
/** * Obtains a {@link ConfigModel} for the given class (Which should have {@link Configured} annotation on it.) */ public ConfigModel buildModel(String fullyQualifiedClassName) { ActiveDescriptor<? extends ConfigInjector<?>> desc; synchronized (cache) { desc = cache.get(fullyQualifiedClassName); if (desc == null) { desc = (ActiveDescriptor<? extends ConfigInjector<?>>) habitat.getBestDescriptor(new InjectionTargetFilter(fullyQualifiedClassName)); if (desc == null) { throw new ConfigurationException("ConfigInjector for %s is not found, is it annotated with @Configured",fullyQualifiedClassName); } cache.put(fullyQualifiedClassName, desc); } } return buildModel(desc); }
public void lookupInjectorByFilter() { ActiveDescriptor desc = habitat.getBestDescriptor( new InjectionTargetFilter(EjbContainerAvailability.class.getName())); assert(desc != null && desc.getImplementation().equals(EjbContainerAvailabilityInjector.class.getName())); }
private static boolean addIfNotThere(ServiceLocator locator, DynamicConfiguration config, DescriptorImpl desc, HK2Loader loader) { IndexedFilter filter = BuilderHelper.createContractFilter(desc.getImplementation()); if (locator.getBestDescriptor(filter) != null) return false; if (loader != null) { desc.setLoader(loader); } config.bind(desc); return true; }
if (locator.getBestDescriptor(BuilderHelper.createContractFilter(PROPERTY_GENERATED_INJECTOR_CLASS)) != null) return;
@Override public ActiveDescriptor<?> getBestDescriptor(Filter filter) { return delegate.getBestDescriptor(filter); }
@Override public ActiveDescriptor<?> getBestDescriptor(Filter filter) { return delegate.getBestDescriptor(filter); }
private synchronized ServiceHandle<?> getServiceFromName(String id) { if (locator == null) throw new IllegalStateException( "ServiceLocator must be set"); ActiveDescriptor<?> best = locator.getBestDescriptor(BuilderHelper.createTokenizedFilter(id)); if (best == null) return null; return locator.getServiceHandle(best); }
/** * Obtains the {@link ConfigModel} from the "global" element name. * * <p> * This method uses {@link #buildModel} to lazily build models if necessary. * * @return * Null if no configurable component is registered under the given global element name. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public ConfigModel getModelByElementName(String elementName) { ActiveDescriptor<?> i = habitat.getBestDescriptor( BuilderHelper.createNameAndContractFilter(ConfigInjector.class.getName(), elementName)); if(i==null) return null; return buildModel((ActiveDescriptor<? extends ConfigInjector>) i); }
/** * Returns the best service matching the passed in fully qualified * class name of the service * * @param locator The locator to find the service in * @param className The fully qualified class name of the service * @return The found service, or null if there is no service with this class name */ @SuppressWarnings("unchecked") public static <T> T getService(ServiceLocator locator, String className) { if (locator == null || className == null) throw new IllegalArgumentException(); ActiveDescriptor<T> ad = (ActiveDescriptor<T>) locator.getBestDescriptor(BuilderHelper.createContractFilter(className)); if (ad == null) return null; return locator.getServiceHandle(ad).getService(); }
/** * Returns the best service matching the passed in fully qualified * class name of the service * * @param locator The locator to find the service in * @param className The fully qualified class name of the service * @return The found service, or null if there is no service with this class name */ @SuppressWarnings("unchecked") public static <T> T getService(ServiceLocator locator, String className) { if (locator == null || className == null) throw new IllegalArgumentException(); ActiveDescriptor<T> ad = (ActiveDescriptor<T>) locator.getBestDescriptor(BuilderHelper.createContractFilter(className)); if (ad == null) return null; return locator.getServiceHandle(ad).getService(); }
/** * Returns the best service matching the passed in fully qualified * class name of the service * * @param locator The locator to find the service in * @param className The fully qualified class name of the service * @return The found service, or null if there is no service with this class name */ @SuppressWarnings("unchecked") public static <T> T getService(ServiceLocator locator, String className) { if (locator == null || className == null) throw new IllegalArgumentException(); ActiveDescriptor<T> ad = (ActiveDescriptor<T>) locator.getBestDescriptor(BuilderHelper.createContractFilter(className)); if (ad == null) return null; return locator.getServiceHandle(ad).getService(); }
@SuppressWarnings("unchecked") public Archivist getArchivist(String archiveType) { ActiveDescriptor<Archivist> best = (ActiveDescriptor<Archivist>) habitat.getBestDescriptor(new ArchivistFilter(archiveType, ARCHIVE_TYPE, Archivist.class)); if (best == null) return null; return habitat.getServiceHandle(best).getService(); }
@Override public Object create(Context ic) throws NamingException { ActiveDescriptor<?> descriptor = habitat.getBestDescriptor( BuilderHelper.createContractFilter("javax.transaction.UserTransaction")); if (descriptor == null) return null; return habitat.getServiceHandle(descriptor).getService(); } }, false);
@Override public Object create(Context ic) throws NamingException { ActiveDescriptor<?> descriptor = habitat.getBestDescriptor( BuilderHelper.createContractFilter("javax.transaction.UserTransaction")); if (descriptor == null) return null; return habitat.getServiceHandle(descriptor).getService(); } }, false);
/** * Given a command name, return the name of the class that implements that * command in the server. */ private static String getCommandClass(String cmdName) { ServiceLocator h = getManHabitat(); String cname = "org.glassfish.api.admin.AdminCommand"; ActiveDescriptor<?> ad = h.getBestDescriptor( BuilderHelper.createNameAndContractFilter(cname, cmdName)); if (ad == null) return null; return ad.getImplementation(); }
public void lookupInjectorByFilter() { ActiveDescriptor desc = habitat.getBestDescriptor( new InjectionTargetFilter(EjbContainerAvailability.class.getName())); assert(desc != null && desc.getImplementation().equals(EjbContainerAvailabilityInjector.class.getName())); }
private static boolean addIfNotThere(ServiceLocator locator, DynamicConfiguration config, DescriptorImpl desc, HK2Loader loader) { IndexedFilter filter = BuilderHelper.createContractFilter(desc.getImplementation()); if (locator.getBestDescriptor(filter) != null) return false; if (loader != null) { desc.setLoader(loader); } config.bind(desc); return true; }
private static boolean addIfNotThere(ServiceLocator locator, DynamicConfiguration config, DescriptorImpl desc, HK2Loader loader) { IndexedFilter filter = BuilderHelper.createContractFilter(desc.getImplementation()); if (locator.getBestDescriptor(filter) != null) return false; if (loader != null) { desc.setLoader(loader); } config.bind(desc); return true; }
public Class getClassForFullName(String configBeanClassName) { ActiveDescriptor<?> descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName)); if (descriptor != null) { if (!descriptor.isReified()) { descriptor = serviceLocator.reifyDescriptor(descriptor); } return getClassFromDescriptor(descriptor); } else { descriptor = serviceLocator.getBestDescriptor(BuilderHelper.createContractFilter(configBeanClassName + "Injector")); if (!descriptor.isReified()) { descriptor = serviceLocator.reifyDescriptor(descriptor); } ConfigInjector injector = (ConfigInjector) serviceLocator.getServiceHandle(descriptor).getService(); return getClassFromInjector(injector); } }