geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r515780 - in /geronimo/server/trunk/modules: geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/ geronimo-client/src/main/java/org/apache/geronimo/client/ geronimo-connector-builder/src/main/java/org/apache/geronimo/co...
Date Wed, 07 Mar 2007 21:39:56 GMT
Author: djencks
Date: Wed Mar  7 13:39:55 2007
New Revision: 515780

URL: http://svn.apache.org/viewvc?view=rev&rev=515780
Log:
GERONMO-2887 More work to on injections and lifecycle methods

Modified:
    geronimo/server/trunk/modules/geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
    geronimo/server/trunk/modules/geronimo-client/src/main/java/org/apache/geronimo/client/AppClientContainer.java
    geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
    geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilder.java
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
    geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-client-builder/src/main/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
Wed Mar  7 13:39:55 2007
@@ -57,6 +57,7 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.SingleElementCollection;
 import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.j2ee.deployment.AppClientModule;
 import org.apache.geronimo.j2ee.deployment.ConnectorModule;
 import org.apache.geronimo.j2ee.deployment.CorbaGBeanNameSource;
@@ -578,7 +579,7 @@
                     }
                 }
 
-                Map<String, List<Injection>> injectionsMap;
+                Map<String, Holder> injectionsMap;
                 // add the app client static jndi provider
                 //TODO track resource ref shared and app managed security
                 AbstractName jndiContextName = earContext.getNaming().createChildName(appClientDeploymentContext.getModuleName(),
"StaticJndiContext", "StaticJndiContext");
@@ -641,11 +642,11 @@
                         appClientContainerGBeanData.setAttribute("defaultPrincipal", defaultPrincipal);
                     }
                     appClientContainerGBeanData.setReferencePattern("JNDIContext", jndiContextName);
-                    List<Injection> injections = injectionsMap.get(appClientModule.getMainClassName());
+                    Holder injections = injectionsMap.get(appClientModule.getMainClassName());
                     if (injections != null) {
                         appClientContainerGBeanData.setAttribute("injections", injections);
                     }
-                    List<Injection> callbackHandlerInjections = injectionsMap.get(callbackHandlerClassName);
+                    Holder callbackHandlerInjections = injectionsMap.get(callbackHandlerClassName);
                     if (callbackHandlerInjections != null) {
                         appClientContainerGBeanData.setAttribute("callbackHandlerInjections",
callbackHandlerInjections);
                     }

Modified: geronimo/server/trunk/modules/geronimo-client/src/main/java/org/apache/geronimo/client/AppClientContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-client/src/main/java/org/apache/geronimo/client/AppClientContainer.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-client/src/main/java/org/apache/geronimo/client/AppClientContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-client/src/main/java/org/apache/geronimo/client/AppClientContainer.java
Wed Mar  7 13:39:55 2007
@@ -33,8 +33,11 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.geronimo.j2ee.annotation.Holder;
+import org.apache.geronimo.j2ee.annotation.LifecycleMethod;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.security.ContextManager;
 import org.apache.geronimo.security.Callers;
@@ -47,7 +50,7 @@
 /**
  * @version $Rev$ $Date$
  */
