You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by li...@apache.org on 2007/10/08 20:52:41 UTC
svn commit: r582934 [2/2] - in
/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util:
./ META-INF/ src/ src/org/ src/org/apache/ src/org/apache/geronimo/
src/org/apache/geronimo/devtools/ src/org/apache/geronimo/devtools/j2g/
src/o...
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/src/org/apache/geronimo/devtools/j2g/util/resources/xml/XMLConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/src/org/apache/geronimo/devtools/j2g/util/resources/xml/XMLConversionHelper.java?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/src/org/apache/geronimo/devtools/j2g/util/resources/xml/XMLConversionHelper.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/src/org/apache/geronimo/devtools/j2g/util/resources/xml/XMLConversionHelper.java Mon Oct 8 11:52:38 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.geronimo.devtools.j2g.util.resources.xml;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.devtools.j2g.util.resources.Constants;
+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://geronimo.apache.org/xml/ns/j2g-1.0";
+
+ 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/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/src/org/apache/geronimo/devtools/j2g/util/resources/xml/XMLConversionHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss-web.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss-web.xml?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss-web.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss-web.xml Mon Oct 8 11:52:38 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+
+<!--DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 3.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd"-->
+
+<jboss-web>
+ <security-domain>securityDomation</security-domain>
+ <context-root>/myApp</context-root>
+ <resource-env-ref>
+ <resource-env-ref-name>envResource1</resource-env-ref-name>
+ <jndi-name>jdbc/TestDB</jndi-name>
+ </resource-env-ref>
+ <resource-ref>
+ <res-ref-name>resource1</res-ref-name>
+ <jndi-name>jdbc/TestDB</jndi-name>
+ </resource-ref>
+ <security-role>
+ <role-name>amila1</role-name>
+ <principal-name>amila1</principal-name>
+ </security-role>
+ <security-role>
+ <role-name>amila2</role-name>
+ <principal-name>amila2</principal-name>
+ </security-role>
+ <ejb-ref>
+ <ejb-ref-name>ejb/TestEJB</ejb-ref-name>
+ <jndi-name>ejb/TestEJB</jndi-name>
+ </ejb-ref>
+ <ejb-local-ref>
+ <ejb-ref-name>ejb/LocalTestEJB</ejb-ref-name>
+ <local-jndi-name>ejb/LocalEJB</local-jndi-name>
+ </ejb-local-ref>
+</jboss-web>
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss-web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss.xml?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss.xml Mon Oct 8 11:52:38 2007
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+
+<!--DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 3.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd"-->
+
+<jboss>
+ <enterprise-beans>
+ <session>
+ <ejb-name>EJBTestRunnerEJB</ejb-name>
+ <jndi-name>ejb/EJBTestRunner</jndi-name>
+ </session>
+ <entity>
+ <ejb-name>OrganizationEJB</ejb-name>
+ <local-jndi-name>crimeportal/Organization</local-jndi-name>
+ </entity>
+ <entity>
+ <ejb-name>GangsterEJB</ejb-name>
+ <local-jndi-name>crimeportal/Gangster</local-jndi-name>
+ </entity>
+ <entity>
+ <ejb-name>JobEJB</ejb-name>
+ <local-jndi-name>crimeportal/Job</local-jndi-name>
+ </entity>
+ </enterprise-beans>
+</jboss>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/jboss-xml/jboss.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/geronimo-mail-service.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/geronimo-mail-service.xml?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/geronimo-mail-service.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/geronimo-mail-service.xml Mon Oct 8 11:52:38 2007
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+ <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+ <environment>
+ <moduleId>
+ <groupId>j2g</groupId>
+ <artifactId>Mail</artifactId>
+ <version>1.0</version>
+ <type>car</type>
+ </moduleId>
+ <dependencies>
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>javamail</artifactId>
+ </dependency>
+ </dependencies>
+ </environment>
+ <gbean name="mailSession" class="org.apache.geronimo.mail.MailGBean">
+ <attribute name="properties">
+mail.store.protocol=pop3
+mail.transport.protocol=smtp
+mail.user=nobody
+mail.pop3.host=pop3.nosuchhost.nosuchdomain.com
+mail.smtp.host=smtp.nosuchhost.nosuchdomain.com
+mail.from=nobody@nosuchhost.nosuchdomain.com
+mail.debug=false
+ </attribute>
+ </gbean>
+</module>
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/geronimo-mail-service.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/mail-service.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/mail-service.xml?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/mail-service.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/mail-service.xml Mon Oct 8 11:52:38 2007
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<!-- DOCTYPE server
+ PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd"-->
+<!-- $Id: mail-service.xml 561821 2007-08-01 15:05:12Z pmcmahan $ -->
+
+<server>
+
+ <!-- ==================================================================== -->
+ <!-- Mail Connection Factory -->
+ <!-- ==================================================================== -->
+
+ <mbean code="org.jboss.mail.MailService"
+ name="jboss:service=Mail">
+ <attribute name="JNDIName">java:/Mail</attribute>
+ <attribute name="User">nobody</attribute>
+ <attribute name="Password">none</attribute>
+ <attribute name="Configuration">
+ <!-- Test -->
+ <configuration>
+ <!-- Change to your mail server prototocol -->
+ <property name="mail.store.protocol" value="pop3"/>
+ <property name="mail.transport.protocol" value="smtp"/>
+
+ <!-- Change to the user who will receive mail -->
+ <property name="mail.user" value="nobody"/>
+
+ <!-- Change to the mail server -->
+ <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>
+
+ <!-- Change to the SMTP gateway server -->
+ <property name="mail.smtp.host" value="smtp.nosuchhost.nosuchdomain.com"/>
+
+ <!-- Change to the address mail will be from -->
+ <property name="mail.from" value="nobody@nosuchhost.nosuchdomain.com"/>
+
+ <!-- Enable debugging output from the javamail classes -->
+ <property name="mail.debug" value="false"/>
+ </configuration>
+ </attribute>
+ </mbean>
+
+</server>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/mail/mail-service.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/test-app-jboss/openejb-jar-serialized.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/test-app-jboss/openejb-jar-serialized.xml?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/test-app-jboss/openejb-jar-serialized.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/test-app-jboss/openejb-jar-serialized.xml Mon Oct 8 11:52:38 2007
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1" xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>j2g</sys:groupId>
+ <sys:artifactId>ejb-module</sys:artifactId>
+ <sys:version>1.0</sys:version>
+ <sys:type>jar</sys:type>
+ </sys:moduleId>
+ <sys:dependencies/>
+ </sys:environment>
+</openejb-jar>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test-apps/test-app-jboss/openejb-jar-serialized.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/descriptors/xml/test/TestXMLConversionHelper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/descriptors/xml/test/TestXMLConversionHelper.java?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/descriptors/xml/test/TestXMLConversionHelper.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/descriptors/xml/test/TestXMLConversionHelper.java Mon Oct 8 11:52:38 2007
@@ -0,0 +1,102 @@
+/**
+ * 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.devtools.j2g.util.descriptors.xml.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.devtools.j2g.util.descriptors.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.Node;
+import org.dom4j.QName;
+import org.dom4j.XPath;
+
+public class TestXMLConversionHelper extends TestCase {
+
+ public void testGetDocument() {
+
+ File file = new File("test-apps/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-apps/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-apps/test-app-jboss/openejb-jar-serialized.xml";
+ String directoryName = "test-apps/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:author2[text() = 'rasika']");
+
+ Map hashMap = new HashMap();
+ hashMap.put("ns1", "http://covalent.com");
+ xpath.setNamespaceURIs(hashMap);
+ Node node = (Node) xpath.evaluate(root);
+
+ }
+}
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/descriptors/xml/test/TestXMLConversionHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/resources/xml/test/XMLConversionHelperTestCase.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/resources/xml/test/XMLConversionHelperTestCase.java?rev=582934&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/resources/xml/test/XMLConversionHelperTestCase.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/resources/xml/test/XMLConversionHelperTestCase.java Mon Oct 8 11:52:38 2007
@@ -0,0 +1,107 @@
+/**
+ * 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.devtools.j2g.util.resources.xml.test;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.devtools.j2g.util.resources.Constants;
+import org.apache.geronimo.devtools.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.io.SAXReader;
+
+/**
+ * The TestCase for the XML Convertion Helper Class inside resource conversion tool
+ * Test Methods were written to each needed method to test
+ */
+public class XMLConversionHelperTestCase 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/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.util/test/org/apache/geronimo/devtools/j2g/util/resources/xml/test/XMLConversionHelperTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native