/** * This method can be used to populate the service locator with files that * have been written out using the {@link DescriptorImpl} writeObject method. * * @param serviceLocator The service locator to populate. May not be null. * @param fileFinder An object that finds files in the environment. May not be null. * @param postProcessors A post-processor that allows the environment to modify the set * of descriptors that are added to the system. May be null, in which case the descriptors * read in are those that are used to populate the serviceLocator * @throws IOException In case of an error */ public static List<ActiveDescriptor> populate(final ServiceLocator serviceLocator, DescriptorFileFinder fileFinder, List <? extends PopulatorPostProcessor> postProcessors) throws IOException { if (postProcessors == null) postProcessors = new LinkedList<PopulatorPostProcessor>(); DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); List<ActiveDescriptor<?>> retVal = populator.populate(fileFinder, postProcessors.toArray(new PopulatorPostProcessor[postProcessors.size()])); return (List<ActiveDescriptor>) ((List) retVal); }
public void populate(ServiceLocator locator) throws Exception { DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); populator.populate(new ClasspathDescriptorFileFinder(getClass().getClassLoader())); }
/** * This method can be used to populate the service locator with files that * have been written out using the {@link DescriptorImpl} writeObject method. * * @param serviceLocator The service locator to populate. May not be null. * @param fileFinder An object that finds files in the environment. May not be null. * @param postProcessors A post-processor that allows the environment to modify the set * of descriptors that are added to the system. May be null, in which case the descriptors * read in are those that are used to populate the serviceLocator * @throws IOException In case of an error */ public static List<ActiveDescriptor> populate(final ServiceLocator serviceLocator, DescriptorFileFinder fileFinder, List <? extends PopulatorPostProcessor> postProcessors) throws IOException { if (postProcessors == null) postProcessors = new LinkedList<PopulatorPostProcessor>(); DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); List<ActiveDescriptor<?>> retVal = populator.populate(fileFinder, postProcessors.toArray(new PopulatorPostProcessor[postProcessors.size()])); return (List<ActiveDescriptor>) ((List) retVal); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected List<ActiveDescriptor> parseInhabitants(Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException { ArrayList<PopulatorPostProcessor> allPostProcessors = new ArrayList<PopulatorPostProcessor>(); allPostProcessors.add(new Hk2LoaderPopulatorPostProcessor(singleClassLoader)); if (postProcessors != null) { allPostProcessors.addAll(postProcessors); } DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); List<ActiveDescriptor<?>> retVal = populator.populate( new ClasspathDescriptorFileFinder(singleClassLoader, name), allPostProcessors.toArray(new PopulatorPostProcessor[allPostProcessors.size()])); return (List<ActiveDescriptor>) ((List) retVal); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected List<ActiveDescriptor> parseInhabitants(Module module, String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws IOException { ArrayList<PopulatorPostProcessor> allPostProcessors = new ArrayList<PopulatorPostProcessor>(); allPostProcessors.add(new Hk2LoaderPopulatorPostProcessor(singleClassLoader)); if (postProcessors != null) { allPostProcessors.addAll(postProcessors); } DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); List<ActiveDescriptor<?>> retVal = populator.populate( new ClasspathDescriptorFileFinder(singleClassLoader, name), allPostProcessors.toArray(new PopulatorPostProcessor[allPostProcessors.size()])); return (List<ActiveDescriptor>) ((List) retVal); }
@Override public boolean configure(FeatureContext context) { try { dcs.getPopulator().populate(new InhabitantsFileFinder(JAR_DEFAULT)); dcs.getPopulator().populate(new InhabitantsFileFinder(WEB_DEFAULT)); dcs.getPopulator().populate(new InhabitantsFileFinder(WEB_APP)); ServiceLocatorUtilities.enableImmediateScope(locator); ServiceLocatorUtilities.enableTopicDistribution(locator); return true; } catch (IOException | MultiException e) { return false; } }
/** * {@inheritDoc} */ @Override public ServiceLocator create(String name, ServiceLocator parent) { ServiceLocator retVal = super.create(name, parent); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; } }
/** * This method is often the first line of a stand-alone client that wishes to use HK2. * It creates a ServiceLocator with the given name (or a randomly generated name if * null is passed in) and then populates that service locator with services found in * the META-INF/hk2-locator/default files that can be found with the classloader that * loaded HK2 (usually the system classloader). * * @param name The name of the service locator to create. If there is already a service * locator of this name this method will use that one to populate. If this is null * a randomly assigned name will be given to the service locator, and it will not be * tracked by the system. If this is NOT null then this service locator can be found * with {@link ServiceLocatorFactory#find(String)}. * @return A service locator that has been populated with services * @throws MultiException If there was a failure when populating or creating the ServiceLocator */ public static ServiceLocator createAndPopulateServiceLocator(String name) throws MultiException { ServiceLocator retVal = ServiceLocatorFactory.getInstance().create(name); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; }
/** * This method is often the first line of a stand-alone client that wishes to use HK2. * It creates a ServiceLocator with the given name (or a randomly generated name if * null is passed in) and then populates that service locator with services found in * the META-INF/hk2-locator/default files that can be found with the classloader that * loaded HK2 (usually the system classloader). * * @param name The name of the service locator to create. If there is already a service * locator of this name this method will use that one to populate. If this is null * a randomly assigned name will be given to the service locator, and it will not be * tracked by the system. If this is NOT null then this service locator can be found * with {@link ServiceLocatorFactory#find(String)}. * @return A service locator that has been populated with services * @throws MultiException If there was a failure when populating or creating the ServiceLocator */ public static ServiceLocator createAndPopulateServiceLocator(String name) throws MultiException { ServiceLocator retVal = ServiceLocatorFactory.getInstance().create(name); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; }
/** * This method is often the first line of a stand-alone client that wishes to use HK2. * It creates a ServiceLocator with the given name (or a randomly generated name if * null is passed in) and then populates that service locator with services found in * the META-INF/hk2-locator/default files that can be found with the classloader that * loaded HK2 (usually the system classloader). * * @param name The name of the service locator to create. If there is already a service * locator of this name this method will use that one to populate. If this is null * a randomly assigned name will be given to the service locator, and it will not be * tracked by the system. If this is NOT null then this service locator can be found * with {@link ServiceLocatorFactory#find(String)}. * @return A service locator that has been populated with services * @throws MultiException If there was a failure when populating or creating the ServiceLocator */ public static ServiceLocator createAndPopulateServiceLocator(String name) throws MultiException { ServiceLocator retVal = ServiceLocatorFactory.getInstance().create(name); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; }
/** * This method is often the first line of a stand-alone client that wishes to use HK2. * It creates a ServiceLocator with the given name (or a randomly generated name if * null is passed in) and then populates that service locator with services found in * the META-INF/hk2-locator/default files that can be found with the classloader that * loaded HK2 (usually the system classloader). * * @param name The name of the service locator to create. If there is already a service * locator of this name this method will use that one to populate. If this is null * a randomly assigned name will be given to the service locator, and it will not be * tracked by the system. If this is NOT null then this service locator can be found * with {@link ServiceLocatorFactory#find(String)}. * @return A service locator that has been populated with services * @throws MultiException If there was a failure when populating or creating the ServiceLocator */ public static ServiceLocator createAndPopulateServiceLocator(String name) throws MultiException { ServiceLocator retVal = ServiceLocatorFactory.getInstance().create(name); DynamicConfigurationService dcs = retVal.getService(DynamicConfigurationService.class); Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException e) { throw new MultiException(e); } return retVal; }
Populator populator = dcs.getPopulator(); try { populator.populate(); } catch (IOException | MultiException e) { throw new MultiException(e);
void addScans(InjectionManager injectionManager, TestDescriptor testDescriptor, ClassLoader classLoader) throws TestifyException { try { DynamicConfigurationService dcs = injectionManager.getInstance(DynamicConfigurationService.class); DynamicConfiguration dc = dcs.createDynamicConfiguration(); Populator populator = dcs.getPopulator(); for (Scan scan : testDescriptor.getScans()) { JerseyDescriptorPopulator descriptorPopulator = new JerseyDescriptorPopulator(classLoader, scan.value()); populator.populate(descriptorPopulator); } dc.commit(); } catch (IOException | MultiException e) { throw ExceptionUtil.INSTANCE.propagate("Could not populate service instance", e); } }
void addScans(ServiceLocator serviceLocator, TestDescriptor testDescriptor, ClassLoader classLoader) throws TestifyException { try { DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); DynamicConfiguration dc = dcs.createDynamicConfiguration(); Populator populator = dcs.getPopulator(); for (Scan scan : testDescriptor.getScans()) { HK2DescriptorPopulator descriptorPopulator = new HK2DescriptorPopulator(classLoader, scan.value()); populator.populate(descriptorPopulator); } dc.commit(); } catch (IOException | MultiException e) { throw ExceptionUtil.INSTANCE.propagate("Could not populate service instance", e); } }