Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EB5B99128 for ; Fri, 31 Aug 2012 08:36:51 +0000 (UTC) Received: (qmail 60158 invoked by uid 500); 31 Aug 2012 08:36:51 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 58893 invoked by uid 500); 31 Aug 2012 08:36:44 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 58833 invoked by uid 99); 31 Aug 2012 08:36:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 08:36:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2012 08:36:40 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E9214238896F; Fri, 31 Aug 2012 08:35:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: genspring@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120831083557.E9214238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 problems = new ArrayList(); + 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 problems = new ArrayList(); - 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 postConstruct = holder.getPostConstruct(); + if (postConstruct != null) { + Holder.apply(o, clazz, postConstruct); + } + } + + } }