You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ec...@apache.org on 2008/03/28 08:03:32 UTC

svn commit: r642103 - in /geronimo/samples/branches/1.0/migration-jca: ./ meta/geronimo/ meta/jboss/ src/com/ibm/j2g/jca/ src/org/ src/org/apache/ src/org/apache/geronimo/ src/org/apache/geronimo/demo/ src/org/apache/geronimo/demo/jca/ src/org/apache/g...

Author: ecraig
Date: Fri Mar 28 00:03:29 2008
New Revision: 642103

URL: http://svn.apache.org/viewvc?rev=642103&view=rev
Log:
GERONIMO-3910
Cleaned up samples/branches/1.0/migration-jca


Added:
    geronimo/samples/branches/1.0/migration-jca/src/org/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnection.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnectionFactory.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionFactoryImpl.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionImpl.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnection.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionFactory.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionMetaData.java
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/
    geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/FileRetrieverServlet.java
Removed:
    geronimo/samples/branches/1.0/migration-jca/src/com/ibm/j2g/jca/
Modified:
    geronimo/samples/branches/1.0/migration-jca/build.xml
    geronimo/samples/branches/1.0/migration-jca/meta/geronimo/jca-plan.xml
    geronimo/samples/branches/1.0/migration-jca/meta/geronimo/ra.xml
    geronimo/samples/branches/1.0/migration-jca/meta/jboss/jca-ds.xml
    geronimo/samples/branches/1.0/migration-jca/meta/jboss/ra.xml
    geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/geronimo-web.xml
    geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/web.xml
    geronimo/samples/branches/1.0/migration-jca/web/index.jsp

Modified: geronimo/samples/branches/1.0/migration-jca/build.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/build.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/build.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/build.xml Fri Mar 28 00:03:29 2008
@@ -93,7 +93,7 @@
             <arg value="--password"/>
             <arg value="${geronimo.password}"/>
             <arg value="undeploy"/>
-            <arg value="com/ibm/j2g/jca.war"/>
+            <arg value="org/apache/geronimo/demo/jca.war"/>
         </java>
 
         <java jar="${geronimo.home}/bin/deployer.jar" fork="true">
@@ -102,7 +102,7 @@
             <arg value="--password"/>
             <arg value="${geronimo.password}"/>
             <arg value="undeploy"/>
-            <arg value="com/ibm/j2g/jca.rar"/>
+            <arg value="org/apache/geronimo/demo/jca.rar"/>
         </java>
 
         <java jar="${geronimo.home}/bin/deployer.jar" fork="true">

Modified: geronimo/samples/branches/1.0/migration-jca/meta/geronimo/jca-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/meta/geronimo/jca-plan.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/meta/geronimo/jca-plan.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/meta/geronimo/jca-plan.xml Fri Mar 28 00:03:29 2008
@@ -19,13 +19,13 @@
 <!-- This is Geronimo-specific descriptor -->
 
 <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector" version="1.5"
-        configId="com/ibm/j2g/jca.rar" 
+        configId="org/apache/geronimo/demo/jca.rar" 
         parentId="org/apache/geronimo/Server">
 
     <resourceadapter>
         <outbound-resourceadapter>
             <connection-definition>
-                <connectionfactory-interface>com.ibm.j2g.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
+                <connectionfactory-interface>org.apache.geronimo.demo.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
                 <connectiondefinition-instance>
                     <name>FileRetriever</name>
                     <config-property-setting name="RepositoryPath">..</config-property-setting>

Modified: geronimo/samples/branches/1.0/migration-jca/meta/geronimo/ra.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/meta/geronimo/ra.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/meta/geronimo/ra.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/meta/geronimo/ra.xml Fri Mar 28 00:03:29 2008
@@ -23,22 +23,22 @@
         version="1.5">
 
     <display-name>FileRetriever</display-name>
-    <vendor-name>IBM</vendor-name>
+    <vendor-name>Apache</vendor-name>
     <eis-type>File system</eis-type>
     <resourceadapter-version>1.0</resourceadapter-version>
     <resourceadapter>
         <outbound-resourceadapter>
             <connection-definition>