-public final class AppClientContainer {
+public final class AppClientContainer implements GBeanLifecycle {
     private static final Class[] MAIN_ARGS = {String[].class};
 
     public static LoginContext loginContext;
@@ -56,21 +59,22 @@
     private final AppClientPlugin jndiContext;
     private final AbstractName appClientModuleName;
     private final String realmName;
-    private final Class callbackHandlerClass;
+    private final String callbackHandlerClass;
     private final Subject defaultSubject;
     private final Method mainMethod;
     private final ClassLoader classLoader;
     private final Kernel kernel;
-    private final List<Injection> injections;
-    private final List<Injection> callbackHandlerinjections;
+    private final Holder injections;
+    private final Holder callbackHandlerinjections;
+    private CallbackHandler callbackHandler;
 
     public AppClientContainer(String mainClassName,
             AbstractName appClientModuleName,
             String realmName,
             String callbackHandlerClassName,
             DefaultPrincipal defaultPrincipal,
-            List<Injection> injections,
-            List<Injection> callbackHandlerinjections,
+            Holder injections,
+            Holder callbackHandlerinjections,
             AppClientPlugin jndiContext,
             ClassLoader classLoader,
             Kernel kernel
@@ -81,15 +85,16 @@
             throw new IllegalArgumentException("You must supply both realmName and callbackHandlerClass
or neither");
         }
         this.realmName = realmName;
-        if (callbackHandlerClassName != null) {
-            try {
-                this.callbackHandlerClass = classLoader.loadClass(callbackHandlerClassName);
-            } catch (ClassNotFoundException e) {
-                throw new AppClientInitializationException("Could not load callbackHandlerClass",
e);
-            }
-        } else {
-            callbackHandlerClass = null;
-        }
+        this.callbackHandlerClass = callbackHandlerClassName;
+//        if (callbackHandlerClassName != null) {
+//            try {
+//                this.callbackHandlerClass = classLoader.loadClass(callbackHandlerClassName);
+//            } catch (ClassNotFoundException e) {
+//                throw new AppClientInitializationException("Could not load callbackHandlerClass",
e);
+//            }
+//        } else {
+//            callbackHandlerClass = null;
+//        }
         if (defaultPrincipal != null) {
             defaultSubject = ConfigurationUtil.generateDefaultSubject(defaultPrincipal, classLoader);
         } else {
@@ -130,8 +135,47 @@
 //        LoginContext loginContext = null;
         try {
             thread.setContextClassLoader(classLoader);
+            jndiContext.startClient(appClientModuleName, kernel, classLoader);
+            Context componentContext = jndiContext.getJndiContext();
+
             if (callbackHandlerClass != null) {
+                ObjectRecipe objectRecipe = new ObjectRecipe(callbackHandlerClass);
+                objectRecipe.allow(Option.FIELD_INJECTION);
+                objectRecipe.allow(Option.PRIVATE_PROPERTIES);
+                objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
+                if (callbackHandlerinjections != null && callbackHandlerinjections.getInjections()
!= null) {
+                    //TODO figure out how to call a String[] arg constructor
+                    for (Injection injection : callbackHandlerinjections.getInjections())
{
+                        try {
+                            String jndiName = injection.getJndiName();
+                            //our componentContext is attached to jndi at "java:comp" so
we remove that when looking stuff up in it
+                            Object object = componentContext.lookup("env/" + jndiName);
+                            if (object instanceof String) {
+                                String string = (String) object;
+                                // Pass it in raw so it could be potentially converted to
+                                // another data type by an xbean-reflect property editor
+                                objectRecipe.setProperty(injection.getTargetName(), string);
+                            } else {
+                                objectRecipe.setProperty(injection.getTargetName(), new StaticRecipe(object));
+                            }
+                        } catch (NamingException e) {
+//                        log.warn("could not look up ", e);
+                        }
+                    }
+                }
+                callbackHandler = (CallbackHandler) objectRecipe.create(classLoader);
+                Map unsetProperties = objectRecipe.getUnsetProperties();
+                if (unsetProperties.size() > 0) {
+                    for (Object property : unsetProperties.keySet()) {
+//                log.warning("Injection: No such property '"+property+"' in class "+_class.getName());
+                    }
+                }
+                if (callbackHandlerinjections != null && callbackHandlerinjections.getPostConstruct()
!= null) {
+                    LifecycleMethod postConstruct = callbackHandlerinjections.getPostConstruct();
+                    postConstruct.call(callbackHandler, null);
+                }
                 //look for a constructor taking the args
+                /*
                 CallbackHandler callbackHandler;
                 try {
                     Constructor cArgs = callbackHandlerClass.getConstructor(new Class[] {String[].class});
@@ -139,6 +183,7 @@
                 } catch (NoSuchMethodException e) {
                     callbackHandler = (CallbackHandler) callbackHandlerClass.newInstance();
                 }
+                */
                 loginContext = new LoginContext(realmName, callbackHandler);
                 try {
                     loginContext.login();
@@ -149,15 +194,13 @@
                 clientSubject = loginContext.getSubject();
             }
             ContextManager.setCallers(clientSubject, clientSubject);
-            jndiContext.startClient(appClientModuleName, kernel, classLoader);
-            Context componentContext = jndiContext.getJndiContext();
             ObjectRecipe objectRecipe = new ObjectRecipe(mainClassName);
             objectRecipe.allow(Option.FIELD_INJECTION);
             objectRecipe.allow(Option.PRIVATE_PROPERTIES);
             objectRecipe.allow(Option.STATIC_PROPERTIES);
             objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
-            if (injections != null) {
-                for (Injection injection : injections) {
+            if (injections != null && injections.getInjections() != null) {
+                for (Injection injection : injections.getInjections()) {
                     try {                                                          
                         String jndiName = injection.getJndiName();
                         //our componentContext is attached to jndi at "java:comp" so we remove
that when looking stuff up in it
@@ -175,13 +218,17 @@
                     }
                 }
             }
-            objectRecipe.setStaticProperties(classLoader);
+            Class clazz = objectRecipe.setStaticProperties(classLoader);
             Map unsetProperties = objectRecipe.getUnsetProperties();
             if (unsetProperties.size() > 0) {
                 for (Object property : unsetProperties.keySet()) {
 //                log.warning("Injection: No such property '"+property+"' in class "+_class.getName());
                 }
             }
+            if (injections != null && injections.getPostConstruct() != null) {
+                LifecycleMethod postConstruct = injections.getPostConstruct();
+                postConstruct.call(null, clazz);
+            }
 
             if (clientSubject == null) {
                 mainMethod.invoke(null, new Object[]{args});
@@ -208,16 +255,35 @@
             }
             throw new Error(e);
         } finally {
-            if (loginContext != null) {
-                loginContext.logout();
-            }
-            jndiContext.stopClient(appClientModuleName);
-
+            //How can this work??
             thread.setContextClassLoader(oldClassLoader);
             ContextManager.popCallers(oldCallers);
         }
     }
 
+    public void doStart() throws Exception {
+    }
+
+    public void doStop() throws Exception {
+        if (callbackHandler != null && callbackHandlerinjections != null &&
callbackHandlerinjections.getPreDestroy() != null) {
+            LifecycleMethod preDestroy = callbackHandlerinjections.getPreDestroy();
+            preDestroy.call(callbackHandler, null);
+        }
+        if (loginContext != null) {
+            loginContext.logout();
+        }
+        jndiContext.stopClient(appClientModuleName);
+    }
+
+    public void doFail() {
+        try {
+            doStop();
+        } catch (Exception e) {
+            //ignore
+        }
+    }
+
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {
@@ -230,8 +296,8 @@
         infoFactory.addAttribute("realmName", String.class, true);
         infoFactory.addAttribute("callbackHandlerClassName", String.class, true);
         infoFactory.addAttribute("defaultPrincipal", DefaultPrincipal.class, true);
-        infoFactory.addAttribute("injections", List.class, true);
-        infoFactory.addAttribute("callbackHandlerInjections", List.class, true);
+        infoFactory.addAttribute("injections", Holder.class, true);
+        infoFactory.addAttribute("callbackHandlerInjections", Holder.class, true);
 
         infoFactory.addReference("JNDIContext", AppClientPlugin.class, NameFactory.GERONIMO_SERVICE);
 
@@ -257,4 +323,5 @@
     public static GBeanInfo getGBeanInfo() {
         return GBEAN_INFO;
     }
+
 }

Modified: geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
Wed Mar  7 13:39:55 2007
@@ -251,6 +251,17 @@
         public boolean processResource(AnnotatedApp annotatedApp, Resource annotation, Class
cls, Method method, Field field) {
             String resourceName = getResourceName(annotation, method, field);
             String resourceType = getResourceType(annotation, method, field);
+            boolean isResourceRef = false;
+            if (resourceType.equals("javax.sql.DataSource") ||
+                    resourceType.equals("javax.jms.ConnectionFactory") ||
+                    resourceType.equals("javax.jms.QueueConnectionFactory") ||
+                    resourceType.equals("javax.jms.TopicConnectionFactory") ||
+                    resourceType.equals("javax.mail.Session") ||
+                    resourceType.equals("java.net.URL") ||
+                    resourceType.equals("javax.resource.cci.ConnectionFactory") ||
+                    resourceType.endsWith("ConnectionFactory")) {
+                isResourceRef = true;
+            } else
             if (resourceType.equals("javax.sql.DataSource") ||
                     resourceType.equals("javax.jms.ConnectionFactory") ||
                     resourceType.equals("javax.jms.QueueConnectionFactory") ||

Modified: geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilder.java
Wed Mar  7 13:39:55 2007
@@ -26,6 +26,7 @@
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.deployment.AbstractNamespaceBuilder;
 import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.XmlObject;
@@ -49,12 +50,12 @@
             return result;
         }
     };
-    Key<Map<String, List<Injection>>> INJECTION_KEY = new Key<Map<String,
List<Injection>>>() {
+    Key<Map<String, Holder>> INJECTION_KEY = new Key<Map<String, Holder>>()
{
 
-        public Map<String, List<Injection>> get(Map context) {
-            Map<String, List<Injection>> result = (Map<String, List<Injection>>)
context.get(this);
+        public Map<String, Holder> get(Map context) {
+            Map<String, Holder> result = (Map<String, Holder>) context.get(this);
             if (result == null) {
-                result = new HashMap<String, List<Injection>>();
+                result = new HashMap<String, Holder>();
                 context.put(this, result);
             }
             return result;

Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
Wed Mar  7 13:39:55 2007
@@ -24,23 +24,45 @@
 import java.io.Serializable;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class Holder implements Serializable {
 
-    public static final Holder EMPTY = new Holder(null, null, null);
+    public static final Holder EMPTY = new Holder() {
+
+        @Override
+        public void setInjections(List<Injection> injections) {
+        }
+
+        @Override
+        public void setPostConstruct(LifecycleMethod postConstruct) {
+        }
+
+        @Override
+        public void setPreDestroy(LifecycleMethod preDestroy) {
+        }
+    };
     
-    private final List<Injection> injections;
-    private final LifecycleMethod postConstruct;
-    private final LifecycleMethod preDestroy;
+    private List<Injection> injections;
+    private LifecycleMethod postConstruct;
+    private LifecycleMethod preDestroy;
+
+
+    public Holder() {
+    }
 
 
-    public Holder(List<Injection> injections, LifecycleMethod postConstruct, LifecycleMethod
preDestroy) {
+    public void setInjections(List<Injection> injections) {
         this.injections = injections;
+    }
+
+    public void setPostConstruct(LifecycleMethod postConstruct) {
         this.postConstruct = postConstruct;
-        this.preDestroy = preDestroy;
     }
 
+    public void setPreDestroy(LifecycleMethod preDestroy) {
+        this.preDestroy = preDestroy;
+    }
 
     public List<Injection> getInjections() {
         return injections;

Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
(original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
Wed Mar  7 13:39:55 2007
@@ -25,7 +25,7 @@
 import java.lang.reflect.Method;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class LifecycleMethod implements Serializable {
 
@@ -46,8 +46,10 @@
         return methodName;
     }
 
-    public void call(Object o) throws IllegalAccessException, InvocationTargetException {
-        Class clazz = o.getClass();
+    public void call(Object o, Class clazz) throws IllegalAccessException, InvocationTargetException
{
+        if (clazz == null) {
+            clazz = o.getClass();
+        }
         Method m;
         try {
             m = clazz.getMethod(methodName);

Modified: geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
Wed Mar  7 13:39:55 2007
@@ -345,12 +345,7 @@
         }
 
         Map compContext = NamingBuilder.JNDI_KEY.get(buildingContext);
-        Map<String, List<Injection>> injections = NamingBuilder.INJECTION_KEY.get(buildingContext);
-        Map<String, Holder> holders = new HashMap<String, Holder> ();
-        //TODO naming builders should return the holder map
-        for (Map.Entry<String, List<Injection>> entry: injections.entrySet())
{
-            holders.put(entry.getKey(), new Holder(entry.getValue(), null, null));
-        }
+        Map<String, Holder> injections = NamingBuilder.INJECTION_KEY.get(buildingContext);
 
         GBeanData webModuleData = new GBeanData(moduleName, JettyWebAppContext.GBEAN_INFO);
         try {
@@ -362,7 +357,7 @@
                 webModuleData.setReferencePattern("J2EEApplication", earContext.getModuleName());
             }
 
-            webModuleData.setAttribute("injections", holders);
+            webModuleData.setAttribute("injections", injections);
 
             webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
             Set securityRoles = collectRoleNames(webApp);

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
Wed Mar  7 13:39:55 2007
@@ -381,7 +381,7 @@
         LifecycleMethod postConstruct = holder.getPostConstruct();
         if (postConstruct != null) {
             try {
-                postConstruct.call(filter);
+                postConstruct.call(filter, null);
             } catch (InvocationTargetException e) {
                 Throwable cause = e.getCause();
                 throw (InstantiationException)new InstantiationException("Could not call
postConstruct method").initCause(cause);
@@ -397,7 +397,7 @@
         if (holder != null) {
             LifecycleMethod lifecycleMethod = holder.getPreDestroy();
             if (lifecycleMethod != null) {
-                lifecycleMethod.call(o);
+                lifecycleMethod.call(o, o.getClass());
             }
         }
     }

Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?view=diff&rev=515780&r1=515779&r2=515780
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Wed Mar  7 13:39:55 2007
@@ -17,14 +17,14 @@
 
 package org.apache.geronimo.naming.deployment;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
 
 import javax.xml.namespace.QName;
 
@@ -33,24 +33,26 @@
 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.j2ee.annotation.Holder;
+import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.geronimo.j2ee.annotation.LifecycleMethod;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.NamingBuilder;
-import org.apache.geronimo.j2ee.annotation.Injection;
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.Dependency;
+import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
 import org.apache.geronimo.schema.NamespaceElementConverter;
-import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
 import org.apache.geronimo.xbeans.geronimo.naming.GerAbstractNamingEntryDocument;
-import org.apache.geronimo.xbeans.javaee.XsdStringType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
 import org.apache.geronimo.xbeans.javaee.InjectionTargetType;
+import org.apache.geronimo.xbeans.javaee.XsdStringType;
 import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
 
 /**
  * @version $Rev$ $Date$
@@ -291,17 +293,43 @@
 
 
     protected void addInjections(String jndiName, InjectionTargetType[] injectionTargetArray,
Map sharedContext) {
-        Map<String, List<Injection>> injectionsMap = NamingBuilder.INJECTION_KEY.get(sharedContext);
+        Map<String, Holder> holders = NamingBuilder.INJECTION_KEY.get(sharedContext);
         for (InjectionTargetType injectionTarget : injectionTargetArray) {
             String targetName = injectionTarget.getInjectionTargetName().getStringValue().trim();
             String targetClassName = injectionTarget.getInjectionTargetClass().getStringValue().trim();
-            List<Injection> injections = injectionsMap.get(targetClassName);
+            Holder holder = getHolder(holders, targetClassName);
+            List<Injection> injections = holder.getInjections();
             if (injections == null) {
                 injections = new ArrayList<Injection>();
-                injectionsMap.put(targetClassName, injections);
+                holder.setInjections(injections);
             }
             injections.add(new Injection(targetClassName, targetName, jndiName));
         }
     }
 
+    protected void addPostConstruct(LifecycleMethod postConstruct, Map sharedContext) {
+        Map<String, Holder> holders = NamingBuilder.INJECTION_KEY.get(sharedContext);
+        String targetClassName = postConstruct.getTargetClassName();
+        Holder holder = getHolder(holders, targetClassName);
+        holder.setPostConstruct(postConstruct);
+    }
+
+    protected void addPreDestroy(LifecycleMethod preDestroy, Map sharedContext) {
+        Map<String, Holder> holders = NamingBuilder.INJECTION_KEY.get(sharedContext);
+        String targetClassName = preDestroy.getTargetClassName();
+        Holder holder = getHolder(holders, targetClassName);
+        holder.setPreDestroy(preDestroy);
+    }
+
+    private Holder getHolder(Map<String, Holder> holders, String targetClassName) {
+        Holder holder = holders.get(targetClassName);
+        if (holder == null) {
+            holder = new Holder();
+            holders.put(targetClassName, holder);
+        }
+        return holder;
+    }
+
 }
+
+



Mime
View raw message