geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r515004 - in /geronimo/server/trunk/modules: geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/ geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/ geronimo-jetty6/src/main/java/org/apache/geronimo/jet...
Date Tue, 06 Mar 2007 07:23:10 GMT
Author: djencks
Date: Mon Mar  5 23:23:09 2007
New Revision: 515004

URL: http://svn.apache.org/viewvc?view=rev&rev=515004
Log:
GERONIMO-2887 put the injections and postCreate and preDestroy info in one object

Added:
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
  (with props)
    geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
  (with props)
Modified:
    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/InternalJettyServletHolder.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyFilterHolder.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java

Added: 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=auto&rev=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
Mon Mar  5 23:23:09 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.j2ee.annotation;
+
+import java.util.List;
+import java.io.Serializable;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class Holder implements Serializable {
+
+    public static final Holder EMPTY = new Holder(null, null, null);
+    
+    private final List<Injection> injections;
+    private final LifecycleMethod postConstruct;
+    private final LifecycleMethod preDestroy;
+
+
+    public Holder(List<Injection> injections, LifecycleMethod postConstruct, LifecycleMethod
preDestroy) {
+        this.injections = injections;
+        this.postConstruct = postConstruct;
+        this.preDestroy = preDestroy;
+    }
+
+
+    public List<Injection> getInjections() {
+        return injections;
+    }
+
+    public LifecycleMethod getPostConstruct() {
+        return postConstruct;
+    }
+
+    public LifecycleMethod getPreDestroy() {
+        return preDestroy;
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 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=auto&rev=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
(added)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
Mon Mar  5 23:23:09 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.j2ee.annotation;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class LifecycleMethod implements Serializable {
+
+    private final String targetClassName;
+    private final String methodName;
+
+
+    public LifecycleMethod(String targetClassName, String methodName) {
+        this.targetClassName = targetClassName;
+        this.methodName = methodName;
+    }
+
+    public String getTargetClassName() {
+        return targetClassName;
+    }
+
+    public String getMethodName() {
+        return methodName;
+    }
+
+    public void call(Object o) throws IllegalAccessException, InvocationTargetException {
+        Class clazz = o.getClass();
+        Method m;
+        try {
+            m = clazz.getMethod(methodName);
+        } catch (NoSuchMethodException e) {
+            throw new AssertionError("We checked that the class had this method at deploy
time. expected class: " + targetClassName + ", actual class: " + clazz.getName() + ", method:
" + methodName);
+        }
+        if (!m.isAccessible()) {
+            try {
+                m.setAccessible(true);
+                m.invoke(o);
+            } finally {
+                m.setAccessible(false);
+            }
+        } else {
+        m.invoke(o);
+        }
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/LifecycleMethod.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=515004&r1=515003&r2=515004
==============================================================================
--- 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
Mon Mar  5 23:23:09 2007
@@ -66,6 +66,7 @@
 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder;
 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.jetty6.Host;
 import org.apache.geronimo.jetty6.JettyDefaultServletHolder;
 import org.apache.geronimo.jetty6.JettyFilterHolder;
@@ -332,6 +333,11 @@
         getNamingBuilders().buildNaming(webApp, jettyWebApp, earConfiguration, earConfiguration,
(Module) webModule, buildingContext);
         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));
+        }
 
         GBeanData webModuleData = new GBeanData(moduleName, JettyWebAppContext.GBEAN_INFO);
         try {
@@ -343,7 +349,7 @@
                 webModuleData.setReferencePattern("J2EEApplication", earContext.getModuleName());
             }
 
-            webModuleData.setAttribute("injections", injections);
+            webModuleData.setAttribute("injections", holders);
 
             webModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD());
             Set securityRoles = collectRoleNames(webApp);

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java?view=diff&rev=515004&r1=515003&r2=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
Mon Mar  5 23:23:09 2007
@@ -89,6 +89,10 @@
         return servletRegistration.newInstance(_class);
     }
 
