[jboss-cvs] JBossAS SVN: r112376 - in projects/jboss-jca/trunk/as/src: test/java/org/jboss/jca/as/converters and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 26 05:49:01 EDT 2011


Author: jeff.zhang
Date: 2011-10-26 05:49:01 -0400 (Wed, 26 Oct 2011)
New Revision: 112376

Added:
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactories.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactoriesImpl.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyCfParser.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyConnectionFactoryImp.java
Modified:
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSource.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSources.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DatasourcesImpl.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyDsParser.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/Main.java
   projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/TxConnectionFactory.java
   projects/jboss-jca/trunk/as/src/test/java/org/jboss/jca/as/converters/ParserTestCase.java
Log:
[JBJCA-679] converter for -ra.xml

Added: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactories.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactories.java	                        (rev 0)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactories.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.as.converters;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ * ConnectionFactories
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public interface ConnectionFactories
+{
+   /**
+    * Get the TxConnectionFactory
+    *
+    * @return the list of TxConnectionFactory
+    */
+   public List<TxConnectionFactory> getTxConnectionFactory();
+
+   /**
+    * Get the NoTxConnectionFactory
+    *
+    * @return the list of NoTxConnectionFactory
+    */
+   public List<NoTxConnectionFactory> getNoTxConnectionFactory();
+
+   /**
+   *
+   * A Tag.
+   *
+   */
+   public enum Tag
+   {
+      /** always first
+       *
+       */
+      UNKNOWN(null),
+
+      /**
+       * tx-connection-factory tag
+       */
+      TX_CONNECTION_FACTORY("tx-connection-factory"),
+
+      /**
+       * no-tx-connection-factory tag
+       */
+      NO_TX_CONNECTION_FACTORY("no-tx-connection-factory");
+
+      private final String name;
+
+      /**
+       *
+       * Create a new Tag.
+       *
+       * @param name a name
+       */
+      Tag(final String name)
+      {
+         this.name = name;
+      }
+
+      /**
+       * Get the local name of this element.
+       *
+       * @return the local name
+       */
+      public String getLocalName()
+      {
+         return name;
+      }
+
+      /**
+       * {@inheritDoc}
+       */
+      public String toString()
+      {
+         return name;
+      }
+
+      private static final Map<String, Tag> MAP;
+
+      static
+      {
+         final Map<String, Tag> map = new HashMap<String, Tag>();
+         for (Tag element : values())
+         {
+            final String name = element.getLocalName();
+            if (name != null)
+               map.put(name, element);
+         }
+         MAP = map;
+      }
+
+      /**
+      *
+      * Static method to get enum instance given localName XsdString
+      *
+      * @param localName a XsdString used as localname (typically tag name as defined in xsd)
+      * @return the enum instance
+      */
+      public static Tag forName(String localName)
+      {
+         final Tag element = MAP.get(localName);
+         return element == null ? UNKNOWN : element;
+      }
+   }
+}

Added: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactoriesImpl.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactoriesImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/ConnectionFactoriesImpl.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.as.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A ConnectionFactoriesImpl .
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class ConnectionFactoriesImpl implements ConnectionFactories
+{
+   private List<NoTxConnectionFactory> noTxConnectionFactory = new ArrayList<NoTxConnectionFactory>();
+   private List<TxConnectionFactory> txConnectionFactory = new ArrayList<TxConnectionFactory>();
+   
+   /**
+    * ConnectionFactoriesImpl
+    * @param noTxConnectionFactory noTxConnectionFactory
+    * @param txConnectionFactory txConnectionFactory
+    */
+   public ConnectionFactoriesImpl(
+         List<NoTxConnectionFactory> noTxConnectionFactory,
+         List<TxConnectionFactory> txConnectionFactory)
+   {
+      this.noTxConnectionFactory = noTxConnectionFactory;
+      this.txConnectionFactory = txConnectionFactory;
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuilder out = new StringBuilder();
+      out.append("<resource-adapter>\n");
+
+      for (ConnectionFactory cf : noTxConnectionFactory)
+      {
+         
+         out.append(cf.toString());
+      }
+      for (ConnectionFactory cf : txConnectionFactory)
+      {
+         out.append(cf.toString());
+      }
+
+      out.append("\n</resource-adapter>\n");
+      return out.toString();
+   }
+
+   @Override
+   public List<TxConnectionFactory> getTxConnectionFactory()
+   {
+      return txConnectionFactory;
+   }
+
+   @Override
+   public List<NoTxConnectionFactory> getNoTxConnectionFactory()
+   {
+      return noTxConnectionFactory;
+   }
+
+}

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSource.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSource.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSource.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -33,16 +33,9 @@
  * @author Jeff Zhang
  * @version $Revision: $
  */