-                <managedconnectionfactory-class>com.ibm.j2g.jca.connector.impl.FileRetrieverManagedConnectionFactory</managedconnectionfactory-class>
+                <managedconnectionfactory-class>org.apache.geronimo.demo.jca.connector.impl.FileRetrieverManagedConnectionFactory</managedconnectionfactory-class>
                 <config-property>
                     <description>Path to the directory being the file repository</description>
                     <config-property-name>RepositoryPath</config-property-name>
                     <config-property-type>java.lang.String</config-property-type>
                 </config-property>
-                <connectionfactory-interface>com.ibm.j2g.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
-                <connectionfactory-impl-class>com.ibm.j2g.jca.connector.impl.FileRetrieverConnectionFactoryImpl</connectionfactory-impl-class>
-                <connection-interface>com.ibm.j2g.jca.connector.FileRetrieverConnection</connection-interface>
-                <connection-impl-class>com.ibm.j2g.jca.connector.impl.FileRetrieverConnectionImpl</connection-impl-class>
+                <connectionfactory-interface>org.apache.geronimo.demo.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
+                <connectionfactory-impl-class>org.apache.geronimo.demo.jca.connector.impl.FileRetrieverConnectionFactoryImpl</connectionfactory-impl-class>
+                <connection-interface>org.apache.geronimo.demo.jca.connector.FileRetrieverConnection</connection-interface>
+                <connection-impl-class>org.apache.geronimo.demo.jca.connector.impl.FileRetrieverConnectionImpl</connection-impl-class>
             </connection-definition>
             <transaction-support>NoTransaction</transaction-support>
             <reauthentication-support>false</reauthentication-support>

Modified: geronimo/samples/branches/1.0/migration-jca/meta/jboss/jca-ds.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/meta/jboss/jca-ds.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/meta/jboss/jca-ds.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/meta/jboss/jca-ds.xml Fri Mar 28 00:03:29 2008
@@ -27,7 +27,7 @@
     <no-tx-connection-factory>
         <jndi-name>FileRetriever</jndi-name>
         <rar-name>jca.rar</rar-name>
-        <connection-definition>com.ibm.j2g.jca.connector.FileRetrieverConnectionFactory</connection-definition>
+        <connection-definition>org.apache.geronimo.demo.jca.connector.FileRetrieverConnectionFactory</connection-definition>
         <config-property name="RepositoryPath" type="java.lang.String">..</config-property>
     </no-tx-connection-factory>
 

Modified: geronimo/samples/branches/1.0/migration-jca/meta/jboss/ra.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/meta/jboss/ra.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/meta/jboss/ra.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/meta/jboss/ra.xml Fri Mar 28 00:03:29 2008
@@ -23,23 +23,23 @@
         version="1.5">
 
     <display-name>FileRetriever</display-name>
-    <vendor-name>IBM</vendor-name>
+    <vendor-name>Apache</vendor-name>
     <eis-type>File system</eis-type>
     <resourceadapter-version>1.0</resourceadapter-version>
     <resourceadapter>
         <resourceadapter-class>org.jboss.resource.deployment.DummyResourceAdapter</resourceadapter-class>
         <outbound-resourceadapter>
             <connection-definition>
-                <managedconnectionfactory-class>com.ibm.j2g.jca.connector.impl.FileRetrieverManagedConnectionFactory</managedconnectionfactory-class>
+                <managedconnectionfactory-class>org.apache.geronimo.jca.connector.impl.FileRetrieverManagedConnectionFactory</managedconnectionfactory-class>
                 <config-property>
                     <description>Path to the directory being the file repository</description>
                     <config-property-name>RepositoryPath</config-property-name>
                     <config-property-type>java.lang.String</config-property-type>
                 </config-property>
