[jboss-cvs] JBossAS SVN: r109120 - in projects/jboss-jca/trunk/doc/userguide/en: modules and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 4 06:23:31 EDT 2010


Author: jeff.zhang
Date: 2010-11-04 06:23:30 -0400 (Thu, 04 Nov 2010)
New Revision: 109120

Added:
   projects/jboss-jca/trunk/doc/userguide/en/modules/sample.xml
Modified:
   projects/jboss-jca/trunk/doc/userguide/en/master.xml
Log:
[JBJCA-459] add helloworld sample into user guide document

Modified: projects/jboss-jca/trunk/doc/userguide/en/master.xml
===================================================================
--- projects/jboss-jca/trunk/doc/userguide/en/master.xml	2010-11-04 09:49:28 UTC (rev 109119)
+++ projects/jboss-jca/trunk/doc/userguide/en/master.xml	2010-11-04 10:23:30 UTC (rev 109120)
@@ -15,6 +15,7 @@
         <!ENTITY community SYSTEM "modules/community.xml">
         <!ENTITY troubleshooting SYSTEM "modules/troubleshooting.xml">
         <!ENTITY schemas SYSTEM "modules/schemas.xml">
+        <!ENTITY sample SYSTEM "modules/sample.xml">
         ]>
 <book lang="en">
    <bookinfo>
@@ -60,4 +61,6 @@
 
    &schemas;
 
+   &sample;
+
 </book>

