Refine search
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { if (scheduler.hasScheduledMethod(type.getRawType())) { // Add the listener encounter.register(new ScheduleListener<I>(scheduler)); } } }
@Override public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { final Provider<EventBus> eventBusProvider = typeEncounter.getProvider(EventBus.class); if (EventBusAware.class.isAssignableFrom(typeLiteral.getRawType())) { typeEncounter.register( new InjectionListener<I>() { @Override public void afterInjection(Object o) { ((EventBusAware)o).setEventBus(eventBusProvider.get()); } }); } } }
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) Class<?> clazz = type.getRawType(); encounter.addError("@InjectProperty method must only take one parameter."); encounter.register(new ConfigMethodInjector<>(method, configValue)); encounter.addError("Configuration not set for '"+prop+"' on method "+method.getName() +" in class "+clazz.getName());
@Test public void testPropertySetting() throws Exception { IMocksControl control = createControl(); TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class); Provider<Injector> injectorProvider = control.createMock(Provider.class); Injector injector = control.createMock(Injector.class); expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider); expect(injectorProvider.get()).andReturn(injector).anyTimes(); Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>(); encounter.register(and(anyObject(MembersInjector.class), capture(capture))); SecurityManager securityManager = control.createMock(SecurityManager.class); String property = "myPropertyValue"; expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property); expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty")))) .andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!")))); expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes(); control.replay(); BeanTypeListener underTest = new BeanTypeListener(); underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter); SomeInjectableBean bean = new SomeInjectableBean(); capture.getValue().injectMembers(bean); assertSame(securityManager, bean.securityManager); assertSame(property, bean.myProperty); assertNull(bean.unavailableProperty); control.verify(); }
@Override public <T> void hear(TypeLiteral<T> literal, TypeEncounter<T> encounter) { Class<? super T> klass = literal.getRawType(); for (Method method : klass.getDeclaredMethods()) { if (method.isSynthetic()) { continue; } final MethodInterceptor interceptor = getInterceptor(method); if (interceptor != null) { encounter.bindInterceptor(Matchers.only(method), interceptor); } } }
@Test public void testHearDestroyable() throws Exception { TypeEncounter encounter = createMock(TypeEncounter.class); encounter.register(anyObject(DestroyableInjectionListener.class)); replay(encounter); LifecycleTypeListener underTest = new LifecycleTypeListener(null); underTest.hear(TypeLiteral.get(MyDestroyable.class), encounter); verify(encounter); }
public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) { Provider<EventCasterInternal> eventCasterProvider = null; for (final Class<?> interfaceClass : interfacesInInheritanceHierarchy(type.getRawType())) { final TypeLiteral<?> interfaceType = type.getSupertype(interfaceClass); if (bindings.contains(interfaceType)) { if(eventCasterProvider == null) { eventCasterProvider = encounter.getProvider(EventCasterInternal.class); } encounter.register(new RegisterInjectedEventListeners<I>(interfaceType, eventCasterProvider)); } } }
public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { typeEncounter.register(new InjectionListener<I>() { public void afterInjection(I i) { m_eventBus.register(i); if (i instanceof KairosPostConstructInit) { ((KairosPostConstructInit)i).init(); } } }); } });
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { final Provider<JmxExporter> exporter = encounter.getProvider(JmxExporter.class); encounter.register(new InjectionListener<I>() { @Override public void afterInjection(I injectee) { exporter.get().register(injectee); } }); } });
/** * {@inheritDoc} */ public <I> void hear( final TypeLiteral<I> typeLiteral, final TypeEncounter<I> typeEncounter ) { try { new ClassVisitor() .registerHandler( Mock.class, new AnnotationHandler<Mock, Field>() { public void handle( Mock annotation, Field field ) throws HandleException { typeEncounter.register( new MockMembersInjector<I>( field, mockedObjects ) ); } } ) .visit( typeLiteral.getRawType() ); } catch ( HandleException e ) { typeEncounter.addError( e ); } }
PlexusRequirements( final TypeEncounter<?> encounter ) { locatorProvider = encounter.getProvider( PlexusBeanLocator.class ); }
encounter.addError("Cannot obtain config value for " + parameter.getParameterizedType() + " at path: " + path); return Optional.empty();
@Override public <T> void hear(TypeLiteral<T> literal, TypeEncounter<T> encounter) { Class<? super T> klass = literal.getRawType(); for (Method method : klass.getDeclaredMethods()) { if (method.isSynthetic()) { continue; } final MethodInterceptor interceptor = getInterceptor(method); if (interceptor != null) { encounter.bindInterceptor(Matchers.only(method), interceptor); } } }
@Test public void testHearInitializable() throws Exception { TypeEncounter encounter = createMock(TypeEncounter.class); encounter.register(anyObject(InitializableInjectionListener.class)); replay(encounter); LifecycleTypeListener underTest = new LifecycleTypeListener(null); underTest.hear(TypeLiteral.get(MyInitializable.class), encounter); verify(encounter); }
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { encounter.register(new InjectionListener<I>() { @Override public void afterInjection(I injectee) { if (KairosMetricReporter.class.isAssignableFrom(injectee.getClass())) { m_reporters.add((KairosMetricReporter)injectee); } } }); } }
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { final Provider<JMSClient> client = encounter.getProvider(JMSClient.class); encounter.register(new InjectionListener<I>() { @Override public void afterInjection(I injectee) { List<Destination> destinations = new LinkedList<Destination>(); if (injectee.getClass().isAnnotationPresent(Destinations.class)) { destinations.addAll(Arrays.asList(injectee.getClass().getAnnotation(Destinations.class).value())); } if (injectee.getClass().isAnnotationPresent(Destination.class)) { destinations.add(injectee.getClass().getAnnotation(Destination.class)); } for (Destination destination : destinations) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Registering JMS subscriber " + injectee.getClass().getName() + " to " + destination.value()); } client.get().subscribe( destination.value(), destination.selector().length() > 0 ? destination.selector() : null, (JMSListener) injectee); } } }); } }
/** * Constructor of the listener. Initializes all the fields. * * @param typeEncounter Type encounter instance, provided by Guice. */ public PageObjectInjectorListener(TypeEncounter<?> typeEncounter) { this.webDriverProvider = typeEncounter.getProvider(WebDriver.class); this.locatorStackProvider = typeEncounter.getProvider(ContextStack.class); this.registry = typeEncounter.getProvider(FieldProviderRegistry.class); this.frameMap = typeEncounter.getProvider(FrameMap.class); this.bobcatWebElementFactoryProvider = typeEncounter.getProvider(BobcatWebElementFactory.class); }
/** * 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); }
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { if (hasLifecycleMethod(type.getRawType())) { // Add the listener encounter.register(new LifecycleListener<I>()); } } }
@Override public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { final Provider<EventBus> eventBusProvider = typeEncounter.getProvider(EventBus.class); List<Method> methods = ClassUtils.getAnnotatedMethods(typeLiteral.getRawType(), Subscribe.class); if (methods != null && !methods.isEmpty()) { typeEncounter.register( new InjectionListener<I>() { @Override public void afterInjection(Object o) { eventBusProvider.get().register(o); } }); } } }