@SuppressWarnings("unchecked") <T, X> void registerBeans(@Observes AfterBeanDiscovery event, final BeanManager beanManager) { if (beanManager.getBeans(RemoteCacheManager.class).isEmpty()) { LOGGER.addDefaultRemoteCacheManager(); event.addBean(createDefaultRemoteCacheManagerBean(beanManager)); } for (Map.Entry<Type, Set<Annotation>> entry : remoteCacheInjectionPoints.entrySet()) { event.addBean( new BeanBuilder(beanManager) .readFromType(beanManager.createAnnotatedType(Reflections.getRawType(entry.getKey()))) .addType(entry.getKey()) .addQualifiers(entry.getValue()) .beanLifecycle( new ContextualLifecycle<RemoteCache<?, ?>>() { @Override public RemoteCache<?, ?> create( Bean<RemoteCache<?, ?>> bean, CreationalContext<RemoteCache<?, ?>> ctx) { return remoteCacheProducer.produce(ctx); } @Override public void destroy( Bean<RemoteCache<?, ?>> bean, RemoteCache<?, ?> instance, CreationalContext<RemoteCache<?, ?>> ctx) { remoteCacheProducer.dispose(instance); } }) .create()); } }
@Override @SuppressWarnings("unchecked") public JCDIInjectionContext createManagedObject( Class managedClass, BundleDescriptor bundle, boolean invokePostConstruct) { JCDIInjectionContext context = null; Object managedObject = null; try { managedObject = createEEManagedObject(bundle.getManagedBeanByBeanClass(managedClass.getName())); } catch (Exception e) { e.printStackTrace(); } WeldContainer wc = getWeldContainer(); if (wc != null) { BeanManager beanManager = wc.getBeanManager(); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedClass); InjectionTarget target = beanManager.createInjectionTarget(annotatedType); CreationalContext cc = beanManager.createCreationalContext(null); target.inject(managedObject, cc); if (invokePostConstruct) { target.postConstruct(managedObject); } context = new JCDIInjectionContextImpl(target, cc, managedObject); } return context; }
private RequestMappingInfo findMethodRequestMapping(FacesContext context, Bean<?> bean) { RequestMappingInfo result = null; Class clazz = bean.getBeanClass(); AnnotatedType annotatedType = beanManager.createAnnotatedType(clazz); Set<AnnotatedMethod> annotatedMethodSet = annotatedType.getMethods(); for (AnnotatedMethod method : annotatedMethodSet) { if (method.isAnnotationPresent(RequestMapping.class)) { RequestMapping requestMapping = method.getAnnotation(RequestMapping.class); String[] mappings = requestMapping.value(); String mapping = null; for (String current : mappings) { String pathInfo = context.getExternalContext().getRequestPathInfo(); if (pathInfo.equals(current)) { result = new RequestMappingInfo(); result.setBean(bean); result.setMethod(method.getJavaMember()); result.setRequestMapping(mapping); result.setMappingType(RequestMappingInfo.MappingType.EXACT); break; } else if (current.endsWith("*")) { current = current.substring(0, current.length() - 1); if (pathInfo.startsWith(current)) { if (result == null) { result = new RequestMappingInfo(); result.setBean(bean); result.setMethod(method.getJavaMember()); result.setRequestMapping(current); result.setMappingType(RequestMappingInfo.MappingType.PREFIX); } else if (current.length() > result.getLength()) { result.setBean(bean); result.setMethod(method.getJavaMember()); result.setRequestMapping(current); result.setMappingType(RequestMappingInfo.MappingType.PREFIX); } } } else if (current.startsWith("*")) { current = current.substring(1); if (pathInfo.endsWith(current)) { result = new RequestMappingInfo(); result.setBean(bean); result.setMethod(method.getJavaMember()); result.setRequestMapping(current); result.setMappingType(RequestMappingInfo.MappingType.EXTENSION); break; } } } } if (result != null && (result.getMappingType().equals(RequestMappingInfo.MappingType.EXACT) || (result.getMappingType().equals(RequestMappingInfo.MappingType.EXTENSION)))) { break; } } return result; }
/** * Used to register the method validation interceptor binding annotation. * * @param beforeBeanDiscoveryEvent event fired before the bean discovery process starts * @param beanManager the bean manager. */ public void beforeBeanDiscovery( @Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent, final BeanManager beanManager) { Contracts.assertNotNull( beforeBeanDiscoveryEvent, "The BeforeBeanDiscovery event cannot be null"); Contracts.assertNotNull(beanManager, "The BeanManager cannot be null"); // Register the interceptor explicitly. This way, no beans.xml is needed AnnotatedType<ValidationInterceptor> annotatedType = beanManager.createAnnotatedType(ValidationInterceptor.class); beforeBeanDiscoveryEvent.addAnnotatedType(annotatedType); }
private SyntheticBean<?> camelContextBean(BeanManager manager, Annotation... qualifiers) { SyntheticAnnotated annotated = new SyntheticAnnotated( DefaultCamelContext.class, manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(), qualifiers); return new SyntheticBean<>( manager, annotated, DefaultCamelContext.class, environment.camelContextInjectionTarget( new SyntheticInjectionTarget<>(DefaultCamelContext::new), annotated, manager, this), bean -> "Default Camel context bean with qualifiers " + bean.getQualifiers()); }
public Object createEntityListenerAndInjectDependancies(Class entityListenerClass) throws NamingException { AnnotatedType<Object> aType = beanManager.createAnnotatedType(entityListenerClass); InjectionTarget<Object> injectionTarget = beanManager.<Object>createInjectionTarget(aType); Object entityListener = injectionTarget.produce(beanManager.<Object>createCreationalContext(null)); synchronized (injectionTargets) { injectionTargets.put(entityListener, injectionTarget); } injectionTarget.postConstruct(entityListener); creationalContext = beanManager.<Object>createCreationalContext(null); injectionTarget.inject(entityListener, creationalContext); return entityListener; }
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) { final AnnotatedType annotationType = manager.createAnnotatedType(CDITransactionContext.class); final InjectionTarget injectionTarget = manager.createInjectionTarget(annotationType); final CreationalContext creationalContext = manager.createCreationalContext(null); final CDITransactionContext context = new CDITransactionContext(); injectionTarget.inject(context, creationalContext); injectionTarget.postConstruct(CDITransactionContext.class); if (logger.isDebugEnabled()) { logger.debug("afterBeanDiscovery -> context " + context); } context.setBeanManager(manager); event.addContext(context); }
@Override @SuppressWarnings("unchecked") public void injectManagedObject(Object managedObject, BundleDescriptor bundle) { WeldContainer wc = getWeldContainer(); if (wc != null) { BeanManager beanManager = wc.getBeanManager(); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedObject.getClass()); InjectionTarget target = beanManager.createInjectionTarget(annotatedType); CreationalContext cc = beanManager.createCreationalContext(null); target.inject(managedObject, cc); } }
@Override public <T> T createInterceptorInstance(Class<T> interceptorClass, BundleDescriptor bundle) { T interceptorInstance = null; WeldContainer wc = getWeldContainer(); if (wc != null) { BeanManager beanManager = wc.getBeanManager(); AnnotatedType annotatedType = beanManager.createAnnotatedType(interceptorClass); InjectionTarget target = ((WeldManager) beanManager) .getInjectionTargetFactory(annotatedType) .createInterceptorInjectionTarget(); CreationalContext cc = beanManager.createCreationalContext(null); interceptorInstance = (T) target.produce(cc); target.inject(interceptorInstance, cc); } return interceptorInstance; }
public void addStageConfig(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) { bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigurationValueProducer.class)); }
/** * Register all admin CDI beans. * * @param bbd the bbd event * @param bm the bean manager */ public void register(@Observes BeforeBeanDiscovery bbd, BeanManager bm) { // Current API bbd.addAnnotatedType(bm.createAnnotatedType(CompensationManagerImpl.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorMandatory.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorNever.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorNotSupported.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorRequired.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorRequiresNew.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensationInterceptorSupports.class)); bbd.addAnnotatedType(bm.createAnnotatedType(TxCompensateInterceptor.class)); bbd.addAnnotatedType(bm.createAnnotatedType(TxConfirmInterceptor.class)); bbd.addAnnotatedType(bm.createAnnotatedType(TxLoggedInterceptor.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CancelOnFailureInterceptor.class)); bbd.addAnnotatedType(bm.createAnnotatedType(CompensatableActionProducer.class)); bbd.addAnnotatedType(bm.createAnnotatedType(DeserializersContainerProducer.class)); }
void registerApple(@Observes BeforeBeanDiscovery event, BeanManager manager) { event.addAnnotatedType( new AnnotatedTypeWrapper<Pear>( manager.createAnnotatedType(Pear.class), false, Juicy.Literal.INSTANCE)); }