Added: projects/jboss-jca/trunk/doc/userguide/en/modules/sample.xml
===================================================================
--- projects/jboss-jca/trunk/doc/userguide/en/modules/sample.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/doc/userguide/en/modules/sample.xml	2010-11-04 10:23:30 UTC (rev 109120)
@@ -0,0 +1,1396 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix id="sample">
+  <title>Sample</title>
+
+  <section id="sample_helloworld">
+    <title>Helloworld Sample</title>
+
+    <section id="sample_resourceadpater">
+      <title>Helloworld Resource Adapter</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.util.logging.Logger;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ConfigProperty;
+import javax.resource.spi.Connector;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.TransactionSupport;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+
+import javax.transaction.xa.XAResource;
+
+/**
+ * HelloWorldResourceAdapter
+ *
+ * @version $Revision: $
+ */
+ at Connector(
+   reauthenticationSupport = false,
+   transactionSupport = TransactionSupport.TransactionSupportLevel.NoTransaction)
+public class HelloWorldResourceAdapter implements ResourceAdapter
+{
+   /** The logger */
+   private static Logger log = Logger.getLogger("HelloWorldResourceAdapter");
+
+   /** Name property */
+   @ConfigProperty(defaultValue = "AS 7", supportsDynamicUpdates = true)
+   private String name;
+
+   /**
+    * default constructor
+    */
+   public HelloWorldResourceAdapter()
+   {
+   }
+
+   /** 
+    * set name
+    * @param name The value
+    */
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   /** 
+    * get name
+    * @return The value
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * This is called during the activation of a message endpoint.
+    *
+    * @param endpointFactory a message endpoint factory instance.
+    * @param spec an activation spec JavaBean instance.
+    * @throws ResourceException generic exception 
+    */
+   public void endpointActivation(MessageEndpointFactory endpointFactory,
+                                  ActivationSpec spec) throws ResourceException
+   {
+   }
+
+   /**
+    * This is called when a message endpoint is deactivated. 
+    *
+    * @param endpointFactory a message endpoint factory instance.
+    * @param spec an activation spec JavaBean instance.
+    */
+   public void endpointDeactivation(MessageEndpointFactory endpointFactory,
+                                    ActivationSpec spec)
+   {
+   }
+
+   /**
+    * This is called when a resource adapter instance is bootstrapped.
+    *
+    * @param ctx a bootstrap context containing references 
+    * @throws ResourceAdapterInternalException indicates bootstrap failure.
+    */
+   public void start(BootstrapContext ctx)
+      throws ResourceAdapterInternalException
+   {
+   }
+
+   /**
+    * This is called when a resource adapter instance is undeployed or
+    * during application server shutdown. 
+    */
+   public void stop()
+   {
+   }
+
+   /**
+    * This method is called by the application server during crash recovery.
+    *
+    * @param specs an array of ActivationSpec JavaBeans 
+    * @throws ResourceException generic exception 
+    * @return an array of XAResource objects
+    */
+   public XAResource[] getXAResources(ActivationSpec[] specs)
+      throws ResourceException
+   {
+      return null;
+   }
+
+   /** 
+    * Returns a hash code value for the object.
+    * @return a hash code value for this object.
+    */
+   @Override
+   public int hashCode()
+   {
+      int result = 17;
+      if (name != null)
+         result += 31 * result + 7 * name.hashCode();
+      else
+         result += 31 * result + 7;
+      return result;
+   }
+
+   /** 
+    * Indicates whether some other object is equal to this one.
+    * @param   other   the reference object with which to compare.
+    * @return true if this object is the same as the obj argument; false otherwise.
+    */
+   @Override
+   public boolean equals(Object other)
+   {
+      if (other == null)
+         return false;
+      if (other == this)
+         return true;
+      if (!(other instanceof HelloWorldResourceAdapter))
+         return false;
+      HelloWorldResourceAdapter obj = (HelloWorldResourceAdapter)other;
+      boolean result = true; 
+      if (result)
+      {
+         if (name == null)
+            result = obj.getName() == null;
+         else
+            result = name.equals(obj.getName());
+      }
+      return result;
+   }
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_mcf">
+      <title>Helloworld Managed Connection Factory</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionDefinition;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterAssociation;
+
+import javax.security.auth.Subject;
+
+/**
+ * HelloWorldManagedConnectionFactory
+ *
+ * @version $Revision: $
+ */
+ at ConnectionDefinition(connectionFactory = HelloWorldConnectionFactory.class,
+   connectionFactoryImpl = HelloWorldConnectionFactoryImpl.class,
+   connection = HelloWorldConnection.class,
+   connectionImpl = HelloWorldConnectionImpl.class)
+public class HelloWorldManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /** The logger */
+   private static Logger log = Logger.getLogger("HelloWorldManagedConnectionFactory");
+
+   /** The resource adapter */
+   private ResourceAdapter ra;
+
+   /** The logwriter */
+   private PrintWriter logwriter;
+
+   /**
+    * default constructor
+    */
+   public HelloWorldManagedConnectionFactory()
+   {
+   }
+
+   /**
+    * Creates a Connection Factory instance. 
+    *
+    * @return   EIS-specific Connection Factory instance or javax.resource.cci.ConnectionFactory instance
+    * @throws   ResourceException Generic exception
+    */
+   public Object createConnectionFactory() throws ResourceException
+   {
+      return createConnectionFactory(new HelloWorldConnectionManager());
+   }
+
+   /**
+    * Creates a Connection Factory instance. 
+    *
+    * @param    cxManager    ConnectionManager to be associated with created EIS connection factory instance
+    * @return   EIS-specific Connection Factory instance or javax.resource.cci.ConnectionFactory instance
+    * @throws   ResourceException Generic exception
+    */
+   public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
+   {
+      return new HelloWorldConnectionFactoryImpl(this, cxManager);
+   }
+
+   /**
+    * Creates a new physical connection to the underlying EIS resource manager.
+    *
+    * @param   subject        Caller's security information
+    * @param   cxRequestInfo  Additional resource adapter specific connection request information
+    * @throws  ResourceException     generic exception
+    * @return  ManagedConnection instance 
+    */
+   public ManagedConnection createManagedConnection(Subject subject,
+                                                    ConnectionRequestInfo cxRequestInfo) 
+      throws ResourceException
+   {
+      return new HelloWorldManagedConnection(this);
+   }
+
+   /**
+    * Returns a matched connection from the candidate set of connections. 
+    *
+    * @param   connectionSet   candidate connection set
+    * @param   subject        Caller's security information
+    * @param   cxRequestInfo  Additional resource adapter specific connection request information
+    * @throws  ResourceException     generic exception
+    * @return  ManagedConnection if resource adapter finds an acceptable match otherwise null 
+    */
+   public ManagedConnection matchManagedConnections(Set connectionSet,
+                                                    Subject subject, ConnectionRequestInfo cxRequestInfo) 
+      throws ResourceException
+   {
+      ManagedConnection result = null;
+
+      Iterator it = connectionSet.iterator();
+      while (result == null && it.hasNext()) 
+      {
+         ManagedConnection mc = (ManagedConnection)it.next();
+         if (mc instanceof HelloWorldManagedConnection) 
+         {
+            HelloWorldManagedConnection hwmc = (HelloWorldManagedConnection)mc;
+            result = hwmc;
+         }
+      }
+
+      return result;
+   }
+
+   /**
+    * Get the log writer for this ManagedConnectionFactory instance.
+    *
+    * @return  PrintWriter
+    * @throws  ResourceException     generic exception
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      return logwriter;
+   }
+
+   /**
+    * Set the log writer for this ManagedConnectionFactory instance.
+    *
+    * @param   out PrintWriter - an out stream for error logging and tracing
+    * @throws  ResourceException     generic exception
+    */
+   public void setLogWriter(PrintWriter out) throws ResourceException
+   {
+      logwriter = out;
+   }
+
+   /**
+    * Get the resource adapter
+    *
+    * @return The handle
+    */
+   public ResourceAdapter getResourceAdapter()
+   {
+      return ra;
+   }
+
+   /**
+    * Set the resource adapter
+    *
+    * @param ra The handle
+    */
+   public void setResourceAdapter(ResourceAdapter ra)
+   {
+      this.ra = ra;
+   }
+
+   /** 
+    * Returns a hash code value for the object.
+    * @return a hash code value for this object.
+    */
+   @Override
+   public int hashCode()
+   {
+      int result = 17;
+      return result;
+   }
+
+   /** 
+    * Indicates whether some other object is equal to this one.
+    * @param   other   the reference object with which to compare.
+    * @return true if this object is the same as the obj argument; false otherwise.
+    */
+   @Override
+   public boolean equals(Object other)
+   {
+      if (other == null)
+         return false;
+      if (other == this)
+         return true;
+      if (!(other instanceof HelloWorldManagedConnectionFactory))
+         return false;
+      HelloWorldManagedConnectionFactory obj = (HelloWorldManagedConnectionFactory)other;
+      boolean result = true; 
+      return result;
+   }
+
+
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_mc">
+      <title>Helloworld Managed Connection</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import javax.resource.NotSupportedException;
+import javax.resource.ResourceException;
+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;
+
+/**
+ * HelloWorldManagedConnection
+ *
+ * @version $Revision: $
+ */
+public class HelloWorldManagedConnection implements ManagedConnection
+{
+   /** The logger */
+   private static Logger log = Logger.getLogger("HelloWorldManagedConnection");
+
+   /** MCF */
+   private HelloWorldManagedConnectionFactory mcf;
+
+   /** Log writer */
+   private PrintWriter logWriter;
+
+   /** Listeners */
+   private List<ConnectionEventListener> listeners;
+
+   /** Connection */
+   private Object connection;
+
+   /**
+    * default constructor
+    * @param mcf mcf
+    */
+   public HelloWorldManagedConnection(HelloWorldManagedConnectionFactory mcf)
+   {
+      this.mcf = mcf;
+      this.logWriter = null;
+      this.listeners = new ArrayList<ConnectionEventListener>(1);
+      this.connection = null;
+   }
+
+   /**
+    * Creates a new connection handle for the underlying physical connection 
+    * represented by the ManagedConnection instance. 
+    *
+    * @param        subject        security context as JAAS subject
+    * @param        cxRequestInfo  ConnectionRequestInfo instance
+    * @return       generic Object instance representing the connection handle. 
+    * @throws  ResourceException     generic exception if operation fails
+    */
+   public Object getConnection(Subject subject,
+                               ConnectionRequestInfo cxRequestInfo) 
+      throws ResourceException
+   {
+      connection = new HelloWorldConnectionImpl(mcf);
+
+      return connection;
+   }
+
+   /**
+    * Used by the container to change the association of an 
+    * application-level connection handle with a ManagedConneciton instance.
+    *
+    * @param   connection  Application-level connection handle
+    * @throws  ResourceException     generic exception if operation fails
+    */
+   public void associateConnection(Object connection) throws ResourceException
+   {
+      this.connection = connection;
+   }
+
+   /**
+    * Application server calls this method to force any cleanup on the ManagedConnection instance.
+    *
+    * @throws    ResourceException     generic exception if operation fails
+    */
+   public void cleanup() throws ResourceException
+   {
+   }
+
+   /**
+    * Destroys the physical connection to the underlying resource manager.
+    *
+    * @throws    ResourceException     generic exception if operation fails
+    */
+   public void destroy() throws ResourceException
+   {
+      this.connection = null;
+   }
+
+   /**
+    * Adds a connection event listener to the ManagedConnection instance.
+    *
+    * @param  listener   a new ConnectionEventListener to be registered
+    */
+   public void addConnectionEventListener(ConnectionEventListener listener)
+   {
+      if (listener == null)
+         throw new IllegalArgumentException("Listener is null");
+
+      listeners.add(listener);
+   }
+
+   /**
+    * Removes an already registered connection event listener from the ManagedConnection instance.
+    *
+    * @param  listener   already registered connection event listener to be removed
+    */
+   public void removeConnectionEventListener(ConnectionEventListener listener)
+   {
+      if (listener == null)
+         throw new IllegalArgumentException("Listener is null");
+
+      listeners.remove(listener);
+   }
+
+   /**
+    * Gets the log writer for this ManagedConnection instance.
+    *
+    * @return  Character ourput stream associated with this Managed-Connection instance
+    * @throws ResourceException     generic exception if operation fails
+    */
+   public PrintWriter getLogWriter() throws ResourceException
+   {
+      return logWriter;
+   }
+
+   /**
+    * Sets the log writer for this ManagedConnection instance.
+    *
+    * @param      out        Character Output stream to be associated
+    * @throws     ResourceException  generic exception if operation fails
+    */
+   public void setLogWriter(PrintWriter out) throws ResourceException
+   {
+      this.logWriter = out;
+   }
+
+   /**
+    * Returns an <code>javax.resource.spi.LocalTransaction</code> instance.
+    *
+    * @return     LocalTransaction instance
+    * @throws ResourceException     generic exception if operation fails
+    */
+   public LocalTransaction getLocalTransaction() throws ResourceException
+   {
+      throw new NotSupportedException("LocalTransaction not supported");
+   }
+
+   /**
+    * Returns an <code>javax.transaction.xa.XAresource</code> instance. 
+    *
+    * @return     XAResource instance
+    * @throws ResourceException     generic exception if operation fails
+    */
+   public XAResource getXAResource() throws ResourceException
+   {
+      throw new NotSupportedException("GetXAResource not supported");
+   }
+
+   /**
+    * Gets the metadata information for this connection's underlying EIS resource manager instance. 
+    *
+    * @return ManagedConnectionMetaData instance
+    * @throws ResourceException     generic exception if operation fails
+    */
+   public ManagedConnectionMetaData getMetaData() throws ResourceException
+   {
+      return new HelloWorldManagedConnectionMetaData();
+   }
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_cf">
+      <title>Helloworld Connection Factory</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.io.Serializable;
+
+import javax.resource.Referenceable;
+import javax.resource.ResourceException;
+
+/**
+ * HelloWorldConnectionFactory
+ *
+ * @version $Revision: $
+ */
+public interface HelloWorldConnectionFactory extends Serializable, Referenceable
+{
+   /** 
+    * get connection from factory
+    *
+    * @return HelloWorldConnection instance
+    * @exception ResourceException Thrown if a connection can't be obtained
+    */
+   public HelloWorldConnection getConnection() throws ResourceException;
+
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_cfimpl">
+      <title>Helloworld Connection Factory Impl</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import javax.naming.NamingException;
+import javax.naming.Reference;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+
+/**
+ * HelloWorldConnectionFactoryImpl
+ *
+ * @version $Revision: $
+ */
+public class HelloWorldConnectionFactoryImpl implements HelloWorldConnectionFactory
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   private Reference reference;
+
+   private HelloWorldManagedConnectionFactory mcf;
+   private ConnectionManager connectionManager;
+
+   /**
+    * default constructor
+    * @param   mcf       ManagedConnectionFactory
+    * @param   cxManager ConnectionManager
+    */
+   public HelloWorldConnectionFactoryImpl(HelloWorldManagedConnectionFactory mcf,
+                                          ConnectionManager cxManager)
+   {
+      this.mcf = mcf;
+      this.connectionManager = cxManager;
+   }
+
+   /** 
+    * get connection from factory
+    *
+    * @return HelloWorldConnection instance
+    * @exception ResourceException Thrown if a connection can't be obtained
+    */
+   @Override
+   public HelloWorldConnection getConnection() throws ResourceException
+   {
+      return new HelloWorldConnectionImpl(mcf);
+   }
+
+   /**
+    * Get the Reference instance.
+    *
+    * @return Reference instance
+    * @exception NamingException Thrown if a reference can't be obtained
+    */
+   @Override
+   public Reference getReference() throws NamingException
+   {
+      return reference;
+   }
+
+   /**
+    * Set the Reference instance.
+    *
+    * @param   reference  A Reference instance
+    */
+   @Override
+   public void setReference(Reference reference)
+   {
+      this.reference = reference;
+   }
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_connection">
+      <title>Helloworld Connection</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+/**
+ * HelloWorldConnection
+ *
+ * @version $Revision: $
+ */
+public interface HelloWorldConnection
+{
+   /**
+    * helloWorld
+    * @return String
+    */
+   public String helloWorld();
+
+   /**
+    * helloWorld
+    * @param name name
+    * @return String
+    */
+   public String helloWorld(String name);
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_connectionimpl">
+      <title>Helloworld Connection Impl</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.util.logging.Logger;
+
+/**
+ * HelloWorldConnectionImpl
+ *
+ * @version $Revision: $
+ */
+public class HelloWorldConnectionImpl implements HelloWorldConnection
+{
+   /** The logger */
+   private static Logger log = Logger.getLogger("HelloWorldConnectionImpl");
+
+   /** ManagedConnectionFactory */
+   private HelloWorldManagedConnectionFactory mcf;
+
+   /**
+    * default constructor
+    * @param mcf HelloWorldManagedConnectionFactory
+    */
+   public HelloWorldConnectionImpl(HelloWorldManagedConnectionFactory mcf)
+   {
+      this.mcf = mcf;
+   }
+
+   /**
+    * call helloWorld
+    * @return String helloworld
+    */
+   public String helloWorld()
+   {
+      return helloWorld(((HelloWorldResourceAdapter)mcf.getResourceAdapter()).getName());
+   }
+
+   /**
+    * call helloWorld
+    * @param name String name
+    * @return String helloworld
+    */
+   public String helloWorld(String name)
+   {
+      return "Hello World, " + name + " !";
+   }
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_cm">
+      <title>Helloworld Connection Manager</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+
+/**
+ * HelloWorldConnectionManager
+ *
+ * @version $Revision: $
+ */
+public class HelloWorldConnectionManager implements ConnectionManager
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * default constructor
+    */
+   public HelloWorldConnectionManager()
+   {
+
+   }
+
+   /**
+    * Allocate a connection
+    *
+    * @param mcf The managed connection factory
+    * @param cri The connection request information
+    * @return Object The connection
+    * @exception ResourceException Thrown if an error occurs
+    */
+   @Override
+   public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cri) throws ResourceException
+   {
+      return null;
+   }
+
+
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_metadata">
+      <title>Helloworld Managed Connection MetaData</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import javax.resource.ResourceException;
+
+import javax.resource.spi.ManagedConnectionMetaData;
+
+/**
+ * HelloWorldManagedConnectionMetaData
+ *
+ * @version $Revision: $
+ */
+public class HelloWorldManagedConnectionMetaData implements ManagedConnectionMetaData
+{
+   /**
+    * default constructor
+    */
+   public HelloWorldManagedConnectionMetaData()
+   {
+   }
+
+   /**
+    * Returns Product name of the underlying EIS instance connected through the ManagedConnection.
+    *
+    * @return Product name of the EIS instance
+    * @throws ResourceException Thrown if an error occurs
+    */
+   @Override
+   public String getEISProductName() throws ResourceException
+   {
+      return "HelloWorld Resource Adapter";
+   }
+
+   /**
+    * Returns Product version of the underlying EIS instance connected through the ManagedConnection.
+    *
+    * @return Product version of the EIS instance
+    * @throws ResourceException Thrown if an error occurs
+    */
+   @Override
+   public String getEISProductVersion() throws ResourceException
+   {
+      return "1.0";
+   }
+
+   /**
+    * Returns maximum limit on number of active concurrent connections 
+    *
+    * @return Maximum limit for number of active concurrent connections
+    * @throws ResourceException Thrown if an error occurs
+    */
+   @Override
+   public int getMaxConnections() throws ResourceException
+   {
+      return 0;
+   }
+
+   /**
+    * Returns name of the user associated with the ManagedConnection instance
+    *
+    * @return  name of the user
+    * @throws ResourceException Thrown if an error occurs
+    */
+   @Override
+   public String getUserName() throws ResourceException
+   {
+      return null;
+   }
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_ironjacamarxml">
+      <title>Helloworld ironjacamar.xml</title>
+      <programlisting>
+<![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+
+<ironjacamar>
+  
+   <connection-definitions>
+     <connection-definition class-name="org.jboss.jca.samples.helloworld.HelloWorldManagedConnectionFactory" 
+                            jndi-name="java:/eis/HelloWorld"/>
+   </connection-definitions>
+   
+</ironjacamar>
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_testcase">
+      <title>Helloworld Connection Testcase</title>
+      <programlisting>
+<![CDATA[
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.samples.helloworld;
+
+import java.util.UUID;
+import java.util.logging.Logger;
+
+import javax.annotation.Resource;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.junit.Assert.*;
+
+
+/**
+ * ConnectorTestCase
+ *
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class ConnectorTestCase
+{
+   private static Logger log = Logger.getLogger("ConnectorTestCase");
+
+   private static String deploymentName = "ConnectorTestCase";
+
+   /**
+    * Define the deployment
+    *
+    * @return The deployment archive
+    */
+   @Deployment
+   public static ResourceAdapterArchive createDeployment()
+   {
+      ResourceAdapterArchive raa =
+         ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar");
+      JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + ".jar");
+      ja.addClasses(HelloWorldResourceAdapter.class, HelloWorldManagedConnectionFactory.class, 
+         HelloWorldManagedConnection.class, HelloWorldManagedConnectionMetaData.class, 
+         HelloWorldConnectionManager.class, HelloWorldConnectionFactory.class, 
+         HelloWorldConnectionFactoryImpl.class, HelloWorldConnection.class, HelloWorldConnectionImpl.class);
+      raa.addLibrary(ja);
+
+      return raa;
+   }
+
+   /** resource */
+   @Resource(mappedName = "java:/eis/ConnectorTestCase")
+   private HelloWorldConnectionFactory connectionFactory;
+
+   /**
+    * Test helloWorld
+    *
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testHelloWorldNoArgs() throws Throwable
+   {
+      assertNotNull(connectionFactory);
+      HelloWorldConnection connection = connectionFactory.getConnection();
+      assertNotNull(connection);
+      String result = connection.helloWorld();
+   }
+
+   /**
+    * Test helloWorld
+    *
+    * @exception Throwable Thrown if case of an error
+    */
+   @Test
+   public void testHelloWorldNameString() throws Throwable
+   {
+      assertNotNull(connectionFactory);
+      HelloWorldConnection connection = connectionFactory.getConnection();
+      assertNotNull(connection);
+      String result = connection.helloWorld(null);
+   }
+
+
+}
+
+ ]]>
+      </programlisting>
+    </section>
+
+    <section id="sample_buildxml">
+      <title>Helloworld Ant build.xml</title>
+      <programlisting>
+<![CDATA[
+<!--
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+-->
+
+<project name="jca-test" basedir="." default="rar">
+
+  <!-- ================================= 
+       Properties              
+       ================================= -->
+  <property name="build.dir" value="${basedir}/build" />
+  <property name="target.dir" value="${basedir}/target" />
+  <property name="lib.dir" value="${basedir}/lib" />
+
+  <property name="javac.debug" value="on" />
+  <property name="javac.deprecation" value="on" />
+  <property name="javac.optimize" value="off" />
+
+  <property name="junit.printsummary" value="yes" />
+  <property name="junit.haltonerror" value="no" />
+  <property name="junit.haltonfailure" value="no" />
+  <property name="junit.fork" value="yes" />
+  <property name="junit.timeout" value="60000" />
+  <property name="junit.jvm" value="" />
+  <property name="junit.jvm.options" value="-Xms128m -Xmx512m -XX:MaxPermSize=256m" />
+  <property name="junit.batchtest.haltonerror" value="no" />
+  <property name="junit.batchtest.haltonfailure" value="no" />
+  <property name="junit.batchtest.fork" value="yes" />
+  
+  <path id="lib.path.id">
+    <fileset dir="${lib.dir}">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+    
+  <path id="test.lib.path.id">
+    <fileset dir="${lib.dir}">
+      <include name="**/*.jar"/>
+    </fileset>
+    <fileset dir="${build.dir}">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+  
+  <!-- ================================= 
+       Target: compile
+       ================================= -->
+  <target name="compile">
+    <mkdir dir="${build.dir}" />
+
+    <javac srcdir="${basedir}/src/main/java"
+           destdir="${build.dir}"
+           classpathref="lib.path.id">
+    </javac> 
+  </target>
+  
+  <!-- ================================= 
+       Target: rar
+       ================================= -->
+  <target name="rar" depends="compile">
+    <mkdir dir="${target.dir}" />
+    <mkdir dir="${basedir}/src/main/resources" />
+    <jar destfile="${build.dir}/helloworld.jar"
+         basedir="${build.dir}"
+         includes="**/*.class"/>
+    <jar destfile="${target.dir}/helloworld.rar">
+      <fileset dir="${basedir}/src/main/resources" includes="META-INF/*"/>
+      <fileset dir="${build.dir}" includes="**/*.jar"/>
+    </jar>
+  </target>
+  
+      
+  <!-- ================================= 
+       Target: prepare-test
+       ================================= -->
+  <target name="prepare-test">
+    <mkdir dir="${build.dir}/test" />
+
+    <javac srcdir="src/test"
+           destdir="${build.dir}/test"
+           classpathref="test.lib.path.id"
+           debug="${javac.debug}"
+           deprecation="${javac.deprecation}"
+           optimize="${javac.optimize}">
+      <compilerarg value="-Xlint"/>
+    </javac> 
+
+    <copy todir="${build.dir}/test">
+      <fileset dir="src/main/resources"/>
+      <fileset dir="src/test/resources"/>
+    </copy>
+  </target>
+
+  <!-- ================================= 
+       Target: test
+       ================================= -->
+  <target name="test" depends="rar, prepare-test">
+    <mkdir dir="${basedir}/reports"/>
+
+    <junit dir="src/test"
+           printsummary="${junit.printsummary}"
+           haltonerror="${junit.haltonerror}"
+           haltonfailure="${junit.haltonfailure}"
+           fork="${junit.fork}"
+           timeout="${junit.timeout}">
+      
+      <jvmarg line="${junit.jvm.options}"/>
+      <sysproperty key="archives.dir" value="${target.dir}"/>
+      <sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
+      <sysproperty key="log4j.defaultInitOverride" value="true"/>
+      <sysproperty key="org.jboss.logging.Logger.pluginClass" value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
+      <sysproperty key="test.dir" value="${build.dir}/test"/>
+      <sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
+      <sysproperty key="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
+      
+      <classpath>
+        <fileset dir="${lib.dir}" includes="**/*.jar" />
+        <fileset dir="${build.dir}" includes="*.jar" />
+        <pathelement location="${build.dir}/test"/>
+      </classpath>
+      
+      <formatter type="plain"/>
+      <formatter type="xml"/>
+      
+      <batchtest todir="${basedir}/reports"
+                 haltonerror="${junit.batchtest.haltonerror}"
+                 haltonfailure="${junit.batchtest.haltonfailure}"
+                 fork="${junit.batchtest.fork}">
+        
+        <fileset dir="${build.dir}/test">
+          <include name="**/*TestCase.class"/>
+        </fileset>
+      </batchtest>
+
+    </junit>
+    
+  </target>
+  
+  <!-- ================================= 
+       Target: docs
+       ================================= -->
+  <target name="docs" depends="compile">
+    <mkdir dir="${target.dir}/docs"/>
+    <javadoc packagenames="*"
+             sourcepath="src/main/java"
+             destdir="${target.dir}/docs"
+             classpathref="lib.path.id">
+    </javadoc>
+  </target>
+  
+  <!-- ================================= 
+       Target: clean              
+       ================================= -->
+  <target name="clean">
+    <delete dir="${build.dir}"/>
+    <delete dir="${target.dir}"/>
+  </target>
+
+</project>
+
+ ]]>
+      </programlisting>
+    </section>
+
+  </section>
+
+
+</appendix>



More information about the jboss-cvs-commits mailing list