Author: mageshbk(a)jboss.com
Date: 2008-03-10 07:39:32 -0400 (Mon, 10 Mar 2008)
New Revision: 5903
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/JavaToWSDL.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/JavaToWSDLHelper.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Writer.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java
Log:
[JBWS-2018] Fixed - JavatoWSDL Package to Namespace mapping does not support multiple
packages
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/JavaToWSDL.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/JavaToWSDL.java 2008-03-10
11:29:50 UTC (rev 5902)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/JavaToWSDL.java 2008-03-10
11:39:32 UTC (rev 5903)
@@ -25,8 +25,10 @@
import java.io.StringWriter;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.xml.rpc.encoding.TypeMapping;
@@ -242,11 +244,18 @@
* think about changing just the type namespace as the types are
* generated using the typenamespace.
*
- * @param pn The Map
+ * @param map The Map
*/
- public void setPackageNamespaceMap(Map<String,String> pn)
+ public void setPackageNamespaceMap(Map<String,String> map)
{
- this.packageNamespaceMap = pn;
+ //Lets convert the namespace->package map to package->namespace map
+ Set<String> keys = map.keySet();
+ Iterator<String> iter = keys.iterator();
+ while (iter != null && iter.hasNext())
+ {
+ String pkg = iter.next();
+ packageNamespaceMap.put(map.get(pkg), pkg);
+ }
}
public void setOperationMap(Map<String, List<OperationConfig>>
operationMap)
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/JavaToWSDLHelper.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/JavaToWSDLHelper.java 2008-03-10
11:29:50 UTC (rev 5902)
+++
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/JavaToWSDLHelper.java 2008-03-10
11:39:32 UTC (rev 5903)
@@ -82,7 +82,6 @@
private JavaWsdlMapping javaWsdlMapping = new JavaWsdlMapping();
private Map<QName, JavaXmlTypeMapping> mappedTypes = new HashMap<QName,
JavaXmlTypeMapping>();
private Set<String> mappedPackages = new HashSet<String>();
- private Map<String,String> packageNamespaceMap = new
HashMap<String,String>();
private Set<String> mappedExceptions = new HashSet<String>();
protected void processTypes()
@@ -249,7 +248,9 @@
for(FaultMetaData fmd : operation.getFaults())
{
- JavaXmlTypeMapping typeMapping = mappedTypes.get(fmd.getXmlType());
+ String ns = getNamespace(fmd.getJavaType(),
fmd.getXmlType().getNamespaceURI());
+ QName newXmlType = new QName(ns, fmd.getXmlType().getLocalPart());
+ JavaXmlTypeMapping typeMapping = mappedTypes.get(newXmlType);
if (typeMapping == null)
continue;
@@ -277,7 +278,7 @@
// Add package mapping for SEI
String name = endpoint.getServiceEndpointInterface().getPackage().getName();
- String namespace = packageNamespaceMap.get(name);
+ String namespace = getNamespace(name);
if (namespace == null)
namespace = WSDLUtils.getInstance().getTypeNamespace(name);
addPackageMapping(name, namespace);
@@ -309,7 +310,7 @@
WsdlReturnValueMapping returnMapping = new WsdlReturnValueMapping(methodMapping);
returnMapping.setMethodReturnValue(type);
returnMapping.setWsdlMessagePartName(name);
- String messageName = interfaceName + "_" +
operation.getQName().getLocalPart() + "Response";;
+ String messageName = interfaceName + "_" +
operation.getQName().getLocalPart() + "Response";
QName messageQName = new QName(wsdl.getTargetNamespace(), messageName,
"wsdlMsgNS");
returnMapping.setWsdlMessage(messageQName);
methodMapping.setWsdlReturnValueMapping(returnMapping);
@@ -358,6 +359,7 @@
if(Holder.class.isAssignableFrom(javaType))
javaType = WSDLUtils.getInstance().getJavaTypeForHolder(javaType);
JBossXSModel xsModel = javaToXSD.generateForSingleType(xmlType, javaType,
elementNames);
+ String namespace = getNamespace(javaType, xmlType.getNamespaceURI());
// Now that the schema object graph is built,
// ask JavaToXSD to provide a list of xsmodels to be plugged
// into WSDLTypes
@@ -365,22 +367,34 @@
throw new WSException("XSModel is null");
WSDLTypes wsdlTypes = wsdl.getWsdlTypes();
- WSDLUtils.addSchemaModel(wsdlTypes, xmlType.getNamespaceURI(), xsModel);
- wsdl.registerNamespaceURI(xmlType.getNamespaceURI(), null);
+ WSDLUtils.addSchemaModel(wsdlTypes, namespace, xsModel);
+ wsdl.registerNamespaceURI(namespace, null);
//Also get any custom namespaces
SchemaCreatorIntf schemaCreator = javaToXSD.getSchemaCreator();
mergeJavaWsdlMapping(schemaCreator.getJavaWsdlMapping());
- HashMap map = schemaCreator.getCustomNamespaceMap();
- Set keys = map != null ? map.keySet() : null;
+ //Register the global config namespaces
+ /*Map<String, String> nsmap = schemaCreator.getPackageNamespaceMap();
+ Set keys = nsmap != null ? nsmap.keySet() : null;
Iterator iter = (keys != null && !keys.isEmpty()) ? keys.iterator() :
null;
while (iter != null && iter.hasNext())
{
- String pref = (String)iter.next();
- String ns = (String)map.get(pref);
+ String pkg = (String)iter.next();
+ String ns = nsmap.get(pkg);
if (ns != null)
wsdl.registerNamespaceURI(ns, null);
+ }*/
+ //Register the custom generated namespaces
+ Map<String, String> nsmap = schemaCreator.getCustomNamespaceMap();
+ Set keys = nsmap != null ? nsmap.keySet() : null;
+ Iterator iter = (keys != null && !keys.isEmpty()) ? keys.iterator() :
null;
+ while (iter != null && iter.hasNext())
+ {
+ String prefix = (String)iter.next();
+ String ns = nsmap.get(prefix);
+ if (ns != null)
+ wsdl.registerNamespaceURI(ns, null);
}
}
@@ -390,7 +404,7 @@
for (PackageMapping packageMapping : source.getPackageMappings())
{
String name = packageMapping.getPackageType();
- String namespaceURI = packageMapping.getNamespaceURI();
+ String namespaceURI = getNamespace(name, packageMapping.getNamespaceURI());
addPackageMapping(name, namespaceURI);
}
@@ -401,17 +415,22 @@
if (name == null)
name = type.getAnonymousTypeQName();
+ //override namespace from globalconfig
+ String pkgName = getJustPackageName(type.getJavaType());
+ String ns = getNamespace(pkgName, name.getNamespaceURI());
+ name = new QName(ns, name.getLocalPart(), name.getPrefix());
+
if (mappedTypes.containsKey(name))
continue;
+ addPackageMapping(pkgName, ns);
mappedTypes.put(name, type);
JavaXmlTypeMapping typeCopy = new JavaXmlTypeMapping(javaWsdlMapping);
typeCopy.setQNameScope(type.getQnameScope());
typeCopy.setAnonymousTypeQName(type.getAnonymousTypeQName());
typeCopy.setJavaType(type.getJavaType());
- typeCopy.setRootTypeQName(type.getRootTypeQName());
-
+ typeCopy.setRootTypeQName(name);
for (VariableMapping variable : type.getVariableMappings())
{
VariableMapping variableCopy = new VariableMapping(typeCopy);
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java 2008-03-10
11:29:50 UTC (rev 5902)
+++
stack/native/trunk/src/main/java/org/jboss/ws/tools/schema/SchemaTypeCreator.java 2008-03-10
11:39:32 UTC (rev 5903)
@@ -304,12 +304,12 @@
if (xmlType != null)
{
name = xmlType.getLocalPart();
- namespace = xmlType.getNamespaceURI();
+ namespace = getNamespace(javaType, xmlType.getNamespaceURI());
}
else
{
name = WSDLUtils.getJustClassName(javaType);
- namespace = getNamespace(javaType);
+ namespace = getNamespace(javaType, null);
}
// Check if it is a JAX-RPC enumeration
@@ -574,12 +574,12 @@
if (isComponentArray == false)
{
name = utils.getJustClassName(componentType.getName()) + ".Array";
- namespace = getNamespace(componentType);
+ namespace = getNamespace(componentType, null);
}
else
{
name = xst.getName() + ".Array";
- namespace = xst.getNamespace();
+ namespace = getNamespace(componentType, xst.getNamespace());
}
}
@@ -701,19 +701,34 @@
}
}
- private String getNamespace(Class javaType)
+ private String getNamespace(Class javaType, String defaultNS)
{
if (javaType.isPrimitive())
return Constants.NS_JBOSSWS_URI + "/primitives";
Package javaPackage = javaType.getPackage();
if (javaPackage == null)
- throw new WSException("Cannot determine namespace, Class had no
package");
+ {
+ if (defaultNS != null)
+ {
+ return defaultNS;
+ }
+ else
+ {
+ throw new WSException("Cannot determine namespace, Class had no
package");
+ }
+ }
String packageName = javaPackage.getName();
String ns = packageNamespaceMap.get(packageName);
- if (ns == null)
+ if (ns == null && defaultNS == null)
+ {
ns = utils.getTypeNamespace(packageName);
+ }
+ else if (ns == null)
+ {
+ ns = defaultNS;
+ }
allocatePrefix(ns);
@@ -731,12 +746,12 @@
String namespace;
if (xmlType != null)
{
- namespace = xmlType.getNamespaceURI();
+ namespace = getNamespace(javaType, xmlType.getNamespaceURI());
name = xmlType.getLocalPart();
}
else
{
- namespace = getNamespace(javaType);
+ namespace = getNamespace(javaType, null);
name = WSDLUtils.getJustClassName(javaType);
}
@@ -749,6 +764,8 @@
xsModel.addXSComplexTypeDefinition(complexType);
xsModel.addXSElementDeclaration(sutils.createGlobalXSElementDeclaration(name,
complexType, namespace));
typeMapping.register(javaType, new QName(namespace, name), null, null);
+ generateExceptionParticles(namespace, javaType, types, particles);
+
registerJavaTypeMapping(new QName(namespace, name), javaType,
"complexType", particles, null);
Class superClass = javaType.getSuperclass();
@@ -758,7 +775,6 @@
complexType.setBaseType(baseType);
}
- generateExceptionParticles(namespace, javaType, types, particles);
boolean found = hasConstructor(javaType, types);
boolean noarg = found && types.size() == 0;
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Writer.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Writer.java 2008-03-10
11:29:50 UTC (rev 5902)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDL11Writer.java 2008-03-10
11:39:32 UTC (rev 5903)
@@ -292,8 +292,7 @@
if (writtenFaultMessages.contains(exceptionName))
continue;
- WSDLInterfaceFault interfaceFault =
operation.getWsdlInterface().getFault(fault.getRef());
- QName xmlName = interfaceFault.getElement();
+ QName xmlName = fault.getRef();
buffer.append("<message name='" + exceptionName + "'
>");
String prefix = wsdl.getPrefix(xmlName.getNamespaceURI());
@@ -456,8 +455,7 @@
for (WSDLInterfaceOperationOutfault fault : operation.getOutfaults())
{
QName element = fault.getRef();
- String faultPrefix = wsdl.getPrefix(element.getNamespaceURI());
- buffer.append("<fault message='" + faultPrefix +
":" + element.getLocalPart());
+ buffer.append("<fault message='" + prefix + ":" +
element.getLocalPart());
buffer.append("' name='" + element.getLocalPart() +
"'/>");
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java 2008-03-10
11:29:50 UTC (rev 5902)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java 2008-03-10
11:39:32 UTC (rev 5903)
@@ -23,7 +23,10 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
@@ -82,6 +85,8 @@
protected abstract void processTypes();
+ protected Map<String,String> packageNamespaceMap = new
HashMap<String,String>();
+
protected void processEndpoint(WSDLService service, EndpointMetaData endpoint)
{
WSDLEndpoint wsdlEndpoint = new WSDLEndpoint(service, endpoint.getPortName());
@@ -238,7 +243,9 @@
wsdlInterface.addFault(interfaceFault);
WSDLInterfaceOperationOutfault outfault = new
WSDLInterfaceOperationOutfault(interfaceOperation);
- outfault.setRef(faultName);
+ String ns = getNamespace(fault.getJavaType(),
operation.getQName().getNamespaceURI());
+ QName outFaultName = new QName(ns, fault.getXmlName().getLocalPart());
+ outfault.setRef(outFaultName);
interfaceOperation.addOutfault(outfault);
WSDLBindingFault bindingFault = new WSDLBindingFault(wsdlBinding);
@@ -399,7 +406,11 @@
}
else
{
- WSDLRPCPart part = new WSDLRPCPart(returnParameter.getPartName(),
returnParameter.getXmlType());
+ QName xmlType = returnParameter.getXmlType();
+ String ns = getNamespace(returnParameter.getJavaType(),
xmlType.getNamespaceURI());
+ QName newXmlType = new QName(ns, xmlType.getLocalPart());
+ WSDLRPCPart part = new WSDLRPCPart(partName, newXmlType);
+
output.addChildPart(part);
}
addSignatureItem(interfaceOperation, returnParameter, true);
@@ -422,7 +433,11 @@
}
else
{
- WSDLRPCPart part = new WSDLRPCPart(param.getPartName(), param.getXmlType());
+ QName xmlType = param.getXmlType();
+
+ String ns = getNamespace(param.getJavaType(), xmlType.getNamespaceURI());
+ QName newXmlType = new QName(ns, xmlType.getLocalPart());
+ WSDLRPCPart part = new WSDLRPCPart(param.getPartName(), newXmlType);
if (param.getMode() != ParameterMode.OUT)
input.addChildPart(part);
if (twoWay && param.getMode() != ParameterMode.IN)
@@ -472,6 +487,18 @@
wsdl.registerNamespaceURI(ns, "tns");
wsdl.registerNamespaceURI(Constants.NS_SCHEMA_XSD, "xsd");
+ // Register global namespaces
+ if (packageNamespaceMap != null)
+ {
+ Set<String> keys = packageNamespaceMap.keySet();
+ Iterator<String> iter = keys.iterator();
+ while (iter != null && iter.hasNext())
+ {
+ String pkg = iter.next();
+ wsdl.registerNamespaceURI(packageNamespaceMap.get(pkg), null);
+ }
+ }
+
String soapURI = null;
String soapPrefix = null;
for (EndpointMetaData ep : service.getEndpoints())
@@ -497,4 +524,44 @@
return wsdl;
}
+
+ protected String getNamespace(String packageName, String defaultNS)
+ {
+ String retNS = defaultNS;
+ //Get it from global config if it is overriden
+ if (packageNamespaceMap != null)
+ {
+ String ns = packageNamespaceMap.get(packageName);
+ if (ns != null)
+ {
+ retNS = ns;
+ }
+ }
+ return retNS;
+ }
+
+ protected String getNamespace(String packageName)
+ {
+ return getNamespace(packageName, wsdl.getTargetNamespace());
+ }
+
+ protected String getNamespace(Class type, String defaultNS)
+ {
+ Package pkg = type.getPackage();
+ String pkgName = null;
+ if (pkg != null)
+ {
+ pkgName = pkg.getName();
+ }
+ return getNamespace(pkgName, defaultNS);
+ }
+
+ protected String getJustPackageName(String classname)
+ {
+ int index = classname.lastIndexOf(".");
+ if (index < 0)
+ index = classname.length();
+ else index = index;
+ return classname.substring(0,index);
+ }
}