[jboss-svn-commits] JBL Code SVN: r25725 - in labs/jbossesb/branches/JBESB_4_4_GA_FP/product: rosetta/src/org/jboss/internal/soa/esb/webservice and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 19 04:43:07 EDT 2009
Author: beve
Date: 2009-03-19 04:43:07 -0400 (Thu, 19 Mar 2009)
New Revision: 25725
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/build-distr.xml
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/ivy.xml
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBContractGenerator.java
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/ESBContractGeneratorUnitTest.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2470 "Duplicate schema types in wsdl generated by EBWS"
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/build-distr.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/build-distr.xml 2009-03-19 05:08:03 UTC (rev 25724)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/build-distr.xml 2009-03-19 08:43:07 UTC (rev 25725)
@@ -138,6 +138,7 @@
<!-- Mina -->
<fileset dir="${lib.dir}" includes="mina-*.jar"/>
<fileset dir="${lib.dir}" includes="slf4j-*.jar"/>
+ <fileset dir="${lib.dir}" includes="xmlunit-*.jar"/>
<fileset dir="${lib.dir}" includes="freemarker-*.jar"/>
</copy>
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/ivy.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/ivy.xml 2009-03-19 05:08:03 UTC (rev 25724)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/ivy.xml 2009-03-19 08:43:07 UTC (rev 25725)
@@ -80,5 +80,9 @@
<dependency org="sun-jaxb" name="jaxb-xjc" rev="2.1.4"/>
<dependency org="org.freemarker" name="freemarker" rev="2.3.9"/>
+
+ <!-- xmlunit -->
+ <dependency org="xmlunit" name="xmlunit" rev="1.2"/>
+
</dependencies>
</ivy-module>
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBContractGenerator.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBContractGenerator.java 2009-03-19 05:08:03 UTC (rev 25724)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/internal/soa/esb/webservice/ESBContractGenerator.java 2009-03-19 08:43:07 UTC (rev 25725)
@@ -29,7 +29,17 @@
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
+import org.custommonkey.xmlunit.XMLUnit;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+import org.dom4j.util.NodeComparator;
import javax.wsdl.Binding;
import javax.wsdl.BindingFault;
import javax.wsdl.BindingInput;
@@ -80,7 +90,9 @@
// add types
Types types = def.createTypes();
def.setTypes(types);
- Set<String> schemasAdded = new HashSet<String>();
+
+ // Keeps track of schema types added to avoid duplicates.
+ Set<String> schemasAdded = new HashSet<String>();
Message reqMessage = null;
Message resMessage = null;
@@ -97,14 +109,8 @@
.getResourceAsStream(inXsd, ESBContractGenerator.class),
false, false);
if (doc != null) {
- /*
- String schemaNs = getSchemaNs(doc);
- if (schemaNs != null) {
- schemasAdded.add(schemaNs);
- }
- */
reqMessage = addMessage(def, doc.getDocumentElement(),
- serviceInfo.getRequestName(), "in", ++nsSuffixCounter);
+ serviceInfo.getRequestName(), "in", ++nsSuffixCounter, schemasAdded);
}
} catch (Exception e) {
throw new ConfigurationException("File defined in inXsd attribute '" + inXsd + "' not found in classpath.", e);
@@ -117,10 +123,8 @@
.getResourceAsStream(outXsd, ESBContractGenerator.class),
false, false);
if (doc != null) {
- //if (!schemasAdded.contains(getSchemaNs(doc))) {
- resMessage = addMessage(def, doc.getDocumentElement(),
- serviceInfo.getResponseName(), "out", ++nsSuffixCounter);
- //}
+ resMessage = addMessage(def, doc.getDocumentElement(),
+ serviceInfo.getResponseName(), "out", ++nsSuffixCounter, schemasAdded);
}
} catch (Exception e) {
throw new ConfigurationException("File defined in outXsd attribute '" + outXsd + "' not found in classpath.", e);
@@ -137,11 +141,9 @@
.getResourceAsStream(xsd, ESBContractGenerator.class),
false, false);
if (doc != null) {
- // if (!schemasAdded.contains(getSchemaNs(doc))) {
- addFaultMessage(faultMessages, def, doc.getDocumentElement(),
- serviceInfo.getFaultName(), "fault", ++nsSuffixCounter);
- }
- //}
+ addFaultMessage(faultMessages, def, doc.getDocumentElement(),
+ serviceInfo.getFaultName(), "fault", ++nsSuffixCounter, schemasAdded);
+ }
}
} catch (Exception e) {
throw new ConfigurationException("File defined in faultXsd attribute '" + faultXsd + "' not found in classpath.", e);
@@ -163,17 +165,47 @@
return sw.toString();
}
- private static void addSchema(Types types, Element xsdElement) {
- SchemaImpl schemaImpl = new SchemaImpl();
- schemaImpl.setElement(xsdElement);
- schemaImpl.setElementType(XSD_QN);
- types.addExtensibilityElement(schemaImpl);
+ private static void addSchema(Types types, Element xsdElement, Set<String> schemasAdded) throws SAXException, IOException, TransformerException {
+ if (add(xsdElement, schemasAdded))
+ {
+ SchemaImpl schemaImpl = new SchemaImpl();
+ schemaImpl.setElement(xsdElement);
+ schemaImpl.setElementType(XSD_QN);
+ types.addExtensibilityElement(schemaImpl);
+ }
}
- private static Message addMessage(Definition def, Element element, String msgName, String partName, int nsSuffixCounter) {
+ private static boolean add(final Element schemaElement, final Set<String> schemasAdded) throws SAXException, IOException, TransformerException
+ {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ StringWriter writer = new StringWriter();
+ Result result = new StreamResult(writer);
+ transformer.transform(new DOMSource(schemaElement), result);
+ String newType = writer.toString();
+ if (schemasAdded.size() == 0)
+ {
+ return schemasAdded.add(newType);
+ }
+ else
+ {
+ XMLUnit.setIgnoreWhitespace(true);
+ for (String existingType : schemasAdded)
+ {
+ if (!XMLUnit.compareXML(existingType, newType).identical())
+ {
+ return schemasAdded.add(newType);
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private static Message addMessage(Definition def, Element element, String msgName, String partName, int nsSuffixCounter, Set<String> schemasAdded)throws SAXException, IOException, TransformerException {
String schemaNs = YADOMUtil
.getAttribute(element, "targetNamespace", "");
- addSchema(def.getTypes(), element);
+ addSchema(def.getTypes(), element, schemasAdded);
if (def.getNamespace(schemaNs) == null) {
def.addNamespace("ns" + nsSuffixCounter, schemaNs);
}
@@ -193,10 +225,10 @@
private static void addFaultMessage(final List<Message> faultMessages,
Definition def, Element element, String msgName, String partName,
- int nsSuffixCounter) {
+ int nsSuffixCounter, Set<String> schemasAdded) throws SAXException, IOException, TransformerException {
String schemaNs = YADOMUtil
.getAttribute(element, "targetNamespace", "");
- addSchema(def.getTypes(), element);
+ addSchema(def.getTypes(), element, schemasAdded);
if (def.getNamespace(schemaNs) == null) {
def.addNamespace("ns" + nsSuffixCounter, schemaNs);
}
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/ESBContractGeneratorUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/ESBContractGeneratorUnitTest.java 2009-03-19 05:08:03 UTC (rev 25724)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/tests/src/org/jboss/internal/soa/esb/webservice/ESBContractGeneratorUnitTest.java 2009-03-19 08:43:07 UTC (rev 25725)
@@ -62,14 +62,12 @@
executeTest("jbossesb_config_08.110.xml") ;
}
-/* Will fix this with my next task checkin dealing with duplicate import types
public void testDuplicateSchemas() throws Exception {
Definition def = executeTest("jbossesb_duplicate_schemas.xml") ;
Types types = def.getTypes();
List schemas = types.getExtensibilityElements();
assertEquals(1,schemas.size());
}
-*/
private Definition executeTest(final String resourceName) throws Exception {
More information about the jboss-svn-commits
mailing list