You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/12/28 03:22:48 UTC

svn commit: r607160 [1/2] - in /openejb/trunk/openejb3: assembly/openejb-tomcat/ assembly/openejb-tomcat/openejb-tomcat-naming/ assembly/openejb-tomcat/openejb-tomcat-naming/src/ assembly/openejb-tomcat/openejb-tomcat-naming/src/main/ assembly/openejb-...

Author: dblevins
Date: Thu Dec 27 18:22:44 2007
New Revision: 607160

URL: http://svn.apache.org/viewvc?rev=607160&view=rev
Log:
OPENEJB-741: Support for Tomcat 5.5

Added:
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/   (with props)
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/pom.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/AbstractObjectFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/EjbFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/LegacyAnnotationProcessor.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/NamingUtil.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceContextFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceUnitFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/ResourceFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/SystemComponentFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/UserTransactionFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/WsFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/resources/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/test/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/test/java/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/test/resources/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/   (with props)
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/maven.xml
      - copied, changed from r605804, openejb/trunk/openejb3/assembly/openejb-tomcat/maven.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/pom.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/project.properties
      - copied unchanged from r605103, openejb/trunk/openejb3/assembly/openejb-tomcat/project.properties
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/assembly/
      - copied from r605103, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/assembly/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/
      - copied from r605103, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/BackportUtil.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/LegacyAnnotationProcessorListener.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedListenersListener.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedServletsListener.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/TomcatJndiBuilder.java
      - copied, changed from r605804, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/TomcatJndiBuilder.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/TomcatVersion.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/TomcatWebAppBuilder.java
      - copied, changed from r605804, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/java/org/apache/openejb/tomcat/TomcatWebAppBuilder.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/
      - copied from r605103, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/resources/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/ServerClassLoader
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
      - copied unchanged from r606528, openejb/trunk/openejb3/assembly/openejb-tomcat/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/test/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/test/conf/
      - copied from r605103, openejb/trunk/openejb3/assembly/openejb-tomcat/src/test/conf/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/test/java/
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/test/resources/
    openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/LoaderJar.java
Removed:
    openejb/trunk/openejb3/assembly/openejb-tomcat/maven.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/AbstractObjectFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/EjbFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/NamingUtil.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/PersistenceContextFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/PersistenceUnitFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ResourceFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/SystemComponentFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/UserTransactionFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/WsFactory.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/project.properties
    openejb/trunk/openejb3/assembly/openejb-tomcat/src/
Modified:
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/TomcatLoader.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/installer/Installer.java
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/README.txt
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/WEB-INF/web.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/openejb.xml
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/testhome.jsp
    openejb/trunk/openejb3/assembly/openejb-tomcat/pom.xml
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DebuggableVmHackery.java
    openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/LoaderServlet.java
    openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/OpenEJBListener.java
    openejb/trunk/openejb3/container/openejb-loader/src/main/java/org/apache/openejb/loader/TomcatClassPath.java

