Author: alex.guizar(a)jboss.com
Date: 2006-12-23 17:57:14 -0500 (Sat, 23 Dec 2006)
New Revision: 1769
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/PortComponentMetaData.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebserviceDescriptionMetaData.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebservicesMetaData.java
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/WSDotXMLCreator.java
trunk/jbossws-tests/src/main/resources/tools/jbws1090/webservices.xml
trunk/jbossws-tests/src/main/resources/tools/jbws1090/wstools-config.xml
trunk/jbossws-tests/src/main/resources/tools/metadatafixture/webservices.xml
Log:
JBWS-1317
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/PortComponentMetaData.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/PortComponentMetaData.java 2006-12-23
22:06:30 UTC (rev 1768)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/PortComponentMetaData.java 2006-12-23
22:57:14 UTC (rev 1769)
@@ -168,18 +168,17 @@
*/
public String serialize()
{
- StringBuilder builder = new StringBuilder("<port-component>
<port-component-name>");
- builder.append(portComponentName +
"</port-component-name><wsdl-port>impl:");
- builder.append(wsdlPort.getLocalPart() +
"</wsdl-port><service-endpoint-interface>");
- builder.append(serviceEndpointInterface);
- builder.append("</service-endpoint-interface>");
+ StringBuilder builder = new StringBuilder("<port-component>");
+
builder.append("<port-component-name>").append(portComponentName).append("</port-component-name>");
+ builder.append("<wsdl-port
xmlns:").append(wsdlPort.getPrefix()).append("='").append(wsdlPort.getNamespaceURI()).append("'>");
+
builder.append(wsdlPort.getPrefix()).append(':').append(wsdlPort.getLocalPart()).append("</wsdl-port>");
+
builder.append("<service-endpoint-interface>").append(serviceEndpointInterface).append("</service-endpoint-interface>");
builder.append("<service-impl-bean>");
if (ejbLink != null)
{
builder.append("<ejb-link>");
builder.append(ejbLink);
builder.append("</ejb-link>");
-
}
else
{
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebserviceDescriptionMetaData.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebserviceDescriptionMetaData.java 2006-12-23
22:06:30 UTC (rev 1768)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebserviceDescriptionMetaData.java 2006-12-23
22:57:14 UTC (rev 1769)
@@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -85,16 +84,14 @@
*
* @return
*/
- public Collection getPortComponentQNames()
+ public Collection<QName> getPortComponentQNames()
{
//TODO:Check if there is just one QName that drives all portcomponents
//or each port component can have a distinct QName (namespace/prefix)
//Maintain uniqueness of the QName
- Map map = new HashMap();
- Iterator iter = portComponents.iterator();
- while (iter != null && iter.hasNext())
+ Map<String, QName> map = new HashMap<String, QName>();
+ for (PortComponentMetaData pcm : portComponents)
{
- PortComponentMetaData pcm = (PortComponentMetaData)iter.next();
QName qname = pcm.getWsdlPort();
map.put(qname.getPrefix(), qname);
}
@@ -109,16 +106,13 @@
*/
public PortComponentMetaData getPortComponentByWsdlPort(String name)
{
- ArrayList pcNames = new ArrayList();
- Iterator it = portComponents.iterator();
- while (it.hasNext())
+ ArrayList<String> pcNames = new ArrayList<String>();
+ for (PortComponentMetaData pc : portComponents)
{
- PortComponentMetaData pc = (PortComponentMetaData)it.next();
String wsdlPortName = pc.getWsdlPort().getLocalPart();
if (wsdlPortName.equals(name))
- {
return pc;
- }
+
pcNames.add(wsdlPortName);
}
@@ -163,11 +157,10 @@
*/
public String serialize()
{
- StringBuilder buffer = new StringBuilder("<webservice-description>
<webservice-description-name>");
- buffer.append(this.webserviceDescriptionName);
- buffer.append("</webservice-description-name>");
- buffer.append("<wsdl-file>" + wsdlFile +
"</wsdl-file>");
- buffer.append("<jaxrpc-mapping-file>" + jaxrpcMappingFile +
"</jaxrpc-mapping-file>");
+ StringBuilder buffer = new
StringBuilder("<webservice-description>");
+
buffer.append("<webservice-description-name>").append(webserviceDescriptionName).append("</webservice-description-name>");
+
buffer.append("<wsdl-file>").append(wsdlFile).append("</wsdl-file>");
+
buffer.append("<jaxrpc-mapping-file>").append(jaxrpcMappingFile).append("</jaxrpc-mapping-file>");
for (PortComponentMetaData pm : portComponents)
buffer.append(pm.serialize());
buffer.append("</webservice-description>");
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebservicesMetaData.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebservicesMetaData.java 2006-12-23
22:06:30 UTC (rev 1768)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/webservices/WebservicesMetaData.java 2006-12-23
22:57:14 UTC (rev 1769)
@@ -24,11 +24,8 @@
import java.net.URL;
import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Map;
-import javax.xml.namespace.QName;
-
import org.jboss.ws.Constants;
// $Id$
@@ -76,34 +73,46 @@
//Serialize as a String
public String serialize()
{
+ //Construct the webservices.xml definitions
StringBuilder buffer = new StringBuilder();
- //Construct the webservices.xml definitions
- List qnames = new ArrayList();
- Iterator iter = webserviceDescriptions.iterator();
- while (iter != null && iter.hasNext())
- {
- WebserviceDescriptionMetaData wmd = (WebserviceDescriptionMetaData)iter.next();
- qnames.addAll(wmd.getPortComponentQNames());
- }
- createHeader(buffer, qnames);
+
+ // header: opening webservices tag
+ createHeader(buffer);
+
+ // webservice-description subelements
for (WebserviceDescriptionMetaData wm : webserviceDescriptions)
buffer.append(wm.serialize());
+
+ // closing webservices tag
buffer.append("</webservices>");
return buffer.toString();
}
- private void createHeader(StringBuilder buf, List qnames)
+ private void createHeader(StringBuilder buf)
{
buf.append("<webservices
xmlns='http://java.sun.com/xml/ns/j2ee'");
- buf.append(" xmlns:xsi='" + Constants.NS_SCHEMA_XSI +
"'");
- //Lets append the port type namespaces
- Iterator iter = qnames.iterator();
- while (iter != null && iter.hasNext())
+ buf.append("
xmlns:xsi='").append(Constants.NS_SCHEMA_XSI).append('\'');
+ buf.append("
xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd'");
+ buf.append(" version='1.1'>");
+ }
+
+ private String createAlternatePrefix(String prefix, Map<String, String>
namespaces)
+ {
+ // allocate working buffer
+ StringBuilder altPrefixBuilder = new StringBuilder(prefix);
+ // remember original length
+ int baseLength = prefix.length();
+
+ for (int i = 2; i < Integer.MAX_VALUE; i++)
{
- QName qn = (QName)iter.next();
- buf.append("
xmlns:").append(qn.getPrefix()).append("='").append(qn.getNamespaceURI()).append("'");
+ // append a natural number to the original prefix
+ String altPrefix = altPrefixBuilder.append(i).toString();
+ // if the alternate prefix does not match an existing one, we're done
+ if (!namespaces.containsKey(altPrefix))
+ return altPrefix;
+ // truncate buffer to original length
+ altPrefixBuilder.setLength(baseLength);
}
- buf.append("
xsi:schemaLocation='http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd'");
- buf.append(" version='1.1' >");
+ throw new IllegalArgumentException("could not create alternate prefix from:
" + prefix);
}
}
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/tools/WSDotXMLCreator.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/tools/WSDotXMLCreator.java 2006-12-23
22:06:30 UTC (rev 1768)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/tools/WSDotXMLCreator.java 2006-12-23
22:57:14 UTC (rev 1769)
@@ -31,14 +31,15 @@
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
-import org.jboss.ws.core.utils.DOMUtils;
-import org.jboss.ws.core.utils.DOMWriter;
import org.jboss.ws.metadata.webservices.PortComponentMetaData;
import org.jboss.ws.metadata.webservices.WebserviceDescriptionMetaData;
+import org.jboss.ws.metadata.webservices.WebservicesFactory;
import org.jboss.ws.metadata.webservices.WebservicesMetaData;
import org.jboss.ws.tools.interfaces.WSDotXMLCreatorIntf;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
/**
* Creates the webservices.xml deployment descriptor
@@ -142,37 +143,42 @@
/* (non-Javadoc)
* @see org.jboss.ws.tools.WSDotXMLCreatorIntf#generateWSXMLDescriptor(java.io.File)
*/
- public void generateWSXMLDescriptor(File file) throws IOException
+ public void generateWSXMLDescriptor(File wsXmlFile) throws IOException
{
WebservicesMetaData webservices = constructWSMetaData();
- Element webservicesElem;
- if (append && file.exists())
+ // handle append flag
+ if (append && wsXmlFile.exists())
{
- // append generated webservice descriptions to existing file
- // parse existing file
- InputStream wsxmlStream = new FileInputStream(file);
- webservicesElem = DOMUtils.parse(wsxmlStream);
- wsxmlStream.close();
+ WebservicesMetaData existingWebservices;
- // obtain <webservice-description> subelements and append them to
<webservices>
- Document webservicesDoc = webservicesElem.getOwnerDocument();
- for (WebserviceDescriptionMetaData wsdescription :
webservices.getWebserviceDescriptions())
+ // parse existing webservices descriptor
+ InputStream wsXmlStream = new FileInputStream(wsXmlFile);
+ try
{
- String wsdescriptionString = wsdescription.serialize();
- Element wsdescriptionElem = DOMUtils.parse(wsdescriptionString);
- webservicesElem.appendChild(webservicesDoc.importNode(wsdescriptionElem,
true));
+ Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
+ ObjectModelFactory factory = new WebservicesFactory(wsXmlFile.toURL());
+ existingWebservices =
(WebservicesMetaData)unmarshaller.unmarshal(wsXmlStream, factory, null);
}
+ catch (JBossXBException e)
+ {
+ throw new WSException("Could not unmarshal existing webservices
descriptor: " + wsXmlFile, e);
+ }
+ finally
+ {
+ wsXmlStream.close();
+ }
+
+ // append generated webservice-descriptions to existing descriptor
+ for (WebserviceDescriptionMetaData webserviceDescription :
webservices.getWebserviceDescriptions())
+ existingWebservices.addWebserviceDescription(webserviceDescription);
+
+ webservices = existingWebservices;
}
- else
- {
- // write generated webservices descriptor to new file
- String wmdata = webservices.serialize();
- webservicesElem = DOMUtils.parse(wmdata);
- }
- FileWriter fw = new FileWriter(file);
- fw.write(DOMWriter.printNode(webservicesElem, true));
+ // (re-)write generated webservices descriptor to file
+ FileWriter fw = new FileWriter(wsXmlFile);
+ fw.write(webservices.serialize());
fw.close();
}
@@ -195,7 +201,7 @@
wsdm.setJaxrpcMappingFile(this.mappingFile);
PortComponentMetaData pm1 = new PortComponentMetaData(wsdm);
pm1.setPortComponentName(portName);
- pm1.setWsdlPort(new QName(this.targetNamespace, portName, "impl"));
+ pm1.setWsdlPort(new QName(this.targetNamespace, portName, "portNS"));
pm1.setServiceEndpointInterface(seiName);
if (this.servletLink != null && this.servletLink.length() > 0)
pm1.setServletLink(this.servletLink);
Modified: trunk/jbossws-tests/src/main/resources/tools/jbws1090/webservices.xml
===================================================================
--- trunk/jbossws-tests/src/main/resources/tools/jbws1090/webservices.xml 2006-12-23
22:06:30 UTC (rev 1768)
+++ trunk/jbossws-tests/src/main/resources/tools/jbws1090/webservices.xml 2006-12-23
22:57:14 UTC (rev 1769)
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<webservices
xmlns="http://java.sun.com/xml/ns/j2ee"
-
xmlns:impl="http://test.jboss.org/ws4eesimple"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
version="1.1">
@@ -12,7 +11,7 @@
<jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>ValidURL</port-component-name>
- <wsdl-port>impl:ValidURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:ValidURL...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -20,7 +19,7 @@
</port-component>
<port-component>
<port-component-name>InvalidURL</port-component-name>
- <wsdl-port>impl:InvalidURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:InvalidU...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -28,7 +27,7 @@
</port-component>
<port-component>
<port-component-name>ValidSecureURL</port-component-name>
- <wsdl-port>impl:ValidSecureURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:ValidSec...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -36,7 +35,7 @@
</port-component>
<port-component>
<port-component-name>InvalidSecureURL</port-component-name>
- <wsdl-port>impl:InvalidSecureURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:InvalidS...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -50,7 +49,7 @@
<jaxrpc-mapping-file>WEB-INF/additional-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>AdditionalEndpointPort</port-component-name>
- <wsdl-port>impl:AdditionalEndpointPort</wsdl-port>
+ <wsdl-port
xmlns:portNS="http://ws.test.jboss.org/jbws1090">portNS:Addi...
<service-endpoint-interface>org.jboss.test.ws.tools.jbws1090.AdditionalEndpoint</service-endpoint-interface>
<service-impl-bean>
<servlet-link>AdditionalServlet</servlet-link>
Modified: trunk/jbossws-tests/src/main/resources/tools/jbws1090/wstools-config.xml
===================================================================
--- trunk/jbossws-tests/src/main/resources/tools/jbws1090/wstools-config.xml 2006-12-23
22:06:30 UTC (rev 1768)
+++ trunk/jbossws-tests/src/main/resources/tools/jbws1090/wstools-config.xml 2006-12-23
22:57:14 UTC (rev 1769)
@@ -5,8 +5,8 @@
<java-wsdl>
<service name="AdditionalService"
endpoint="org.jboss.test.ws.tools.jbws1090.AdditionalEndpoint"
style="rpc" />
- <namespaces target-namespace="http://org.jboss.test.ws/jbws1090"
- type-namespace="http://org.jboss.test.ws/jbws1090/type" />
+ <namespaces
target-namespace="http://ws.test.jboss.org/jbws1090"
+
type-namespace="http://ws.test.jboss.org/jbws1090/type" />
<mapping file="additional-mapping.xml" />
<webservices servlet-link="AdditionalServlet" append="true"
/>
</java-wsdl>
Modified: trunk/jbossws-tests/src/main/resources/tools/metadatafixture/webservices.xml
===================================================================
---
trunk/jbossws-tests/src/main/resources/tools/metadatafixture/webservices.xml 2006-12-23
22:06:30 UTC (rev 1768)
+++
trunk/jbossws-tests/src/main/resources/tools/metadatafixture/webservices.xml 2006-12-23
22:57:14 UTC (rev 1769)
@@ -2,7 +2,6 @@
<webservices
xmlns="http://java.sun.com/xml/ns/j2ee"
-
xmlns:impl="http://test.jboss.org/ws4eesimple"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
version="1.1">
@@ -13,7 +12,7 @@
<jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>ValidURL</port-component-name>
- <wsdl-port>impl:ValidURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:ValidURL...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -21,7 +20,7 @@
</port-component>
<port-component>
<port-component-name>InvalidURL</port-component-name>
- <wsdl-port>impl:InvalidURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:InvalidU...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -29,7 +28,7 @@
</port-component>
<port-component>
<port-component-name>ValidSecureURL</port-component-name>
- <wsdl-port>impl:ValidSecureURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:ValidSec...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>
@@ -37,7 +36,7 @@
</port-component>
<port-component>
<port-component-name>InvalidSecureURL</port-component-name>
- <wsdl-port>impl:InvalidSecureURLPort</wsdl-port>
+ <wsdl-port
xmlns:impl="http://test.jboss.org/ws4eesimple">impl:InvalidS...
<service-endpoint-interface>org.jboss.test.webservice.ws4eesimple.HelloWs</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloJavaBean</servlet-link>