[jboss-cvs] JBossAS SVN: r98966 - in projects/jboss-jca/trunk: fungal/src/main/java/org/jboss/jca/fungal/deployment and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 2 15:11:47 EST 2010


Author: jesper.pedersen
Date: 2010-01-02 15:11:47 -0500 (Sat, 02 Jan 2010)
New Revision: 98966

Added:
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/FactoryType.java
Modified:
   projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/ConstructorType.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
   projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java
   projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd
Log:
[JBJCA-252] Support factory bean in deployment

Modified: projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml
===================================================================
--- projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/doc/developerguide/en/modules/fungal.xml	2010-01-02 20:11:47 UTC (rev 98966)
@@ -88,6 +88,10 @@
           <para>defines a parameter value for a constructor.</para>
         </listitem>
         <listitem>
+          <code>&lt;factory&gt;</code>
+          <para>defines a factory bean for a constructor.</para>
+        </listitem>
+        <listitem>
           <code>&lt;depends&gt;</code>
           <para>defines an explicit dependency to another bean.</para>
         </listitem>

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/ConstructorType.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/ConstructorType.java	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/ConstructorType.java	2010-01-02 20:11:47 UTC (rev 98966)
@@ -32,6 +32,7 @@
 public class ConstructorType
 {
    private List<ParameterType> parameter;
+   private FactoryType factory;
    private String factoryMethod;
    private String factoryClass;
    
@@ -41,6 +42,7 @@
    public ConstructorType()
    {
       parameter = null;
+      factory = null;
       factoryMethod = null;
       factoryClass = null;
    }
@@ -58,6 +60,24 @@
    }
 
    /**
+    * Get the factory
+    * @return The value
+    */
+   public FactoryType getFactory()
+   {
+      return factory;
+   }
+   
+   /**
+    * Set the factory
+    * @param value The value
+    */
+   public void setFactory(FactoryType value)
+   {
+      factory = value;
+   }
+
+   /**
     * Get the factory method
     * @return The value
     */

Added: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/FactoryType.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/FactoryType.java	                        (rev 0)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/FactoryType.java	2010-01-02 20:11:47 UTC (rev 98966)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.fungal.deployment;
+
+/**
+ * Represents a factory element
+ */
+public class FactoryType
+{
+   private String bean;
+
+   /**
+    * Constructor
+    */
+   public FactoryType()
+   {
+      bean = null;
+   }
+
+   /**
+    * Get the bean
+    * @return The value
+    */
+   public String getBean()
+   {
+      return bean;
+   }
+
+   /**
+    * Set the bean
+    * @param value The value
+    */
+   public void setBean(String value)
+   {
+      bean = value;
+   }
+}

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/deployment/Unmarshaller.java	2010-01-02 20:11:47 UTC (rev 98966)
@@ -232,7 +232,13 @@
                String name = xmlStreamReader.getLocalName();
 
                if ("parameter".equals(name))
+               {
                   result.getParameter().add(readParameter(xmlStreamReader));
+               }
+               else if ("factory".equals(name))
+               {
+                  result.setFactory(readFactory(xmlStreamReader));
+               }
 
                break;
             default :
@@ -797,4 +803,36 @@
 
       return result;
    }
+
+   /**
+    * Read: <factory>
+    * @param xmlStreamReader The XML stream
+    * @return The factory
+    * @exception XMLStreamException Thrown if an exception occurs
+    */
+   private FactoryType readFactory(XMLStreamReader xmlStreamReader) throws XMLStreamException
+   {
+      FactoryType result = new FactoryType();
+
+      for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++)
+      {
+         String name = xmlStreamReader.getAttributeLocalName(i);
+         if ("bean".equals(name))
+         {
+            result.setBean(xmlStreamReader.getAttributeValue(i));
+         }
+      }
+
+      int eventCode = xmlStreamReader.next();
+
+      while (eventCode != XMLStreamReader.END_ELEMENT)
+      {
+         eventCode = xmlStreamReader.next();
+      }
+
+      if (!"factory".equals(xmlStreamReader.getLocalName()))
+         throw new XMLStreamException("factory tag not completed");
+
+      return result;
+   }
 }

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/DeploymentDeployer.java	2010-01-02 20:11:47 UTC (rev 98966)
@@ -283,6 +283,7 @@
             for (DependsType dt : dts)
             {
                result.add(dt.getValue());
+               kernel.addBeanDependants(bt.getName(), dt.getValue());
             }
          }
 
