geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1379359 - in /geronimo/server/branches/3.0/plugins: j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
Date Fri, 31 Aug 2012 08:35:57 GMT
Author: genspring
Date: Fri Aug 31 08:35:57 2012
New Revision: 1379359

URL: http://svn.apache.org/viewvc?rev=1379359&view=rev
Log:
GERONIMO-6384 @PostConstruct have to be called after the object is initialized and after dependency
injection is performed

Modified:
    geronimo/server/branches/3.0/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
    geronimo/server/branches/3.0/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java

Modified: geronimo/server/branches/3.0/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java?rev=1379359&r1=1379358&r2=1379359&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
(original)
+++ geronimo/server/branches/3.0/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
Fri Aug 31 08:35:57 2012
@@ -156,39 +156,46 @@ public class Holder implements Serializa
     public boolean isEmpty() {
         return (injectionMap == null || injectionMap.isEmpty()) && (postConstruct
== null || postConstruct.isEmpty()) && (preDestroy == null || preDestroy.isEmpty());
     }
+    
+    public Object newInstanceWithoutPostConstruct(String className, ClassLoader classLoader,
Context context) throws IllegalAccessException, InstantiationException {
+         ObjectRecipe objectRecipe = new ObjectRecipe(className);
+         objectRecipe.allow(Option.FIELD_INJECTION);
+         objectRecipe.allow(Option.PRIVATE_PROPERTIES);
+         Class<?> clazz;
+         try {
+             clazz = classLoader.loadClass(className);
+         } catch (ClassNotFoundException e) {
+             throw (InstantiationException) new InstantiationException("Can't load class
" + className + " in classloader: " + classLoader).initCause(e);
+         }
+         List<NamingException> problems = new ArrayList<NamingException>();
+         while (clazz != Object.class) {
+             addInjections(clazz.getName(), context, objectRecipe, problems);
+             clazz = clazz.getSuperclass();
+         }
+         if (!problems.isEmpty()) {
+             throw new InstantiationException("Some objects to be injected were not found
in jndi: " + problems);
+         }
+         Object result;
+         try {
+             result = objectRecipe.create(classLoader);
+         } catch (ConstructionException e) {
+             throw (InstantiationException) new InstantiationException("Could not construct
object").initCause(e);
+         }
+         InvocationContext invocationContext = new InvocationContext(context, result);
+         try {
+             for (Interceptor interceptor : interceptors) {
+                 interceptor.instancerCreated(invocationContext);
+             }
+         } catch (InterceptorException e) {
+             throw (InstantiationException) new InstantiationException("Interceptor invocation
failed").initCause(e);
+         }
+         
+         return result;
+    }
 
     public Object newInstance(String className, ClassLoader classLoader, Context context)
throws IllegalAccessException, InstantiationException {
-        ObjectRecipe objectRecipe = new ObjectRecipe(className);
-        objectRecipe.allow(Option.FIELD_INJECTION);
-        objectRecipe.allow(Option.PRIVATE_PROPERTIES);
-        Class<?> clazz;
-        try {
-            clazz = classLoader.loadClass(className);
-        } catch (ClassNotFoundException e) {
-            throw (InstantiationException) new InstantiationException("Can't load class "
+ className + " in classloader: " + classLoader).initCause(e);
-        }
-        List<NamingException> problems = new ArrayList<NamingException>();
-        while (clazz != Object.class) {
-            addInjections(clazz.getName(), context, objectRecipe, problems);
-            clazz = clazz.getSuperclass();
-        }
-        if (!problems.isEmpty()) {
-            throw new InstantiationException("Some objects to be injected were not found
in jndi: " + problems);
-        }
-        Object result;
-        try {
-            result = objectRecipe.create(classLoader);
-        } catch (ConstructionException e) {
-            throw (InstantiationException) new InstantiationException("Could not construct
object").initCause(e);
-        }
-        InvocationContext invocationContext = new InvocationContext(context, result);
-        try {
-            for (Interceptor interceptor : interceptors) {
-                interceptor.instancerCreated(invocationContext);
-            }
-        } catch (InterceptorException e) {
-            throw (InstantiationException) new InstantiationException("Interceptor invocation
failed").initCause(e);
-        }
+
+        Object result = this.newInstanceWithoutPostConstruct(className, classLoader, context);
 
         if (getPostConstruct() != null) {
             try {

Modified: geronimo/server/branches/3.0/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java?rev=1379359&r1=1379358&r2=1379359&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
(original)
+++ geronimo/server/branches/3.0/plugins/myfaces/geronimo-myfaces/src/main/java/org/apache/geronimo/myfaces/LifecycleProviderGBean.java
Fri Aug 31 08:35:57 2012
@@ -33,14 +33,14 @@ import org.apache.geronimo.j2ee.annotati
 import org.apache.geronimo.j2ee.annotation.LifecycleMethod;
 import org.apache.geronimo.j2ee.jndi.ContextSource;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.myfaces.config.annotation.LifecycleProvider;
+import org.apache.myfaces.config.annotation.LifecycleProvider2;
 import org.osgi.framework.Bundle;
 
 /**
  * @version $Rev$ $Date$
  */
 @GBean
-public class LifecycleProviderGBean implements LifecycleProvider {
+public class LifecycleProviderGBean implements LifecycleProvider2 {
 
     private final Holder holder;
     private final Context context;
@@ -62,7 +62,7 @@ public class LifecycleProviderGBean impl
         if (className == null) {
             throw new InstantiationException("no class name provided");
         }
-        return holder.newInstance(className, classLoader, context);
+        return holder.newInstanceWithoutPostConstruct(className, classLoader, context);
     }
 
     public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException
{
@@ -74,4 +74,17 @@ public class LifecycleProviderGBean impl
             }
         }
     }
+
+    @Override
+    public void postConstruct(Object o) throws IllegalAccessException,InvocationTargetException
{
+
+        Class<?> clazz = o.getClass();
+        if (holder != null) {
+            Map<String, LifecycleMethod> postConstruct = holder.getPostConstruct();
+            if (postConstruct != null) {
+                Holder.apply(o, clazz, postConstruct);
+            }
+        }
+
+    }
 }



Mime
View raw message