throws InjectionException { Method m = injInfo.getPostConstructMethod(); injInfo.getPostConstructMethodName(); (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; throw new InjectionException ("InjectionManager exception. PostConstruct method " + injInfo.getPostConstructMethodName() + " could not be found in class " + injInfo.getClassName());
private Method getPreDestroyMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPreDestroyMethod(); if( m == null ) { String preDestroyMethodName = injInfo.getPreDestroyMethodName(); // Check for the method within the resourceClass only. // This does not include super-classses. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PreDestroy // methods with no arguments. if( next.getName().equals(preDestroyMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPreDestroyMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.predestroy-not-found", "InjectionManager exception. PreDestroy method: {0} not found in class: {1}", injInfo.getPreDestroyMethodName(), injInfo.getClassName())); } return m; }
envDescriptor.getInjectionInfoByClass(nextClass); if( injInfo.getInjectionResources().size() > 0 ) { _inject(nextClass, instance, componentId, injInfo.getInjectionResources()); if( injInfo.getPostConstructMethodName() != null ) {
/** * <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); } }
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 ); } } } }
@Override public InjectionInfo getInjectionInfoByClass(Class clazz) { // TODO This is invariant data so we could cache it String className = clazz.getName(); LifecycleCallbackDescriptor postConstructDesc = getPostConstructDescriptorByClass(className); String postConstructMethodName = (postConstructDesc != null) ? postConstructDesc.getLifecycleCallbackMethod() : null; LifecycleCallbackDescriptor preDestroyDesc = getPreDestroyDescriptorByClass(className); String preDestroyMethodName = (preDestroyDesc != null) ? preDestroyDesc.getLifecycleCallbackMethod() : null; InjectionInfo injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName, getInjectableResourcesByClass(className)); return injectionInfo; }
envDescriptor.getInjectionInfoByClass(nextClass); if( injInfo.getPreDestroyMethodName() != null ) {
envDescriptor.getInjectionInfoByClass(nextClass); if( injInfo.getInjectionResources().size() > 0 ) { _inject(nextClass, instance, componentId, injInfo.getInjectionResources()); if( injInfo.getPostConstructMethodName() != null ) {
if (injInfo.getPostConstructMethodName() != null) {
@Override public InjectionInfo getInjectionInfoByClass(Class clazz) { // TODO This is invariant data so we could cache it String className = clazz.getName(); LifecycleCallbackDescriptor postConstructDesc = getPostConstructDescriptorByClass(className); String postConstructMethodName = (postConstructDesc != null) ? postConstructDesc.getLifecycleCallbackMethod() : null; LifecycleCallbackDescriptor preDestroyDesc = getPreDestroyDescriptorByClass(className); String preDestroyMethodName = (preDestroyDesc != null) ? preDestroyDesc.getLifecycleCallbackMethod() : null; InjectionInfo injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName, getInjectableResourcesByClass(className)); return injectionInfo; }
envDescriptor.getInjectionInfoByClass(nextClass); if( injInfo.getPreDestroyMethodName() != null ) {
throws InjectionException { Method m = injInfo.getPostConstructMethod(); injInfo.getPostConstructMethodName(); (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; throw new InjectionException ("InjectionManager exception. PostConstruct method " + injInfo.getPostConstructMethodName() + " could not be found in class " + injInfo.getClassName());
private Method getPreDestroyMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPreDestroyMethod(); if( m == null ) { String preDestroyMethodName = injInfo.getPreDestroyMethodName(); // Check for the method within the resourceClass only. // This does not include super-classses. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PreDestroy // methods with no arguments. if( next.getName().equals(preDestroyMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPreDestroyMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.predestroy-not-found", "InjectionManager exception. PreDestroy method: {0} not found in class: {1}", injInfo.getPreDestroyMethodName(), injInfo.getClassName())); } return m; }
envDescriptor.getInjectionInfoByClass(nextClass); if (injInfo.getPostConstructMethodName() != null) {
String preDestroyMethodName = (preDestroyDesc != null) ? preDestroyDesc.getLifecycleCallbackMethod() : null; injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName, getInjectableResourcesByClass(className,
private Method getPostConstructMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPostConstructMethod(); if( m == null ) { String postConstructMethodName = injInfo.getPostConstructMethodName(); // Check for the method within the resourceClass only. // This does not include super-classes. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PostConstruct // methods with no arguments. if( next.getName().equals(postConstructMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.postconstruct-not-found", "InjectionManager exception. PostConstruct method: {0} not found in class: {1}", injInfo.getPostConstructMethodName(), injInfo.getClassName())); } return m; }
envDescriptor.getInjectionInfoByClass(nextClass); if (injInfo.getPostConstructMethodName() != null) {
String preDestroyMethodName = (preDestroyDesc != null) ? preDestroyDesc.getLifecycleCallbackMethod() : null; injectionInfo = new InjectionInfo(className, postConstructMethodName, preDestroyMethodName, getInjectableResourcesByClass(className,
private Method getPostConstructMethod(InjectionInfo injInfo, Class resourceClass) throws InjectionException { Method m = injInfo.getPostConstructMethod(); if( m == null ) { String postConstructMethodName = injInfo.getPostConstructMethodName(); // Check for the method within the resourceClass only. // This does not include super-classes. for(Method next : resourceClass.getDeclaredMethods()) { // InjectionManager only handles injection into PostConstruct // methods with no arguments. if( next.getName().equals(postConstructMethodName) && (next.getParameterTypes().length == 0) ) { m = next; injInfo.setPostConstructMethod(m); break; } } } if( m == null ) { throw new InjectionException(localStrings.getLocalString( "injection-manager.postconstruct-not-found", "InjectionManager exception. PostConstruct method: {0} not found in class: {1}", injInfo.getPostConstructMethodName(), injInfo.getClassName())); } return m; }