Propchange: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec 27 18:22:44 2007
@@ -0,0 +1,11 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin
+

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/pom.xml?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/pom.xml (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/pom.xml Thu Dec 27 18:22:44 2007
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<!-- $Rev: 600338 $ $Date: 2007-12-02 09:08:04 -0800 (Sun, 02 Dec 2007) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>openejb-tomcat</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>3.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-tomcat-naming</artifactId>
+  <packaging>jar</packaging>
+  <name>OpenEJB :: Assembly :: Tomcat :: Naming</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-loader</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-cxf</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-client</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>catalina</artifactId>
+      <version>5.5.23</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>naming-factory</artifactId>
+      <version>5.5.23</version>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+</project>

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/AbstractObjectFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/AbstractObjectFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/AbstractObjectFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/AbstractObjectFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,77 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import static org.apache.openejb.tomcat.naming.NamingUtil.JNDI_NAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.JNDI_PROVIDER_ID;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+public abstract class AbstractObjectFactory implements ObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        Reference ref = (Reference) object;
+
+        // the jndi context to use for the lookup (usually null which is the default context)
+        String jndiProviderId = getProperty(ref, JNDI_PROVIDER_ID);
+
+        // the jndi name
+        String jndiName = getProperty(ref, JNDI_NAME);
+        if (jndiName == null) {
+            jndiName = buildJndiName(ref);
+        }
+
+        // look up the reference
+        Object value = lookup(jndiProviderId, jndiName);
+        return value;
+    }
+
+    protected abstract String buildJndiName(Reference reference) throws NamingException;
+
+    protected Object lookup(String jndiProviderId, String jndiName) throws NamingException {
+        Context externalContext = getContext(jndiProviderId);
+        synchronized (externalContext) {
+            /* According to the JNDI SPI specification multiple threads may not access the same JNDI
+            Context *instance* concurrently. Since we don't know the origines of the federated context we must
+            synchonrize access to it.  JNDI SPI Sepecifiation 1.2 Section 2.2
+            */
+            return externalContext.lookup(jndiName);
+        }
+    }
+
+    protected Context getContext(String jndiProviderId) throws NamingException {
+        if (jndiProviderId != null) {
+            String contextJndiName = "java:openejb/remote_jndi_contexts/" + jndiProviderId;
+            ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+            Context context = (Context) containerSystem.getJNDIContext().lookup(contextJndiName);
+            return context;
+        } else {
+            ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+            Context context = containerSystem.getJNDIContext();
+            return context;
+        }
+    }
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/EjbFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/EjbFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/EjbFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/EjbFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,92 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.naming.EjbRef;
+import org.apache.openejb.core.ivm.EjbObjectInputStream;
+import org.apache.openejb.core.ivm.IntraVmCopyMonitor;
+import static org.apache.openejb.tomcat.naming.NamingUtil.DEPLOYMENT_ID;
+import static org.apache.openejb.tomcat.naming.NamingUtil.EXTERNAL;
+import static org.apache.openejb.tomcat.naming.NamingUtil.LOCAL;
+import static org.apache.openejb.tomcat.naming.NamingUtil.REMOTE;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+import static org.apache.openejb.tomcat.naming.NamingUtil.isPropertyTrue;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Hashtable;
+
+public class EjbFactory extends AbstractObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        // ignore non ejb-refs
+        if (!(object instanceof EjbRef)) {
+            return null;
+        }
+
+        // lookup the value
+        Object value = super.getObjectInstance(object, name, context, environment);
+
+        // if this is an external reference, copy it into the local class loader
+        if (isPropertyTrue((Reference) object, EXTERNAL)) {
+            value = copy(value);
+        }
+
+        // done
+        return value;
+    }
+
+    protected String buildJndiName(Reference reference) throws NamingException {
+        String jndiName;// get and verify deploymentId
+        String deploymentId = getProperty(reference, DEPLOYMENT_ID);
+        if (deploymentId == null) throw new NamingException("ejb-ref deploymentId is null");
+
+        // get and verify interface type
+        String interfaceType = getProperty(reference, REMOTE);
+        if (interfaceType == null) {
+            interfaceType = getProperty(reference, LOCAL);
+        }
+        if (interfaceType == null) throw new NamingException("ejb-ref interface type is null");
+
+        // build jndi name using the deploymentId and interface type
+        jndiName = "java:openejb/Deployment/" + deploymentId + "/" + interfaceType;
+        return jndiName;
+    }
+
+    private static Object copy(Object source) throws Exception {
+        IntraVmCopyMonitor.preCrossClassLoaderOperation();
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+            ObjectOutputStream out = new ObjectOutputStream(baos);
+            out.writeObject(source);
+            out.close();
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream in = new EjbObjectInputStream(bais);
+            Object copy = in.readObject();
+            return copy;
+        } finally {
+            IntraVmCopyMonitor.postCrossClassLoaderOperation();
+        }
+    }
+}
\ No newline at end of file

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/LegacyAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/LegacyAnnotationProcessor.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/LegacyAnnotationProcessor.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/LegacyAnnotationProcessor.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,247 @@
+/**
+ * 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.openejb.tomcat.naming;
+
+/*
+ * 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.
+ */
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.naming.NamingException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.xml.ws.WebServiceRef;
+
+public class LegacyAnnotationProcessor {
+
+    protected javax.naming.Context context = null;
+
+    public LegacyAnnotationProcessor(javax.naming.Context context) {
+        this.context = context;
+    }
+
+
+    /**
+     * Call postConstruct method on the specified instance.
+     */
+    public void postConstruct(Object instance)
+        throws IllegalAccessException, InvocationTargetException {
+
+        Method[] methods = instance.getClass().getDeclaredMethods();
+        Method postConstruct = null;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].isAnnotationPresent(PostConstruct.class)) {
+                if ((postConstruct != null)
+                        || (methods[i].getParameterTypes().length != 0)
+                        || (Modifier.isStatic(methods[i].getModifiers()))
+                        || (methods[i].getExceptionTypes().length > 0)
+                        || (!methods[i].getReturnType().getName().equals("void"))) {
+                    throw new IllegalArgumentException("Invalid PostConstruct annotation");
+                }
+                postConstruct = methods[i];
+            }
+        }
+
+        // At the end the postconstruct annotated
+        // method is invoked
+        if (postConstruct != null) {
+            boolean accessibility = postConstruct.isAccessible();
+            postConstruct.setAccessible(true);
+            postConstruct.invoke(instance);
+            postConstruct.setAccessible(accessibility);
+        }
+    }
+
+
+    /**
+     * Call preDestroy method on the specified instance.
+     */
+    public void preDestroy(Object instance)
+        throws IllegalAccessException, InvocationTargetException {
+
+        Method[] methods = instance.getClass().getDeclaredMethods();
+        Method preDestroy = null;
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].isAnnotationPresent(PreDestroy.class)) {
+                if ((preDestroy != null)
+                        || (methods[i].getParameterTypes().length != 0)
+                        || (Modifier.isStatic(methods[i].getModifiers()))
+                        || (methods[i].getExceptionTypes().length > 0)
+                        || (!methods[i].getReturnType().getName().equals("void"))) {
+                    throw new IllegalArgumentException("Invalid PreDestroy annotation");
+                }
+                preDestroy = methods[i];
+            }
+        }
+
+        // At the end the postconstruct annotated
+        // method is invoked
+        if (preDestroy != null) {
+            boolean accessibility = preDestroy.isAccessible();
+            preDestroy.setAccessible(true);
+            preDestroy.invoke(instance);
+            preDestroy.setAccessible(accessibility);
+        }
+
+    }
+
+
+    /**
+     * Inject resources in specified instance.
+     */
+    public void processAnnotations(Object instance)
+        throws IllegalAccessException, InvocationTargetException, NamingException {
+
+        if (context == null) {
+            // No resource injection
+            return;
+        }
+
+        // Initialize fields annotations
+        Field[] fields = instance.getClass().getDeclaredFields();
+        for (int i = 0; i < fields.length; i++) {
+            if (fields[i].isAnnotationPresent(Resource.class)) {
+                Resource annotation = (Resource) fields[i].getAnnotation(Resource.class);
+                lookupFieldResource(context, instance, fields[i], annotation.name());
+            }
+            if (fields[i].isAnnotationPresent(EJB.class)) {
+                EJB annotation = (EJB) fields[i].getAnnotation(EJB.class);
+                lookupFieldResource(context, instance, fields[i], annotation.name());
+            }
+            if (fields[i].isAnnotationPresent(WebServiceRef.class)) {
+                WebServiceRef annotation =
+                    (WebServiceRef) fields[i].getAnnotation(WebServiceRef.class);
+                lookupFieldResource(context, instance, fields[i], annotation.name());
+            }
+            if (fields[i].isAnnotationPresent(PersistenceContext.class)) {
+                PersistenceContext annotation =
+                    (PersistenceContext) fields[i].getAnnotation(PersistenceContext.class);
+                lookupFieldResource(context, instance, fields[i], annotation.name());
+            }
+            if (fields[i].isAnnotationPresent(PersistenceUnit.class)) {
+                PersistenceUnit annotation =
+                    (PersistenceUnit) fields[i].getAnnotation(PersistenceUnit.class);
+                lookupFieldResource(context, instance, fields[i], annotation.name());
+            }
+        }
+
+        // Initialize methods annotations
+        Method[] methods = instance.getClass().getDeclaredMethods();
+        for (int i = 0; i < methods.length; i++) {
+            if (methods[i].isAnnotationPresent(Resource.class)) {
+                Resource annotation = (Resource) methods[i].getAnnotation(Resource.class);
+                lookupMethodResource(context, instance, methods[i], annotation.name());
+            }
+            if (methods[i].isAnnotationPresent(EJB.class)) {
+                EJB annotation = (EJB) methods[i].getAnnotation(EJB.class);
+                lookupMethodResource(context, instance, methods[i], annotation.name());
+            }
+            if (methods[i].isAnnotationPresent(WebServiceRef.class)) {
+                WebServiceRef annotation =
+                    (WebServiceRef) methods[i].getAnnotation(WebServiceRef.class);
+                lookupMethodResource(context, instance, methods[i], annotation.name());
+            }
+            if (methods[i].isAnnotationPresent(PersistenceContext.class)) {
+                PersistenceContext annotation =
+                    (PersistenceContext) methods[i].getAnnotation(PersistenceContext.class);
+                lookupMethodResource(context, instance, methods[i], annotation.name());
+            }
+            if (methods[i].isAnnotationPresent(PersistenceUnit.class)) {
+                PersistenceUnit annotation =
+                    (PersistenceUnit) methods[i].getAnnotation(PersistenceUnit.class);
+                lookupMethodResource(context, instance, methods[i], annotation.name());
+            }
+        }
+
+    }
+
+
+    /**
+     * Inject resources in specified field.
+     */
+    protected static void lookupFieldResource(javax.naming.Context context,
+            Object instance, Field field, String name)
+        throws NamingException, IllegalAccessException {
+
+        Object lookedupResource = null;
+        boolean accessibility = false;
+
+        if ((name != null) && (name.length() > 0)) {
+            lookedupResource = context.lookup(name);
+        } else {
+            lookedupResource = context.lookup(instance.getClass().getName() + "/" + field.getName());
+        }
+
+        accessibility = field.isAccessible();
+        field.setAccessible(true);
+        field.set(instance, lookedupResource);
+        field.setAccessible(accessibility);
+    }
+
+
+    /**
+     * Inject resources in specified method.
+     */
+    protected static void lookupMethodResource(javax.naming.Context context,
+            Object instance, Method method, String name)
+        throws NamingException, IllegalAccessException, InvocationTargetException {
+
+        if (!method.getName().startsWith("set")
+                || method.getParameterTypes().length != 1
+                || !method.getReturnType().getName().equals("void")) {
+            throw new IllegalArgumentException("Invalid method resource injection annotation");
+        }
+
+        Object lookedupResource = null;
+        boolean accessibility = false;
+
+        if ((name != null) &&
+                (name.length() > 0)) {
+            lookedupResource = context.lookup(name);
+        } else {
+            lookedupResource =
+                context.lookup(instance.getClass().getName() + "/" + method.getName().substring(3));
+        }
+
+        accessibility = method.isAccessible();
+        method.setAccessible(true);
+        method.invoke(instance, lookedupResource);
+        method.setAccessible(accessibility);
+    }
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/NamingUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/NamingUtil.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/NamingUtil.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/NamingUtil.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,116 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.naming.EjbRef;
+
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class NamingUtil {
+    public static final String NAME = "name";
+    public static final String DEPLOYMENT_ID = "deploymentid";
+    public static final String EXTERNAL = "external";
+    public static final String LOCAL = "local";
+    public static final String REMOTE = EjbRef.REMOTE;
+    public static final String JNDI_NAME = "jndiname";
+    public static final String JNDI_PROVIDER_ID = "jndiproviderid";
+    public static final String UNIT = "unit";
+    public static final String EXTENDED = "extended";
+    public static final String PROPERTIES = "properties";
+    public static final String RESOURCE_ID = "resourceid";
+    public static final String COMPONENT_TYPE = "componenttype";
+    public static final String WS_ID = "wsid";
+    public static final String WS_CLASS = "wsclass";
+    public static final String WS_QNAME = "wsqname";
+    public static final String WS_PORT_QNAME = "wsportqname";
+    public static final String WSDL_URL = "wsdlurl";
+
+    private static final AtomicInteger id = new AtomicInteger(31);
+    private static final Map<String,Object> registry = new HashMap<String,Object>();
+
+    public static String getProperty(Reference ref, String name) {
+        RefAddr addr = ref.get(name);
+        if (addr == null) return null;
+        Object value = addr.getContent();
+        return (String) value;
+    }
+
+    public static boolean isPropertyTrue(Reference ref, String name) {
+        RefAddr addr = ref.get(name);
+        if (addr == null) return false;
+        Object value = addr.getContent();
+        return Boolean.parseBoolean("" + value);
+    }
+
+    public static void setStaticValue(Resource resource, Object value) {
+        setStaticValue(resource, null, value);
+    }
+
+    public static void setStaticValue(Resource resource, String name, Object value) {
+        name = name != null ? "-" + name : "";
+        String token = "" + id.incrementAndGet();
+        registry.put(token, value);
+        resource.setProperty("static-token" + name, token);
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public static<T> T getStaticValue(Reference ref) {
+        return (T) getStaticValue(ref, null);
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public static <T> T getStaticValue(Reference ref, String name) {
+        name = name != null ? "-" + name : "";
+        String token = getProperty(ref, "static-token" + name);
+        if (token == null) {
+            return null;
+        }
+        T object = (T) registry.get(token);
+        return object;
+    }
+
+    public static Class<?> loadClass(String className) {
+        if (className == null) return null;
+        try {
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            if (classLoader != null) {
+                try {
+                    Class clazz = classLoader.loadClass(className);
+                    return clazz;
+                } catch(ClassNotFoundException e) {
+                }
+            }
+            return Class.forName(className);
+        } catch (ClassNotFoundException e) {
+            return null;
+        }
+    }
+
+    /**
+     * This interface exists because the class org.apache.catalina.deploy.ContextResource
+     * is not available in the common classloader in tomcat 55
+     */
+    public interface Resource {
+        void setProperty(String name, Object value);
+    }
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceContextFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceContextFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceContextFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceContextFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,55 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.naming.ResourceRef;
+import static org.apache.openejb.tomcat.naming.NamingUtil.JNDI_NAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getStaticValue;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import java.util.Hashtable;
+
+public class PersistenceContextFactory extends AbstractObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        // ignore non resource-refs
+        if (!(object instanceof ResourceRef)) {
+            return null;
+        }
+
+        Reference ref = (Reference) object;
+
+        Object value;
+        if (getProperty(ref, JNDI_NAME) != null) {
+            // lookup the value in JNDI
+            value = super.getObjectInstance(object, name, context, environment);
+        } else {
+            // value is hard hard coded in the properties
+            value = getStaticValue(ref);
+        }
+
+        return value;
+    }
+
+    protected String buildJndiName(Reference reference) throws NamingException {
+        throw new UnsupportedOperationException();
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceUnitFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceUnitFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceUnitFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/PersistenceUnitFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,55 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.naming.ResourceRef;
+import static org.apache.openejb.tomcat.naming.NamingUtil.JNDI_NAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getStaticValue;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import java.util.Hashtable;
+
+public class PersistenceUnitFactory extends AbstractObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        // ignore non resource-refs
+        if (!(object instanceof ResourceRef)) {
+            return null;
+        }
+
+        Reference ref = (Reference) object;
+
+        Object value;
+        if (getProperty(ref, JNDI_NAME) != null) {
+            // lookup the value in JNDI
+            value = super.getObjectInstance(object, name, context, environment);
+        } else {
+            // value is hard hard coded in the properties
+            value = getStaticValue(ref);
+        }
+
+        return value;
+    }
+
+    protected String buildJndiName(Reference reference) throws NamingException {
+        throw new UnsupportedOperationException();
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/ResourceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/ResourceFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/ResourceFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/ResourceFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,54 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import static org.apache.openejb.tomcat.naming.NamingUtil.NAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.RESOURCE_ID;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import java.net.URL;
+import java.util.Hashtable;
+
+public class ResourceFactory extends AbstractObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        Reference reference = ((Reference) object);
+        if (reference.getClassName().equals("java.net.URL")) {
+            String resourceId = getProperty(reference, RESOURCE_ID);
+            return new URL(resourceId);
+        }
+        return super.getObjectInstance(object, name, context, environment);
+    }
+
+    protected String buildJndiName(Reference reference) throws NamingException {
+        // get and verify interface type
+        String resourceId = getProperty(reference, RESOURCE_ID);
+        if (resourceId == null) {
+            resourceId = getProperty(reference, NAME);
+        }
+        if (resourceId == null) throw new NamingException("Resource reference id is null");
+
+        // build jndi name using the deploymentId and interface type
+        String jndiName = "java:openejb/Resource/" + resourceId;
+        return jndiName;
+    }
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/SystemComponentFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/SystemComponentFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/SystemComponentFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/SystemComponentFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,44 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.openejb.loader.SystemInstance;
+import static org.apache.openejb.tomcat.naming.NamingUtil.COMPONENT_TYPE;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+import static org.apache.openejb.tomcat.naming.NamingUtil.loadClass;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+public class SystemComponentFactory implements ObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        Reference ref = (Reference) object;
+
+        // load the component type class
+        String className = getProperty(ref, COMPONENT_TYPE);
+        Class<?> clazz = loadClass(className);
+        if (clazz == null) return null;
+
+        // lookup the value
+        Object value = SystemInstance.get().getComponent(clazz);
+        return value;
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/UserTransactionFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/UserTransactionFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/UserTransactionFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/UserTransactionFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.openejb.core.CoreUserTransaction;
+import org.apache.openejb.loader.SystemInstance;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.spi.ObjectFactory;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import java.util.Hashtable;
+
+public class UserTransactionFactory implements ObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        // get the transaction manager
+        TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
+        if (transactionManager == null) {
+            throw new NamingException("transaction manager not found");
+        }
+
+        // if transaction manager implements user transaction we are done
+        if (transactionManager instanceof UserTransaction) {
+            return transactionManager;
+        }
+
+        // wrap transaction manager with user transaction
+        return new CoreUserTransaction(transactionManager);
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/WsFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/WsFactory.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/WsFactory.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-naming/src/main/java/org/apache/openejb/tomcat/naming/WsFactory.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,126 @@
+/**
+ *
+ * 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.openejb.tomcat.naming;
+
+import org.apache.naming.ResourceRef;
+import org.apache.openejb.Injection;
+import org.apache.openejb.core.ivm.naming.JaxWsServiceReference;
+import org.apache.openejb.core.webservices.HandlerChainData;
+import org.apache.openejb.core.webservices.PortRefData;
+import static org.apache.openejb.tomcat.naming.NamingUtil.JNDI_NAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.WSDL_URL;
+import static org.apache.openejb.tomcat.naming.NamingUtil.WS_CLASS;
+import static org.apache.openejb.tomcat.naming.NamingUtil.WS_ID;
+import static org.apache.openejb.tomcat.naming.NamingUtil.WS_PORT_QNAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.WS_QNAME;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getProperty;
+import static org.apache.openejb.tomcat.naming.NamingUtil.getStaticValue;
+import static org.apache.openejb.tomcat.naming.NamingUtil.loadClass;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+
+public class WsFactory extends AbstractObjectFactory {
+    public Object getObjectInstance(Object object, Name name, Context context, Hashtable environment) throws Exception {
+        // ignore non resource-refs
+        if (!(object instanceof ResourceRef)) {
+            return null;
+        }
+
+        Reference ref = (Reference) object;
+
+        Object value;
+        if (getProperty(ref, JNDI_NAME) != null) {
+            // lookup the value in JNDI
+            value = super.getObjectInstance(object, name, context, environment);
+        } else {
+            // load service class which is used to construct the port
+            String serviceClassName = getProperty(ref, WS_CLASS);
+            Class<? extends Service> serviceClass = Service.class;
+            if (serviceClassName != null) {
+                serviceClass = loadClass(serviceClassName).asSubclass(Service.class);
+                if (serviceClass == null) {
+                    throw new NamingException("Could not load service type class "+ serviceClassName);
+                }
+            }
+
+            // load the reference class which is the ultimate type of the port
+            Class<?> referenceClass = loadClass(ref.getClassName());
+
+            // if ref class is a subclass of Service, use it for the service class
+            if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
+                serviceClass = referenceClass.asSubclass(Service.class);
+            }
+
+            // PORT ID
+            String serviceId = getProperty(ref, WS_ID);
+
+            // Service QName
+            QName serviceQName = null;
+            if (getProperty(ref, WS_QNAME) != null) {
+                serviceQName = QName.valueOf(getProperty(ref, WS_QNAME));
+            }
+
+            // WSDL URL
+            URL wsdlUrl = null;
+            if (getProperty(ref, WSDL_URL) != null) {
+                wsdlUrl = new URL(getProperty(ref, WSDL_URL));
+            }
+
+            // Port QName
+            QName portQName = null;
+            if (getProperty(ref, WS_PORT_QNAME) != null) {
+                portQName = QName.valueOf(getProperty(ref, WS_PORT_QNAME));
+            }
+
+            // port refs
+            List<PortRefData> portRefs = getStaticValue(ref, "port-refs");
+            if (portRefs == null) portRefs = Collections.emptyList();
+
+            // HandlerChain
+            List<HandlerChainData> handlerChains = getStaticValue(ref, "handler-chains");
+            if (handlerChains == null) handlerChains = Collections.emptyList();
+            List<Injection> injections = getStaticValue(ref, "injections");
+            if (injections == null) injections = Collections.emptyList();
+
+            JaxWsServiceReference serviceReference = new JaxWsServiceReference(serviceId,
+                    serviceQName,
+                    serviceClass, portQName,
+                    referenceClass,
+                    wsdlUrl,
+                    portRefs,
+                    handlerChains,
+                    injections);
+            value = serviceReference.getObject();
+        }
+
+        return value;
+    }
+
+    protected String buildJndiName(Reference reference) throws NamingException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec 27 18:22:44 2007
@@ -0,0 +1,11 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin
+

Copied: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/maven.xml (from r605804, openejb/trunk/openejb3/assembly/openejb-tomcat/maven.xml)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/maven.xml?p2=openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/maven.xml&p1=openejb/trunk/openejb3/assembly/openejb-tomcat/maven.xml&r1=605804&r2=607160&rev=607160&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/maven.xml (original)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/maven.xml Thu Dec 27 18:22:44 2007
@@ -31,6 +31,7 @@
       <j:set var="tomcat.version" value="5.5.23"/>
       <j:set var="tomcat.prefix" value="apache"/>
       <j:set var="tomcat.server.lib" value="server/lib"/>
+      <j:set var="tomcat.server.webapps" value="server/webapps"/>
       <attainGoal name="tomcat.env"/>
     </goal>
 
@@ -74,7 +75,7 @@
 
     <goal name="setup:tomcat">
       <j:set var="targetDir" value="${basedir}/target/"/>
-      <j:set var="tomcat.download" value="http://www.apache.org/dist/tomcat/tomcat-${tomcat.branch}/v${tomcat.version}/bin/${tomcat.prefix}-tomcat-${tomcat.version}.zip"/>
+      <j:set var="tomcat.download" value="http://archive.apache.org/dist/tomcat/tomcat-${tomcat.branch}/v${tomcat.version}/bin/${tomcat.prefix}-tomcat-${tomcat.version}.zip"/>
 
       <j:set var="tomcat.src" value="${maven.repo.local}/tomcat/distributions/${tomcat.prefix}-tomcat-${tomcat.version}.zip"/>
       <j:set var="tomcat.dist" value="${maven.repo.local}/tomcat/distributions/${tomcat.prefix}-tomcat-${tomcat.version}.zip"/>
@@ -108,7 +109,7 @@
     <goal name="setup:tomcat-src">
       <j:set var="targetDir" value="${basedir}/src/"/>
 
-      <j:set var="tomcat.download" value="http://www.apache.org/dist/tomcat/tomcat-${tomcat.branch}/v${tomcat.version}/src/${tomcat.prefix}-tomcat-${tomcat.version}-src.zip"/>
+      <j:set var="tomcat.download" value="http://archive.apache.org/dist/tomcat/tomcat-${tomcat.branch}/v${tomcat.version}/src/${tomcat.prefix}-tomcat-${tomcat.version}-src.zip"/>
       <j:set var="tomcat.dist" value="${maven.repo.local}/tomcat/distributions/${tomcat.prefix}-tomcat-${tomcat.version}-src.zip"/>
 
       <!-- Download tomcat if it isn't in the repo -->
@@ -187,7 +188,7 @@
     <goal name="setup:loader-webapp">
       <!-- Unzip openejb war -->
       <mkdir dir="${tomcat.webapps}/openejb"/>
-      <unjar src="${basedir}/target/openejb-tomcat-${openejb.version}.war" dest="${tomcat.webapps}/openejb"/>
+      <unjar src="${basedir}/target/openejb-tomcat-webapp-${openejb.version}.war" dest="${tomcat.webapps}/openejb"/>
     </goal>
 
     <goal name="setup:itests:ejb-jar">

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/pom.xml?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/pom.xml (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/pom.xml Thu Dec 27 18:22:44 2007
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<!-- $Rev: 600338 $ $Date: 2007-12-02 09:08:04 -0800 (Sun, 02 Dec 2007) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>openejb-tomcat</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>3.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-tomcat-webapp</artifactId>
+  <packaging>jar</packaging>
+  <name>OpenEJB :: Assembly :: Tomcat :: Webapp</name>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>attached</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <appendAssemblyId>false</appendAssemblyId>
+          <descriptor>src/main/assembly/war.xml</descriptor>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy</id>
+            <phase>process-resources</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.openejb</groupId>
+                  <artifactId>openejb-itests-standalone-client</artifactId>
+                  <version>${version}</version>
+                  <outputDirectory>${project.build.directory}</outputDirectory>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.openejb</groupId>
+                  <artifactId>openejb-itests-web</artifactId>
+                  <version>${version}</version>
+                  <type>war</type>
+                  <outputDirectory>${project.build.directory}</outputDirectory>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.openejb</groupId>
+                  <artifactId>openejb-itests-beans</artifactId>
+                  <version>${version}</version>
+                  <outputDirectory>${project.build.directory}</outputDirectory>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>junit</groupId>
+                  <artifactId>junit</artifactId>
+                  <version>4.1</version>
+                  <outputDirectory>${project.build.directory}</outputDirectory>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-loader</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>${version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.geronimo.modules</groupId>
+          <artifactId>geronimo-kernel</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.geronimo.modules</groupId>
+          <artifactId>geronimo-webservices</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.geronimo.modules</groupId>
+          <artifactId>geronimo-naming</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.geronimo.modules</groupId>
+          <artifactId>geronimo-timer</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.geronimo.modules</groupId>
+          <artifactId>geronimo-security</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-cxf</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.javamail</groupId>
+      <artifactId>geronimo-javamail_1.4_mail</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jaxr_1.0_spec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-saaj_1.1_spec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-client</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-tomcat-naming</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-server</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-ejbd</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-hsql</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-http</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-telnet</artifactId>
+      <version>${version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-client</artifactId>
+      <version>${version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-itests-beans</artifactId>
+      <version>${version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>catalina</artifactId>
+      <version>6.0.13</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>naming-factory</artifactId>
+      <version>5.5.23</version>
+      <optional>true</optional>
+    </dependency>
+  </dependencies>
+</project>

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/BackportUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/BackportUtil.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/BackportUtil.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/BackportUtil.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,144 @@
+/**
+ * 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.openejb.tomcat;
+
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.deploy.NamingResources;
+import org.apache.catalina.core.NamingContextListener;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardWrapper;
+import org.apache.catalina.deploy.ContextService;
+
+import javax.servlet.Servlet;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BackportUtil {
+
+    private static API api;
+
+    static {
+        if (TomcatVersion.v6.isTheVersion()){
+            api = new Tomcat6();
+        } else {
+            api = new Tomcat55();
+        }
+    }
+
+    private static API getAPI() {
+        return api;
+    }
+
+    public static Servlet getServlet(Wrapper wrapper) {
+        return getAPI().getServlet(wrapper);
+    }
+
+    public static NamingContextListener getNamingContextListener(StandardContext standardContext) {
+        return getAPI().getNamingContextListener(standardContext);
+    }
+
+    public static String findServiceName(NamingResources naming, String refName) {
+        return getAPI().findServiceName(naming, refName);
+    }
+
+    public static void removeService(NamingContextListener namingContextListener, String serviceName) {
+        getAPI().removeService(namingContextListener, serviceName);
+    }
+
+    public static interface API {
+        Servlet getServlet(Wrapper wrapper);
+        String findServiceName(NamingResources naming, String refName);
+        NamingContextListener getNamingContextListener(StandardContext standardContext);
+        void removeService(NamingContextListener namingContextListener, String serviceName);
+    }
+
+
+    public static class Tomcat6 implements API {
+        public Servlet getServlet(Wrapper wrapper) {
+            return wrapper.getServlet();
+        }
+
+        public NamingContextListener getNamingContextListener(StandardContext standardContext) {
+            return standardContext.getNamingContextListener();
+        }
+
+        public String findServiceName(NamingResources naming, String referenceName) {
+            ContextService service = naming.findService(referenceName);
+            return (service != null)?service.getName():null;
+        }
+
+        public void removeService(NamingContextListener namingContextListener, String serviceName) {
+            namingContextListener.removeService(serviceName);
+        }
+    }
+
+    public static class Tomcat55 implements API {
+        private final Field namingContextListener;
+        private final Field instance;
+
+        public Tomcat55() {
+            namingContextListener = getField(StandardContext.class, "namingContextListener");
+            instance = getField(StandardWrapper.class, "instance");
+        }
+
+
+        public Servlet getServlet(Wrapper wrapper) {
+            try {
+                return (Servlet) instance.get(wrapper);
+            } catch (IllegalAccessException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        public NamingContextListener getNamingContextListener(StandardContext standardContext) {
+            try {
+                return (NamingContextListener) namingContextListener.get(standardContext);
+            } catch (IllegalAccessException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        public String findServiceName(NamingResources naming, String refName) {
+            return null;
+        }
+
+        public void removeService(NamingContextListener namingContextListener, String serviceName) {
+        }
+
+        private Field getField(final Class clazz, final String name) {
+            return (Field) AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    try {
+                        Field field = clazz.getDeclaredField(name);
+                        field.setAccessible(true);
+                        return field;
+                    } catch (Exception e2) {
+                        throw (IllegalStateException) new IllegalStateException("Unable to find or access the '"+name+"' field in "+clazz.getName()).initCause(e2);
+                    }
+                }
+            });
+        }
+
+    }
+
+
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/LegacyAnnotationProcessorListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/LegacyAnnotationProcessorListener.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/LegacyAnnotationProcessorListener.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/LegacyAnnotationProcessorListener.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,54 @@
+/**
+ * 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.openejb.tomcat;
+
+import org.apache.openejb.tomcat.naming.LegacyAnnotationProcessor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LegacyAnnotationProcessorListener {
+    protected final LegacyAnnotationProcessor annotationProcessor;
+
+    public LegacyAnnotationProcessorListener(LegacyAnnotationProcessor annotationProcessor) {
+        this.annotationProcessor = annotationProcessor;
+    }
+
+    protected void postConstruct(Object object) {
+        try {
+            annotationProcessor.postConstruct(object);
+        } catch (Exception e) {
+            throw new IllegalStateException("PostConstruct Failed " + object.getClass(), e);
+        }
+    }
+
+    protected void processAnnotations(Object object) {
+        try {
+            annotationProcessor.processAnnotations(object);
+        } catch (Exception e) {
+            throw new IllegalStateException("Dependency Injection Failed " + object.getClass(), e);
+        }
+    }
+
+    protected void preDestroy(Object object) {
+        try {
+            annotationProcessor.preDestroy(object);
+        } catch (Exception e) {
+            throw new IllegalStateException("PreDestroy Failed " + object.getClass(), e);
+        }
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedListenersListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedListenersListener.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedListenersListener.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedListenersListener.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,117 @@
+/**
+ * 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.openejb.tomcat;
+
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.core.StandardContext;
+import org.apache.openejb.tomcat.naming.LegacyAnnotationProcessor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeSet;
+
+/**
+ * The StandardContext only calls these events for the listeners in the
+ * getApplicationLifecycleListeners() list and not for any listeners in the
+ * getApplicationEventListeners() list.  This is a big pain as we need to
+ * do annotation processing for both.  The code gets a bit tricky as a result.
+ *
+ * Note this class only pertains to Tomcat 5.5.x and before, not 6.0.x and after.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProcessAnnotatedListenersListener extends LegacyAnnotationProcessorListener implements ContainerListener {
+    private Object[] applicationLifecycleListeners;
+    private TreeSet destroyed;
+
+    public ProcessAnnotatedListenersListener(LegacyAnnotationProcessor annotationProcessor) {
+        super(annotationProcessor);
+    }
+
+    public void containerEvent(ContainerEvent event) {
+        String type = event.getType();
+        if ("beforeContextInitialized".equals(type)) {
+            listenerStart(event);
+        } else if ("afterContextDestroyed".equals(type)) {
+            listenerStop(event);
+        }
+    }
+
+    /**
+     * We must process all the listeners on the very first "beforeContextInitialized" event of this Container
+     * @param event
+     */
+    private void listenerStart(ContainerEvent event) {
+        if (!isFirstBeforeContextInitializedEvent(event)) return;
+
+        StandardContext standardContext = (StandardContext) event.getContainer();
+
+        for (Object listener : getListeners(standardContext)) {
+            processAnnotations(listener);
+            postConstruct(listener);
+        }
+    }
+
+    private boolean isFirstBeforeContextInitializedEvent(ContainerEvent event) {
+        if (applicationLifecycleListeners != null) return false;
+
+        StandardContext standardContext = (StandardContext) event.getContainer();
+        applicationLifecycleListeners = standardContext.getApplicationLifecycleListeners();
+        destroyed = new TreeSet();
+        return true;
+    }
+
+    /**
+     * We must process all the listeners on the very last "afterContextDestroyed" event of this Container
+     *
+     * Looking at the code it's possible that if a ContainerListener threw an exception in the
+     * afterContextDestroyed event that the afterContextDestroyed will get fired again in the catch block,
+     * so we need to watch for that.  We use a set to ensure we can track uniqe events.
+     * @param event
+     */
+    private void listenerStop(ContainerEvent event) {
+        if (!isLastAfterContextDestroyedEvent(event)) return;
+
+        StandardContext standardContext = (StandardContext) event.getContainer();
+
+        for (Object listener : getListeners(standardContext)) {
+            preDestroy(listener);
+        }
+    }
+
+    private boolean isLastAfterContextDestroyedEvent(ContainerEvent event) {
+        // Something very strange is going on if either of these are null at this stage
+        if (destroyed == null || applicationLifecycleListeners == null) return false;
+
+        // We've already been called and processed our last event
+        if (destroyed.size() == applicationLifecycleListeners.length) return false;
+
+        Object listener = event.getData();
+        destroyed.add(listener);
+
+        return (destroyed.size() == applicationLifecycleListeners.length);
+    }
+
+    private List getListeners(StandardContext standardContext) {
+        ArrayList listeners = new ArrayList();
+        for (Object o : standardContext.getApplicationEventListeners()) listeners.add(o);
+        for (Object o : standardContext.getApplicationLifecycleListeners()) listeners.add(o);
+        return listeners;
+    }
+
+}

Added: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedServletsListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedServletsListener.java?rev=607160&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedServletsListener.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/java/org/apache/openejb/tomcat/ProcessAnnotatedServletsListener.java Thu Dec 27 18:22:44 2007
@@ -0,0 +1,55 @@
+/**
+ * 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.openejb.tomcat;
+
+import org.apache.catalina.InstanceEvent;
+import org.apache.catalina.InstanceListener;
+import org.apache.openejb.tomcat.naming.LegacyAnnotationProcessor;
+
+/**
+ * Processes annotations for a v5 Tomcat install
+ * Listener is added to each StandardWrapper
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProcessAnnotatedServletsListener extends LegacyAnnotationProcessorListener implements InstanceListener {
+
+    public ProcessAnnotatedServletsListener(LegacyAnnotationProcessor annotationProcessor) {
+        super(annotationProcessor);
+    }
+
+    public void instanceEvent(InstanceEvent event) {
+        String type = event.getType();
+        if (InstanceEvent.BEFORE_INIT_EVENT.equals(type)) {
+            beforeInit(event);
+        } else if (InstanceEvent.AFTER_DESTROY_EVENT.equals(type)) {
+            afterDestroy(event);
+        }
+    }
+
+    private void beforeInit(InstanceEvent event) {
+        Object object = event.getServlet();
+        processAnnotations(object);
+        postConstruct(object);
+    }
+
+    private void afterDestroy(InstanceEvent event) {
+        Object object = event.getServlet();
+        preDestroy(object);
+    }
+
+}