@@ -300,12 +301,21 @@
                {
                   InjectType it = (InjectType)element;
                   result.add(it.getBean());
-
-                  kernel.addBeanDependants(it.getBean(), bt.getName());
+                  kernel.addBeanDependants(bt.getName(), it.getBean());
                }
             }
          }
 
+         ConstructorType ct = bt.getConstructor();
+         if (ct != null && ct.getFactory() != null)
+         {
+            if (result == null)
+               result = new HashSet<String>();
+
+            result.add(ct.getFactory().getBean());
+            kernel.addBeanDependants(bt.getName(), ct.getFactory().getBean());
+         }
+
          return result;
       }
 
@@ -357,16 +367,23 @@
          else
          {
             ConstructorType ct = bt.getConstructor();
-            Class factoryClass = Class.forName(ct.getFactoryClass(), true, cl);
+            Object factoryObject = null;
             Method factoryMethod = null;
             Object[] args = null;
 
-            if (ct.getParameter().size() == 0)
+            if (ct.getParameter().size() == 0 && ct.getFactory() == null)
             {
+               Class factoryClass = Class.forName(ct.getFactoryClass(), true, cl);
                factoryMethod = factoryClass.getMethod(ct.getFactoryMethod(), (Class[])null);
             }
+            else if (ct.getParameter().size() == 0 && ct.getFactory() != null)
+            {
+               factoryObject = kernel.getBean(ct.getFactory().getBean());
+               factoryMethod = factoryObject.getClass().getMethod(ct.getFactoryMethod(), (Class[])null);
+            }
             else
             {
+               Class factoryClass = Class.forName(ct.getFactoryClass(), true, cl);
                Method[] factoryMethods = factoryClass.getMethods();
             
                List<Method> candidates = new ArrayList<Method>();
@@ -443,7 +460,7 @@
                }
             }
 
-            instance = factoryMethod.invoke((Object)null, args);
+            instance = factoryMethod.invoke(factoryObject, args);
             clz = instance.getClass();
          }
 

Modified: projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/fungal/src/main/java/org/jboss/jca/fungal/impl/KernelImpl.java	2010-01-02 20:11:47 UTC (rev 98966)
@@ -405,6 +405,9 @@
          }
       }
 
+      // Log shutdown
+      info(VERSION + " stopped");
+
       // Reset to the old class loader
       SecurityActions.setThreadContextClassLoader(oldClassLoader);
    }

Modified: projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd
===================================================================
--- projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd	2010-01-02 16:35:59 UTC (rev 98965)
+++ projects/jboss-jca/trunk/fungal/src/main/resources/deployment.xsd	2010-01-02 20:11:47 UTC (rev 98966)
@@ -43,11 +43,16 @@
    <xsd:complexType name="constructorType">
      <xsd:sequence>
        <xsd:element name="parameter" type="parameterType" maxOccurs="unbounded" minOccurs="0"/>
+       <xsd:element name="factory" type="factoryType" maxOccurs="1" minOccurs="0"/>
      </xsd:sequence>
      <xsd:attribute name="factoryMethod" type="xsd:token"/>
      <xsd:attribute name="factoryClass" type="xsd:token"/>
    </xsd:complexType>
 
+   <xsd:complexType name="factoryType">
+     <xsd:attribute name="bean" type="xsd:token"/>
+   </xsd:complexType>
+
    <xsd:complexType name="mapType">
      <xsd:sequence>
        <xsd:element name="entry" type="entryType" maxOccurs="unbounded" minOccurs="0"/>




More information about the jboss-cvs-commits mailing list