com.google.inject.TypeLiteral Java Examples
The following examples show how to use
com.google.inject.TypeLiteral.
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: SeleniumClassModule.java From che with Eclipse Public License 2.0 | 6 votes |
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { traverseClassHierarchy( type.getRawType(), (clazz) -> { for (Field field : clazz.getDeclaredFields()) { if (field.getType() == TestWorkspace.class && field.isAnnotationPresent(InjectTestWorkspace.class)) { encounter.register( new TestWorkspaceInjector<>( field, field.getAnnotation(InjectTestWorkspace.class), injectorProvider.get())); } } }); }
Example #2
Source File: SharingProfileModule.java From guacamole-client with Apache License 2.0 | 6 votes |
@Override protected void configure() { // Create the required DirectoryResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryResource<SharingProfile, APISharingProfile>>() {}, SharingProfileDirectoryResource.class ) .build(new TypeLiteral<DirectoryResourceFactory<SharingProfile, APISharingProfile>>() {})); // Create the required DirectoryObjectResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryObjectResource<SharingProfile, APISharingProfile>>() {}, SharingProfileResource.class ) .build(new TypeLiteral<DirectoryObjectResourceFactory<SharingProfile, APISharingProfile>>() {})); // Bind translator for converting between SharingProfile and APISharingProfile bind(new TypeLiteral<DirectoryObjectTranslator<SharingProfile, APISharingProfile>>() {}) .to(SharingProfileObjectTranslator.class); }
Example #3
Source File: UrlResolverTest.java From joynr with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { Properties properties = new Properties(); gbidArray = new String[]{}; properties.put(MessagingPropertyKeys.CHANNELID, channelId); Injector injector = Guice.createInjector(new JoynrPropertiesModule(properties), new MessagingTestModule(), new AtmosphereMessagingModule(), new AbstractModule() { @Override protected void configure() { bind(RoutingTable.class).toInstance(mockRoutingTable); bind(String[].class).annotatedWith(Names.named(MessagingPropertyKeys.GBID_ARRAY)) .toInstance(gbidArray); bind(RequestConfig.class).toProvider(HttpDefaultRequestConfigProvider.class) .in(Singleton.class); bind(MessageRouter.class).toInstance(mockMessageRouter); Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() { }); } }); urlResolver = injector.getInstance(UrlResolver.class); }
Example #4
Source File: ModuleManifest.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public ModuleManifest(@Nullable TypeLiteral<Module> type) { // Figure out the module type. If the given type is null, // then try to resolve it from this object's superclass. this.type = type != null ? Types.assertFullySpecified(type) : new ResolvableType<Module>(){}.in(getClass()); this.rawType = (Class<Module>) this.type.getRawType(); this.simpleName = rawType.getSimpleName(); // Resolve the scope type automatically this.scope = (Class<Scope>) new ResolvableType<Scope>(){}.in(getClass()).getRawType(); // Construct various keys related to the module/scope this.key = Key.get(this.type); this.optionalKey = Keys.optional(this.key); this.wrapperKey = ProvisionWrapper.keyOf(this.type); this.contextKey = Key.get(new ResolvableType<Context>(){}.in(getClass())); this.setElementKey = Key.get(new ResolvableType<ProvisionWrapper<? extends Base>>(){}.in(getClass())); }
Example #5
Source File: ActiveConnectionModule.java From guacamole-client with Apache License 2.0 | 6 votes |
@Override protected void configure() { // Create the required DirectoryResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryResource<ActiveConnection, APIActiveConnection>>() {}, ActiveConnectionDirectoryResource.class ) .build(new TypeLiteral<DirectoryResourceFactory<ActiveConnection, APIActiveConnection>>() {})); // Create the required DirectoryObjectResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryObjectResource<ActiveConnection, APIActiveConnection>>() {}, ActiveConnectionResource.class ) .build(new TypeLiteral<DirectoryObjectResourceFactory<ActiveConnection, APIActiveConnection>>() {})); // Bind translator for converting between ActiveConnection and APIActiveConnection bind(new TypeLiteral<DirectoryObjectTranslator<ActiveConnection, APIActiveConnection>>() {}) .to(ActiveConnectionObjectTranslator.class); }
Example #6
Source File: DomainRegistryImplTest.java From business with Mozilla Public License 2.0 | 6 votes |
@SuppressWarnings({"unchecked"}) @Test public void testGetFactoryTypeOfOfT(final @Mocked Factory<?> factory1) { DomainRegistry domainRegistry = createDomainRegistry(); new Expectations() { { injector.getInstance((Key<Factory<AggregateRoot<Long>>>) any); result = factory1; } }; Factory<AggregateRoot<Long>> factory2 = domainRegistry.getFactory( new TypeLiteral<Factory<AggregateRoot<Long>>>() {}.getType()); assertThat(factory2).isEqualTo(factory1); }
Example #7
Source File: InjectableMethodTest.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@Test public void scanForMethods() throws Exception { class Woot { @Yay String foo() { return "foo"; } String bar() { return "bar"; } } List<InjectableMethod<?>> methods = InjectableMethod.forAnnotatedMethods(TypeLiteral.get(Woot.class), new Woot(), Yay.class); Injector injector = Guice.createInjector(Lists.transform(methods, InjectableMethod::bindingModule)); assertEquals("foo", injector.getInstance(String.class)); }
Example #8
Source File: AdsSoapModule.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Configures the factories. * * @param <H> the subclass of {@link AdsServiceClientFactoryHelper} * @param <F> the subclass of {@link BaseAdsServiceClientFactory} * * @param adsServiceClientFactoryTypeLiteral the factory type literal which * contains a {@link AdsServiceClientFactoryInterface} * @param adsServiceDescriptorFactoryTypeLiteral the factory type literal * which contains a {@link AdsServiceDescriptorFactoryInterface} * @param adsServiceClientTypeLiteral the ads service client literal which * contains a {@link AdsServiceClient} * @param adsServiceDescriptorTypeLiteral the ads service descriptor literal * which contains a {@link AdsServiceDescriptor} * @param adsServiceClientFactoryHelperClass the {@link AdsServiceClientFactoryHelper} class * @param baseAdsServiceClientFactoryClass the {@link BaseAdsServiceClientFactory} class */ protected <H extends AdsServiceClientFactoryHelper<C, S, D>, F extends BaseAdsServiceClientFactory<C, S, D>> void configureFactories( TypeLiteral<AdsServiceClientFactoryInterface<C, S, D>> adsServiceClientFactoryTypeLiteral, TypeLiteral<AdsServiceDescriptorFactoryInterface<D>> adsServiceDescriptorFactoryTypeLiteral, TypeLiteral<C> adsServiceClientTypeLiteral, TypeLiteral<D> adsServiceDescriptorTypeLiteral, Class<H> adsServiceClientFactoryHelperClass, Class<F> baseAdsServiceClientFactoryClass) { install( new FactoryModule<C, D, S, H, F>( adsServiceClientFactoryTypeLiteral, adsServiceDescriptorFactoryTypeLiteral, adsServiceClientTypeLiteral, adsServiceDescriptorTypeLiteral, adsServiceClientFactoryHelperClass, baseAdsServiceClientFactoryClass)); }
Example #9
Source File: GsonModule.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override protected void configure() { bind(com.iris.io.json.JsonSerializer.class).to(GsonSerializerImpl.class); bind(com.iris.io.json.JsonDeserializer.class).to(GsonDeserializerImpl.class); Multibinder .newSetBinder(binder(), new TypeLiteral<com.google.gson.JsonSerializer<?>>() {}) .addBinding() .to(AttributeMapSerializer.class); Multibinder .newSetBinder(binder(), new TypeLiteral<com.google.gson.JsonDeserializer<?>>() {}) .addBinding() .to(AttributeMapSerializer.class); Multibinder .newSetBinder(binder(), new TypeLiteral<TypeAdapter<?>>() {}) .addBinding() .to(ByteArrayToBase64TypeAdapter.class); Multibinder .newSetBinder(binder(), new TypeLiteral<TypeAdapterFactory>() {}) .addBinding() .to(TypeTypeAdapterFactory.class); }
Example #10
Source File: NoBackendMessagingModule.java From joynr with Apache License 2.0 | 6 votes |
@Override protected void configure() { bind(MessageReceiver.class).to(NoBackendMessagingReceiver.class); Multibinder<GlobalAddressFactory<? extends Address>> globalAddresses; globalAddresses = Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() { }, Names.named(GlobalAddressProvider.GLOBAL_ADDRESS_FACTORIES)); globalAddresses.addBinding().to(NoBackendGlobalAddressFactory.class); Multibinder<GlobalAddressFactory<? extends Address>> replyToAddresses; replyToAddresses = Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() { }, Names.named(ReplyToAddressProvider.REPLY_TO_ADDRESS_FACTORIES)); replyToAddresses.addBinding().to(NoBackendGlobalAddressFactory.class); }
Example #11
Source File: ActiveConnectionModule.java From guacamole-client with Apache License 2.0 | 6 votes |
@Override protected void configure() { // Create the required DirectoryResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryResource<ActiveConnection, APIActiveConnection>>() {}, ActiveConnectionDirectoryResource.class ) .build(new TypeLiteral<DirectoryResourceFactory<ActiveConnection, APIActiveConnection>>() {})); // Create the required DirectoryObjectResourceFactory implementation install(new FactoryModuleBuilder() .implement( new TypeLiteral<DirectoryObjectResource<ActiveConnection, APIActiveConnection>>() {}, ActiveConnectionResource.class ) .build(new TypeLiteral<DirectoryObjectResourceFactory<ActiveConnection, APIActiveConnection>>() {})); // Bind translator for converting between ActiveConnection and APIActiveConnection bind(new TypeLiteral<DirectoryObjectTranslator<ActiveConnection, APIActiveConnection>>() {}) .to(ActiveConnectionObjectTranslator.class); }
Example #12
Source File: AbstractMethodTypeListener.java From james-project with Apache License 2.0 | 6 votes |
/** * Allows traverse the input klass hierarchy. * * @param parentType the owning type being heard * @param klass encountered by Guice. * @param encounter the injection context. */ private <I> void hear(final TypeLiteral<I> parentType, Class<? super I> klass, TypeEncounter<I> encounter) { Package pkg; if (klass == null || ((pkg = klass.getPackage()) != null && pkg.getName().startsWith(JAVA_PACKAGE))) { return; } for (Class<? extends Annotation> annotationType : annotationTypes) { for (Method method : klass.getDeclaredMethods()) { if (method.isAnnotationPresent(annotationType)) { if (method.getParameterTypes().length != 0) { encounter.addError("Annotated methods with @%s must not accept any argument, found %s", annotationType.getName(), method); } hear(method, parentType, encounter, annotationType); } } } hear(parentType, klass.getSuperclass(), encounter); }
Example #13
Source File: PropertyDataGeneratorsMapperImpl.java From xades4j with GNU Lesser General Public License v3.0 | 5 votes |
@Override public <TProp extends QualifyingProperty> PropertyDataObjectGenerator<TProp> getGenerator( TProp p) throws PropertyDataGeneratorNotAvailableException { try { ParameterizedType pt = Types.newParameterizedType(PropertyDataObjectGenerator.class, p.getClass()); return (PropertyDataObjectGenerator)injector.getInstance(Key.get(TypeLiteral.get(pt))); } catch (RuntimeException ex) { throw new PropertyDataGeneratorNotAvailableException(p, ex); } }
Example #14
Source File: ProtocolModule.java From bt with Apache License 2.0 | 5 votes |
/** * Contribute a message handler for some message type. * <p>Binding key is a unique message type ID, that will be used * to encode and decode the binary representation of a message of this type. * * @since 1.0 * @deprecated since 1.5 in favor of {@link ProtocolModuleExtender#addMessageHandler(int, Class)} and its' overloaded versions */ @Deprecated public static MapBinder<Integer, MessageHandler<? extends Message>> contributeMessageHandler(Binder binder) { return MapBinder.newMapBinder( binder, new TypeLiteral<Integer>(){}, new TypeLiteral<MessageHandler<?>>(){}, MessageHandlers.class); }
Example #15
Source File: TestingKinesisConnectorFactory.java From presto with Apache License 2.0 | 5 votes |
@Override public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) { requireNonNull(catalogName, "connectorId is null"); requireNonNull(config, "config is null"); try { Bootstrap app = new Bootstrap( new JsonModule(), new KinesisModule(), binder -> { binder.bind(TypeManager.class).toInstance(context.getTypeManager()); binder.bind(NodeManager.class).toInstance(context.getNodeManager()); binder.bind(KinesisHandleResolver.class).toInstance(new KinesisHandleResolver()); binder.bind(KinesisClientProvider.class).toInstance(kinesisClientProvider); binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}).to(KinesisTableDescriptionSupplier.class).in(Scopes.SINGLETON); }); Injector injector = app.strictConfig() .doNotInitializeLogging() .setRequiredConfigurationProperties(config) .initialize(); KinesisConnector connector = injector.getInstance(KinesisConnector.class); return connector; } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } }
Example #16
Source File: SystemPermissionsJpaModule.java From che with Eclipse Public License 2.0 | 5 votes |
@Override protected void configure() { bind(new TypeLiteral<AbstractPermissionsDomain<SystemPermissionsImpl>>() {}) .to(SystemDomain.class); bind(JpaSystemPermissionsDao.RemoveSystemPermissionsBeforeUserRemovedEventSubscriber.class) .asEagerSingleton(); Multibinder<PermissionsDao<? extends AbstractPermissions>> storages = Multibinder.newSetBinder( binder(), new TypeLiteral<PermissionsDao<? extends AbstractPermissions>>() {}); storages.addBinding().to(JpaSystemPermissionsDao.class); }
Example #17
Source File: SpoofaxModule.java From spoofax with Apache License 2.0 | 5 votes |
protected void bindSyntax() { bind(SpoofaxSyntaxService.class).in(Singleton.class); bind(ISpoofaxSyntaxService.class).to(SpoofaxSyntaxService.class); bind(new TypeLiteral<ISyntaxService<ISpoofaxInputUnit, ISpoofaxParseUnit>>() {}).to(SpoofaxSyntaxService.class); bind(new TypeLiteral<ISyntaxService<?, ?>>() {}).to(SpoofaxSyntaxService.class); bind(ISyntaxService.class).to(SpoofaxSyntaxService.class); bind(ITermFactory.class).toInstance(new ImploderOriginTermFactory(new TermFactory())); }
Example #18
Source File: AdManagerJaxWsModule.java From googleads-java-lib with Apache License 2.0 | 5 votes |
@Override public void configure() { bind(new TypeLiteral<HeaderHandler<AdManagerSession, AdManagerServiceDescriptor>>() {}) .to(new TypeLiteral<AdManagerJaxWsHeaderHandler>() {}); install(new JaxWsModule()); install(new AdManagerModule()); install(new AdManagerSoapModule()); configureConfigurations(this.getClass().getResource("conf/props/build.properties")); }
Example #19
Source File: BungeeServerManifest.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void configure() { install(new MinecraftServerManifest()); bind(new TypeLiteral<PluginResolver<Plugin>>(){}).to(BungeePluginResolver.class); bind(Loggers.class).to(BungeeLoggerFactory.class); bind(tc.oc.commons.core.chat.Audiences.class).to(tc.oc.commons.bungee.chat.Audiences.class); bind(tc.oc.commons.bungee.chat.Audiences.class).to(BungeeAudiences.class); }
Example #20
Source File: Neo4jModule.java From SciGraph with Apache License 2.0 | 5 votes |
@Override protected void configure() { bind(String.class).annotatedWith(IndicatesNeo4jGraphLocation.class) .toInstance(configuration.getLocation()); bind(CurieUtil.class).toInstance(new CurieUtil(configuration.getCuries())); bind(new TypeLiteral<Map<String, String>>() {}).annotatedWith(IndicatesCurieMapping.class) .toInstance(configuration.getCuries()); bind(Vocabulary.class).to(VocabularyNeo4jImpl.class).in(Singleton.class); bind(new TypeLiteral<ConcurrentMap<String, Long>>() {}).to(IdMap.class).in(Singleton.class); }
Example #21
Source File: GenericGuiceProvider.java From seed with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public T get() { Key<GenericGuiceFactory<T>> factoryKey = (Key<GenericGuiceFactory<T>>) Key.get( TypeLiteral.get( Types.newParameterizedType(GenericGuiceFactory.class, defaultImplClass) )); GenericGuiceFactory<T> genericGuiceFactory = injector.getInstance(factoryKey); return genericGuiceFactory.createResolvedInstance(genericClasses); }
Example #22
Source File: ReflexGenerator.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override protected void configure() { bind(DefinitionRegistry.class) .toInstance(ClasspathDefinitionRegistry.instance()); bind(CapabilityRegistry.class) .to(DefinitionTransformCapabilityRegistry.class) .asEagerSingleton(); bind(new TypeLiteral<Set<URL>>() {}) .annotatedWith(Names.named(GroovyDriverModule.NAME_GROOVY_DRIVER_DIRECTORIES)) .toInstance(createGroovyDriverUrls(options)); }
Example #23
Source File: TestDriverModule.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override protected void configure() { bind(DriverConfig.class); // required to inject drivers into ServiceLocatorDriverRegistry bindMapToInstancesOf( new TypeLiteral<Map<DriverId, DeviceDriver>> () {}, new Function<DeviceDriver, DriverId>() { @Override public DriverId apply(DeviceDriver driver) { return driver.getDriverId(); } } ); bind(PlatformDriverService.class) .asEagerSingleton(); bind(ResourceBundleDAO.class) .to(EmptyResourceBundle.class); Multibinder<DriverServiceRequestHandler> handlers = bindSetOf(DriverServiceRequestHandler.class); handlers.addBinding().to(UpgradeDriverRequestHandler.class); handlers.addBinding().to(MessageHandler.class); bindSetOf(DriverRegistry.class) .addBinding() .to(MapDriverRegistry.class); bind(DriverExecutorRegistry.class).to(PlatformDriverExecutorRegistry.class); }
Example #24
Source File: Injection.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static Key<?> dependencyKey(Key<?> key) { if(isImplicitProvider(key.getTypeLiteral())) { return Key.get(providedType((TypeLiteral<? extends Provider<Object>>) key.getTypeLiteral())); } else { return key; } }
Example #25
Source File: OfferManagerModule.java From attic-aurora with Apache License 2.0 | 5 votes |
@Override protected void configure() { install(new PrivateModule() { @Override protected void configure() { bind(new TypeLiteral<Ordering<HostOffer>>() { }) .toInstance(OfferOrderBuilder.create(options.offer.offerOrder)); bind(OfferSetImpl.class).in(Singleton.class); bind(OfferSet.class).to(OfferSetImpl.class); expose(OfferSet.class); } }); }
Example #26
Source File: ActionConfigJsonModule.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override protected void configure() { bindSetOf(TypeAdapterFactory.class) .addBinding() .toInstance(createActionConfigSerializer()); bindSetOf(new TypeLiteral<TypeAdapter<?>>() {}) .addBinding() .toInstance(new AttributeTypeAdapter()); bindSetOf(new TypeLiteral<TypeAdapter<?>>() {}) .addBinding() .toInstance(new TemplatedExpressionTypeAdapter()); }
Example #27
Source File: FeedPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void configure(Binder binder) { // CHECKSTYLE:OFF binder.bind(new TypeLiteral<Supplier<FeedResult>>(){}) .toInstance(feedSupplier); // CHECKSTYLE:ON }
Example #28
Source File: AdWordsJaxWsModule.java From googleads-java-lib with Apache License 2.0 | 5 votes |
@Override public void configure() { bind(new TypeLiteral<HeaderHandler<AdWordsSession, AdWordsServiceDescriptor>>() {}) .to(new TypeLiteral<AdWordsJaxWsHeaderHandler>() {}); install(new JaxWsModule()); install(new AdWordsModule()); install(new AdWordsSoapModule()); configureConfigurations(this.getClass().getResource("conf/props/build.properties")); }
Example #29
Source File: IndexedCorpusModule.java From termsuite-core with Apache License 2.0 | 5 votes |
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) { Class<?> clazz = typeLiteral.getRawType(); while (clazz != null) { for (Field field : clazz.getDeclaredFields()) { boolean injectAnnoPresent = field.isAnnotationPresent(fr.univnantes.termsuite.framework.InjectLogger.class); if (field.getType() == Logger.class && injectAnnoPresent) { typeEncounter.register(new Slf4JMembersInjector<T>(field)); } } clazz = clazz.getSuperclass(); } }
Example #30
Source File: RangeParserManifest.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void configure() { final TypeLiteral<Range<T>> rangeType = Ranges.typeOf(type); final TypeLiteral<RangeParser<T>> rangeParserType = new ResolvableType<RangeParser<T>>(){}.with(typeArg); final TypeLiteral<RangeProperty<T>> rangePropertyType = new ResolvableType<RangeProperty<T>>(){}.with(typeArg); bindPrimitiveParser(rangeType).to(rangeParserType); // NodeParser<Range<T>> -> RangeParser<T> bind(rangeParserType); // RangeParser<T> install(new PropertyManifest<>(rangeType, rangePropertyType)); }