@Override public Map<Key<?>, Binding<?>> getBindings() { return this.delegateInjector.getBindings(); }
public Map<Key<?>, Binding<?>> getBindings() { return resolve().getBindings(); }
private <U> void _find(Class<U> type, List<ExtensionComponent<U>> result, Injector container) { for (Entry<Key<?>, Binding<?>> e : container.getBindings().entrySet()) { if (type.isAssignableFrom(e.getKey().getTypeLiteral().getRawType())) { Annotation a = annotations.get(e.getKey()); Object o = e.getValue().getProvider().get(); if (o!=null) { GuiceExtensionAnnotation gea = a!=null ? extensionAnnotations.get(a.annotationType()) : null; result.add(new ExtensionComponent<>(type.cast(o), gea != null ? gea.getOrdinal(a) : 0)); } } } }
boolean permitsDuplicates(Injector injector) { return injector.getBindings().containsKey(getPermitDuplicatesKey()); }
@Inject public BodyParserEngineManagerImpl(Injector injector) { Map<String, Provider<? extends BodyParserEngine>> map = Maps.newHashMap(); // Now lookup all explicit bindings, and find the ones that implement // BodyParserEngine for (Map.Entry<Key<?>, Binding<?>> binding : injector.getBindings() .entrySet()) { if (BodyParserEngine.class.isAssignableFrom(binding.getKey() .getTypeLiteral().getRawType())) { Provider<? extends BodyParserEngine> provider = (Provider) binding .getValue().getProvider(); map.put(provider.get().getContentType(), provider); } } this.contentTypeToBodyParserMap = ImmutableMap.copyOf(map); logBodyParserEngines(); }
@Inject public TemplateEngineManagerImpl(Injector injector) { Map<String, Provider<? extends TemplateEngine>> map = new HashMap<>(); // Now lookup all explicit bindings, and find the ones that implement // TemplateEngine for (Map.Entry<Key<?>, Binding<?>> binding : injector.getBindings() .entrySet()) { if (TemplateEngine.class.isAssignableFrom(binding.getKey() .getTypeLiteral().getRawType())) { Provider<? extends TemplateEngine> provider = (Provider) binding .getValue().getProvider(); map.put(provider.get().getContentType(), provider); } } this.contentTypeToTemplateEngineMap = ImmutableMap.copyOf(map); logTemplateEngines(); }
for (final Binding binding : injector.getBindings().values()) { binding.acceptScopingVisitor(new DefaultBindingScopingVisitor() { @Override
public void processInjector(final Injector injector) { List<Binding<?>> rootResourceBindings = new ArrayList<Binding<?>>(); for (final Binding<?> binding : injector.getBindings().values()) { final Type type = binding.getKey().getTypeLiteral().getRawType(); if (type instanceof Class) { final Class<?> beanClass = (Class) type; if (GetRestful.isRootResource(beanClass)) { // deferred registration rootResourceBindings.add(binding); } if (beanClass.isAnnotationPresent(Provider.class)) { LogMessages.LOGGER.info(Messages.MESSAGES.registeringProviderInstance(beanClass.getName())); providerFactory.registerProviderInstance(binding.getProvider().get()); } } } for (Binding<?> binding : rootResourceBindings) { Class<?> beanClass = (Class) binding.getKey().getTypeLiteral().getType(); final ResourceFactory resourceFactory = new GuiceResourceFactory(binding.getProvider(), beanClass); LogMessages.LOGGER.info(Messages.MESSAGES.registeringFactory(beanClass.getName())); registry.addResourceFactory(resourceFactory); } } }
public final void testSpiOnInjector() { ServletSpiVisitor visitor = new ServletSpiVisitor(true); int count = 0; Injector injector = Guice.createInjector(new Module()); for (Binding binding : injector.getBindings().values()) { assertEquals(count++, binding.acceptTargetVisitor(visitor)); } validateVisitor(visitor); }
/** Returns the binding for the given key or null if there is no such binding */ public static Binding<?> getBinding(Injector injector, Key<?> key) { Map<Key<?>, Binding<?>> bindings = injector.getBindings(); Binding<?> binding = bindings.get(key); return binding; }
Injector injector = Guice.createInjector(myModuleInstance); Map<Key<?>,Binding<?>> map = injector.getBindings(); for(Entry<Key<?>, Binding<?>> e : map.entrySet()) { System.out.println(e.getKey() + ": " + e.getValue()); }
/** * Finds all commands that are bound do the command injector. * * @return a collection of keys, one for each command */ private Collection<Key<?>> findCommands() { Map<Key<?>, Binding<?>> commands = commandsInjector.getBindings(); return commands.keySet(); }
/** * @param injector the injector to iterate over */ public GuiceInjectorIterator(Injector injector) { this.injector = injector; keyIterator = injector.getBindings().keySet().iterator(); }
public static boolean hasExplicitBindingFor(Injector injector, Key<?> key) { Injector target = injector; do { if (target.getBindings().containsKey(key)) { return true; } target = target.getParent(); } while (target != null); return false; } }
private Injector findInjector(Key<?> key) { Injector i = injector; while (i != null) { if (i.getBindings().containsKey(key)) { return i; } i = i.getParent(); } return null; }
/** * Gathers Guice {@link Injector} bindings over the hierarchy. */ private static Map<Key<?>, Binding<?>> gatherBindings(Injector injector) { Map<Key<?>, Binding<?>> dst = new HashMap<Key<?>, Binding<?>>(); Injector current = injector; while (current != null) { dst.putAll(current.getBindings()); current = current.getParent(); } return dst; }
static Job[] getJobs(Injector injector) { List<Job> jobs = new ArrayList<>(); for (Map.Entry<Key<?>, Binding<?>> entry : injector.getBindings().entrySet()) { Class<?> clazz = entry.getValue().getKey().getTypeLiteral().getRawType(); if (Job.class.isAssignableFrom(clazz)) { jobs.add((Job) injector.getInstance(clazz)); } } return jobs.toArray(new Job[]{}); }
@Override public Set<Key<?>> getRootKeys(Injector injector) { Set<Key<?>> root = Sets.newHashSet(); for (Key<?> key : injector.getBindings().keySet()) { if (key.getTypeLiteral().getRawType().getPackage() != Guice.class.getPackage() && !loggerKey.equals(key)) { root.add(key); } } return root; } }
private <U> void _find(Class<U> type, List<ExtensionComponent<U>> result, Injector container) { for (Entry<Key<?>, Binding<?>> e : container.getBindings().entrySet()) { if (type.isAssignableFrom(e.getKey().getTypeLiteral().getRawType())) { Annotation a = annotations.get(e.getKey()); Object o = e.getValue().getProvider().get(); if (o!=null) { GuiceExtensionAnnotation gea = a!=null ? extensionAnnotations.get(a.annotationType()) : null; result.add(new ExtensionComponent<>(type.cast(o), gea != null ? gea.getOrdinal(a) : 0)); } } } }
public void testSpiOnVisitor() throws Exception { AssistedInjectSpiVisitor visitor = new AssistedInjectSpiVisitor(); Integer count = 0; Injector injector = Guice.createInjector(new Module()); for (Binding<?> binding : injector.getBindings().values()) { assertEquals(count++, binding.acceptTargetVisitor(visitor)); } validateVisitor(visitor); }