@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; }
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); } }
/** * Read the {@link AnnotatedType}, creating a bean from the class and it's annotations. * * <p> * * <p>By default the bean lifecycle will wrap the result of calling {@link * BeanManager#createInjectionTarget(AnnotatedType)}. * * <p> * * <p>{@link BeanBuilder} does <em>not</em> support reading members of the class to create * producers or observer methods. * * @param type the type to read */ public BeanBuilder<T> readFromType(AnnotatedType<T> type) { this.beanClass = type.getJavaClass(); InjectionTarget<T> injectionTarget; if (!type.getJavaClass().isInterface()) { injectionTarget = beanManager.createInjectionTarget(type); } else { injectionTarget = new DummyInjectionTarget<T>(); } this.beanLifecycle = new DelegatingContextualLifecycle<T>(injectionTarget); this.injectionPoints = injectionTarget.getInjectionPoints(); this.qualifiers = new HashSet<Annotation>(); this.stereotypes = new HashSet<Class<? extends Annotation>>(); this.types = new HashSet<Type>(); for (Annotation annotation : type.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { this.qualifiers.add(annotation); } else if (beanManager.isScope(annotation.annotationType())) { this.scope = annotation.annotationType(); } else if (beanManager.isStereotype(annotation.annotationType())) { this.stereotypes.add(annotation.annotationType()); } if (annotation instanceof Named) { this.name = ((Named) annotation).value(); } if (annotation instanceof Alternative) { this.alternative = true; } } if (this.scope == null) { this.scope = Dependent.class; } for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass()) { this.types.add(c); } for (Class<?> i : type.getJavaClass().getInterfaces()) { this.types.add(i); } if (qualifiers.isEmpty()) { qualifiers.add(new DefaultLiteral()); } qualifiers.add(new AnyLiteral()); this.id = ImmutableBeanWrapper.class.getName() + ":" + Annotateds.createTypeId(type); return this; }