-                <connectionfactory-interface>com.ibm.j2g.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
-                <connectionfactory-impl-class>com.ibm.j2g.jca.connector.impl.FileRetrieverConnectionFactoryImpl</connectionfactory-impl-class>
-                <connection-interface>com.ibm.j2g.jca.connector.FileRetrieverConnection</connection-interface>
-                <connection-impl-class>com.ibm.j2g.jca.connector.impl.FileRetrieverConnectionImpl</connection-impl-class>
+                <connectionfactory-interface>org.apache.geronimo.jca.connector.FileRetrieverConnectionFactory</connectionfactory-interface>
+                <connectionfactory-impl-class>org.apache.geronimo.jca.connector.impl.FileRetrieverConnectionFactoryImpl</connectionfactory-impl-class>
+                <connection-interface>org.apache.geronimo.jca.connector.FileRetrieverConnection</connection-interface>
+                <connection-impl-class>org.apache.geronimo.jca.connector.impl.FileRetrieverConnectionImpl</connection-impl-class>
             </connection-definition>
             <transaction-support>NoTransaction</transaction-support>
             <reauthentication-support>false</reauthentication-support>

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnection.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnection.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnection.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnection.java Fri Mar 28 00:03:29 2008
@@ -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.demo.jca.connector;
+
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+
+import javax.resource.ResourceException;
+
+public interface FileRetrieverConnection {
+
+    /**
+     * Retrieves file and writes its content to the output stream.
+     * @param name name of the file to retrieve
+     * @param stream output stream for writing the file content
+     *     (opening and closing the stream is performed by client)
+     * @throws ResourceException in case of any problem
+     * @throws FileNotFoundException if the file is not found
+     */
+    public void retrieve(String name, OutputStream stream) 
+        throws ResourceException, FileNotFoundException;
+    
+    /**
+     * Retrieves names of files available in the repository
+     * @return array of file names 
+     * @throws ResourceException in case of any problem
+     */
+    public String[] listFiles() throws ResourceException;
+    
+    /**
+     * Retrieves names of directories available in the repository
+     * @return array of directory names 
+     * @throws ResourceException in case of any problem
+     */
+    public String[] listDirectories() throws ResourceException;
+    
+    /**
+     * Closes the connection and all opened file streams
+     * @throws ResourceException in case of any problem
+     */
+    public void close() throws ResourceException;
+}
\ No newline at end of file

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnectionFactory.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnectionFactory.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnectionFactory.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/FileRetrieverConnectionFactory.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,29 @@
+/*
+* 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.demo.jca.connector;
+
+import javax.resource.ResourceException;
+
+public interface FileRetrieverConnectionFactory {
+
+    /**
+     * Retrieves instance of the File Retriever connection
+     * @return File Retriever connection instance
+     * @throws ResourceException in case of any problem
+     */
+    public FileRetrieverConnection getConnection() throws ResourceException;
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionFactoryImpl.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionFactoryImpl.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionFactoryImpl.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,72 @@
+/*
+* 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.demo.jca.connector.impl;
+
+import java.io.Serializable;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.resource.Referenceable;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.apache.geronimo.demo.jca.connector.FileRetrieverConnection;
+import org.apache.geronimo.demo.jca.connector.FileRetrieverConnectionFactory;
+
+
+public class FileRetrieverConnectionFactoryImpl implements
+        FileRetrieverConnectionFactory, Serializable, Referenceable {
+
+    /** Managed connection factory */
+    private ManagedConnectionFactory mcf;
+
+    /** Connection manager */
+    private ConnectionManager cm;
+
+    /** JNDI reference */
+    private Reference reference;
+
+    /**
+     * The constructor
+     * @param factory managed connection factory
+     * @param cm connection manager
+     */
+    public FileRetrieverConnectionFactoryImpl(ManagedConnectionFactory factory,
+            ConnectionManager cm) {
+        this.mcf = factory;
+        this.cm = cm;
+    }
+
+    public FileRetrieverConnection getConnection() throws ResourceException {
+        return (FileRetrieverConnection) cm.allocateConnection(mcf, null);
+    }
+
+    /*
+     * @see javax.resource.Referenceable#setReference(javax.naming.Reference)
+     */
+    public void setReference(Reference reference) {
+        this.reference = reference;
+    }
+
+    /*
+     * @see javax.naming.Referenceable#getReference()
+     */
+    public Reference getReference() throws NamingException {
+        return reference;
+    }
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionImpl.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionImpl.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionImpl.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverConnectionImpl.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,86 @@
+/*
+* 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.demo.jca.connector.impl;
+
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+
+import javax.resource.ResourceException;
+
+import org.apache.geronimo.demo.jca.connector.FileRetrieverConnection;
+
+
+public class FileRetrieverConnectionImpl implements FileRetrieverConnection {
+    
+    /** Underlying physical connection instance */
+    private FileRetrieverManagedConnection mc;
+    
+    /**
+     * The constructor
+     * @param mc underlying physical connection instance
+     */
+    public FileRetrieverConnectionImpl(FileRetrieverManagedConnection mc) {
+        this.mc = mc;
+    }
+    
+    /**
+     * Associates this handle with given underlying physical
+     * connection instance
+     * @param newMc underlying physical connection instance
+     */
+    public void associateConnection(FileRetrieverManagedConnection newMc) {
+        this.mc.removeConnection(this);
+        newMc.addConnection(this);
+        this.mc = newMc;
+    }
+
+    /**
+     * Invalidates the connection
+     */
+    public void invalidate() {
+        mc = null;
+    }
+
+    /*
+     * @see org.apache.geronimo.demo.jca.FileRetrieverConnection#retrieve(java.lang.String, java.io.OutputStream)
+     */
+    public void retrieve(String name, OutputStream stream)
+            throws ResourceException, FileNotFoundException {
+        mc.retrieve(name, stream);
+    }
+
+    /*
+     * @see org.apache.geronimo.demo.jca.FileRetrieverConnection#listFiles()
+     */
+    public String[] listFiles() throws ResourceException {
+        return mc.listFiles();
+    }
+
+    /*
+     * @see org.apache.geronimo.demo.jca.FileRetrieverConnection#listDirectories()
+     */
+    public String[] listDirectories() throws ResourceException {
+        return mc.listDirectories();
+    }
+    
+    /*
+     * @see org.apache.geronimo.demo.jca.FileRetrieverConnection#close()
+     */
+    public void close() throws ResourceException {
+        mc.close(this);
+    }
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnection.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnection.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnection.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnection.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,302 @@
+/*
+* 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.demo.jca.connector.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionEvent;
+import javax.resource.spi.ConnectionEventListener;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.LocalTransaction;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionMetaData;
+import javax.security.auth.Subject;
+import javax.transaction.xa.XAResource;
+
+public class FileRetrieverManagedConnection implements ManagedConnection {
+
+    /** Log writer */
+    private PrintWriter writer;
+
+    /** List of listeners */
+    private List listeners;
+
+    /** Path to the repository containing files to retireve */
+    private String path;
+
+    /** Set of application-level handlers */
+    private Set connectionSet;
+
+    /**
+     * The constructor
+     * @param conReqInfo {@link ConnectionRequestInfo}
+     * @param writer log writer of the factory that calls this constructor
+     * @param repositoryPath path to the repository containing files to retireve
+     */
+    public FileRetrieverManagedConnection(ConnectionRequestInfo conReqInfo,
+            PrintWriter writer, String repositoryPath) {
+        this.writer = writer;
+        this.listeners = new ArrayList();
+        this.connectionSet = new HashSet();
+        this.path = repositoryPath;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#getConnection(javax.security.auth.Subject,
+     *      javax.resource.spi.ConnectionRequestInfo)
+     */
+    public Object getConnection(Subject subj, ConnectionRequestInfo conReqInfo)
+            throws ResourceException {
+        if (this.path == null) {
+            throw new ResourceException("Path to a repository is null");
+        }
+        
+        File repository = new File(this.path);
+        if (!repository.exists() || !repository.isDirectory()) {
+            throw new ResourceException("Path [" + repository.getAbsolutePath()
+                    + "] does not lead to a repository");
+        }
+        FileRetrieverConnectionImpl conn = new FileRetrieverConnectionImpl(this);
+        addConnection(conn);
+        return conn;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#destroy()
+     */
+    public void destroy() throws ResourceException {
+        invalidateAllConnections();
+        synchronized (this.listeners) {
+            listeners = null;
+        }
+        path = null;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#cleanup()
+     */
+    public void cleanup() throws ResourceException {
+        invalidateAllConnections();
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#associateConnection(java.lang.Object)
+     */
+    public void associateConnection(Object conn) throws ResourceException {
+        if (!(conn instanceof FileRetrieverConnectionImpl)) {
+            throw new ResourceException("Connection has an incorrect type");
+        }
+        ((FileRetrieverConnectionImpl)conn).associateConnection(this);
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#addConnectionEventListener(javax.resource.spi.ConnectionEventListener)
+     */
+    public void addConnectionEventListener(ConnectionEventListener listener) {
+        synchronized (this.listeners) {
+            listeners.add(listener);
+        }
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#removeConnectionEventListener(javax.resource.spi.ConnectionEventListener)
+     */
+    public void removeConnectionEventListener(ConnectionEventListener listener) {
+        synchronized (this.listeners) {
+            listeners.remove(listener);
+        }
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#getXAResource()
+     */
+    public XAResource getXAResource() throws ResourceException {
+        throw new NotSupportedException("XA transactions are not supported");
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#getLocalTransaction()
+     */
+    public LocalTransaction getLocalTransaction() throws ResourceException {
+        throw new NotSupportedException("Transactions are not supported");
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#getMetaData()
+     */
+    public ManagedConnectionMetaData getMetaData() throws ResourceException {
+        return new FileRetrieverManagedConnectionMetaData();
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#setLogWriter(java.io.PrintWriter)
+     */
+    public void setLogWriter(PrintWriter out) throws ResourceException {
+        this.writer = out;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnection#getLogWriter()
+     */
+    public PrintWriter getLogWriter() throws ResourceException {
+        return writer;
+    }
+
+    /**
+     * Removes application-level handler from handlers set
+     * @param con handler to remove
+     * @see FileRetrieverConnectionImpl#associateConnection(FileRetrieverManagedConnection)
+     */
+    void removeConnection(FileRetrieverConnectionImpl con) {
+        synchronized (this.connectionSet) {
+            connectionSet.remove(con);
+        }
+    }
+
+    /**
+     * Adds application-level handler to handlers set
+     * @param con handler to add
+     * @see FileRetrieverConnectionImpl#associateConnection(FileRetrieverManagedConnection)
+     */
+    void addConnection(FileRetrieverConnectionImpl con) {
+        synchronized (this.connectionSet) {
+            connectionSet.add(con);
+        }
+    }
+
+    /**
+     * Invalidate all application-level handlers and clears handlers set
+     */
+    void invalidateAllConnections() {
+        synchronized (this.connectionSet) {
+            Iterator itr = connectionSet.iterator();
+            while (itr.hasNext()) {
+                FileRetrieverConnectionImpl con = (FileRetrieverConnectionImpl) itr
+                        .next();
+                con.invalidate();
+            }
+            connectionSet.clear();
+        }
+    }
+
+    /**
+     * Retrieves file and writes its content to the output stream.
+     * @param name name of the file to retrieve
+     * @param stream output stream for writing the file content
+     *     (opening and closing the stream is performed by client)
+     * @throws ResourceException in case of any problem
+     * @throws FileNotFoundException if the file is not found
+     */
+    public void retrieve(String name, OutputStream stream) 
+            throws ResourceException, FileNotFoundException {
+        if (stream == null) {
+            throw new ResourceException("File output stream is null");
+        }
+
+        FileInputStream fin = new FileInputStream(this.path + File.separatorChar + name);
+
+        // Writing the file to the output stream
+        try {
+            byte buffer[] = new byte[1024];
+            int count = 0;
+            while ((count = fin.read(buffer)) > 0) {
+                stream.write(buffer, 0, count);
+            }
+        
+        } catch (IOException e) {
+            new ResourceException(e.getMessage());
+
+        } finally {
+            try {
+                fin.close();
+            } catch (IOException e) {
+                new ResourceException(e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Closes connection
+     * @param con connection to close
+     */
+    public void close(FileRetrieverConnectionImpl con) {
+        ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
+        synchronized (this.listeners) {
+            Iterator itr = listeners.iterator();
+            while (itr.hasNext()) {
+                try {
+                    ((ConnectionEventListener)itr.next()).connectionClosed(event);
+                } catch (Throwable e) {
+                }
+            }
+        }
+        con.invalidate();
+        removeConnection(con);
+    }
+
+    /**
+     * Retrieves names of files available in the repository
+     * @return array of file names 
+     * @throws ResourceException in case of any problem
+     */
+    public String[] listFiles() throws ResourceException {
+        SortedSet names = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+        
+        File repository = new File(this.path);
+        File[] files = repository.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            if (files[i].isFile()) {
+                names.add(files[i].getName());
+            }
+        }
+
+        return (String[])names.toArray(new String[names.size()]);
+    }
+    
+    /**
+     * Retrieves names of directories available in the repository
+     * @return array of directory names 
+     * @throws ResourceException in case of any problem
+     */
+    public String[] listDirectories() throws ResourceException {
+        SortedSet names = new TreeSet(String.CASE_INSENSITIVE_ORDER);
+        
+        File repository = new File(this.path);
+        File[] files = repository.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            if (files[i].isDirectory()) {
+                names.add(files[i].getName());
+            }
+        }
+
+        return (String[])names.toArray(new String[names.size()]);
+    }
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionFactory.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionFactory.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionFactory.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionFactory.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,136 @@
+/*
+* 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.demo.jca.connector.impl;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.security.auth.Subject;
+
+public class FileRetrieverManagedConnectionFactory
+        implements ManagedConnectionFactory {
+
+    /** Log writer */
+    private transient PrintWriter writer;
+
+    /** Path to file system repository */
+    private String repository;
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory(javax.resource.spi.ConnectionManager)
+     */
+    public Object createConnectionFactory(ConnectionManager cm)
+            throws ResourceException {
+        return new FileRetrieverConnectionFactoryImpl(this, cm);
+    }
+
+    /* 
+     * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory()
+     */
+    public Object createConnectionFactory() throws ResourceException {
+        return new FileRetrieverConnectionFactoryImpl(this, null);
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#createManagedConnection(javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo)
+     */
+    public ManagedConnection createManagedConnection(
+            Subject subj,
+            ConnectionRequestInfo conReqInfo)
+            throws ResourceException {
+        return new FileRetrieverManagedConnection(conReqInfo, writer, repository);
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#matchManagedConnections(java.util.Set, javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo)
+     */
+    public ManagedConnection matchManagedConnections(
+            Set set, Subject subj, ConnectionRequestInfo conReqInfo)
+            throws ResourceException {
+        Iterator itr = set.iterator();
+        if (itr.hasNext()) {
+            Object obj = itr.next();
+            if (obj instanceof FileRetrieverManagedConnection) {
+                return (FileRetrieverManagedConnection)obj;
+            }
+        }
+        return null;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#setLogWriter(java.io.PrintWriter)
+     */
+    public void setLogWriter(PrintWriter out) throws ResourceException {
+        this.writer = out;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#getLogWriter()
+     */
+    public PrintWriter getLogWriter() throws ResourceException {
+        return writer;
+    }
+    
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#hashCode()
+     */
+    public int hashCode() {
+        if (repository == null) {
+            return super.hashCode();
+        } else {
+            return repository.hashCode(); 
+        }
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionFactory#equals(java.lang.Object)
+     */
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof FileRetrieverManagedConnectionFactory)) {
+            return false;
+        }
+        if (repository == null) {
+            return false;
+        }
+        return repository.equals(((FileRetrieverManagedConnectionFactory)obj).getRepositoryPath());
+    }
+    
+    /**
+     * Returns path to file system repository
+     * @return path to file system repository
+     */
+    public String getRepositoryPath() {
+        return repository;
+    }
+
+    /**
+     * Sets path to file system repository
+     * @param path path to file system repository
+     */
+    public void setRepositoryPath(String path) {
+        this.repository = path;
+    }
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionMetaData.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionMetaData.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionMetaData.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/connector/impl/FileRetrieverManagedConnectionMetaData.java Fri Mar 28 00:03:29 2008
@@ -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.demo.jca.connector.impl;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ManagedConnectionMetaData;
+
+public class FileRetrieverManagedConnectionMetaData implements
+        ManagedConnectionMetaData {
+
+    /** Default instance of the class */
+    public final static FileRetrieverManagedConnectionMetaData INSTANCE = 
+            new FileRetrieverManagedConnectionMetaData();
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionMetaData#getEISProductName()
+     */
+    public String getEISProductName() throws ResourceException {
+        return "File system EIS";
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionMetaData#getEISProductVersion()
+     */
+    public String getEISProductVersion() throws ResourceException {
+        return "1.0";
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionMetaData#getMaxConnections()
+     */
+    public int getMaxConnections() throws ResourceException {
+        return 0;
+    }
+
+    /*
+     * @see javax.resource.spi.ManagedConnectionMetaData#getUserName()
+     */
+    public String getUserName() throws ResourceException {
+        return "Unknown";
+    }
+}

Added: geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/FileRetrieverServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/FileRetrieverServlet.java?rev=642103&view=auto
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/FileRetrieverServlet.java (added)
+++ geronimo/samples/branches/1.0/migration-jca/src/org/apache/geronimo/demo/jca/web/FileRetrieverServlet.java Fri Mar 28 00:03:29 2008
@@ -0,0 +1,85 @@
+/*
+* 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.demo.jca.web;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.naming.NamingException;
+import javax.resource.ResourceException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.geronimo.demo.jca.connector.FileRetrieverConnection;
+import org.apache.geronimo.demo.jca.connector.FileRetrieverConnectionFactory;
+
+
+public class FileRetrieverServlet extends HttpServlet {
+
+    /** Name of the reference to the File Retriever connector described in the web.xml file */
+    private final static String CONNECTOR_REF_NAME = "java:comp/env/ra/FileRetriever";
+
+    /**
+     * Returns connection to the File Retriever
+     * @return File Retriever connection instance
+     * @throws NamingException in case the File Retriever EIS is not found
+     * @throws ResourceException in case of any problem with File Retriever
+     */
+    public FileRetrieverConnection getConnection() throws NamingException, ResourceException {
+        javax.naming.InitialContext ctx = new javax.naming.InitialContext();
+        FileRetrieverConnectionFactory factory = 
+                (FileRetrieverConnectionFactory)ctx.lookup(CONNECTOR_REF_NAME);
+        return factory.getConnection();
+    }
+    
+    /*
+     * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    protected void service(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        String file = request.getParameter("file");
+        if (file == null) {
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+            return;
+        }
+        
+        FileRetrieverConnection connection = null;
+        try {
+            connection = getConnection();
+            response.setContentType("application/x-download");
+            response.setHeader("Content-Disposition", "attachment; filename=" + file);
+            connection.retrieve(file, response.getOutputStream());
+            
+        } catch (FileNotFoundException fnfe) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            
+        } catch (Exception e) {
+            throw new ServletException(e);
+        
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (ResourceException re) {
+                }
+            }
+        }
+    }
+    
+}

Modified: geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/geronimo-web.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/geronimo-web.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/geronimo-web.xml Fri Mar 28 00:03:29 2008
@@ -19,8 +19,8 @@
 <!-- This is Geronimo-specific descriptor -->
 
 <web-app xmlns="http://geronimo.apache.org/xml/ns/web" 
-        configId="com/ibm/j2g/jca.war"
-        parentId="com/ibm/j2g/jca.rar">
+        configId="org/apache/geronimo/demo/jca.war"
+        parentId="org/apache/geronimo/demo/jca.rar">
 
     <context-root>/jca</context-root>
 

Modified: geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/web.xml?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/web.xml (original)
+++ geronimo/samples/branches/1.0/migration-jca/web/WEB-INF/web.xml Fri Mar 28 00:03:29 2008
@@ -24,7 +24,7 @@
 
     <servlet>
         <servlet-name>FileRetrieverServlet</servlet-name>
-        <servlet-class>com.ibm.j2g.jca.web.FileRetrieverServlet</servlet-class>
+        <servlet-class>org.apache.geronimo.jca.web.FileRetrieverServlet</servlet-class>
     </servlet>
     <servlet-mapping>
         <servlet-name>FileRetrieverServlet</servlet-name>
@@ -33,7 +33,7 @@
 
     <resource-ref>
         <res-ref-name>ra/FileRetriever</res-ref-name>
-        <res-type>com.ibm.j2g.jca.connector.FileRetrieverConnectionFactory</res-type>
+        <res-type>org.apache.geronimo.jca.connector.FileRetrieverConnectionFactory</res-type>
         <res-auth>Container</res-auth>
         <res-sharing-scope>Shareable</res-sharing-scope>
     </resource-ref>

Modified: geronimo/samples/branches/1.0/migration-jca/web/index.jsp
URL: http://svn.apache.org/viewvc/geronimo/samples/branches/1.0/migration-jca/web/index.jsp?rev=642103&r1=642102&r2=642103&view=diff
==============================================================================
--- geronimo/samples/branches/1.0/migration-jca/web/index.jsp (original)
+++ geronimo/samples/branches/1.0/migration-jca/web/index.jsp Fri Mar 28 00:03:29 2008
@@ -17,7 +17,7 @@
 <%@ page language="java"
     contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"
-    import="com.ibm.j2g.jca.connector.*"
+    import="org.apache.geronimo.demo.jca.connector.*"
 %>
 
 <%!