[savara-commits] savara SVN: r347 - branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Aug 13 08:58:08 EDT 2010
Author: objectiser
Date: 2010-08-13 08:58:07 -0400 (Fri, 13 Aug 2010)
New Revision: 347
Added:
branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/
branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java
Modified:
branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
trunk/pom.xml
trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
trunk/validators/jbossesb/pom.xml
Log:
SAVARA-118 - generate xsd imports, instead of wsdl imports, for referenced schema files.
Modified: branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-08-06 08:42:06 UTC (rev 346)
+++ branches/1.0.x/tools/eclipse/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -321,6 +321,7 @@
}
String filename=getWSDLFileName(role, localcm.getModelName().getName(), num);
+ byte[] b=null;
if (i > 0) {
javax.wsdl.Import imp=defns.get(0).createImport();
@@ -330,19 +331,39 @@
imp.setLocationURI(filename);
defns.get(0).addImport(imp);
+
+ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
+
+ writer.writeWSDL(defn, baos);
+
+ b = baos.toByteArray();
+
+ baos.close();
+
} else {
+ org.w3c.dom.Document doc=writer.getDocument(defn);
+
importSchemas(cdmResource, contract, bpelFolderPath,
- defn, defns.get(0));
+ doc);
+
+ // Create bytearray from DOM
+ java.io.ByteArrayOutputStream xmlstr=
+ new java.io.ByteArrayOutputStream();
+
+ DOMSource source=new DOMSource();
+ source.setNode(doc);
+
+ StreamResult result=new StreamResult(xmlstr);
+
+ Transformer trans=
+ TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ b = XMLUtils.format(new String(xmlstr.toByteArray())).getBytes();
}
- java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
-
- writer.writeWSDL(defn, baos);
-
- byte[] b=baos.toByteArray();
-
- baos.close();
-
IPath wsdlPath=bpelFolderPath.append(filename);
IFile wsdlFile=proj.getProject().getWorkspace().getRoot().getFile(wsdlPath);
@@ -362,42 +383,61 @@
}
protected void importSchemas(IFile cdmResource, Contract contract,
- IPath bpelFolderPath, javax.wsdl.Definition defn,
- javax.wsdl.Definition firstDefn) throws Exception {
+ IPath bpelFolderPath, org.w3c.dom.Document doc) throws Exception {
- // Generate imports for specified message schema
- for (Namespace ns : contract.getNamespaces()) {
+ // NOTE: Unfortunate workaround due to issue with WSDLWriter not
+ // generating output for extensible elements created to represent
+ // the xsd:schema/xsd:import elements. So instead had to obtain
+ // the DOM document and insert the relevant elements.
+
+ if (contract.getNamespaces().size() > 0) {
+ org.w3c.dom.Element defnElem=doc.getDocumentElement();
- if (ns.getSchemaLocation() != null &&
- ns.getSchemaLocation().trim().length() > 0) {
+ // Added types node
+ org.w3c.dom.Element types=doc.createElementNS("http://schemas.xmlsoap.org/wsdl/",
+ "types");
+
+ org.w3c.dom.Element schema=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "schema");
+
+ types.appendChild(schema);
+
+ // Generate imports for specified message schema
+ for (Namespace ns : contract.getNamespaces()) {
- java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
-
- while (st.hasMoreTokens()) {
- String location=st.nextToken();
- IFile file=cdmResource.getParent().getFile(new Path(location));
+ if (ns.getSchemaLocation() != null &&
+ ns.getSchemaLocation().trim().length() > 0) {
+
+ java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
- javax.wsdl.Import imp=firstDefn.createImport();
+ while (st.hasMoreTokens()) {
+ String location=st.nextToken();
+ IFile file=cdmResource.getParent().getFile(new Path(location));
- imp.setDefinition(defn);
- imp.setNamespaceURI(ns.getURI());
-
- if (file.exists()) {
- imp.setLocationURI(file.getProjectRelativePath().toPortableString());
+ org.w3c.dom.Element imp=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "import");
- // Copy schema file into generated BPEL project
- IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+ imp.setAttribute("namespace", ns.getURI());
- IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+ if (file.exists()) {
+ imp.setAttribute("schemaLocation", file.getProjectRelativePath().toPortableString());
- copySchema(file, artifactFile, bpelFolderPath);
- } else {
- imp.setLocationURI(location);
+ // Copy schema file into generated BPEL project
+ IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+
+ IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+ copySchema(file, artifactFile, bpelFolderPath);
+ } else {
+ imp.setAttribute("schemaLocation", location);
+ }
+
+ schema.appendChild(imp);
}
-
- firstDefn.addImport(imp);
}
}
+
+ defnElem.insertBefore(types, defnElem.getFirstChild());
}
}
Modified: branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
===================================================================
--- branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-08-06 08:42:06 UTC (rev 346)
+++ branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -32,7 +32,13 @@
import org.eclipse.ui.IWorkbenchPart;
import org.jboss.savara.tools.wsdl.generator.WSDLGeneratorUtil;
import org.jboss.savara.tools.wsdl.generator.soap.*;
+import org.jboss.savara.tools.wsdl.util.XMLUtils;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import org.scribble.contract.model.Contract;
import org.scribble.contract.model.Interface;
import org.scribble.contract.model.Namespace;
@@ -161,6 +167,8 @@
// Check if definition has a port type
if (defn.getPortTypes().size() > 0 || defn.getMessages().size() > 0
|| (f_hasMEP && defn.getServices().size() > 0)) {
+ byte[] b=null; // Bytes to write out
+
String num="";
if (i > 0) {
num += i;
@@ -175,47 +183,87 @@
imp.setNamespaceURI(defn.getTargetNamespace());
imp.setLocationURI(filename);
- defns.get(0).addImport(imp);
+ defns.get(0).addImport(imp);
+
+ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
+
+ writer.writeWSDL(defn, baos);
+
+ b=baos.toByteArray();
+
+ baos.close();
+
} else {
-
- // Generate imports for specified message schema
- for (Namespace ns : contract.getNamespaces()) {
+
+ // NOTE: Unfortunate workaround due to issue with WSDLWriter not
+ // generating output for extensible elements created to represent
+ // the xsd:schema/xsd:import elements. So instead had to obtain
+ // the DOM document and insert the relevant elements.
+
+ org.w3c.dom.Document doc=writer.getDocument(defn);
+
+ if (contract.getNamespaces().size() > 0) {
+ org.w3c.dom.Element defnElem=doc.getDocumentElement();
- if (ns.getSchemaLocation() != null &&
- ns.getSchemaLocation().trim().length() > 0) {
-
- java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
+ // Added types node
+ org.w3c.dom.Element types=doc.createElementNS("http://schemas.xmlsoap.org/wsdl/",
+ "types");
+
+ org.w3c.dom.Element schema=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "schema");
+
+ types.appendChild(schema);
+
+ // Generate imports for specified message schema
+ for (Namespace ns : contract.getNamespaces()) {
- while (st.hasMoreTokens()) {
- String location=st.nextToken();
- IFile file=cdmResource.getParent().getFile(new Path(location));
-
- javax.wsdl.Import imp=defns.get(0).createImport();
+ if (ns.getSchemaLocation() != null &&
+ ns.getSchemaLocation().trim().length() > 0) {
+
+ java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
- imp.setDefinition(defn);
- imp.setNamespaceURI(ns.getURI());
+ while (st.hasMoreTokens()) {
+ String location=st.nextToken();
+ IFile file=cdmResource.getParent().getFile(new Path(location));
- if (file.exists()) {
- IPath relative=file.getFullPath().makeRelativeTo(wsdlFolderPath);
- imp.setLocationURI(relative.toPortableString());
- } else {
- imp.setLocationURI(location);
+ org.w3c.dom.Element imp=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "import");
+
+ imp.setAttribute("namespace", ns.getURI());
+
+ if (file.exists()) {
+ IPath relative=file.getFullPath().makeRelativeTo(wsdlFolderPath);
+ imp.setAttribute("schemaLocation", relative.toPortableString());
+ } else {
+ imp.setAttribute("schemaLocation", location);
+ }
+
+ schema.appendChild(imp);
}
-
- defns.get(0).addImport(imp);
}
}
+
+ defnElem.insertBefore(types, defnElem.getFirstChild());
}
+
+ // Create bytearray from DOM
+ java.io.ByteArrayOutputStream xmlstr=
+ new java.io.ByteArrayOutputStream();
+
+ DOMSource source=new DOMSource();
+ source.setNode(doc);
+
+ StreamResult result=new StreamResult(xmlstr);
+
+ Transformer trans=
+ TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ b = XMLUtils.format(new String(xmlstr.toByteArray())).getBytes();
}
- java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
-
- writer.writeWSDL(defn, baos);
-
- byte[] b=baos.toByteArray();
-
- baos.close();
-
IPath wsdlPath=wsdlFolderPath.append(filename);
IFile wsdlFile=cdmResource.getProject().getWorkspace().getRoot().getFile(wsdlPath);
Added: branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java
===================================================================
--- branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java (rev 0)
+++ branches/1.0.x/tools/eclipse/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -0,0 +1,300 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.util;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.scribble.model.ModelObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * This class defines a set of XML related utility functions.
+ */
+public final class XMLUtils {
+
+ private static final String NS_LABEL = "ns";
+
+ /**
+ * This class converts a DOM representation node to text.
+ * @param node
+ * @return
+ * @throws Exception
+ */
+ public static final String toText(Node node) throws Exception {
+ String ret = null;
+ try {
+ // Transform the DOM represent to text
+ ByteArrayOutputStream xmlstr= new ByteArrayOutputStream();
+ DOMSource source=new DOMSource(node);
+ //source.setNode(node);
+
+ StreamResult result=new StreamResult(xmlstr);
+ Transformer trans= TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ ret = new String(xmlstr.toByteArray());
+
+ if ((node instanceof Document) == false) {
+ // Strip off any <?xml> header
+ int index=ret.indexOf("<?xml");
+ if (index != -1) {
+ index = ret.indexOf("<", 1);
+ if (index != -1) {
+ ret = ret.substring(index);
+ } else {
+ index = ret.indexOf("?>");
+ if (index != -1) {
+ index += 2;
+
+ // Remove any trailing whitespaces after XML header
+ while (index < ret.length() &&
+ Character.isWhitespace(ret.charAt(index))) {
+ index++;
+ }
+
+ ret = ret.substring(index);
+ }
+ }
+ }
+ }
+
+ } catch(Exception e) {
+ throw new Exception("Failed to transform DOM representation into text", e);
+ }
+ if (ret != null) {
+ return format(ret);
+ }
+ return ret;
+ }
+
+
+ /**
+ * Format the xml to well print.
+ *
+ * @param xmltext
+ * @return
+ */
+ public static final String format(String xmltext) {
+ String ret=xmltext;
+ int pos=0;
+ int prevpos=0;
+ StringBuffer buf=new StringBuffer();
+ int level=0;
+
+ while ((pos=ret.indexOf('<', prevpos)) != -1) {
+
+ if (prevpos < pos &&
+ ret.substring(prevpos, pos).trim().length() > 0 &&
+ ret.charAt(prevpos-1) != '?') {
+
+ if (ret.charAt(prevpos) == '\r' &&
+ ret.charAt(prevpos+1) == '\n') {
+ prevpos += 2;
+ }
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+
+ buf.append(ret.substring(prevpos, pos).trim());
+ buf.append("\r\n");
+ }
+
+ int endpos=ret.indexOf('>', pos);
+
+ if (endpos > 0) {
+ boolean noreturn=false;
+
+ if (pos > 0 && ret.charAt(pos+1) == '/') {
+ level--;
+ }
+
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+ buf.append(ret.substring(pos, endpos+1));
+
+ if (ret.charAt(endpos-1)== '?') {
+ //noreturn = true;
+
+ } else if (ret.charAt(endpos-1) == '/') {
+ // Ignore
+ } else if (pos > 0 && ret.charAt(pos+1) == '/') {
+ // Ignore
+
+ } else if (pos > 0 && ret.charAt(pos+1) == '!') {
+ // Ignore
+
+ } else {
+ level++;
+ }
+
+ if (noreturn == false) {
+ buf.append("\r\n");
+ }
+
+ pos = endpos+1;
+ }
+
+ prevpos = pos;
+ }
+
+ if (prevpos != -1 &&
+ ret.substring(prevpos).trim().length() > 0) {
+ buf.append(ret.substring(prevpos));
+ }
+
+ ret = buf.toString();
+
+ return(ret);
+ }
+
+ public static Node getNode(String text) throws Exception {
+ Node ret=null;
+
+ // Transform the text representation to DOM
+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+ fact.setNamespaceAware(true);
+
+ java.io.InputStream xmlstr=
+ new java.io.ByteArrayInputStream(text.getBytes());
+
+ DocumentBuilder builder=fact.newDocumentBuilder();
+ org.w3c.dom.Document doc=builder.parse(xmlstr);
+
+ ret = doc.getDocumentElement();
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the localname part of the supplied
+ * qualified name.
+ *
+ * @param qname The qualified name
+ * @return The localname part
+ */
+ public static String getLocalname(String qname) {
+ String ret=qname;
+ int pos=0;
+
+ if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+ ret = qname.substring(pos+1);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the prefix associated with the supplied namespace.
+ *
+ * @param namespace The namespace
+ * @param nsMap The existing namespace prefix mappings
+ * @return The prefix
+ */
+ public static String getPrefix(String namespace, java.util.Map<String,String> nsMap) {
+ String prefix=null;
+
+ prefix = nsMap.get(namespace);
+
+ if (prefix == null) {
+ prefix = NS_LABEL+(nsMap.size()+1);
+ nsMap.put(namespace, prefix);
+ }
+
+ return(prefix);
+ }
+
+ /**
+ * This method calculates the start and end position of a supplied DOM element, within
+ * the supplied text contents, and sets the values on the supplied ModelObject.
+ *
+ * @param obj The ModelObject to be initialized
+ * @param contents The text contents
+ * @param elem The DOM element to be located in the text
+ */
+ public static void setStartAndEndPosition(ModelObject obj, String contents, org.w3c.dom.Element elem) {
+
+ if (contents != null) {
+ org.w3c.dom.NodeList nl=elem.getOwnerDocument().getElementsByTagName(elem.getNodeName());
+ int elempos=-1;
+
+ for (int i=0; elempos == -1 && i < nl.getLength(); i++) {
+ if (nl.item(i) == elem) {
+ elempos = i;
+ }
+ }
+
+ if (elempos != -1) {
+ int startpos=-1;
+
+ for (int i=0; i <= elempos; i++) {
+ int val1=contents.indexOf("<"+elem.getNodeName()+">", startpos+1);
+ int val2=contents.indexOf("<"+elem.getNodeName()+" ", startpos+1);
+
+ if (val1 == -1 && val2 != -1) {
+ startpos = val2;
+ } else if (val1 != -1 && val2 == -1) {
+ startpos = val1;
+ } else if (val1 == -1 && val2 == -1) {
+ // TODO: Error condition
+ break;
+ } else if (val1 > val2) {
+ startpos = val2;
+ } else {
+ startpos = val1;
+ }
+ }
+
+ if (startpos != -1) {
+ obj.getSource().setStartPosition(startpos);
+
+ // Check if single node
+ int p1=contents.indexOf('>', startpos);
+
+ if (p1 != -1 && contents.charAt(p1-1) == '/') {
+ obj.getSource().setEndPosition(p1);
+ } else {
+
+ org.w3c.dom.NodeList enl=elem.getElementsByTagName(elem.getNodeName());
+
+ int endpos=startpos;
+ String nodetxt="</"+elem.getNodeName()+">";
+
+ for (int i=0; endpos != -1 && i <= enl.getLength(); i++) {
+ endpos = contents.indexOf(nodetxt, endpos+1);
+ }
+
+ if (endpos != -1) {
+ obj.getSource().setEndPosition(endpos+nodetxt.length()-1);
+ }
+ }
+ }
+ }
+ }
+ }
+}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-08-06 08:42:06 UTC (rev 346)
+++ trunk/pom.xml 2010-08-13 12:58:07 UTC (rev 347)
@@ -160,6 +160,17 @@
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
+ <repository>
+ <id>pi4soa</id>
+ <url>http://download.jboss.org/jbosstools/builds/nightly/3.2.helios/jbosstools-pi4soa/all/repo/</url>
+ <layout>p2</layout>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
</repositories>
<distributionManagement>
Modified: trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-08-06 08:42:06 UTC (rev 346)
+++ trunk/tools/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -323,6 +323,7 @@
}
String filename=getWSDLFileName(role, localcm.getModelName().getName(), num);
+ byte[] b=null;
if (i > 0) {
javax.wsdl.Import imp=defns.get(0).createImport();
@@ -332,19 +333,39 @@
imp.setLocationURI(filename);
defns.get(0).addImport(imp);
+
+ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
+
+ writer.writeWSDL(defn, baos);
+
+ b = baos.toByteArray();
+
+ baos.close();
+
} else {
+ org.w3c.dom.Document doc=writer.getDocument(defn);
+
importSchemas(cdmResource, contract, bpelFolderPath,
- defn, defns.get(0));
+ doc);
+
+ // Create bytearray from DOM
+ java.io.ByteArrayOutputStream xmlstr=
+ new java.io.ByteArrayOutputStream();
+
+ DOMSource source=new DOMSource();
+ source.setNode(doc);
+
+ StreamResult result=new StreamResult(xmlstr);
+
+ Transformer trans=
+ TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ b = XMLUtils.format(new String(xmlstr.toByteArray())).getBytes();
}
- java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
-
- writer.writeWSDL(defn, baos);
-
- byte[] b=baos.toByteArray();
-
- baos.close();
-
IPath wsdlPath=bpelFolderPath.append(filename);
IFile wsdlFile=proj.getProject().getWorkspace().getRoot().getFile(wsdlPath);
@@ -364,42 +385,61 @@
}
protected void importSchemas(IFile cdmResource, Contract contract,
- IPath bpelFolderPath, javax.wsdl.Definition defn,
- javax.wsdl.Definition firstDefn) throws Exception {
+ IPath bpelFolderPath, org.w3c.dom.Document doc) throws Exception {
- // Generate imports for specified message schema
- for (Namespace ns : contract.getNamespaces()) {
+ // NOTE: Unfortunate workaround due to issue with WSDLWriter not
+ // generating output for extensible elements created to represent
+ // the xsd:schema/xsd:import elements. So instead had to obtain
+ // the DOM document and insert the relevant elements.
+
+ if (contract.getNamespaces().size() > 0) {
+ org.w3c.dom.Element defnElem=doc.getDocumentElement();
- if (ns.getSchemaLocation() != null &&
- ns.getSchemaLocation().trim().length() > 0) {
+ // Added types node
+ org.w3c.dom.Element types=doc.createElementNS("http://schemas.xmlsoap.org/wsdl/",
+ "types");
+
+ org.w3c.dom.Element schema=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "schema");
+
+ types.appendChild(schema);
+
+ // Generate imports for specified message schema
+ for (Namespace ns : contract.getNamespaces()) {
- java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
-
- while (st.hasMoreTokens()) {
- String location=st.nextToken();
- IFile file=cdmResource.getParent().getFile(new Path(location));
+ if (ns.getSchemaLocation() != null &&
+ ns.getSchemaLocation().trim().length() > 0) {
+
+ java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
- javax.wsdl.Import imp=firstDefn.createImport();
+ while (st.hasMoreTokens()) {
+ String location=st.nextToken();
+ IFile file=cdmResource.getParent().getFile(new Path(location));
- imp.setDefinition(defn);
- imp.setNamespaceURI(ns.getURI());
-
- if (file.exists()) {
- imp.setLocationURI(file.getProjectRelativePath().toPortableString());
+ org.w3c.dom.Element imp=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "import");
- // Copy schema file into generated BPEL project
- IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+ imp.setAttribute("namespace", ns.getURI());
- IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+ if (file.exists()) {
+ imp.setAttribute("schemaLocation", file.getProjectRelativePath().toPortableString());
- copySchema(file, artifactFile, bpelFolderPath);
- } else {
- imp.setLocationURI(location);
+ // Copy schema file into generated BPEL project
+ IPath artifactPath=bpelFolderPath.append(file.getProjectRelativePath());
+
+ IFile artifactFile=cdmResource.getProject().getWorkspace().getRoot().getFile(artifactPath);
+
+ copySchema(file, artifactFile, bpelFolderPath);
+ } else {
+ imp.setAttribute("schemaLocation", location);
+ }
+
+ schema.appendChild(imp);
}
-
- firstDefn.addImport(imp);
}
}
+
+ defnElem.insertBefore(types, defnElem.getFirstChild());
}
}
Modified: trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
===================================================================
--- trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-08-06 08:42:06 UTC (rev 346)
+++ trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -32,7 +32,13 @@
import org.eclipse.ui.IWorkbenchPart;
import org.jboss.savara.tools.wsdl.generator.WSDLGeneratorUtil;
import org.jboss.savara.tools.wsdl.generator.soap.*;
+import org.jboss.savara.tools.wsdl.util.XMLUtils;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import org.jboss.savara.contract.model.Contract;
import org.jboss.savara.contract.model.Interface;
import org.jboss.savara.contract.model.Namespace;
@@ -163,6 +169,8 @@
// Check if definition has a port type
if (defn.getPortTypes().size() > 0 || defn.getMessages().size() > 0
|| (f_hasMEP && defn.getServices().size() > 0)) {
+ byte[] b=null; // Bytes to write out
+
String num="";
if (i > 0) {
num += i;
@@ -177,47 +185,87 @@
imp.setNamespaceURI(defn.getTargetNamespace());
imp.setLocationURI(filename);
- defns.get(0).addImport(imp);
+ defns.get(0).addImport(imp);
+
+ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
+
+ writer.writeWSDL(defn, baos);
+
+ b=baos.toByteArray();
+
+ baos.close();
+
} else {
-
- // Generate imports for specified message schema
- for (Namespace ns : contract.getNamespaces()) {
+
+ // NOTE: Unfortunate workaround due to issue with WSDLWriter not
+ // generating output for extensible elements created to represent
+ // the xsd:schema/xsd:import elements. So instead had to obtain
+ // the DOM document and insert the relevant elements.
+
+ org.w3c.dom.Document doc=writer.getDocument(defn);
+
+ if (contract.getNamespaces().size() > 0) {
+ org.w3c.dom.Element defnElem=doc.getDocumentElement();
- if (ns.getSchemaLocation() != null &&
- ns.getSchemaLocation().trim().length() > 0) {
-
- java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
+ // Added types node
+ org.w3c.dom.Element types=doc.createElementNS("http://schemas.xmlsoap.org/wsdl/",
+ "types");
+
+ org.w3c.dom.Element schema=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "schema");
+
+ types.appendChild(schema);
+
+ // Generate imports for specified message schema
+ for (Namespace ns : contract.getNamespaces()) {
- while (st.hasMoreTokens()) {
- String location=st.nextToken();
- IFile file=cdmResource.getParent().getFile(new Path(location));
-
- javax.wsdl.Import imp=defns.get(0).createImport();
+ if (ns.getSchemaLocation() != null &&
+ ns.getSchemaLocation().trim().length() > 0) {
+
+ java.util.StringTokenizer st=new java.util.StringTokenizer(ns.getSchemaLocation());
- imp.setDefinition(defn);
- imp.setNamespaceURI(ns.getURI());
+ while (st.hasMoreTokens()) {
+ String location=st.nextToken();
+ IFile file=cdmResource.getParent().getFile(new Path(location));
- if (file.exists()) {
- IPath relative=file.getFullPath().makeRelativeTo(wsdlFolderPath);
- imp.setLocationURI(relative.toPortableString());
- } else {
- imp.setLocationURI(location);
+ org.w3c.dom.Element imp=doc.createElementNS("http://www.w3.org/2001/XMLSchema",
+ "import");
+
+ imp.setAttribute("namespace", ns.getURI());
+
+ if (file.exists()) {
+ IPath relative=file.getFullPath().makeRelativeTo(wsdlFolderPath);
+ imp.setAttribute("schemaLocation", relative.toPortableString());
+ } else {
+ imp.setAttribute("schemaLocation", location);
+ }
+
+ schema.appendChild(imp);
}
-
- defns.get(0).addImport(imp);
}
}
+
+ defnElem.insertBefore(types, defnElem.getFirstChild());
}
+
+ // Create bytearray from DOM
+ java.io.ByteArrayOutputStream xmlstr=
+ new java.io.ByteArrayOutputStream();
+
+ DOMSource source=new DOMSource();
+ source.setNode(doc);
+
+ StreamResult result=new StreamResult(xmlstr);
+
+ Transformer trans=
+ TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ b = XMLUtils.format(new String(xmlstr.toByteArray())).getBytes();
}
- java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
-
- writer.writeWSDL(defn, baos);
-
- byte[] b=baos.toByteArray();
-
- baos.close();
-
IPath wsdlPath=wsdlFolderPath.append(filename);
IFile wsdlFile=cdmResource.getProject().getWorkspace().getRoot().getFile(wsdlPath);
Added: trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java
===================================================================
--- trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java (rev 0)
+++ trunk/tools/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/util/XMLUtils.java 2010-08-13 12:58:07 UTC (rev 347)
@@ -0,0 +1,300 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.util;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.scribble.model.ModelObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * This class defines a set of XML related utility functions.
+ */
+public final class XMLUtils {
+
+ private static final String NS_LABEL = "ns";
+
+ /**
+ * This class converts a DOM representation node to text.
+ * @param node
+ * @return
+ * @throws Exception
+ */
+ public static final String toText(Node node) throws Exception {
+ String ret = null;
+ try {
+ // Transform the DOM represent to text
+ ByteArrayOutputStream xmlstr= new ByteArrayOutputStream();
+ DOMSource source=new DOMSource(node);
+ //source.setNode(node);
+
+ StreamResult result=new StreamResult(xmlstr);
+ Transformer trans= TransformerFactory.newInstance().newTransformer();
+ trans.transform(source, result);
+
+ xmlstr.close();
+
+ ret = new String(xmlstr.toByteArray());
+
+ if ((node instanceof Document) == false) {
+ // Strip off any <?xml> header
+ int index=ret.indexOf("<?xml");
+ if (index != -1) {
+ index = ret.indexOf("<", 1);
+ if (index != -1) {
+ ret = ret.substring(index);
+ } else {
+ index = ret.indexOf("?>");
+ if (index != -1) {
+ index += 2;
+
+ // Remove any trailing whitespaces after XML header
+ while (index < ret.length() &&
+ Character.isWhitespace(ret.charAt(index))) {
+ index++;
+ }
+
+ ret = ret.substring(index);
+ }
+ }
+ }
+ }
+
+ } catch(Exception e) {
+ throw new Exception("Failed to transform DOM representation into text", e);
+ }
+ if (ret != null) {
+ return format(ret);
+ }
+ return ret;
+ }
+
+
+ /**
+ * Format the xml to well print.
+ *
+ * @param xmltext
+ * @return
+ */
+ public static final String format(String xmltext) {
+ String ret=xmltext;
+ int pos=0;
+ int prevpos=0;
+ StringBuffer buf=new StringBuffer();
+ int level=0;
+
+ while ((pos=ret.indexOf('<', prevpos)) != -1) {
+
+ if (prevpos < pos &&
+ ret.substring(prevpos, pos).trim().length() > 0 &&
+ ret.charAt(prevpos-1) != '?') {
+
+ if (ret.charAt(prevpos) == '\r' &&
+ ret.charAt(prevpos+1) == '\n') {
+ prevpos += 2;
+ }
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+
+ buf.append(ret.substring(prevpos, pos).trim());
+ buf.append("\r\n");
+ }
+
+ int endpos=ret.indexOf('>', pos);
+
+ if (endpos > 0) {
+ boolean noreturn=false;
+
+ if (pos > 0 && ret.charAt(pos+1) == '/') {
+ level--;
+ }
+
+ for (int i=0; i < level; i++) {
+ buf.append(" ");
+ }
+ buf.append(ret.substring(pos, endpos+1));
+
+ if (ret.charAt(endpos-1)== '?') {
+ //noreturn = true;
+
+ } else if (ret.charAt(endpos-1) == '/') {
+ // Ignore
+ } else if (pos > 0 && ret.charAt(pos+1) == '/') {
+ // Ignore
+
+ } else if (pos > 0 && ret.charAt(pos+1) == '!') {
+ // Ignore
+
+ } else {
+ level++;
+ }
+
+ if (noreturn == false) {
+ buf.append("\r\n");
+ }
+
+ pos = endpos+1;
+ }
+
+ prevpos = pos;
+ }
+
+ if (prevpos != -1 &&
+ ret.substring(prevpos).trim().length() > 0) {
+ buf.append(ret.substring(prevpos));
+ }
+
+ ret = buf.toString();
+
+ return(ret);
+ }
+
+ public static Node getNode(String text) throws Exception {
+ Node ret=null;
+
+ // Transform the text representation to DOM
+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+ fact.setNamespaceAware(true);
+
+ java.io.InputStream xmlstr=
+ new java.io.ByteArrayInputStream(text.getBytes());
+
+ DocumentBuilder builder=fact.newDocumentBuilder();
+ org.w3c.dom.Document doc=builder.parse(xmlstr);
+
+ ret = doc.getDocumentElement();
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the localname part of the supplied
+ * qualified name.
+ *
+ * @param qname The qualified name
+ * @return The localname part
+ */
+ public static String getLocalname(String qname) {
+ String ret=qname;
+ int pos=0;
+
+ if (qname != null && ((pos=qname.indexOf(':')) != -1)) {
+ ret = qname.substring(pos+1);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the prefix associated with the supplied namespace.
+ *
+ * @param namespace The namespace
+ * @param nsMap The existing namespace prefix mappings
+ * @return The prefix
+ */
+ public static String getPrefix(String namespace, java.util.Map<String,String> nsMap) {
+ String prefix=null;
+
+ prefix = nsMap.get(namespace);
+
+ if (prefix == null) {
+ prefix = NS_LABEL+(nsMap.size()+1);
+ nsMap.put(namespace, prefix);
+ }
+
+ return(prefix);
+ }
+
+ /**
+ * This method calculates the start and end position of a supplied DOM element, within
+ * the supplied text contents, and sets the values on the supplied ModelObject.
+ *
+ * @param obj The ModelObject to be initialized
+ * @param contents The text contents
+ * @param elem The DOM element to be located in the text
+ */
+ public static void setStartAndEndPosition(ModelObject obj, String contents, org.w3c.dom.Element elem) {
+
+ if (contents != null) {
+ org.w3c.dom.NodeList nl=elem.getOwnerDocument().getElementsByTagName(elem.getNodeName());
+ int elempos=-1;
+
+ for (int i=0; elempos == -1 && i < nl.getLength(); i++) {
+ if (nl.item(i) == elem) {
+ elempos = i;
+ }
+ }
+
+ if (elempos != -1) {
+ int startpos=-1;
+
+ for (int i=0; i <= elempos; i++) {
+ int val1=contents.indexOf("<"+elem.getNodeName()+">", startpos+1);
+ int val2=contents.indexOf("<"+elem.getNodeName()+" ", startpos+1);
+
+ if (val1 == -1 && val2 != -1) {
+ startpos = val2;
+ } else if (val1 != -1 && val2 == -1) {
+ startpos = val1;
+ } else if (val1 == -1 && val2 == -1) {
+ // TODO: Error condition
+ break;
+ } else if (val1 > val2) {
+ startpos = val2;
+ } else {
+ startpos = val1;
+ }
+ }
+
+ if (startpos != -1) {
+ obj.getSource().setStartPosition(startpos);
+
+ // Check if single node
+ int p1=contents.indexOf('>', startpos);
+
+ if (p1 != -1 && contents.charAt(p1-1) == '/') {
+ obj.getSource().setEndPosition(p1);
+ } else {
+
+ org.w3c.dom.NodeList enl=elem.getElementsByTagName(elem.getNodeName());
+
+ int endpos=startpos;
+ String nodetxt="</"+elem.getNodeName()+">";
+
+ for (int i=0; endpos != -1 && i <= enl.getLength(); i++) {
+ endpos = contents.indexOf(nodetxt, endpos+1);
+ }
+
+ if (endpos != -1) {
+ obj.getSource().setEndPosition(endpos+nodetxt.length()-1);
+ }
+ }
+ }
+ }
+ }
+ }
+}
Modified: trunk/validators/jbossesb/pom.xml
===================================================================
--- trunk/validators/jbossesb/pom.xml 2010-08-06 08:42:06 UTC (rev 346)
+++ trunk/validators/jbossesb/pom.xml 2010-08-13 12:58:07 UTC (rev 347)
@@ -31,24 +31,26 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.jboss.savara.dependencies.pi4soa</groupId>
- <artifactId>pi4soa-common</artifactId>
- <version>3.1.0.M1</version>
+ <groupId>org.jboss.tools</groupId>
+ <artifactId>org.pi4soa.common</artifactId>
+ <version>3.1.0</version>
<!-- >scope>provided</scope -->
</dependency>
<dependency>
- <groupId>org.jboss.savara.dependencies.pi4soa</groupId>
- <artifactId>pi4soa-cdl</artifactId>
- <version>3.1.0.M1</version>
+ <groupId>org.jboss.tools</groupId>
+ <artifactId>org.pi4soa.cdl</artifactId>
+ <version>3.1.0</version>
+ <type>eclipse-plugin</type>
<!-- >scope>provided</scope -->
</dependency>
<dependency>
- <groupId>org.jboss.savara.dependencies.pi4soa</groupId>
- <artifactId>pi4soa-service</artifactId>
- <version>3.1.0.M1</version>
+ <groupId>org.jboss.tools</groupId>
+ <artifactId>org.pi4soa.service</artifactId>
+ <version>3.1.0.v20100727-0348-H31-M1</version>
+ <type>eclipse-plugin</type>
<!-- >scope>provided</scope -->
</dependency>
-
+
<dependency>
<groupId>org.jboss.savara.dependencies.eclipse</groupId>
<artifactId>emf-common</artifactId>
More information about the savara-commits
mailing list