Java Code Examples for com.google.inject.Injector#getParent()
The following examples show how to use
com.google.inject.Injector#getParent() .
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: DropwizardModule.java From dropwizard-guicier with Apache License 2.0 | 6 votes |
private void registerResourcesAndProviders(ResourceConfig config, Injector injector) { while (injector != null) { for (Key<?> key : injector.getBindings().keySet()) { Type type = key.getTypeLiteral().getType(); if (type instanceof Class<?>) { Class<?> c = (Class<?>) type; if (isProviderClass(c)) { LOG.info("Registering {} as a provider class", c.getName()); config.register(c); } else if (isResourceClass(c)) { // Jersey rejects resources that it doesn't think are acceptable // Including abstract classes and interfaces, even if there is a valid Guice binding. if(Resource.isAcceptable(c)) { LOG.info("Registering {} as a root resource class", c.getName()); config.register(c); } else { LOG.warn("Class {} was not registered as a resource; bind a concrete implementation instead", c.getName()); } } } } injector = injector.getParent(); } }
Example 2
Source File: JerseyUtil.java From robe with GNU Lesser General Public License v3.0 | 6 votes |
/** * Registers any Guice-bound providers or root resources. */ public static void registerGuiceBound(Injector injector, final JerseyEnvironment environment) { while (injector != null) { for (Key<?> key : injector.getBindings().keySet()) { Type type = key.getTypeLiteral().getType(); if (type instanceof Class) { Class<?> c = (Class) type; if (isProviderClass(c)) { logger.info("Registering {} as a provider class", c.getName()); environment.register(c); } else if (isRootResourceClass(c)) { // Jersey rejects resources that it doesn't think are acceptable // Including abstract classes and interfaces, even if there is a valid Guice binding. if (Resource.isAcceptable(c)) { logger.info("Registering {} as a root resource class", c.getName()); environment.register(c); } else { logger.warn("Class {} was not registered as a resource. Bind a concrete implementation instead.", c.getName()); } } } } injector = injector.getParent(); } }
Example 3
Source File: Injectors.java From arcusplatform with Apache License 2.0 | 5 votes |
private static List<Binding<?>> collectBindings(Injector injector) { List<Injector> injectors = new ArrayList<Injector>(); Injector i = injector; while(i != null) { injectors.add(0, i); i = i != i.getParent() ? i.getParent() : null; } List<Binding<?>> bindings = new ArrayList<>(); for(Injector i2: injectors) { bindings.addAll(i2.getBindings().values()); } return bindings; }
Example 4
Source File: Injection.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static void forEachBinding(Injector injector, Consumer<? super Binding<?>> consumer) { while(injector != null) { injector.getBindings().forEach((key, binding) -> consumer.accept(binding)); injector = injector.getParent(); } }
Example 5
Source File: GuiceBundle.java From soabase with Apache License 2.0 | 4 votes |
private void registerBoundJerseyComponents(Injector injector, FeatureContext context, Environment environment) { // mostly copied from GuiceComponentProviderFactory#register(ResourceConfig, Injector) while ( injector != null ) { for ( Key<?> key : injector.getBindings().keySet() ) { Type type = key.getTypeLiteral().getType(); if ( type instanceof Class ) { Class<?> c = (Class)type; if ( isProviderClass(c) ) { log.info(String.format("Registering %s as a provider class", c.getName())); context.register(c); loggingConfig.register(c); } else if ( isRootResourceClass(c) ) { log.info(String.format("Registering %s as a root resource class", c.getName())); context.register(c); loggingConfig.register(c); } else if ( componentClasses.contains(c) ) { log.info(String.format("Registering %s", c.getName())); context.register(c); loggingConfig.register(c); } else if ( FilterDefinition.class.equals(c) ) { registerFilter(injector, environment, injector.getBinding(key)); loggingConfig.register(c); } else if ( ServletDefinition.class.equals(c) ) { registerServlet(injector, environment, injector.getBinding(key)); loggingConfig.register(c); } else if ( InternalFilter.class.equals(c) ) { log.debug("Registering internal filter"); context.register(injector.getBinding(key).getProvider().get()); loggingConfig.register(c); } else if ( InternalCommonConfig.class.equals(c) ) { applyInternalCommonConfig(context, (InternalCommonConfig)injector.getBinding(key).getProvider().get()); loggingConfig.register(c); } } } injector = injector.getParent(); } }