-public interface DataSource
+public interface DataSource extends ConnectionFactory
 {
    /**
-    * Get the jndiName.
-    *
-    * @return the jndiName.
-    */
-   public String getJndiName();
-
-   /**
     * Get the useJavaContext.
     *
     * @return the useJavaContext.
@@ -78,70 +71,6 @@
    public String getPassword();
 
    /**
-    *
-    * get the security domain for pure security-domain security management
-    *
-    * @return the security-domain to use
-    */
-   public String getSecurityDomain();
-
-   /**
-    * Get the minPoolSize.
-    *
-    * @return the minPoolSize.
-    */
-   public Integer getMinPoolSize();
-
-   /**
-    * Get the maxPoolSize.
-    *
-    * @return the maxPoolSize.
-    */
-   public Integer getMaxPoolSize();
-
-   /**
-    * Get the blockingTimeoutMillis.
-    *
-    * @return the blockingTimeoutMillis.
-    */
-   public Long getBlockingTimeoutMillis();
-
-   /**
-    * Get the backgroundValidation.
-    *
-    * @return the backgroundValidation.
-    */
-   public Boolean isBackgroundValidation();
-
-   /**
-    * Get the backgroundValidationMillis.
-    *
-    * @return the backgroundValidationMillis.
-    */
-   public Long getBackgroundValidationMillis();
-
-   /**
-    * Get the idleTimeoutMinutes.
-    *
-    * @return the idleTimeoutMinutes.
-    */
-   public Long getIdleTimeoutMinutes();
-
-   /**
-    * Get the allocationRetryWaitMillis.
-    *
-    * @return the allocationRetryWaitMillis.
-    */
-   public Integer getAllocationRetry();
-
-   /**
-    * Get the allocationRetryWaitMillis.
-    *
-    * @return the allocationRetryWaitMillis.
-    */
-   public Long getAllocationRetryWaitMillis();
-
-   /**
     * Get the validateOnMatch.
     *
     * @return the validateOnMatch.
@@ -191,20 +120,6 @@
    public TrackStatementsEnum getTrackStatements();
 
    /**
-    * Get the prefill.
-    *
-    * @return the prefill.
-    */
-   public Boolean isPrefill();
-
-   /**
-    * Get the useFastFail.
-    *
-    * @return the useFastFail.
-    */
-   public Boolean isUseFastFail();
-
-   /**
     * Get the preparedStatementsCacheSize.
     *
     * @return the preparedStatementsCacheSize.

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSources.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSources.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DataSources.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -56,21 +56,6 @@
    public List<XaDataSource> getXaDataSource();
 
    /**
-    * Get the TxConnectionFactory
-    *
-    * @return the list of TxConnectionFactory
-    */
-   public List<TxConnectionFactory> getTxConnectionFactory();
-
-   /**
-    * Get the NoTxConnectionFactory
-    *
-    * @return the list of NoTxConnectionFactory
-    */
-   public List<NoTxConnectionFactory> getNoTxConnectionFactory();
-
-
-   /**
    *
    * A Tag.
    *
@@ -97,18 +82,8 @@
       /**
        * xa-datasource tag
        */
-      XA_DATASOURCE("xa-datasource"),
+      XA_DATASOURCE("xa-datasource");
 
-      /**
-       * tx-connection-factory tag
-       */
-      TX_CONNECTION_FACTORY("tx-connection-factory"),
-
-      /**
-       * no-tx-connection-factory tag
-       */
-      NO_TX_CONNECTION_FACTORY("no-tx-connection-factory");
-
       private final String name;
 
       /**

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DatasourcesImpl.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DatasourcesImpl.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/DatasourcesImpl.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -91,17 +91,4 @@
    {
       return xaDataSource;
    }
-
-   @Override
-   public List<TxConnectionFactory> getTxConnectionFactory()
-   {
-      return null;
-   }
-
-   @Override
-   public List<NoTxConnectionFactory> getNoTxConnectionFactory()
-   {
-      return null;
-   }
-
 }

Added: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyCfParser.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyCfParser.java	                        (rev 0)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyCfParser.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -0,0 +1,542 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.as.converters;
+
+import org.jboss.jca.common.api.metadata.Defaults;
+import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Parser for legacy ds.xml
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class LegacyCfParser extends AbstractParser
+{
+   private static final String DEFAULT_SECURITY_DOMAIN = "other";
+   private static Logger log = Logger.getLogger(LegacyCfParser.class);
+   
+   /**
+    * parse xml string to connection factory
+    * @param xmlInputStream xml file input stream
+    * @return ConnectionFactories
+    * @throws Exception exception
+    */
+   public ConnectionFactories parse(InputStream xmlInputStream) throws Exception
+   {
+      XMLStreamReader reader = null;
+
+      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+      reader = inputFactory.createXMLStreamReader(xmlInputStream);
+      try
+      {
+         return parse(reader);
+      }
+      finally
+      {
+         if (reader != null)
+            reader.close();
+      }
+   }
+
+   private void skipParse(XMLStreamReader reader) throws Exception
+   {
+      int level = 1;
+      while (reader.hasNext() && level > 0)
+      {
+         switch (reader.next()) 
+         {
+            case END_ELEMENT : 
+            {
+               level--;
+               break;
+            }
+            case START_ELEMENT : 
+            {
+               level++;
+               break;
+            }
+            default :
+               continue;
+         }
+      }
+      log.info("Skip parse " + reader.getLocalName());
+      //System.out.println("Skip parse " + reader.getLocalName());
+   }
+   
+
+   private void notSupport(XMLStreamReader reader) throws Exception
+   {
+      log.info("So far not support " + reader.getLocalName());
+   }
+
+   private ConnectionFactories parse(XMLStreamReader reader) throws Exception
+   {
+
+      ConnectionFactories connectionFactories = null;
+
+      //iterate over tags
+      int iterate;
+      try
+      {
+         iterate = reader.nextTag();
+      }
+      catch (XMLStreamException e)
+      {
+         //founding a non tag..go on. Normally non-tag found at beginning are comments or DTD declaration
+         iterate = reader.nextTag();
+      }
+      switch (iterate)
+      {
+         case END_ELEMENT : {
+            // should mean we're done, so ignore it.
+            break;
+         }
+         case START_ELEMENT : {
+
+            switch (Tag.forName(reader.getLocalName()))
+            {
+               case DATASOURCES : {
+                  notSupport(reader);
+                  return null;
+               }
+               case CONNECTION_FACTORIES : {
+                  connectionFactories = parseConnectionFactories(reader);
+                  break;
+               }
+               default :
+                  throw new UnknownTagException(reader.getLocalName());
+            }
+            break;
+         }
+         default :
+            throw new IllegalStateException();
+      }
+
+      return connectionFactories;
+
+   }
+
+   private ConnectionFactories parseConnectionFactories(XMLStreamReader reader) throws Exception
+   {
+      ArrayList<NoTxConnectionFactory> noTxConnectionFactory = new ArrayList<NoTxConnectionFactory>();
+      ArrayList<TxConnectionFactory> txConnectionFactory = new ArrayList<TxConnectionFactory>();
+
+      while (reader.hasNext())
+      {
+         switch (reader.nextTag())
+         {
+            case END_ELEMENT : {
+               if (Tag.forName(reader.getLocalName()) == Tag.CONNECTION_FACTORIES)
+               {
+                  return new ConnectionFactoriesImpl(noTxConnectionFactory, txConnectionFactory);
+               }
+               else
+               {
+                  if (DataSources.Tag.forName(reader.getLocalName()) == DataSources.Tag.UNKNOWN)
+                  {
+                     throw new UnknownTagException(reader.getLocalName());
+                  }
+               }
+               break;
+            }
+            case START_ELEMENT : {
+               switch (ConnectionFactories.Tag.forName(reader.getLocalName()))
+               {
+                  case NO_TX_CONNECTION_FACTORY : {
+                     noTxConnectionFactory.add(parseNoTxConnectionFactory(reader));
+                     break;
+                  }
+                  case TX_CONNECTION_FACTORY : {
+                     txConnectionFactory.add(parseTxConnectionFactory(reader));
+                     break;
+                  }
+                  default :
+                     skipParse(reader);
+               }
+               break;
+            }
+         }
+      }
+      throw new ParserException(reader.getLocalName());
+   }
+
+   private NoTxConnectionFactory parseNoTxConnectionFactory(XMLStreamReader reader) throws Exception
+   {
+      Map<String, String> configProperty = new HashMap<String, String>();
+      String rarName = null;
+      String connectionDefinition = null;
+
+      String poolName = null;
+
+      String jndiName = null;
+
+      Integer minPoolSize = null;
+      Integer maxPoolSize = null;
+      Boolean prefill = Defaults.PREFILL;
+      
+      Long blockingTimeoutMillis = null;
+      Long idleTimeoutMinutes = null;
+
+      Integer allocationRetry = null;
+      Long allocationRetryWaitMillis = null;
+      //Integer xaResourceTimeout = null;
+
+      Boolean backgroundValidation = Defaults.BACKGROUND_VALIDATION;
+      Long backgroundValidationMillis = null;
+      Boolean useFastFail = Defaults.USE_FAST_FAIL;
+      
+      //elements reading
+      while (reader.hasNext())
+      {
+         switch (reader.nextTag())
+         {
+            case END_ELEMENT : {
+               if (ConnectionFactories.Tag.forName(reader.getLocalName()) == 
+                  ConnectionFactories.Tag.NO_TX_CONNECTION_FACTORY)
+               {
+                  LegacyConnectionFactoryImp cfImpl = new LegacyConnectionFactoryImp(jndiName, rarName, poolName,
+                        connectionDefinition, configProperty, TransactionSupportEnum.NoTransaction);
+                  cfImpl.buildTimeOut(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
+                        allocationRetryWaitMillis, null);
+                  cfImpl.buildValidation(backgroundValidation, backgroundValidationMillis, useFastFail);
+                  cfImpl.buildCommonPool(minPoolSize, maxPoolSize, prefill, Defaults.NO_TX_SEPARATE_POOL);
+                  cfImpl.buildResourceAdapterImpl();
+                  return cfImpl;
+               }
+               else
+               {
+                  if (NoTxConnectionFactory.Tag.forName(reader.getLocalName()) == NoTxConnectionFactory.Tag.UNKNOWN)
+                  {
+                     throw new UnknownTagException(reader.getLocalName());
+                  }
+               }
+               break;
+            }
+            case START_ELEMENT : {
+               switch (NoTxConnectionFactory.Tag.forName(reader.getLocalName()))
+               {
+                  case CONFIG_PROPERTY : {
+                     configProperty.put(attributeAsString(reader, "name"), elementAsString(reader));
+                     break;
+                  }
+                  case RAR_NAME : {
+                     rarName = elementAsString(reader);
+                     break;
+                  }
+                  case CONNECTION_DEFINITION : {
+                     connectionDefinition = elementAsString(reader);
+                     break;
+                  }
+                  case JNDI_NAME : {
+                     poolName = elementAsString(reader);
+                     jndiName = "java:jboss/datasources/" + poolName;
+                     break;
+                  }
+                  case MAX_POOL_SIZE : {
+                     maxPoolSize = elementAsInteger(reader);
+                     break;
+                  }
+                  case MIN_POOL_SIZE : {
+                     minPoolSize = elementAsInteger(reader);
+                     break;
+                  }
+                  case PREFILL : {
+                     prefill = elementAsBoolean(reader);
+                     break;
+                  }
+                  case ALLOCATION_RETRY : {
+                     allocationRetry = elementAsInteger(reader);
+                     break;
+                  }
+                  case ALLOCATION_RETRY_WAIT_MILLIS : {
+                     allocationRetryWaitMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case BLOCKING_TIMEOUT_MILLIS : {
+                     blockingTimeoutMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case IDLE_TIMEOUT_MINUTES : {
+                     idleTimeoutMinutes = elementAsLong(reader);
+                     break;
+                  }
+                  case BACKGROUND_VALIDATION : {
+                     backgroundValidation = elementAsBoolean(reader);
+                     break;
+                  }
+                  case BACKGROUND_VALIDATION_MILLIS : {
+                     backgroundValidationMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case USE_FAST_FAIL : {
+                     useFastFail = elementAsBoolean(reader);
+                     break;
+                  }
+                  default :
+                     skipParse(reader);
+
+               }
+               break;
+            }
+            case CHARACTERS : {
+               break;
+            }
+         }
+      }
+      throw new ParserException();
+   }
+
+   private TxConnectionFactory parseTxConnectionFactory(XMLStreamReader reader) throws Exception
+   {
+      Map<String, String> configProperty = new HashMap<String, String>();
+      String rarName = null;
+      String connectionDefinition = null;
+
+      String poolName = null;
+
+      String jndiName = null;
+
+      Integer minPoolSize = null;
+      Integer maxPoolSize = null;
+      Boolean prefill = Defaults.PREFILL;
+      
+      Long blockingTimeoutMillis = null;
+      Long idleTimeoutMinutes = null;
+
+      Integer allocationRetry = null;
+      Long allocationRetryWaitMillis = null;
+      Integer xaResourceTimeout = null;
+
+      Boolean backgroundValidation = Defaults.BACKGROUND_VALIDATION;
+      Long backgroundValidationMillis = null;
+      Boolean useFastFail = Defaults.USE_FAST_FAIL;
+      
+      TransactionSupportEnum transactionSupport = TransactionSupportEnum.LocalTransaction;
+      Boolean noTxSeparatePool = Defaults.NO_TX_SEPARATE_POOL;
+      
+      //elements reading
+      while (reader.hasNext())
+      {
+         switch (reader.nextTag())
+         {
+            case END_ELEMENT : {
+               if (ConnectionFactories.Tag.forName(reader.getLocalName()) == 
+                  ConnectionFactories.Tag.TX_CONNECTION_FACTORY)
+               {
+                  LegacyConnectionFactoryImp cfImpl = new LegacyConnectionFactoryImp(jndiName, rarName, poolName,
+                        connectionDefinition, configProperty, transactionSupport);
+                  cfImpl.buildTimeOut(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
+                        allocationRetryWaitMillis, xaResourceTimeout);
+                  cfImpl.buildValidation(backgroundValidation, backgroundValidationMillis, useFastFail);
+                  cfImpl.buildCommonPool(minPoolSize, maxPoolSize, prefill, noTxSeparatePool);
+                  cfImpl.buildResourceAdapterImpl();
+                  return cfImpl;
+               }
+               else
+               {
+                  if (TxConnectionFactory.Tag.forName(reader.getLocalName()) == TxConnectionFactory.Tag.UNKNOWN)
+                  {
+                     throw new UnknownTagException(reader.getLocalName());
+                  }
+               }
+               break;
+            }
+            case START_ELEMENT : {
+               switch (TxConnectionFactory.Tag.forName(reader.getLocalName()))
+               {
+                  case CONFIG_PROPERTY : {
+                     configProperty.put(attributeAsString(reader, "name"), elementAsString(reader));
+                     break;
+                  }
+                  case RAR_NAME : {
+                     rarName = elementAsString(reader);
+                     break;
+                  }
+                  case CONNECTION_DEFINITION : {
+                     connectionDefinition = elementAsString(reader);
+                     break;
+                  }
+                  case JNDI_NAME : {
+                     poolName = elementAsString(reader);
+                     jndiName = "java:jboss/datasources/" + poolName;
+                     break;
+                  }
+                  case MAX_POOL_SIZE : {
+                     maxPoolSize = elementAsInteger(reader);
+                     break;
+                  }
+                  case MIN_POOL_SIZE : {
+                     minPoolSize = elementAsInteger(reader);
+                     break;
+                  }
+                  case PREFILL : {
+                     prefill = elementAsBoolean(reader);
+                     break;
+                  }
+                  case ALLOCATION_RETRY : {
+                     allocationRetry = elementAsInteger(reader);
+                     break;
+                  }
+                  case ALLOCATION_RETRY_WAIT_MILLIS : {
+                     allocationRetryWaitMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case BLOCKING_TIMEOUT_MILLIS : {
+                     blockingTimeoutMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case IDLE_TIMEOUT_MINUTES : {
+                     idleTimeoutMinutes = elementAsLong(reader);
+                     break;
+                  }
+                  case BACKGROUND_VALIDATION : {
+                     backgroundValidation = elementAsBoolean(reader);
+                     break;
+                  }
+                  case BACKGROUND_VALIDATION_MILLIS : {
+                     backgroundValidationMillis = elementAsLong(reader);
+                     break;
+                  }
+                  case USE_FAST_FAIL : {
+                     useFastFail = elementAsBoolean(reader);
+                     break;
+                  }
+                  case LOCAL_TRANSACTION : {
+                     transactionSupport = TransactionSupportEnum.LocalTransaction;
+                     break;
+                  }
+                  case XA_TRANSACTION : {
+                     transactionSupport = TransactionSupportEnum.XATransaction;
+                     break;
+                  }
+                  case NO_TX_SEPARATE_POOLS : {
+                     noTxSeparatePool = elementAsBoolean(reader);
+                     break;
+                  }
+                  case XA_RESOURCE_TIMEOUT : {
+                     xaResourceTimeout = elementAsInteger(reader);
+                     break;
+                  }
+                  default :
+                     skipParse(reader);
+
+               }
+               break;
+            }
+            case CHARACTERS : {
+               break;
+            }
+         }
+      }
+      throw new ParserException();
+   }
+
+
+   /**
+   *
+   * A Tag.
+   */
+   public enum Tag 
+   {
+      /**
+       * always first
+       */
+      UNKNOWN(null),
+
+      /**
+       * datasources tag
+       */
+      DATASOURCES("datasources"),
+
+      /**
+       * connection-factories tag
+       */
+      CONNECTION_FACTORIES("connection-factories");
+
+      private final String name;
+
+      /**
+       *
+       * Create a new Tag.
+       *
+       * @param name a name
+       */
+      Tag(final String name)
+      {
+         this.name = name;
+      }
+
+      /**
+       * Get the local name of this element.
+       *
+       * @return the local name
+       */
+      public String getLocalName()
+      {
+         return name;
+      }
+
+      private static final Map<String, Tag> MAP;
+
+      static
+      {
+         final Map<String, Tag> map = new HashMap<String, Tag>();
+         for (Tag element : values())
+         {
+            final String name = element.getLocalName();
+            if (name != null)
+               map.put(name, element);
+         }
+         MAP = map;
+      }
+
+      /**
+      *
+      * Static method to get enum instance given localName string
+      *
+      * @param localName a string used as localname (typically tag name as defined in xsd)
+      * @return the enum instance
+      */
+      public static Tag forName(String localName)
+      {
+         final Tag element = MAP.get(localName);
+         return element == null ? UNKNOWN : element;
+      }
+
+   }
+}

Added: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyConnectionFactoryImp.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyConnectionFactoryImp.java	                        (rev 0)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyConnectionFactoryImp.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -0,0 +1,299 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.as.converters;
+
+import org.jboss.jca.common.api.metadata.Defaults;
+import org.jboss.jca.common.api.metadata.common.CommonConnDef;
+import org.jboss.jca.common.api.metadata.common.CommonPool;
+import org.jboss.jca.common.api.metadata.common.TransactionSupportEnum;
+import org.jboss.jca.common.metadata.common.CommonConnDefImpl;
+import org.jboss.jca.common.metadata.common.CommonPoolImpl;
+import org.jboss.jca.common.metadata.common.CommonTimeOutImpl;
+import org.jboss.jca.common.metadata.common.CommonValidationImpl;
+import org.jboss.jca.common.metadata.resourceadapter.ResourceAdapterImpl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A LegacyConnectionFactoryImp impl.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class LegacyConnectionFactoryImp implements TxConnectionFactory
+{
+   private ResourceAdapterImpl raImpl = null;
+
+   private TransactionSupportEnum transactionSupport;
+   private List<CommonConnDef> connectionDefinitions;
+   //private List<CommonAdminObject> adminObjects;
+   //private Map<String, String> configProperties;
+   //private List<String> beanValidationGroups;
+   //private String bootstrapContext;
+
+
+   private CommonTimeOutImpl timeOut;
+
+   private CommonValidationImpl validation;
+
+   private CommonPool pool;
+
+   private String jndiName;
+   private String rarName;
+   private String poolName;
+   private String connectionDefinition;
+   private Map<String, String> configProperty;
+   
+   private Boolean noTxSeparatePool;
+   
+
+   /**
+    * create a LegacyConnectionFactoryImp
+    * 
+    * @param jndiName jndiName
+    * @param rarName rarName
+    * @param poolName poolName
+    * @param connectionDefinition connectionDefinition
+    * @param configProperty configProperty
+    * @param transactionSupport transactionSupport
+    */
+   public LegacyConnectionFactoryImp(String jndiName, String rarName, String poolName,
+         String connectionDefinition, Map<String, String> configProperty, TransactionSupportEnum transactionSupport)
+   {
+      this.jndiName = jndiName;
+      this.rarName = rarName;
+      this.poolName = poolName;
+      if (configProperty != null)
+      {
+         this.configProperty = new HashMap<String, String>(configProperty.size());
+         this.configProperty.putAll(configProperty);
+      }
+      else
+      {
+         this.configProperty = new HashMap<String, String>(0);
+      }
+      this.connectionDefinition = connectionDefinition;
+      this.transactionSupport = transactionSupport;
+   }
+   
+   /**
+    * buildResourceAdapterImpl
+    * @throws Exception exception
+    */
+   public void buildResourceAdapterImpl()  throws Exception
+   {
+      CommonConnDefImpl connDef = new CommonConnDefImpl(configProperty, connectionDefinition, jndiName, poolName, 
+            true, true, false, pool, timeOut, validation, null, null);
+      connectionDefinitions = new ArrayList<CommonConnDef>();
+      connectionDefinitions.add(connDef);
+      raImpl = new ResourceAdapterImpl(rarName, transactionSupport, connectionDefinitions, null,
+            null, null, null);
+   }
+   
+   @Override
+   public String toString()
+   {
+      String out = raImpl.toString();
+      return out;
+   }
+   
+   /**
+    * build timeout part
+    * 
+    * @param blockingTimeoutMillis blockingTimeoutMillis
+    * @param idleTimeoutMinutes idleTimeoutMinutes
+    * @param allocationRetry allocationRetry
+    * @param allocationRetryWaitMillis allocationRetryWaitMillis
+    * @param xaResourceTimeout xaResourceTimeout
+    * @return this 
+    * @throws Exception exception
+    */
+   public LegacyConnectionFactoryImp buildTimeOut(Long blockingTimeoutMillis, Long idleTimeoutMinutes, 
+         Integer allocationRetry, Long allocationRetryWaitMillis, Integer xaResourceTimeout) throws Exception
+   {
+      timeOut = new CommonTimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry,
+            allocationRetryWaitMillis, xaResourceTimeout);
+      return this;
+   }
+   
+   /**
+    * build validation part
+    * 
+    * @param backgroundValidation backgroundValidation
+    * @param backgroundValidationMillis backgroundValidationMillis
+    * @param useFastFail useFastFail
+    * @return this
+    * @throws Exception exception
+    */
+   public LegacyConnectionFactoryImp buildValidation(Boolean backgroundValidation, Long backgroundValidationMillis, 
+         Boolean useFastFail) throws Exception
+   {
+      validation = new CommonValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail);
+      return this;
+   }
+
+   /**
+    * build pool part
+    * 
+    * @param minPoolSize minPoolSize
+    * @param maxPoolSize maxPoolSize
+    * @param prefill prefill
+    * @param noTxSeparatePool noTxSeparatePool
+    * @return this
+    * @throws Exception exception
+    */
+   public LegacyConnectionFactoryImp buildCommonPool(Integer minPoolSize, Integer maxPoolSize, 
+         Boolean prefill, Boolean noTxSeparatePool) throws Exception
+   {
+      pool = new CommonPoolImpl(minPoolSize, maxPoolSize, prefill, Defaults.USE_STRICT_MIN, Defaults.FLUSH_STRATEGY);
+      this.noTxSeparatePool = noTxSeparatePool;
+      return this;
+   }
+   
+   /**
+    * build other properties
+    * 
+    * @return this
+    */
+   public LegacyConnectionFactoryImp buildOther()
+   {
+      return this;
+   }
+   
+
+   @Override
+   public String getJndiName()
+   {
+      return this.jndiName;
+   }
+
+   @Override
+   public String getSecurityDomain()
+   {
+      return null;
+   }
+
+   @Override
+   public Integer getMinPoolSize()
+   {
+      return pool.getMinPoolSize();
+   }
+
+   @Override
+   public Integer getMaxPoolSize()
+   {
+      return pool.getMaxPoolSize();
+   }
+
+   @Override
+   public Long getBlockingTimeoutMillis()
+   {
+      return this.timeOut.getBlockingTimeoutMillis();
+   }
+
+   @Override
+   public Boolean isBackgroundValidation()
+   {
+      return this.validation.isBackgroundValidation();
+   }
+
+   @Override
+   public Long getBackgroundValidationMillis()
+   {
+      return this.validation.getBackgroundValidationMillis();
+   }
+
+   @Override
+   public Long getIdleTimeoutMinutes()
+   {
+      return this.timeOut.getIdleTimeoutMinutes();
+   }
+
+   @Override
+   public Integer getAllocationRetry()
+   {
+      return this.timeOut.getAllocationRetry();
+   }
+
+   @Override
+   public Long getAllocationRetryWaitMillis()
+   {
+      return this.timeOut.getAllocationRetryWaitMillis();
+   }
+   @Override
+   public Boolean isPrefill()
+   {
+      return this.pool.isPrefill();
+   }
+
+   @Override
+   public Boolean isUseFastFail()
+   {
+      return this.validation.isUseFastFail();
+   }
+
+   @Override
+   public Boolean isNoTxSeparatePools()
+   {
+      return this.noTxSeparatePool;
+   }
+
+   
+   @Override
+   public Boolean isTrackConnectionByTx()
+   {
+      return false;
+   }
+
+   @Override
+   public Integer getXaResourceTimeout()
+   {
+      return this.timeOut.getXaResourceTimeout();
+   }
+
+   @Override
+   public String getRarName()
+   {
+      return rarName;
+   }
+
+   @Override
+   public String getConnectionDefinition()
+   {
+      return connectionDefinition;
+   }
+
+   @Override
+   public Map<String, String> getConfigProperties()
+   {
+      return configProperty;
+   }
+
+   @Override
+   public TransactionSupportEnum getTransactionSupport()
+   {
+      return null;
+   }
+}

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyDsParser.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyDsParser.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/LegacyDsParser.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -724,7 +724,7 @@
       DATASOURCES("datasources"),
 
       /**
-       * datasources tag
+       * connection-factories tag
        */
       CONNECTION_FACTORIES("connection-factories");
 

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/Main.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/Main.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/Main.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -64,34 +64,40 @@
       }
       FileInputStream in = null;
       FileOutputStream out = null;
-      String dsxml;
+      String outxml = "";
 
-      if (option.equals("-ds"))
+      try
       {
-         try
+         in = new FileInputStream(oldDsFilename);
+
+         if (option.equals("-ds"))
          {
-            in = new FileInputStream(oldDsFilename);
             LegacyDsParser parser = new LegacyDsParser();
             DataSources ds = parser.parse(in);
-            dsxml = ds.toString();
+            outxml = ds.toString();
          }
-         finally
+         else if (option.equals("-ra"))
          {
-            if (in != null)
-               in.close();
+            LegacyCfParser parser = new LegacyCfParser();
+            ConnectionFactories ds = parser.parse(in);
+            outxml = ds.toString();
          }
+      }
+      finally
+      {
+         if (in != null)
+            in.close();
+      }
+      try
+      {
+         out = new FileOutputStream(newFilename);
+         out.write(outxml.getBytes(Charset.forName("UTF-8")));
+      }
+      finally
+      {
 
-         try
-         {
-            out = new FileOutputStream(newFilename);
-            out.write(dsxml.getBytes(Charset.forName("UTF-8")));
-         }
-         finally
-         {
-
-            if (out != null)
-               out.close();
-         }
+         if (out != null)
+            out.close();
       }
 
       System.out.println("\nConvert successfully!");

Modified: projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/TxConnectionFactory.java
===================================================================
--- projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/TxConnectionFactory.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/main/java/org/jboss/jca/as/converters/TxConnectionFactory.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -67,6 +67,14 @@
       * XaResourceTimeout tag
       */
       XA_RESOURCE_TIMEOUT("xa-resource-timeout"),
+      /**
+       * local-transaction tag
+       */
+      LOCAL_TRANSACTION("local-transaction"),
+      /**
+       * xa-transaction tag
+       */
+      XA_TRANSACTION("xa-transaction"),
 
       /**
        * rar-name tag

Modified: projects/jboss-jca/trunk/as/src/test/java/org/jboss/jca/as/converters/ParserTestCase.java
===================================================================
--- projects/jboss-jca/trunk/as/src/test/java/org/jboss/jca/as/converters/ParserTestCase.java	2011-10-25 14:37:48 UTC (rev 112375)
+++ projects/jboss-jca/trunk/as/src/test/java/org/jboss/jca/as/converters/ParserTestCase.java	2011-10-26 09:49:01 UTC (rev 112376)
@@ -26,6 +26,7 @@
 
 import org.jboss.logging.Logger;
 
+//import org.junit.Ignore;
 import org.junit.Test;
 import static org.junit.Assert.*;
 
@@ -54,9 +55,7 @@
    };
    
    private String[] dsFilesName = {
-      "asapxcess-jb3.2-ds.xml",
       "hsqldb-ds.xml",
-      "cicsr9s-ds.xml",
       "hsqldb-encrypted-ds.xml",
       "oracle-ds.xml",
       "db2-400-ds.xml",
@@ -64,24 +63,29 @@
       "db2-ds.xml",
       "pointbase-ds.xml",
       "jdatastore-ds.xml",
-      "jms-ds.xml",
       "postgres-ds.xml",
       "derby-ds.xml",
       "jsql-ds.xml",
       "mimer-ds.xml",
       "progress-ds.xml",
-      "facets-ds.xml",
       "sapdb-ds.xml",
-      "fastobjects-jboss32-ds.xml",
       "msaccess-ds.xml",
-      "sapr3-ds.xml",
-      "firebird-ds.xml",
       "mssql-ds.xml",
       "solid-ds.xml",
       "sybase-ds.xml",
-      "hajndi-jms-ds.xml",
       "mysql-ds.xml"
    };
+   
+   private String[] cfFilesName = {
+      "asapxcess-jb3.2-ds.xml",
+      "cicsr9s-ds.xml",
+      "jms-ds.xml",
+      "facets-ds.xml",
+      "fastobjects-jboss32-ds.xml",
+      "sapr3-ds.xml",
+      "firebird-ds.xml",
+      "hajndi-jms-ds.xml",
+   };
 
    /**
     * test xa ds parser
@@ -122,4 +126,24 @@
             System.out.println(ds.toString());
       }
    }
+   
+   /**
+    * test cf parser
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testCfParser() throws Throwable
+   {
+      LegacyCfParser parser = new LegacyCfParser();
+      
+      for (String cfFileName : cfFilesName)
+      {
+         System.out.println("\nStart parse... " + cfFileName);
+         InputStream in = ParserTestCase.class.getClassLoader().getResourceAsStream("ds/" + cfFileName);
+         ConnectionFactories ds = parser.parse(in);
+   
+         if (ds != null)
+            System.out.println(ds.toString());
+      }
+   }
 }



More information about the jboss-cvs-commits mailing list