/** * <p>This is based off of code in <code>InjectionManagerImpl</code>.</p> * * @param instance managed bean instance * @param envDescriptor JNDI environment * @throws InjectionException if an error occurs */ private void invokePostConstruct(Object instance, JndiNameEnvironment envDescriptor) throws InjectionException { LinkedList<Method> postConstructMethods = new LinkedList<Method>(); Class<? extends Object> nextClass = instance.getClass(); // Process each class in the inheritance hierarchy, starting with // the most derived class and ignoring java.lang.Object. while ((!Object.class.equals(nextClass)) && (nextClass != null)) { InjectionInfo injInfo = envDescriptor.getInjectionInfoByClass(nextClass); if (injInfo.getPostConstructMethodName() != null) { Method postConstructMethod = getPostConstructMethod (injInfo, nextClass); // Invoke the preDestroy methods starting from // the least-derived class downward. postConstructMethods.addFirst(postConstructMethod); } nextClass = nextClass.getSuperclass(); } for (Method postConstructMethod : postConstructMethods) { invokeLifecycleMethod(postConstructMethod, instance); } }
envDescriptor.getInjectionInfoByClass(nextClass);
envDescriptor.getInjectionInfoByClass(nextClass);
envDescriptor.getInjectionInfoByClass(nextClass);
envDescriptor.getInjectionInfoByClass(nextClass);
envDescriptor.getInjectionInfoByClass(nextClass);
envDescriptor.getInjectionInfoByClass(nextClass);
public <T> void registerInjectionTarget(InjectionTarget<T> injectionTarget, AnnotatedType<T> annotatedType) { if ( bundleContext instanceof EjbBundleDescriptor ) { // we can't handle validting producer fields for ejb bundles because the JNDI environment is not setup // yet for ejbs and so we can't get the correct JndiNameEnvironment to call getInjectionInfoByClass. // getInjectionInfoByClass caches the results and so causes subsequent calls to return invalid information. return; } // We are only validating producer fields of resources. See spec section 3.7.1 Class annotatedClass = annotatedType.getJavaClass(); JndiNameEnvironment jndiNameEnvironment = (JndiNameEnvironment) bundleContext; InjectionInfo injectionInfo = jndiNameEnvironment.getInjectionInfoByClass(annotatedClass); List<InjectionCapable> injectionResources = injectionInfo.getInjectionResources(); for (AnnotatedField<? super T> annotatedField : annotatedType.getFields()) { if ( annotatedField.isAnnotationPresent( Produces.class ) ) { if ( annotatedField.isAnnotationPresent( EJB.class ) ) { validateEjbProducer( annotatedClass, annotatedField, injectionResources ); } else if ( annotatedField.isAnnotationPresent( Resource.class ) ) { validateResourceProducer( annotatedClass, annotatedField, injectionResources ); } else if ( annotatedField.isAnnotationPresent( PersistenceUnit.class ) ) { validateResourceClass(annotatedField, EntityManagerFactory.class); } else if ( annotatedField.isAnnotationPresent( PersistenceContext.class ) ) { validateResourceClass(annotatedField, EntityManager.class); } else if ( annotatedField.isAnnotationPresent( WebServiceRef.class ) ) { validateWebServiceRef( annotatedField ); } } } }