+    public void destroyInstance(Object o) throws Exception {
+        servletRegistration.destroyInstance(o);
+    }
+
     /**
      * Provide the thread's current JettyServletHolder
      *

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyFilterHolder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyFilterHolder.java?view=diff&rev=515004&r1=515003&r2=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyFilterHolder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyFilterHolder.java
Mon Mar  5 23:23:09 2007
@@ -17,19 +17,11 @@
 package org.apache.geronimo.jetty6;
 
 import java.util.Map;
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
 
 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.xbean.recipe.ObjectRecipe;
-import org.apache.xbean.recipe.Option;
-import org.apache.xbean.recipe.StaticRecipe;
 import org.mortbay.jetty.servlet.FilterHolder;
 
 /**
@@ -94,6 +86,22 @@
         public synchronized Object newInstance() throws InstantiationException, IllegalAccessException
{
             return servletRegistration.newInstance(_class);
         }
+
+
+        public void doStop() {
+            //TODO ask jetty folks to have a Holder destroyInstance method.
+            super.doStop();
+            try {
+                destroyInstance(getFilter());
+            } catch (Exception e) {
+                //guess we should log it
+            }
+        }
+
+        public void destroyInstance(Object o) throws Exception {
+            servletRegistration.destroyInstance(o);
+        }
+
     }
     
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java?view=diff&rev=515004&r1=515003&r2=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletRegistration.java
Mon Mar  5 23:23:09 2007
@@ -18,6 +18,7 @@
 
 import java.util.Set;
 import java.util.Map;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.naming.Context;
 
@@ -41,5 +42,6 @@
     AbstractImmutableHandler getLifecycleChain();
 
     Object newInstance(Class clazz) throws InstantiationException, IllegalAccessException;
-    
+
+    void destroyInstance(Object o) throws Exception;
 }

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=515004&r1=515003&r2=515004
==============================================================================
--- 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
Mon Mar  5 23:23:09 2007
@@ -29,6 +29,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.List;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.faces.FactoryFinder;
 import javax.management.MalformedObjectNameException;
@@ -46,6 +47,8 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
 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.jetty6.handler.AbstractImmutableHandler;
 import org.apache.geronimo.jetty6.handler.ComponentContextHandler;
 import org.apache.geronimo.jetty6.handler.InstanceContextHandler;
@@ -100,7 +103,7 @@
     private final WebAppContext webAppContext;//delegate
     private final AbstractImmutableHandler lifecycleChain;
     private final Context componentContext;
-    private final Map<String, List<Injection>> injectionMap;
+    private final Map<String, Holder> injectionMap;
 
     private final Set servletNames = new HashSet();
 
@@ -152,7 +155,7 @@
             PermissionCollection checkedPermissions,
             PermissionCollection excludedPermissions,
 
-            Map<String, List<Injection>> injectionMap,
+            Map<String, Holder> injectionMap,
 
             Host host,
             TransactionManager transactionManager,
@@ -344,7 +347,11 @@
         objectRecipe.allow(Option.PRIVATE_PROPERTIES);
         objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
         String className = clazz.getName();
-        List<Injection> injections = injectionMap.get(className);
+        Holder holder = injectionMap.get(className);
+        if (holder == null) {
+            holder = Holder.EMPTY;
+        }
+        List<Injection> injections = holder.getInjections();
         if (injections != null) {
             for (Injection injection : injections) {
                 try {
@@ -371,8 +378,28 @@
 //                log.warning("Injection: No such property '"+property+"' in class "+_class.getName());
             }
         }
+        LifecycleMethod postConstruct = holder.getPostConstruct();
+        if (postConstruct != null) {
+            try {
+                postConstruct.call(filter);
+            } catch (InvocationTargetException e) {
+                Throwable cause = e.getCause();
+                throw (InstantiationException)new InstantiationException("Could not call
postConstruct method").initCause(cause);
+            }
+        }
         return filter;
 
+    }
+
+    public void destroyInstance(Object o) throws Exception {
+        Class clazz = o.getClass();
+        Holder holder = injectionMap.get(clazz.getName());
+        if (holder != null) {
+            LifecycleMethod lifecycleMethod = holder.getPreDestroy();
+            if (lifecycleMethod != null) {
+                lifecycleMethod.call(o);
+            }
+        }
     }
 
     public void doStart() throws Exception {

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java?view=diff&rev=515004&r1=515003&r2=515004
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty6/AbstractWebModuleTest.java
Mon Mar  5 23:23:09 2007
@@ -49,6 +49,7 @@
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.geronimo.j2ee.annotation.Holder;
 import org.mortbay.jetty.security.Authenticator;
 import org.mortbay.jetty.security.FormAuthenticator;
 
@@ -116,7 +117,7 @@
                 defaultPrincipal,
                 checkedPermissions,
                 excludedPermissions,
-                new HashMap<String, List<Injection>>(),
+                new HashMap<String, Holder>(),
                 null,
                 transactionManager,
                 connectionTrackingCoordinator,



Mime
View raw message