geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcma...@apache.org
Subject svn commit: r520023 [10/10] - in /geronimo/sandbox/j2g: ./ bin/ doc/ src/ src/common/ src/common/META-INF/ src/common/src/ src/common/src/org/ src/common/src/org/apache/ src/common/src/org/apache/apps/ src/common/src/org/apache/apps/j2gmigrator/ src/co...
Date Mon, 19 Mar 2007 17:43:49 GMT
Added: geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java?view=auto&rev=520023
==============================================================================
--- geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
(added)
+++ geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
Mon Mar 19 10:43:27 2007
@@ -0,0 +1,518 @@
+/**
+ *  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.apps.j2gmigrator.resources.xmlutil;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.apps.j2gmigrator.resources.utils.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+
+/**
+ * The XMLConversion Helper Class for the Resources Conversion Tool
+ */
+public class XMLConversionHelper {
+
+    // Initialization of the logger for XMLConversionHelper class
+    private static Log logger = LogFactory.getLog(XMLConversionHelper.class);
+
+    private static final String NAMESPACE_URI = "http://www.ibm.com/j2g";
+
+    private static final String PREFIX = "j2g";
+
+    private static final QName LINE_NUMBER_ATTR = QName.get("lineNumber", PREFIX, NAMESPACE_URI);
+
+    private static final QName COLUMN_NUMBER_ATTR = QName
+            .get("columnNumber", PREFIX, NAMESPACE_URI);
+
+    /**
+     * Create a jboos document from the given file
+     * 
+     * @param file
+     *            input file from the file system or strem
+     * @return the document element of the return file
+     * @throws DocumentException
+     */
+    public static Document getJbossDocument(File file) throws DocumentException {
+        XMLFilter xmlFilter = new XMLFilterImpl() {
+            private Locator locator;
+
+            public void setDocumentLocator(Locator locator) {
+                this.locator = locator;
+                super.setDocumentLocator(locator);
+            }
+
+            public void startElement(String uri, String localName, String qName, Attributes
atts)
+                    throws SAXException {
+                Attributes extAtts;
+                if (locator != null) {
+                    AttributesImpl locationAtts = new AttributesImpl(atts);
+                    addIntAttribute(locationAtts, LINE_NUMBER_ATTR, locator.getLineNumber());
+                    addIntAttribute(locationAtts, COLUMN_NUMBER_ATTR, locator.getColumnNumber());
+                    extAtts = locationAtts;
+                } else {
+                    extAtts = atts;
+                }
+                super.startElement(uri, localName, qName, extAtts);
+            }
+
+            private void addIntAttribute(AttributesImpl locAtts, QName name, int value) {
+                locAtts.addAttribute(name.getNamespaceURI(), name.getName(), name
+                        .getQualifiedName(), "CDATA", String.valueOf(value));
+            }
+
+        };
+
+        SAXReader saxReader = new SAXReader();
+        saxReader.setXMLFilter(xmlFilter);
+        return saxReader.read(file);
+    }
+
+    /**
+     * read the element value
+     * 
+     * @param element
+     * @return the value of the element in the String format
+     */
+    public static String readElementValue(Element element) {
+        return element.getText();
+    }
+
+    /**
+     * obtain the sub element
+     * 
+     * @param element
+     *            the super element
+     * @param subelElementName
+     * @return the sub element
+     */
+    public static Element obtainSubElement(Element element, String subelElementName) {
+        Iterator elementIterator = element.elementIterator();
+        while (elementIterator.hasNext()) {
+            Element itElement = (Element) elementIterator.next();
+            if (itElement.getName().equals(subelElementName)) {
+                return itElement;
+            }
+        }
+        // throw the same element is it does not exist
+        return element;
+    }
+
+    /**
+     * check wether an element contain a sub element refereing the passd params
+     * 
+     * @param element
+     * @param subelElementName
+     * @return boolean value of the check
+     */
+    public static boolean containSubElement(Element element, String subelElementName) {
+        Iterator elementIterator = element.elementIterator();
+        while (elementIterator.hasNext()) {
+            Element itElement = (Element) elementIterator.next();
+            if (itElement.getName().equals(subelElementName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * check wether an element with a attribute contain a sub element refereing
+     * the passd params
+     * 
+     * @param element
+     * @param subelAttributeName
+     * @return boolean value of the check
+     */
+    public static boolean containSubElementWithAttribute(Element element, String subElementName,
+            String subelAttributeName, String subAttributeValue) {
+        Iterator elementIterator = element.elementIterator();
+        while (elementIterator.hasNext()) {
+            Element itElement = (Element) elementIterator.next();
+            if (itElement.getName().equals(subElementName)) {
+                Iterator attribIterator = itElement.attributeIterator();
+                while (attribIterator.hasNext()) {
+                    Attribute itAttribute = (Attribute) attribIterator.next();
+                    if (itAttribute.getName().equals(subelAttributeName)
+                            && itAttribute.getText().equals(subAttributeValue)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * obtain the sub element with by refering the passes params
+     * 
+     * @param element
+     * @param subElementName
+     * @param subelAttributeName
+     * @param subAttributeValue
+     * @return sub element that contains the attribute
+     */
+    public static Element obtainSubElementWithAttribute(Element element, String subElementName,
+            String subelAttributeName, String subAttributeValue) {
+        Iterator elementIterator = element.elementIterator();
+        while (elementIterator.hasNext()) {
+            Element itElement = (Element) elementIterator.next();
+            if (itElement.getName().equals(subElementName)) {
+                Iterator attribIterator = itElement.attributeIterator();
+                while (attribIterator.hasNext()) {
+                    Attribute itAttribute = (Attribute) attribIterator.next();
+                    if (itAttribute.getName().equals(subelAttributeName)
+                            && itAttribute.getText().equals(subAttributeValue)) {
+                        return itElement;
+                    }
+                }
+            }
+        }
+        return element;
+    }
+
+    /**
+     * create a sibling inside the passed element
+     * 
+     * @param siblingName
+     * @param siblingvalue
+     * @return the original element
+     */
+    public static Element createSibling(String siblingName, String siblingvalue, Namespace
namespace) {
+        Element element = DocumentHelper.createElement(new QName(siblingName, namespace));
+        element.addText(siblingvalue);
+        return element;
+    }
+
+    /**
+     * creates a sibling with an attribute inside the passed element
+     * 
+     * @param siblingName
+     * @param siblingvalue
+     * @param attribName
+     * @param attribValue
+     * @return the original element
+     */
+    public static Element createSiblingWithAttrib(String siblingName, String siblingvalue,
+            String attribName, String attribValue, Namespace namespace) {
+        Element element = DocumentHelper.createElement(new QName(siblingName, namespace));
+        element.addText(siblingvalue);
+        element = addAttributeToElement(element, attribName, attribValue);
+        return element;
+    }
+
+    /**
+     * obtain the name from the JNDI Name
+     * 
+     * @param jndiName
+     * @return return the name
+     */
+    public static String obtainNameFromJNDINAME(String jndiName) {
+        // TODO check wether that this jndi name contains a string / if not
+        // return that same name
+        // and look on other cases also
+        String name = (String) jndiName.substring(jndiName.indexOf("/") + 1);
+        return name;
+
+    }
+
+    /**
+     * add attribute to a given element by refering the passed params
+     * 
+     * @param element
+     * @param attrbName
+     * @param attrbValue
+     * @return the original element
+     */
+    public static Element addAttributeToElement(Element element, String attrbName, String
attrbValue) {
+        Attribute attrib = DocumentHelper.createAttribute(element, attrbName, attrbValue);
+        element.add(attrib);
+        return element;
+    }
+
+    /**
+     * creates the drivermap
+     * 
+     * @return driver store hashmap
+     */
+    public static HashMap createDriverStoreHashMap() {
+        // The driver class is desided as the most suitable one for the key in
+        // the hash map
+        HashMap driverDetails = new HashMap();
+        driverDetails.put("org.apache.derby.jdbc.EmbeddedDriver", "org.apache.derby/derby");
+        driverDetails.put("org.apache.derby.jdbc.ClientDriver", "org.apache.derby/derby");
+        driverDetails.put("org.hsqldb.jdbcDriver", "hsqldb/hsqldb");
+        driverDetails.put("com.mysql.jdbc.Driver", "mysql/mysql-connector-java");
+        // TODO do the postgres SQL version from the *-ds.xml (Version known
+        // one)
+        driverDetails.put("org.postgresql.Driver", "postgressql/postgressql");
+        // driverDetails.put("PostgreSql", "postgressql/postgressql-8.1");
+        driverDetails.put("com.mckoi.JDBCDriver", "mckoi/mkjdbc");
+        driverDetails.put("com.sap.dbtech.jdbc.DriverSapDB", "maxdb/sapdbc");
+        // driverDetails.put("SAPDB", "maxdb/sapdbc");
+        // driverDetails.put("SAPDB", "maxdb/sapdbc");
+        driverDetails.put("net.sourceforge.jtds.jdbc.Driver", "jtds/jtds");
+        driverDetails.put("com.sybase.jdbc3.jdbc.SybDriver", "sybase/jconn3");
+        return driverDetails;
+    }
+
+    /**
+     * creates the id combination (groups id and artifact id) when the driver
+     * hash map does not contain the driver writes the dom4j document object to
+     * a file given as fileNmae
+     * 
+     * @param driver_class
+     *            String
+     * @return String representation of the id combination
+     */
+    public static String createIdConbinationWhenDriverMapRetrnsEmpty(String driver_class)
{
+        String idCombination = null;
+        String groupId = null;
+        String artifactId = null;
+        String[] parts = new String[4];
+        String tmp = null;
+        // check wether the package start with either com / org /net
+        String package_starter = driver_class.substring(0, driver_class.indexOf("."));
+        // TODO check for null in this method
+        if (package_starter.equals("com") || package_starter.equals("org")
+                || package_starter.equals("net")) {
+            for (int i = 0; i <= 3; i++) {
+                parts[i] = driver_class.substring(0, driver_class.indexOf("."));
+                tmp = driver_class.substring(driver_class.indexOf(".") + 1, driver_class.length());
+                driver_class = tmp;
+            }
+            groupId = parts[0] + "." + parts[1] + "." + parts[2];
+            artifactId = parts[1] + "-" + parts[2] + "-" + parts[3];
+        } else {
+            for (int i = 0; i <= 1; i++) {
+                parts[i] = driver_class.substring(0, driver_class.indexOf("."));
+                tmp = driver_class.substring(driver_class.indexOf(".") + 1, driver_class.length());
+                driver_class = tmp;
+            }
+            groupId = parts[0];
+            artifactId = parts[0] + "-" + parts[1];
+        }
+        idCombination = groupId + "/" + artifactId;
+        return idCombination;
+    }
+
+    /**
+     * Check file existance
+     * 
+     * @param directory
+     * @param fileName
+     * @return true/false
+     */
+    public static boolean isFileExists(String directory, String fileName) {
+        File sourceFile = new File(directory + "/" + fileName);
+        if (sourceFile.isFile()) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * creates a new geronimo document by refering the passes params
+     * 
+     * @param namespaceName
+     * @param rootName
+     * @param tool
+     * @param JNDIName
+     * @param envNamespaceName
+     * @return the new created geronimo document
+     */
+    public static Document createNewGeronimoDocument(String namespaceName, String rootName,
+            String tool, String JNDIName, String envNamespaceName) {
+        Document document = getEmptyGeronimoDocument(namespaceName, rootName);
+        Element rootElement = document.getRootElement();
+        // add system environment and dependencies element
+        QName envirionmentQName = null;
+        if (!envNamespaceName.equals("")) {
+            Namespace envNS = DocumentHelper.createNamespace("sys", envNamespaceName);
+            envirionmentQName = new QName("environment", envNS);
+        } else {
+            envirionmentQName = new QName("environment", rootElement.getNamespace());
+        }
+        Element envirionmentElement = rootElement.addElement(envirionmentQName);
+        addModuleDetails(envirionmentElement, tool);
+        addDependencyDetails(envirionmentElement, tool, JNDIName);
+        return document;
+    }
+
+    /**
+     * retuns a empty geronimo document by refering the passed parameters
+     * 
+     * @param namespaceName
+     * @param rootName
+     * @return newly created empty geronimo document
+     */
+    private static Document getEmptyGeronimoDocument(String namespaceName, String rootName)
{
+        Namespace namespace = new Namespace("", namespaceName);
+        QName qname = new QName(rootName, namespace);
+        Document document = DocumentHelper.createDocument();
+        document.addElement(qname);
+        return document;
+    }
+
+    /**
+     * add the module details to the geronimo document
+     * 
+     * @param geronimoEnvirionment
+     * @param tool
+     */
+    private static void addModuleDetails(Element geronimoEnvirionment, String tool) {
+        QName qname = new QName("moduleId", geronimoEnvirionment.getNamespace());
+        Element geronimoModuleID = geronimoEnvirionment.addElement(qname);
+        // add groupID
+        qname = new QName("groupId", geronimoModuleID.getNamespace());
+        geronimoModuleID.addElement(qname).setText("j2g");
+        if (tool.equals(Constants.SECURITY_RESOURCE_TOOL)) {
+            qname = new QName("artifactId", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("security");
+            qname = new QName("version", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("1.0");
+            qname = new QName("type", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("rar");
+        } else if (tool.equals(Constants.JMS_RESOURCE_TOOL)) {
+            qname = new QName("artifactId", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("jms");
+            qname = new QName("version", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("1.0");
+            qname = new QName("type", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("jar");
+        } else if (tool.equals(Constants.MAIL_RESOURCE_TOOL)) {
+            qname = new QName("artifactId", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("Mail");
+            qname = new QName("version", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("1.0");
+            qname = new QName("type", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("car");
+        } else if (tool.equals(Constants.DS_RESOURCE_TOOL)) {
+            qname = new QName("artifactId", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("DataSource");
+            qname = new QName("version", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("1.0");
+            qname = new QName("type", geronimoModuleID.getNamespace());
+            geronimoModuleID.addElement(qname).setText("rar");
+        }
+    }
+
+    /**
+     * add the dependancy details to the geronimo docunet
+     * 
+     * @param geronimoEnvirionment
+     * @param tool
+     * @param jndiName
+     */
+    private static void addDependencyDetails(Element geronimoEnvirionment, String tool,
+            String jndiName) {
+        // process the invalid chars
+        jndiName = jndiName.replaceAll("%", "%25");
+        jndiName = jndiName.replaceAll("\\\\/", "%2F");
+        jndiName = jndiName.replaceAll("\\\\\\\\", "%5F");
+        // add prefix
+        jndiName = "j2g/" + jndiName;
+        String firstPart = jndiName.substring(0, jndiName.lastIndexOf("/"));
+        String lastPart = jndiName.substring(jndiName.lastIndexOf("/") + 1);
+        firstPart = firstPart.replaceAll("/", ".");
+        logger.debug("Creating a new dependency with groupID ==> " + firstPart + " artifactID
==> "
+                + lastPart + " version ==> 1.0 type ==> rar");
+        System.out.println("Creating a new dependency with groupID ==> " + firstPart +
" artifactID ==> "
+                + lastPart + " version ==> 1.0 type ==> rar");
+        QName dependenciesQName = new QName("dependencies", geronimoEnvirionment.getNamespace());
+        Element dependenciesElement = geronimoEnvirionment.addElement(dependenciesQName);
+        QName qname = new QName("dependency", geronimoEnvirionment.getNamespace());
+        Element dependencyElement = dependenciesElement.addElement(qname);
+        if (tool.equals(Constants.SECURITY_RESOURCE_TOOL)) {
+            qname = new QName("groupId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("geronimo");
+            qname = new QName("artifactId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("j2ee-security");
+            //qname = new QName("version", dependencyElement.getNamespace());
+            //dependencyElement.addElement(qname).setText("1.0");
+            qname = new QName("type", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("car");
+        } else if (tool.equals(Constants.JMS_RESOURCE_TOOL)) {
+            qname = new QName("groupId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText(firstPart);
+            qname = new QName("artifactId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("jms");
+            qname = new QName("version", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("1.0");
+            qname = new QName("type", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("jar");
+        } else if (tool.equals(Constants.MAIL_RESOURCE_TOOL)) {
+            qname = new QName("groupId", dependencyElement.getNamespace());
+//            dependencyElement.addElement(qname).setText(firstPart);
+            dependencyElement.addElement(qname).setText("geronimo");
+            qname = new QName("artifactId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("javamail");
+            qname = new QName("version", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("1.1");
+            qname = new QName("type", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("car");
+        } else if (tool.equals(Constants.DS_RESOURCE_TOOL)) {
+            qname = new QName("groupId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText(firstPart);
+            qname = new QName("artifactId", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("DataSource");
+            qname = new QName("version", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("1.0");
+            qname = new QName("type", dependencyElement.getNamespace());
+            dependencyElement.addElement(qname).setText("rar");
+        }
+    }
+
+    /**
+     * writes the dom4j document object to a file given as fileNmae
+     * 
+     * @param fileName
+     *            String
+     * @param document
+     *            Document
+     * @throws IOException
+     */
+    public static void saveGeronimoDocument(String fileName, Document document) throws IOException
{
+        // add the XML pretty print
+        OutputFormat format = OutputFormat.createPrettyPrint();
+        // Write the file to the to the filesystem
+        XMLWriter writer = new XMLWriter(new FileWriter(fileName), format);
+        writer.write(document);
+        writer.close();
+    }
+}

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/src/org/apache/apps/j2gmigrator/resources/xmlutil/XMLConversionHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java?view=auto&rev=520023
==============================================================================
--- geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
(added)
+++ geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
Mon Mar 19 10:43:27 2007
@@ -0,0 +1,115 @@
+/**
+ *  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.apps.j2gmigrator.descriptors.xmlutil;
+
+import junit.framework.TestCase;
+import org.jaxen.*;
+import org.jaxen.dom.DOMXPath;
+import org.apache.apps.j2gmigrator.descriptors.util.Constants;
+import org.apache.apps.j2gmigrator.descriptors.xmlutil.XMLConversionHelper;
+import org.dom4j.*;
+import org.dom4j.XPath;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Author: amila
+ * Date: Aug 29, 2006
+ */
+public class TestXMLConversionHelper extends TestCase {
+
+    public void testGetDocument() {
+
+        File file = new File("test-resources/jboss-xml/jboss-web.xml");
+        try {
+            Document doucument = XMLConversionHelper.getDocument(file);
+            System.out.println("Got document");
+        } catch (DocumentException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+
+    }
+
+    public void testGetGeronimoElement() {
+
+        String directoryName = "test-resources/jboss-xml";
+        try {
+            Document geronimoDocument = XMLConversionHelper.getOpenEJBJarDocument(directoryName);
+            
+            Element geronimoElement = XMLConversionHelper.getGeronimoElement(geronimoDocument.getRootElement(),
+                    "//ejb:enterprise-beans", "enterprise-beans",
+                    geronimoDocument.getRootElement().getNamespace());
+            System.out.println("Result ok");
+        } catch (DocumentException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
+
+    public void testSaveOpenEJBDocument(){
+        String fileName = "test-resources/test-app-jboss/openejb-jar-serialized.xml";
+        String directoryName = "test-resources/test-app-jboss";
+        try {
+            Document document = XMLConversionHelper.getOpenEJBJarDocument(directoryName);
+            XMLConversionHelper.saveOpenEJBDocument(fileName,document);
+        } catch (DocumentException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        } catch (IOException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
+
+    public void testXpath() {
+
+        Document document = DocumentHelper.createDocument();
+
+        Namespace namespace = new Namespace("", "http://covalent.com");
+        QName qname = new QName("root", namespace);
+        Element root = document.addElement(qname);
+
+        qname = new QName("author1", namespace);
+        Element author1 = root.addElement(qname);
+        author1.setText("amila");
+
+        qname = new QName("author2", namespace);
+        Element author2 = root.addElement(qname);
+        author2.setText("rasika");
+
+//        XPath xpath = document.createXPath("//ns1:author");
+//        Map hashMap = new HashMap();
+//        hashMap.put("ns1","http://covalent.com");
+//        xpath.setNamespaceURIs(hashMap);
+//        List nodes = xpath.selectNodes(document);
+//        System.out.println("List size ==> " + nodes.size());
+
+        XPath xpath = document.createXPath("//ns1:author2[text() = 'rasika']");
+
+        Map hashMap = new HashMap();
+        hashMap.put("ns1", "http://covalent.com");
+        xpath.setNamespaceURIs(hashMap);
+        Node node = (Node) xpath.evaluate(root);
+
+
+        System.out.println("ok.........");
+
+
+    }
+}

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/descriptors/xmlutil/TestXMLConversionHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java?view=auto&rev=520023
==============================================================================
--- geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
(added)
+++ geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
Mon Mar 19 10:43:27 2007
@@ -0,0 +1,108 @@
+/**
+ *  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.apps.j2gmigrator.resources.xmlutil.test;
+
+import java.io.File;
+import junit.framework.TestCase;
+
+import org.apache.apps.j2gmigrator.resources.utils.Constants;
+import org.apache.apps.j2gmigrator.resources.xmlutil.XMLConversionHelper;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.io.SAXReader;
+
+/**
+ * The TestCase for the XML Convertion Helper Class inside resource conversion tool
+ * Test Methods were written to each needed method to test
+ * @author sandakith
+ * @date 24082006
+ */
+public class XMLConvertionHelperTestCase extends TestCase {
+
+	public void testMethod_crateSibling() {
+		
+		Element element = XMLConversionHelper.createSibling("name", "TradeDs", new Namespace("test","test"));
+		System.out.println("testMethod_crateSibling : "+ element.asXML());
+		System.out.println("testMethod_crateSibling : "+element.getText());
+		assertNotNull(element);
+	}
+	
+	public void testMethod_obtainNameFromJNDINAME() {
+		String result = XMLConversionHelper.obtainNameFromJNDINAME("jdbc/TradeDs");
+		System.out.println("testMethod_obtainNameFromJNDINAME : "+result);
+		assertNotNull(result);
+	}
+	
+	public void testMethod_addAttributeToElement() {
+		Element element = DocumentHelper.createElement("config-property-setting");
+		Element result = XMLConversionHelper.addAttributeToElement(element,"name", "UserName");
+		System.out.println("addAttributeToElement : "+ result.asXML());
+		assertNotNull(result);
+	}
+	
+	public void testMethod_createSiblingWithAttrib() {
+		Element result = XMLConversionHelper.createSiblingWithAttrib("config-property-setting","root","name",
"UserName", new Namespace("test","test"));
+		System.out.println("createSiblingWithAttrib : "+ result.asXML());
+		assertNotNull(result);
+	}
+	
+	
+	public void testMethod_createIdConbinationWhenDriverMapRetrnsEmpty() {
+		String[] test = {"oracle.jdbc.OracleDriver","com.microsoft.jdbc.sqlserver.SQLServerDriver","com.ibm.db2.jcc.DB2Driver",
+						"org.test.test.test.DB2Driver", "net.test.test.test.DB2Driver"};
+		for(int a= 0; a<=4 ; a++){
+			String result = XMLConversionHelper.createIdConbinationWhenDriverMapRetrnsEmpty(test[a]);
+			System.out.println("createIdConbinationWhenDriverMapRetrnsEmpty : "+ result);
+			assertNotNull(result);
+		}	
+	}
+	
+	public void testMethod_containSubElementWithAttribute(){
+		File mailFile = new File(Constants.TEST_RESOURCES_DIRECTORY+Constants.MAIL_RESOURCE_TOOL+"/"+Constants.JBOSS_VALID_MAIL_XML_FILE);
+        SAXReader saxReader = new SAXReader();
+        Document mailDocument;
+		try {
+			mailDocument = saxReader.read(mailFile);
+			Element subMailElement = XMLConversionHelper.obtainSubElement(mailDocument.getRootElement(),
"mbean");
+			boolean result = XMLConversionHelper.containSubElementWithAttribute(subMailElement,"attribute","name","Password");
+			assert(result);
+		} catch (DocumentException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+	public void testMethod_obtainSubElementWithAttribute(){
+		File mailFile = new File(Constants.TEST_RESOURCES_DIRECTORY+Constants.MAIL_RESOURCE_TOOL+"/"+Constants.JBOSS_VALID_MAIL_XML_FILE);
+        SAXReader saxReader = new SAXReader();
+        Document mailDocument;
+		try {
+			mailDocument = saxReader.read(mailFile);
+			Element subMailElement = XMLConversionHelper.obtainSubElement(mailDocument.getRootElement(),
"mbean");
+			Element result= XMLConversionHelper.obtainSubElementWithAttribute(subMailElement,"attribute","name","Password");
+			System.out.println(result.asXML());
+			assertNotNull("obtainSubElementWithAttribute : "+result);
+		} catch (DocumentException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
+}

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/j2g/src2/xml-conversion-helper/test/org/apache/apps/j2gmigrator/resources/xmlutil/test/XMLConvertionHelperTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message