org.glassfish.hk2.api.DynamicConfiguration Java Examples

The following examples show how to use org.glassfish.hk2.api.DynamicConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuiceComponentProviderTest.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
private <T> void givenInjections(ServiceBindingBuilder<T> bindingBuilder) {
    new MockUp<GuiceComponentProvider>() {
        @Mock
        DynamicConfiguration getConfiguration(final ServiceLocator locator) {
            return dynamicConfiguration;
        }

        @Mock
        ServiceBindingBuilder<T> newFactoryBinder(final Factory<T> factory) {
            return bindingBuilder;
        }

        @Mock
        void addBinding(final BindingBuilder<T> builder, final DynamicConfiguration configuration) {
        }
    };
}
 
Example #2
Source File: RestApplication.java    From jerseyoauth2 with MIT License 6 votes vote down vote up
@Inject
   public RestApplication(ServiceLocator serviceLocator) {
	DynamicConfiguration dc = Injections.getConfiguration(serviceLocator);

       Injections.addBinding(Injections.newBinder(DatabaseClientService.class).to(IClientService.class),dc);
       Injections.addBinding(Injections.newBinder(Configuration.class).to(IConfiguration.class),dc);
       Injections.addBinding(Injections.newBinder(Configuration.class).to(IRSConfiguration.class),dc);
       Injections.addBinding(Injections.newBinder(DefaultPrincipalUserService.class).to(IUserService.class),dc);
       Injections.addBinding(Injections.newBinder(CachingAccessTokenStorage.class).to(IAccessTokenStorageService.class),dc);
       Injections.addBinding(Injections.newBinder(IntegratedAccessTokenVerifier.class).to(IAccessTokenVerifier.class),dc);
       Injections.addBinding(Injections.newBinder(RequestFactory.class).to(IRequestFactory.class),dc);
       Injections.addBinding(Injections.newBinder(MD5TokenGenerator.class).to(ITokenGenerator.class),dc);
       Injections.addBinding(Injections.newBinder(UUIDClientIdGenerator.class).to(IClientIdGenerator.class),dc);
	
	EntityManagerFactory emf = new PersistenceProvider().get();
       Injections.addBinding(Injections.newBinder(emf).to(EntityManagerFactory.class),dc);
       
       CacheManager cacheManager = new DefaultCacheManagerProvider().get();
       Injections.addBinding(Injections.newBinder(cacheManager).to(CacheManager.class),dc);
       
       dc.commit();
}
 
Example #3
Source File: TypeFactory.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(DynamicConfiguration config) {
  Injections.addBinding(
          Injections.newFactoryBinder(this).to(type).in(Singleton.class),
          config);
  Injections.addBinding(
          Injections.newBinder(this).to(ValueFactoryProvider.class),
          config);
}
 
Example #4
Source File: GuiceComponentProvider.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private <T> void registerBindingsInHK2(Class<T> componentClass, Set<Class<?>> providerContracts) {
    ServiceBindingBuilder<T> componentBindingBuilder = getBindingBuilder(componentClass);
    componentBindingBuilder.to(componentClass);
    bindProviderContracts(componentBindingBuilder, providerContracts);

    DynamicConfiguration dynamicConfiguration = getConfiguration(serviceLocator);
    addBinding(componentBindingBuilder, dynamicConfiguration);
    dynamicConfiguration.commit();
}
 
Example #5
Source File: TypeFactory.java    From shiro-jersey with Apache License 2.0 5 votes vote down vote up
@Override
public void bind(DynamicConfiguration config) {
  Injections.addBinding(
          Injections.newFactoryBinder(this).to(type).in(Singleton.class),
          config);
  Injections.addBinding(
          Injections.newBinder(this).to(ValueFactoryProvider.class),
          config);
}
 
Example #6
Source File: GuiceComponentProvider.java    From seed with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Add a binding represented by the binding builder to the HK2 dynamic configuration.
 *
 * @param builder       binding builder.
 * @param configuration HK2 dynamic configuration.
 */
private static void addBinding(final BindingBuilder<?> builder, final DynamicConfiguration configuration) {
    BindingBuilderFactory.addBinding(builder, configuration);
}
 
Example #7
Source File: GuiceComponentProvider.java    From seed with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Get service locator {@link DynamicConfiguration dynamic configuration}.
 *
 * @param locator HK2 service locator.
 * @return dynamic configuration for a given service locator.
 */
private static DynamicConfiguration getConfiguration(final ServiceLocator locator) {
    final DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    return dcs.createDynamicConfiguration();
}