geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcma...@apache.org
Subject svn commit: r561821 [5/12] - in /geronimo/sandbox/j2g: ./ configurator/ doc/ plugins/ plugins/org.apache.geronimo.j2g.common/ plugins/org.apache.geronimo.j2g.descriptors/ plugins/org.apache.geronimo.j2g.descriptors/src/ plugins/org.apache.geronimo.j2g....
Date Wed, 01 Aug 2007 15:05:17 GMT
Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties?view=diff&rev=561821&r1=561820&r2=561821
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
Wed Aug  1 08:05:12 2007
@@ -1,30 +1,30 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
- # Set root logger level to DEBUG and its only appender to console.
-log4j.rootLogger=INFO
-
-#define loggers
-#pluging logger
-log4j.logger.com.ibm.j2g=DEBUG,console
-
-# console is set to be a ConsoleAppender.
-log4j.appender.console=org.apache.log4j.ConsoleAppender
-
-# console uses PatternLayout.
-log4j.appender.console.layout=org.apache.log4j.PatternLayout
-#log4j.appender.console.layout.ConversionPattern=[%t] %-5p %l - %m%n
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+ # Set root logger level to DEBUG and its only appender to console.
+log4j.rootLogger=INFO
+
+#define loggers
+#pluging logger
+log4j.logger.com.ibm.j2g=DEBUG,console
+
+# console is set to be a ConsoleAppender.
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+
+# console uses PatternLayout.
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+#log4j.appender.console.layout.ConversionPattern=[%t] %-5p %l - %m%n
 log4j.appender.console.layout.ConversionPattern=[%t] %-5p - %m%n

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/commons-logging.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java?view=diff&rev=561821&r1=561820&r2=561821
==============================================================================
--- geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
(original)
+++ geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
Wed Aug  1 08:05:12 2007
@@ -1,355 +1,355 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.j2g.resources.datasource;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.j2g.common.IFileMigration;
-import org.apache.geronimo.j2g.common.IOutput;
-import org.apache.geronimo.j2g.common.Tool;
-import org.apache.geronimo.j2g.util.resources.Constants;
-import org.apache.geronimo.j2g.util.resources.xml.XMLConversionHelper;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.QName;
-
-/**
- * Class which implement the Data Source File Migration 
- */
-public class DSResourcesTool implements IFileMigration {
-
-    // Initialization of the IOutput for DSResourcesTool class
-    IOutput out = Tool.getCurrent().getOutput();
-    // Initialization of the logger for DSResourcesTool class
-    Log logger = LogFactory.getLog(DSResourcesTool.class);
-
-    /**
-     * mgration method from data source jboss discripters to geronimo
-     * discriptors
-     * 
-     * @param sourceFile :data source jboss discriptor file
-     * @return status of the migration
-     */
-    public boolean migrate(File sourceFile, File rootDirectory) {
-        boolean migrated = false;
-            String directoryName = sourceFile.getParent();
-            String jbossDSFileName = sourceFile.getName();
-            logger.debug("Directory Name ==> " + directoryName
-                    + " jboss data source file Name ==> " + jbossDSFileName);
-
-            if (jbossDSFileName.endsWith(Constants.JBOSS_VALID_DS_XML_FILE)) {
-                // Checking wether file is a valid *-ds.xml file
-                String driverType = jbossDSFileName.substring(0, jbossDSFileName.lastIndexOf("-"));
-                out.info(DSResourcesTool.class.getSimpleName(), "Converting Jboss datasource
xml file in " + directoryName);
-                try {
-                    Document jbossDocument = XMLConversionHelper.getJbossDocument(sourceFile);
-                    Document geronimoDocument = migrationFromJboss2Geronimo(jbossDocument
-                            .getRootElement());
-                    String geronimoDSFileName = directoryName + File.separator + driverType
-                            + Constants.GERONIMO_PLAN_FILE;
-                    // Check whether the file already exists if so
-                    // back up at and save that or check the req
-                    // This was done in upper level of the tool
-                    XMLConversionHelper.saveGeronimoDocument(geronimoDSFileName, geronimoDocument);
-                    migrated = true;
-                    out.info(DSResourcesTool.class.getSimpleName(), "The Datasource Resource
File Migration Complete!!!\n");
-                } catch (DocumentException e) {
-                    out.error(DSResourcesTool.class.getSimpleName(), "Error occured while
reading xml descriptor "
-    								+ sourceFile.getAbsolutePath()
-    								+ ". It is possible that the migrator cannot download the xml schema or the xml
file has incorrect syntax. Nested exception:"
-    								+ e.getMessage());
-                } catch (IOException e) {
-                    out.error(DSResourcesTool.class.getSimpleName(), "IO exception " + e.getMessage());
-                }
-            }
-        return migrated;
-    }
-
-    /**
-     * Accepts the jboss side Elements that holdes the discripter infomation and
-     * return the geronimo discripter
-     * 
-     * @param jbossRootElement
-     * @return geronimo plan
-     */
-    private Document migrationFromJboss2Geronimo(Element jbossRootElement) {
-        Document geronimo_ds_plan = createNewGeronimoDocument(jbossRootElement);
-        return geronimo_ds_plan;
-    }
-
-    /**
-     * Createt the new geronimo document from the given namesppace and the root
-     * elament with default elements
-     * 
-     * @param namespaceName
-     *            String of the namespace
-     * @param rootName
-     *            String root Element name
-     * @return a new dom4j document for geronimo-ds-plan.xml
-     */
-    public Document createNewGeronimoDocument(Element jbossRootElement) {
-        Namespace connectorNamespace = new Namespace("", Constants.NAMESPACE_CONNECTOR);
-        Namespace environmentNamespace = new Namespace(Constants.ENV_NAMESPACE_PREFIX,
-                Constants.NAMESPACE_ENV);
-
-        Element local_tx_datasurceElement = XMLConversionHelper.obtainSubElement(jbossRootElement,
-                "local-tx-datasource");
-        Element jndi_name = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
-                "jndi-name");
-        Element connection_url = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
-                "connection-url");
-        Element driver_class = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
-                "driver-class");
-        Element user_name = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
-                "user-name");
-        Element password = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
-                "password");
-        Element dependenciesElement = createDependenciesElement(driver_class.getStringValue(),
-                environmentNamespace);
-        Element connectiondefinition_instanceElement = DocumentHelper.createElement(new QName(
-                "connectiondefinition-instance", connectorNamespace));
-        connectiondefinition_instanceElement.add(XMLConversionHelper.createSibling("name",
-                XMLConversionHelper.obtainNameFromJNDINAME(XMLConversionHelper
-                        .readElementValue(jndi_name)), connectorNamespace));
-        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
-                "config-property-setting", XMLConversionHelper.readElementValue(user_name),
"name",
-                "UserName", connectorNamespace));
-        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
-                "config-property-setting", XMLConversionHelper.readElementValue(password),
"name",
-                "Password", connectorNamespace));
-        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
-                "config-property-setting", XMLConversionHelper.readElementValue(driver_class),
-                "name", "Driver", connectorNamespace));
-        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
-                "config-property-setting", XMLConversionHelper.readElementValue(connection_url),
-                "name", "ConnectionURL", connectorNamespace));
-        Element connection_managerElement = null;
-        if (checkForConnectionMangerDetails(local_tx_datasurceElement)) {
-            connection_managerElement = createConnectionManagerElement(local_tx_datasurceElement,
-                    connectorNamespace);
-        } else {
-            connection_managerElement = createDefaultConnectionManagerElement(connectorNamespace);
-        }
-        connectiondefinition_instanceElement.add(connection_managerElement);
-        QName connectorQName = new QName("connector", connectorNamespace);
-        QName environmentQName = new QName("environment", environmentNamespace);
-        Element artifactIdElement = DocumentHelper.createElement((new QName("artifactId",
-                environmentNamespace)));
-        artifactIdElement.addText(XMLConversionHelper.obtainNameFromJNDINAME(XMLConversionHelper
-                .readElementValue(jndi_name)));
-        Element moduleIdElement = DocumentHelper.createElement((new QName("moduleId",
-                environmentNamespace)));
-        moduleIdElement.add(artifactIdElement);
-        Element conenctorElement = DocumentHelper.createElement(connectorQName);
-        dependenciesElement.add(environmentNamespace);
-        Element environmentElement = conenctorElement.addElement(environmentQName);
-        environmentElement.add(moduleIdElement);
-        environmentElement.add(dependenciesElement);
-        QName resourceadapterQName = new QName("resourceadapter", connectorNamespace);
-        Element resourceadapterElement = conenctorElement.addElement(resourceadapterQName);
-        Element outbound_resourceadapterElement = DocumentHelper.createElement(new QName(
-                "outbound-resourceadapter", connectorNamespace));
-        Element connector_definitionElement = DocumentHelper.createElement(new QName(
-                "connection-definition", connectorNamespace));
-        Element connecttionfactory_interfaceElement = DocumentHelper.createElement(new QName(
-                "connectionfactory-interface", connectorNamespace));
-        connecttionfactory_interfaceElement.addText(Constants.CONNECTION_FACTORY_INTERFACE);
-        connector_definitionElement.add(connecttionfactory_interfaceElement);
-        connector_definitionElement.add(connectiondefinition_instanceElement);
-        resourceadapterElement.add(outbound_resourceadapterElement);
-        outbound_resourceadapterElement.add(connector_definitionElement);
-        Document document = DocumentHelper.createDocument();
-        document.add(conenctorElement);
-        out.warn(DSResourcesTool.class.getSimpleName(), "The JAR holding the " + driver_class.getStringValue()
-                + " JDBC Driver should be installed under <GERONIMO_HOME>/repository/");
-        return document;
-    }
-
-    /**
-     * creates the connection manager element by refereing the jboss side
-     * localtxelement
-     * 
-     * @param local_tx_datasurceElement
-     * @param environmentNamespace
-     * @return the connection manager element for geronimo ds plan
-     */
-    public Element createConnectionManagerElement(Element local_tx_datasurceElement,
-            Namespace environmentNamespace) {
-        Element connectionmanagerElement = DocumentHelper.createElement(new QName(
-                "connectionmanager", environmentNamespace));
-        Element local_transactionElement = DocumentHelper.createElement(new QName(
-                "local-transaction", environmentNamespace));
-        Element single_poolElement = DocumentHelper.createElement(new QName("single-pool",
-                environmentNamespace));
-        Element max_sizeElement = DocumentHelper.createElement(new QName("max-size",
-                environmentNamespace));
-        Element min_sizeElement = DocumentHelper.createElement(new QName("min-size",
-                environmentNamespace));
-        Element blocking_timeout_millisecondsElement = DocumentHelper.createElement(new QName(
-                "blocking-timeout-milliseconds", environmentNamespace));
-        Element idle_timeout_minutesElement = DocumentHelper.createElement(new QName(
-                "idle-timeout-minutes", environmentNamespace));
-        Element match_oneElement = DocumentHelper.createElement(new QName("match-one",
-                environmentNamespace));
-        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "max-pool-size"))
{
-            Element max_sizeElement_jboss = XMLConversionHelper.obtainSubElement(
-                    local_tx_datasurceElement, "max-pool-size");
-            max_sizeElement.addText(XMLConversionHelper.readElementValue(max_sizeElement_jboss));
-        } else {
-            max_sizeElement.addText("10");
-        }
-        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "min-pool-size"))
{
-            Element min_sizeElement_jboss = XMLConversionHelper.obtainSubElement(
-                    local_tx_datasurceElement, "min-pool-size");
-            min_sizeElement.addText(XMLConversionHelper.readElementValue(min_sizeElement_jboss));
-        } else {
-            min_sizeElement.addText("0");
-        }
-        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement,
-                "blocking-timeout-milliseconds")) {
-            Element blocking_timeout_millisecondsElement_jboss = XMLConversionHelper
-                    .obtainSubElement(local_tx_datasurceElement, "blocking-timeout-milliseconds");
-            blocking_timeout_millisecondsElement.addText(XMLConversionHelper
-                    .readElementValue(blocking_timeout_millisecondsElement_jboss));
-        } else {
-            blocking_timeout_millisecondsElement.addText("5000");
-        }
-        if (XMLConversionHelper
-                .containSubElement(local_tx_datasurceElement, "idle-timeout-minutes")) {
-            Element idle_timeout_minutesElement_jboss = XMLConversionHelper.obtainSubElement(
-                    local_tx_datasurceElement, "idle-timeout-minutes");
-            idle_timeout_minutesElement.addText(XMLConversionHelper
-                    .readElementValue(idle_timeout_minutesElement_jboss));
-        } else {
-            idle_timeout_minutesElement.addText("30");
-        }
-        single_poolElement.add(max_sizeElement);
-        single_poolElement.add(min_sizeElement);
-        single_poolElement.add(blocking_timeout_millisecondsElement);
-        single_poolElement.add(idle_timeout_minutesElement);
-        single_poolElement.add(match_oneElement);
-        connectionmanagerElement.add(local_transactionElement);
-        connectionmanagerElement.add(single_poolElement);
-        return connectionmanagerElement;
-    }
-
-    /**
-     * create the dependencies element by refering the driver class string
-     * 
-     * @param driver_class
-     * @return dependencies element
-     */
-    private Element createDependenciesElement(String driver_class, Namespace environmentNamespace)
{
-        String id_combination = null;
-        String groupId = null;
-        String artifactId = null;
-        logger.debug("The input driver class to the Dependancy element : " + driver_class);
-        HashMap driverMap = XMLConversionHelper.createDriverStoreHashMap();
-        // if the driver is already in the driver map or else
-        if (driverMap.containsKey(driver_class)) {
-            id_combination = (String) driverMap.get(driver_class);
-        } else {
-            id_combination = XMLConversionHelper
-                    .createIdConbinationWhenDriverMapRetrnsEmpty(driver_class);
-        }
-        groupId = id_combination.substring(0, id_combination.indexOf("/"));
-        artifactId = id_combination.substring(id_combination.indexOf("/") + 1, id_combination
-                .length());
-        QName groupIdQName = new QName("groupId", environmentNamespace);
-        Element groupIdElement = DocumentHelper.createElement(groupIdQName);
-        groupIdElement.addText(groupId);
-        QName artifactIdQName = new QName("artifactId", environmentNamespace);
-        Element artifactIdElement = DocumentHelper.createElement(artifactIdQName);
-        artifactIdElement.addText(artifactId);
-        QName typeQName = new QName("type", environmentNamespace);
-        Element typeElement = DocumentHelper.createElement(typeQName);
-        typeElement.addText("jar");
-        QName dependenciesQName = new QName("dependencies", environmentNamespace);
-        Element dependenciesElement = DocumentHelper.createElement(dependenciesQName);
-        QName dependencyQName = new QName("dependency", environmentNamespace);
-        Element dependencyElement = DocumentHelper.createElement(dependencyQName);
-        dependencyElement.add(groupIdElement);
-        dependencyElement.add(artifactIdElement);
-        dependencyElement.add(typeElement);
-        dependenciesElement.add(dependencyElement);
-        return dependenciesElement;
-    }
-
-    /**
-     * creates the default connection manager element
-     * 
-     * @param environmentNamespace
-     * @return the connection manager element
-     */
-    public Element createDefaultConnectionManagerElement(Namespace environmentNamespace)
{
-        Element connectionmanagerElement = DocumentHelper.createElement(new QName(
-                "connectionmanager", environmentNamespace));
-        Element local_transactionElement = DocumentHelper.createElement(new QName(
-                "local-transaction", environmentNamespace));
-        Element single_poolElement = DocumentHelper.createElement(new QName("single-pool",
-                environmentNamespace));
-        Element max_sizeElement = DocumentHelper.createElement(new QName("max-size",
-                environmentNamespace));
-        Element min_sizeElement = DocumentHelper.createElement(new QName("min-size",
-                environmentNamespace));
-        Element blocking_timeout_millisecondsElement = DocumentHelper.createElement(new QName(
-                "blocking-timeout-milliseconds", environmentNamespace));
-        Element idle_timeout_minutesElement = DocumentHelper.createElement(new QName(
-                "idle-timeout-minutes", environmentNamespace));
-        Element match_oneElement = DocumentHelper.createElement(new QName("match-one",
-                environmentNamespace));
-        max_sizeElement.addText("10");
-        min_sizeElement.addText("0");
-        blocking_timeout_millisecondsElement.addText("5000");
-        idle_timeout_minutesElement.addText("30");
-        single_poolElement.add(max_sizeElement);
-        single_poolElement.add(min_sizeElement);
-        single_poolElement.add(blocking_timeout_millisecondsElement);
-        single_poolElement.add(idle_timeout_minutesElement);
-        single_poolElement.add(match_oneElement);
-        connectionmanagerElement.add(local_transactionElement);
-        connectionmanagerElement.add(single_poolElement);
-        return connectionmanagerElement;
-    }
-
-    /**
-     * retuns true if any of the elements were found on JBoss side
-     * 
-     * @param local_tx_datasurceElement
-     * @return status
-     */
-    private boolean checkForConnectionMangerDetails(Element local_tx_datasurceElement) {
-        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "min-pool-size")
-                || XMLConversionHelper
-                        .containSubElement(local_tx_datasurceElement, "max-pool-size")
-                || XMLConversionHelper.containSubElement(local_tx_datasurceElement,
-                        "idle-timeout-minutes")
-                || XMLConversionHelper.containSubElement(local_tx_datasurceElement,
-                        "blocking-timeout-milliseconds")) {
-            return true;
-        }
-        return false;
-    }
-
-}
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.j2g.resources.datasource;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.j2g.common.IFileMigration;
+import org.apache.geronimo.j2g.common.IOutput;
+import org.apache.geronimo.j2g.common.Tool;
+import org.apache.geronimo.j2g.util.resources.Constants;
+import org.apache.geronimo.j2g.util.resources.xml.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+
+/**
+ * Class which implement the Data Source File Migration 
+ */
+public class DSResourcesTool implements IFileMigration {
+
+    // Initialization of the IOutput for DSResourcesTool class
+    IOutput out = Tool.getCurrent().getOutput();
+    // Initialization of the logger for DSResourcesTool class
+    Log logger = LogFactory.getLog(DSResourcesTool.class);
+
+    /**
+     * mgration method from data source jboss discripters to geronimo
+     * discriptors
+     * 
+     * @param sourceFile :data source jboss discriptor file
+     * @return status of the migration
+     */
+    public boolean migrate(File sourceFile, File rootDirectory) {
+        boolean migrated = false;
+            String directoryName = sourceFile.getParent();
+            String jbossDSFileName = sourceFile.getName();
+            logger.debug("Directory Name ==> " + directoryName
+                    + " jboss data source file Name ==> " + jbossDSFileName);
+
+            if (jbossDSFileName.endsWith(Constants.JBOSS_VALID_DS_XML_FILE)) {
+                // Checking wether file is a valid *-ds.xml file
+                String driverType = jbossDSFileName.substring(0, jbossDSFileName.lastIndexOf("-"));
+                out.info(DSResourcesTool.class.getSimpleName(), "Converting Jboss datasource
xml file in " + directoryName);
+                try {
+                    Document jbossDocument = XMLConversionHelper.getJbossDocument(sourceFile);
+                    Document geronimoDocument = migrationFromJboss2Geronimo(jbossDocument
+                            .getRootElement());
+                    String geronimoDSFileName = directoryName + File.separator + driverType
+                            + Constants.GERONIMO_PLAN_FILE;
+                    // Check whether the file already exists if so
+                    // back up at and save that or check the req
+                    // This was done in upper level of the tool
+                    XMLConversionHelper.saveGeronimoDocument(geronimoDSFileName, geronimoDocument);
+                    migrated = true;
+                    out.info(DSResourcesTool.class.getSimpleName(), "The Datasource Resource
File Migration Complete!!!\n");
+                } catch (DocumentException e) {
+                    out.error(DSResourcesTool.class.getSimpleName(), "Error occured while
reading xml descriptor "
+    								+ sourceFile.getAbsolutePath()
+    								+ ". It is possible that the migrator cannot download the xml schema or the xml
file has incorrect syntax. Nested exception:"
+    								+ e.getMessage());
+                } catch (IOException e) {
+                    out.error(DSResourcesTool.class.getSimpleName(), "IO exception " + e.getMessage());
+                }
+            }
+        return migrated;
+    }
+
+    /**
+     * Accepts the jboss side Elements that holdes the discripter infomation and
+     * return the geronimo discripter
+     * 
+     * @param jbossRootElement
+     * @return geronimo plan
+     */
+    private Document migrationFromJboss2Geronimo(Element jbossRootElement) {
+        Document geronimo_ds_plan = createNewGeronimoDocument(jbossRootElement);
+        return geronimo_ds_plan;
+    }
+
+    /**
+     * Createt the new geronimo document from the given namesppace and the root
+     * elament with default elements
+     * 
+     * @param namespaceName
+     *            String of the namespace
+     * @param rootName
+     *            String root Element name
+     * @return a new dom4j document for geronimo-ds-plan.xml
+     */
+    public Document createNewGeronimoDocument(Element jbossRootElement) {
+        Namespace connectorNamespace = new Namespace("", Constants.NAMESPACE_CONNECTOR);
+        Namespace environmentNamespace = new Namespace(Constants.ENV_NAMESPACE_PREFIX,
+                Constants.NAMESPACE_ENV);
+
+        Element local_tx_datasurceElement = XMLConversionHelper.obtainSubElement(jbossRootElement,
+                "local-tx-datasource");
+        Element jndi_name = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
+                "jndi-name");
+        Element connection_url = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
+                "connection-url");
+        Element driver_class = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
+                "driver-class");
+        Element user_name = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
+                "user-name");
+        Element password = XMLConversionHelper.obtainSubElement(local_tx_datasurceElement,
+                "password");
+        Element dependenciesElement = createDependenciesElement(driver_class.getStringValue(),
+                environmentNamespace);
+        Element connectiondefinition_instanceElement = DocumentHelper.createElement(new QName(
+                "connectiondefinition-instance", connectorNamespace));
+        connectiondefinition_instanceElement.add(XMLConversionHelper.createSibling("name",
+                XMLConversionHelper.obtainNameFromJNDINAME(XMLConversionHelper
+                        .readElementValue(jndi_name)), connectorNamespace));
+        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
+                "config-property-setting", XMLConversionHelper.readElementValue(user_name),
"name",
+                "UserName", connectorNamespace));
+        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
+                "config-property-setting", XMLConversionHelper.readElementValue(password),
"name",
+                "Password", connectorNamespace));
+        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
+                "config-property-setting", XMLConversionHelper.readElementValue(driver_class),
+                "name", "Driver", connectorNamespace));
+        connectiondefinition_instanceElement.add(XMLConversionHelper.createSiblingWithAttrib(
+                "config-property-setting", XMLConversionHelper.readElementValue(connection_url),
+                "name", "ConnectionURL", connectorNamespace));
+        Element connection_managerElement = null;
+        if (checkForConnectionMangerDetails(local_tx_datasurceElement)) {
+            connection_managerElement = createConnectionManagerElement(local_tx_datasurceElement,
+                    connectorNamespace);
+        } else {
+            connection_managerElement = createDefaultConnectionManagerElement(connectorNamespace);
+        }
+        connectiondefinition_instanceElement.add(connection_managerElement);
+        QName connectorQName = new QName("connector", connectorNamespace);
+        QName environmentQName = new QName("environment", environmentNamespace);
+        Element artifactIdElement = DocumentHelper.createElement((new QName("artifactId",
+                environmentNamespace)));
+        artifactIdElement.addText(XMLConversionHelper.obtainNameFromJNDINAME(XMLConversionHelper
+                .readElementValue(jndi_name)));
+        Element moduleIdElement = DocumentHelper.createElement((new QName("moduleId",
+                environmentNamespace)));
+        moduleIdElement.add(artifactIdElement);
+        Element conenctorElement = DocumentHelper.createElement(connectorQName);
+        dependenciesElement.add(environmentNamespace);
+        Element environmentElement = conenctorElement.addElement(environmentQName);
+        environmentElement.add(moduleIdElement);
+        environmentElement.add(dependenciesElement);
+        QName resourceadapterQName = new QName("resourceadapter", connectorNamespace);
+        Element resourceadapterElement = conenctorElement.addElement(resourceadapterQName);
+        Element outbound_resourceadapterElement = DocumentHelper.createElement(new QName(
+                "outbound-resourceadapter", connectorNamespace));
+        Element connector_definitionElement = DocumentHelper.createElement(new QName(
+                "connection-definition", connectorNamespace));
+        Element connecttionfactory_interfaceElement = DocumentHelper.createElement(new QName(
+                "connectionfactory-interface", connectorNamespace));
+        connecttionfactory_interfaceElement.addText(Constants.CONNECTION_FACTORY_INTERFACE);
+        connector_definitionElement.add(connecttionfactory_interfaceElement);
+        connector_definitionElement.add(connectiondefinition_instanceElement);
+        resourceadapterElement.add(outbound_resourceadapterElement);
+        outbound_resourceadapterElement.add(connector_definitionElement);
+        Document document = DocumentHelper.createDocument();
+        document.add(conenctorElement);
+        out.warn(DSResourcesTool.class.getSimpleName(), "The JAR holding the " + driver_class.getStringValue()
+                + " JDBC Driver should be installed under <GERONIMO_HOME>/repository/");
+        return document;
+    }
+
+    /**
+     * creates the connection manager element by refereing the jboss side
+     * localtxelement
+     * 
+     * @param local_tx_datasurceElement
+     * @param environmentNamespace
+     * @return the connection manager element for geronimo ds plan
+     */
+    public Element createConnectionManagerElement(Element local_tx_datasurceElement,
+            Namespace environmentNamespace) {
+        Element connectionmanagerElement = DocumentHelper.createElement(new QName(
+                "connectionmanager", environmentNamespace));
+        Element local_transactionElement = DocumentHelper.createElement(new QName(
+                "local-transaction", environmentNamespace));
+        Element single_poolElement = DocumentHelper.createElement(new QName("single-pool",
+                environmentNamespace));
+        Element max_sizeElement = DocumentHelper.createElement(new QName("max-size",
+                environmentNamespace));
+        Element min_sizeElement = DocumentHelper.createElement(new QName("min-size",
+                environmentNamespace));
+        Element blocking_timeout_millisecondsElement = DocumentHelper.createElement(new QName(
+                "blocking-timeout-milliseconds", environmentNamespace));
+        Element idle_timeout_minutesElement = DocumentHelper.createElement(new QName(
+                "idle-timeout-minutes", environmentNamespace));
+        Element match_oneElement = DocumentHelper.createElement(new QName("match-one",
+                environmentNamespace));
+        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "max-pool-size"))
{
+            Element max_sizeElement_jboss = XMLConversionHelper.obtainSubElement(
+                    local_tx_datasurceElement, "max-pool-size");
+            max_sizeElement.addText(XMLConversionHelper.readElementValue(max_sizeElement_jboss));
+        } else {
+            max_sizeElement.addText("10");
+        }
+        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "min-pool-size"))
{
+            Element min_sizeElement_jboss = XMLConversionHelper.obtainSubElement(
+                    local_tx_datasurceElement, "min-pool-size");
+            min_sizeElement.addText(XMLConversionHelper.readElementValue(min_sizeElement_jboss));
+        } else {
+            min_sizeElement.addText("0");
+        }
+        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement,
+                "blocking-timeout-milliseconds")) {
+            Element blocking_timeout_millisecondsElement_jboss = XMLConversionHelper
+                    .obtainSubElement(local_tx_datasurceElement, "blocking-timeout-milliseconds");
+            blocking_timeout_millisecondsElement.addText(XMLConversionHelper
+                    .readElementValue(blocking_timeout_millisecondsElement_jboss));
+        } else {
+            blocking_timeout_millisecondsElement.addText("5000");
+        }
+        if (XMLConversionHelper
+                .containSubElement(local_tx_datasurceElement, "idle-timeout-minutes")) {
+            Element idle_timeout_minutesElement_jboss = XMLConversionHelper.obtainSubElement(
+                    local_tx_datasurceElement, "idle-timeout-minutes");
+            idle_timeout_minutesElement.addText(XMLConversionHelper
+                    .readElementValue(idle_timeout_minutesElement_jboss));
+        } else {
+            idle_timeout_minutesElement.addText("30");
+        }
+        single_poolElement.add(max_sizeElement);
+        single_poolElement.add(min_sizeElement);
+        single_poolElement.add(blocking_timeout_millisecondsElement);
+        single_poolElement.add(idle_timeout_minutesElement);
+        single_poolElement.add(match_oneElement);
+        connectionmanagerElement.add(local_transactionElement);
+        connectionmanagerElement.add(single_poolElement);
+        return connectionmanagerElement;
+    }
+
+    /**
+     * create the dependencies element by refering the driver class string
+     * 
+     * @param driver_class
+     * @return dependencies element
+     */
+    private Element createDependenciesElement(String driver_class, Namespace environmentNamespace)
{
+        String id_combination = null;
+        String groupId = null;
+        String artifactId = null;
+        logger.debug("The input driver class to the Dependancy element : " + driver_class);
+        HashMap driverMap = XMLConversionHelper.createDriverStoreHashMap();
+        // if the driver is already in the driver map or else
+        if (driverMap.containsKey(driver_class)) {
+            id_combination = (String) driverMap.get(driver_class);
+        } else {
+            id_combination = XMLConversionHelper
+                    .createIdConbinationWhenDriverMapRetrnsEmpty(driver_class);
+        }
+        groupId = id_combination.substring(0, id_combination.indexOf("/"));
+        artifactId = id_combination.substring(id_combination.indexOf("/") + 1, id_combination
+                .length());
+        QName groupIdQName = new QName("groupId", environmentNamespace);
+        Element groupIdElement = DocumentHelper.createElement(groupIdQName);
+        groupIdElement.addText(groupId);
+        QName artifactIdQName = new QName("artifactId", environmentNamespace);
+        Element artifactIdElement = DocumentHelper.createElement(artifactIdQName);
+        artifactIdElement.addText(artifactId);
+        QName typeQName = new QName("type", environmentNamespace);
+        Element typeElement = DocumentHelper.createElement(typeQName);
+        typeElement.addText("jar");
+        QName dependenciesQName = new QName("dependencies", environmentNamespace);
+        Element dependenciesElement = DocumentHelper.createElement(dependenciesQName);
+        QName dependencyQName = new QName("dependency", environmentNamespace);
+        Element dependencyElement = DocumentHelper.createElement(dependencyQName);
+        dependencyElement.add(groupIdElement);
+        dependencyElement.add(artifactIdElement);
+        dependencyElement.add(typeElement);
+        dependenciesElement.add(dependencyElement);
+        return dependenciesElement;
+    }
+
+    /**
+     * creates the default connection manager element
+     * 
+     * @param environmentNamespace
+     * @return the connection manager element
+     */
+    public Element createDefaultConnectionManagerElement(Namespace environmentNamespace)
{
+        Element connectionmanagerElement = DocumentHelper.createElement(new QName(
+                "connectionmanager", environmentNamespace));
+        Element local_transactionElement = DocumentHelper.createElement(new QName(
+                "local-transaction", environmentNamespace));
+        Element single_poolElement = DocumentHelper.createElement(new QName("single-pool",
+                environmentNamespace));
+        Element max_sizeElement = DocumentHelper.createElement(new QName("max-size",
+                environmentNamespace));
+        Element min_sizeElement = DocumentHelper.createElement(new QName("min-size",
+                environmentNamespace));
+        Element blocking_timeout_millisecondsElement = DocumentHelper.createElement(new QName(
+                "blocking-timeout-milliseconds", environmentNamespace));
+        Element idle_timeout_minutesElement = DocumentHelper.createElement(new QName(
+                "idle-timeout-minutes", environmentNamespace));
+        Element match_oneElement = DocumentHelper.createElement(new QName("match-one",
+                environmentNamespace));
+        max_sizeElement.addText("10");
+        min_sizeElement.addText("0");
+        blocking_timeout_millisecondsElement.addText("5000");
+        idle_timeout_minutesElement.addText("30");
+        single_poolElement.add(max_sizeElement);
+        single_poolElement.add(min_sizeElement);
+        single_poolElement.add(blocking_timeout_millisecondsElement);
+        single_poolElement.add(idle_timeout_minutesElement);
+        single_poolElement.add(match_oneElement);
+        connectionmanagerElement.add(local_transactionElement);
+        connectionmanagerElement.add(single_poolElement);
+        return connectionmanagerElement;
+    }
+
+    /**
+     * retuns true if any of the elements were found on JBoss side
+     * 
+     * @param local_tx_datasurceElement
+     * @return status
+     */
+    private boolean checkForConnectionMangerDetails(Element local_tx_datasurceElement) {
+        if (XMLConversionHelper.containSubElement(local_tx_datasurceElement, "min-pool-size")
+                || XMLConversionHelper
+                        .containSubElement(local_tx_datasurceElement, "max-pool-size")
+                || XMLConversionHelper.containSubElement(local_tx_datasurceElement,
+                        "idle-timeout-minutes")
+                || XMLConversionHelper.containSubElement(local_tx_datasurceElement,
+                        "blocking-timeout-milliseconds")) {
+            return true;
+        }
+        return false;
+    }
+
+}

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/j2g/plugins/org.apache.geronimo.j2g.resources/src/org/apache/geronimo/j2g/resources/datasource/DSResourcesTool.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message