/** * Register/bind custom provider instances. Registered providers will be handled * always as Singletons. * * @param instances custom provider instances. */ public void bindInstances(final Iterable<Object> instances) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Object instance : instances) { bindInstance(instance, dc); } dc.commit(); }
/** * Register/bind custom provider instances. Registered providers will be handled * always as Singletons. * * @param instances custom provider instances. */ public void bindInstances(final Iterable<Object> instances) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Object instance : instances) { bindInstance(instance, dc); } dc.commit(); }
/** * Register/bind custom provider instances. Registered providers will be handled * always as Singletons. * * @param instances custom provider instances. */ public void bindInstances(final Iterable<Object> instances) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Object instance : instances) { bindInstance(instance, dc); } dc.commit(); }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Class<?>... classes) { if (classes != null && classes.length > 0) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, false); } dc.commit(); } }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Class<?>... classes) { if (classes != null && classes.length > 0) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, false); } dc.commit(); } }
/** * Binds {@code resourceClass} into HK2 context as singleton. * * The bound class is then cached internally so that any sub-sequent attempt to bind that class * as a singleton is silently ignored. * * @param <T> type of the resource class. * @param resourceClass resource class that should be bound. If the class is not * annotated with {@link javax.inject.Singleton Singleton annotation} it * will be ignored by this method. */ public <T> void bindResource(Class<T> resourceClass) { if (bindingCache.contains(resourceClass)) { return; } synchronized (bindingCacheLock) { if (bindingCache.contains(resourceClass)) { return; } final DynamicConfiguration dc = Injections.getConfiguration(locator); unsafeBindResource(resourceClass, null, dc); dc.commit(); } }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Class<?>... classes) { if (classes != null && classes.length > 0) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, false); } dc.commit(); } }
/** * Register/bind custom provider classes that may also be resources. Registered * providers/resources will be handled always as Singletons unless annotated by * {@link PerLookup}. * * <p> * If {@code bindAsResources} is set to {@code true}, the providers will also be bound * as resources. * </p> * * @param classes custom provider classes. * @param bindResources if {@code true}, the provider classes will also be bound as * resources. */ public void bindClasses(final Iterable<Class<?>> classes, final boolean bindResources) { if (classes == null || !classes.iterator().hasNext()) { return; } final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, bindResources); } dc.commit(); }
private Set<Binder> configureBinders(final ServiceLocator locator, final Set<Binder> configured) { final Set<Binder> allConfigured = Sets.newIdentityHashSet(); allConfigured.addAll(configured); final Collection<Binder> binders = getBinders(configured); if (!binders.isEmpty()) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Binder binder : binders) { binder.bind(dc); allConfigured.add(binder); } dc.commit(); } return allConfigured; }
/** * Register/bind custom provider classes that may also be resources. Registered * providers/resources will be handled always as Singletons unless annotated by * {@link PerLookup}. * * <p> * If {@code bindAsResources} is set to {@code true}, the providers will also be bound * as resources. * </p> * * @param classes custom provider classes. * @param bindResources if {@code true}, the provider classes will also be bound as * resources. */ public void bindClasses(final Iterable<Class<?>> classes, final boolean bindResources) { if (classes == null || !classes.iterator().hasNext()) { return; } final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, bindResources); } dc.commit(); }
private Set<Binder> configureBinders(final ServiceLocator locator, final Set<Binder> configured) { final Set<Binder> allConfigured = Sets.newIdentityHashSet(); allConfigured.addAll(configured); final Collection<Binder> binders = getBinders(configured); if (!binders.isEmpty()) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Binder binder : binders) { binder.bind(dc); allConfigured.add(binder); } dc.commit(); } return allConfigured; }
/** * Bind all providers contained in {@code providerBag} (classes and instances) using HK2 service locator. Configuration is * also committed. * * @param componentBag bag of provider classes and instances. * @param constrainedTo current runtime (client or server). * @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning). * @param locator HK2 service locator the binder will use to bind the providers into. */ public static void bindProviders(final ComponentBag componentBag, final RuntimeType constrainedTo, final Set<Class<?>> registeredClasses, final ServiceLocator locator) { final DynamicConfiguration dc = Injections.getConfiguration(locator); bindProviders(componentBag, constrainedTo, registeredClasses, dc); dc.commit(); }
/** * Bind all providers contained in {@code providerBag} (classes and instances) using HK2 service locator. Configuration is * also committed. * * @param componentBag bag of provider classes and instances. * @param constrainedTo current runtime (client or server). * @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning). * @param locator HK2 service locator the binder will use to bind the providers into. */ public static void bindProviders(final ComponentBag componentBag, final RuntimeType constrainedTo, final Set<Class<?>> registeredClasses, final ServiceLocator locator) { final DynamicConfiguration dc = Injections.getConfiguration(locator); bindProviders(componentBag, constrainedTo, registeredClasses, dc); dc.commit(); }
/** * Bind all providers contained in {@code providerBag} (classes and instances) using HK2 service locator. Configuration is * also committed. * * @param componentBag bag of provider classes and instances. * @param constrainedTo current runtime (client or server). * @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning). * @param locator HK2 service locator the binder will use to bind the providers into. */ public static void bindProviders(final ComponentBag componentBag, final RuntimeType constrainedTo, final Set<Class<?>> registeredClasses, final ServiceLocator locator) { final DynamicConfiguration dc = Injections.getConfiguration(locator); bindProviders(componentBag, constrainedTo, registeredClasses, dc); dc.commit(); }
private Set<Binder> configureBinders(final ServiceLocator locator, final Set<Binder> configured) { final Set<Binder> allConfigured = Sets.newIdentityHashSet(); allConfigured.addAll(configured); final Collection<Binder> binders = getBinders(configured); if (!binders.isEmpty()) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Binder binder : binders) { binder.bind(dc); allConfigured.add(binder); } dc.commit(); } return allConfigured; }
private void registerManagedObjectsFinalizer(ServiceLocator locator) { DynamicConfiguration dc = Injections.getConfiguration(locator); ScopedBindingBuilder<ManagedObjectsFinalizer> binder = Injections.newBinder(ManagedObjectsFinalizer.class) .to(ManagedObjectsFinalizer.class) .in(Singleton.class); Injections.addBinding(binder, dc); dc.commit(); }
private void registerManagedObjectsFinalizer(ServiceLocator locator) { DynamicConfiguration dc = Injections.getConfiguration(locator); ScopedBindingBuilder<ManagedObjectsFinalizer> binder = Injections.newBinder(ManagedObjectsFinalizer.class) .to(ManagedObjectsFinalizer.class) .in(Singleton.class); Injections.addBinding(binder, dc); dc.commit(); }
private void bindWaeRestoringExceptionMapper() { final DynamicConfiguration dc = Injections.getConfiguration(locator); final ServiceBindingBuilder bindingBuilder = Injections.newFactoryBinder(new CdiFactory(TransactionalExceptionMapper.class, locator, beanManager, true)); bindingBuilder.to(ExceptionMapper.class); Injections.addBinding(bindingBuilder, dc); dc.commit(); }
private void registerManagedObjectsFinalizer(ServiceLocator locator) { DynamicConfiguration dc = Injections.getConfiguration(locator); ScopedBindingBuilder<ManagedObjectsFinalizer> binder = Injections.newBinder(ManagedObjectsFinalizer.class) .to(ManagedObjectsFinalizer.class) .in(Singleton.class); Injections.addBinding(binder, dc); dc.commit(); }
private void bindHk2ClassAnalyzer() { final ClassAnalyzer defaultClassAnalyzer = locator.getService(ClassAnalyzer.class, ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME); final int skippedElements = methodsToSkip.size() + fieldsToSkip.size(); final ClassAnalyzer customizedClassAnalyzer = skippedElements > 0 ? new InjecteeSkippingAnalyzer(defaultClassAnalyzer, methodsToSkip, fieldsToSkip) : defaultClassAnalyzer; final DynamicConfiguration dc = Injections.getConfiguration(locator); final ScopedBindingBuilder bindingBuilder = Injections.newBinder(customizedClassAnalyzer); bindingBuilder.analyzeWith(ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME) .to(ClassAnalyzer.class) .named(CDI_CLASS_ANALYZER); Injections.addBinding(bindingBuilder, dc); dc.commit(); }