Author: darran.lofthouse(a)jboss.com
Date: 2008-08-04 07:59:00 -0400 (Mon, 04 Aug 2008)
New Revision: 7997
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/WSDLToJava.java
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/config/ToolsSchemaConfigReader.java
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/ToolsHelper.java
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java
Log:
Backport -r 5390
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/WSDLToJava.java
===================================================================
---
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2008-08-04
11:57:40 UTC (rev 7996)
+++
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2008-08-04
11:59:00 UTC (rev 7997)
@@ -205,7 +205,7 @@
if (namespacePackageMap == null)
namespacePackageMap = new HashMap<String, String>();
String pkg = iter.next();
- namespacePackageMap.put(map.get(pkg), pkg);
+ namespacePackageMap.put(pkg, map.get(pkg));
}
}
@@ -338,7 +338,8 @@
if (cl == null)
{
String faultTypeName = (!xt.getAnonymous()) ? faultXMLType.getLocalPart()
: faultXMLName.getLocalPart();
- buf.append(seiPkgName + "." +
JavaUtils.capitalize(faultTypeName));
+ String packageName = getPackageName(xt.getNamespace());
+ buf.append(packageName + "." +
JavaUtils.capitalize(faultTypeName));
}
else buf.append(cl.getName());
buf.append(",");
@@ -639,8 +640,9 @@
className = className.substring(1);
className = ToolsUtils.convertInvalidCharacters(className);
className = utils.firstLetterUpperCase(className);
- className = seiPkgName + "." + className + arraySuffix;
+ String packageName = getPackageName(xt.getNamespace());
+ className = packageName + "." + className + arraySuffix;
if (holder)
{
className = holderWriter.getOrCreateHolder(className,
getLocationForJavaGeneration());
@@ -763,7 +765,8 @@
className = className.substring(1);
className = ToolsUtils.convertInvalidCharacters(className);
className = utils.firstLetterUpperCase(className);
- return seiPkgName + "." + className + arraySuffix;
+ String packageName = getPackageName(xt.getNamespace());
+ return packageName + "." + className + arraySuffix;
}
if (cls.isArray())
@@ -822,7 +825,10 @@
XSDTypeToJava xtj = new XSDTypeToJava(generateSerializableTypes);
xtj.setTypeMapping(this.typeMapping);
- xtj.createJavaFile((XSComplexTypeDefinition)xt, containingElement,
getLocationForJavaGeneration(), seiPkgName, xsmodel, exception);
+ String targetNS = wsdl.getTargetNamespace();
+ String tgtNS = xt.getNamespace();
+ String packName = getPackageName(tgtNS);
+ xtj.createJavaFile((XSComplexTypeDefinition)xt, containingElement,
getLocationForJavaGeneration(), packName, xsmodel, exception);
}
public void setParameterStyle(String paramStyle)
@@ -830,4 +836,20 @@
this.parameterStyle = paramStyle;
}
+ private String getPackageName(String targetNamespace)
+ {
+ //Get it from global config
+ if (namespacePackageMap != null)
+ {
+ String pkg = namespacePackageMap.get(targetNamespace);
+ if (pkg != null)
+ {
+ return pkg;
+ }
+ }
+
+ //return NamespacePackageMapping.getJavaPackageName(targetNamespace);
+ //Default behaviour will always generate all classes in the SEI package only
+ return seiPkgName;
+ }
}
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/config/ToolsSchemaConfigReader.java
===================================================================
---
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/config/ToolsSchemaConfigReader.java 2008-08-04
11:57:40 UTC (rev 7996)
+++
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/config/ToolsSchemaConfigReader.java 2008-08-04
11:59:00 UTC (rev 7997)
@@ -255,7 +255,7 @@
{
String pkgname = attrs.getValue(PACKAGE_ATTRIBUTE);
String ns = attrs.getValue(NAMESPACE_ATTRIBUTE);
- globalc.packageNamespaceMap.put(pkgname, ns);
+ globalc.packageNamespaceMap.put(ns, pkgname);
}
return globalc;
}
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java
===================================================================
---
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java 2008-08-04
11:57:40 UTC (rev 7996)
+++
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java 2008-08-04
11:59:00 UTC (rev 7997)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -76,6 +77,7 @@
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
import org.jboss.ws.metadata.wsdl.xsd.SchemaUtils;
import org.jboss.ws.tools.HeaderUtil;
+import org.jboss.ws.tools.NamespacePackageMapping;
import org.jboss.ws.tools.RPCSignature;
import org.jboss.ws.tools.ToolsUtils;
import org.jboss.ws.tools.WSToolsConstants;
@@ -97,6 +99,7 @@
private String typeNamespace;
private String serviceName = null;
private String packageName = null;
+ private Map<String, String> namespacePackageMap = null;
private Set<String> registeredTypes = new HashSet<String>();
private Set<String> registeredExceptions = new HashSet<String>();
@@ -107,11 +110,13 @@
private String parameterStyle;
- public MappingFileGeneratorHelper(WSDLDefinitions wsdl, String sname, String pname,
Class seiClass, LiteralTypeMapping ltm, String paramStyle)
+ public MappingFileGeneratorHelper(WSDLDefinitions wsdl, String sname, Map<String,
String> map, Class seiClass, LiteralTypeMapping ltm, String paramStyle)
{
this.wsdlDefinitions = wsdl;
this.serviceName = sname;
- this.packageName = pname;
+ String targetNS = wsdl.getTargetNamespace();
+ packageName = NamespacePackageMapping.getJavaPackageName(targetNS);
+ this.namespacePackageMap = map;
this.typeMapping = ltm;
this.wsdlStyle = utils.getWSDLStyle(wsdl);
@@ -150,7 +155,7 @@
String prefix = WSToolsConstants.WSTOOLS_CONSTANT_MAPPING_SERVICE_PREFIX;
ServiceInterfaceMapping sim = new ServiceInterfaceMapping(jwm);
String className = ToolsUtils.firstLetterUpperCase(javaServiceName);
- sim.setServiceInterface(packageName + "." + className);
+ sim.setServiceInterface(getPackageName(targetNS) + "." + className);
sim.setWsdlServiceName(new QName(targetNS, serviceName, prefix));
WSDLEndpoint[] endpoints = ser.getEndpoints();
@@ -198,7 +203,7 @@
ServiceEndpointInterfaceMapping seim = new
ServiceEndpointInterfaceMapping(jwm);
String className = ToolsUtils.firstLetterUpperCase(javaPortName);
- seim.setServiceEndpointInterface(packageName + "." + className);
+ seim.setServiceEndpointInterface(getPackageName(targetNS) + "." +
className);
seim.setWsdlPortType(new QName(targetNS, portName, "portTypeNS"));
seim.setWsdlBinding(new QName(targetNS, bindName, "bindingNS"));
constructServiceEndpointMethodMapping(seim, wsdlintf);
@@ -317,11 +322,15 @@
//Check it is a holder.
if (wiop.getInputByPartName(xmlName.getLocalPart()) == null)
{
-
+ String nameSpace = null;
+ if (xt != null)
+ {
+ nameSpace = xt.getNamespace();
+ }
if (xt instanceof XSSimpleTypeDefinition)
xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xt);
- String javaType = getJavaTypeAsString(xmlName, xmlType, array, primitive);
+ String javaType = getJavaTypeAsString(xmlName, xmlType, nameSpace, array,
primitive);
if ((isDocStyle() == false && "void".equals(javaType)) ==
false)
{
@@ -458,11 +467,18 @@
QName xmlType = returnParameter.getType();
XSTypeDefinition xt = schemaModel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
+ String nameSpace = null;
+ if (xt != null)
+ {
+ nameSpace = xt.getNamespace();
+ }
if (xt instanceof XSSimpleTypeDefinition)
+ {
xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xt);
+ }
WsdlReturnValueMapping wrvm = new WsdlReturnValueMapping(semm);
- wrvm.setMethodReturnValue(getJavaTypeAsString(xmlName, xmlType, false, true));
+ wrvm.setMethodReturnValue(getJavaTypeAsString(xmlName, xmlType, nameSpace,
false, true));
QName messageName = WSDLUtils.getWsdl11Output(wiop).getMessageName();
wrvm.setWsdlMessage(new QName(messageName.getNamespaceURI(),
messageName.getLocalPart(), WSToolsConstants.WSTOOLS_CONSTANT_MAPPING_WSDL_MESSAGE_NS));
wrvm.setWsdlMessagePartName(partName);
@@ -527,7 +543,7 @@
XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
addJavaXMLTypeMap(xt, xmlName.getLocalPart(), "", "",
jwm, true);
- String exceptionType = getJavaTypeAsString(null, xmlType, false, true);
+ String exceptionType = getJavaTypeAsString(null, xmlType,
xt.getNamespace(), false, true);
if (registeredExceptions.contains(exceptionType) == false)
{
@@ -720,7 +736,7 @@
if (localName == null)
{
String tempName = containingElement +
ToolsUtils.firstLetterUpperCase(name);
- javaType = getJavaTypeAsString(null, new QName(tempName), false, true);
+ javaType = getJavaTypeAsString(null, new QName(tempName),
xt.getNamespace(), false, true);
StringBuilder temp = new StringBuilder();
if (containingType != null && containingType.length() > 0)
temp.append(">").append(containingType);
@@ -730,7 +746,7 @@
}
else
{
- javaType = getJavaTypeAsString(null, new QName(localName), false, true);
+ javaType = getJavaTypeAsString(null, new QName(localName),
xt.getNamespace(), false, true);
jxtm.setRootTypeQName(new QName(xt.getNamespace(), xt.getName(),
"typeNS"));
}
@@ -841,7 +857,7 @@
}
}
- private String getJavaTypeAsString(QName xmlName, QName xmlType, boolean array,
boolean primitive)
+ private String getJavaTypeAsString(QName xmlName, QName xmlType, String targetNS,
boolean array, boolean primitive)
{
String jtype = null;
@@ -886,7 +902,7 @@
if (className.charAt(0) == '>')
className = className.substring(1);
className = ToolsUtils.convertInvalidCharacters(className);
- jtype = packageName + "." + utils.firstLetterUpperCase(className);
+ jtype = getPackageName(targetNS) + "." +
utils.firstLetterUpperCase(className);
}
else
{
@@ -934,7 +950,7 @@
String targetNS = wsdlDefinitions.getTargetNamespace();
MethodParamPartsMapping mppm = new MethodParamPartsMapping(semm);
mppm.setParamPosition(paramPosition);
- String javaType = getJavaTypeAsString(xmlName, xmlType, array, primitive);
+ String javaType = getJavaTypeAsString(xmlName, xmlType, targetNS, array,
primitive);
mppm.setParamType(javaType);
//WSDL Message Mapping
@@ -946,4 +962,19 @@
mppm.setWsdlMessageMapping(wmm);
return mppm;
}
+
+ private String getPackageName(String targetNamespace)
+ {
+ //Get it from global config
+ if (namespacePackageMap != null)
+ {
+ String pkg = namespacePackageMap.get(targetNamespace);
+ if (pkg != null)
+ {
+ return pkg;
+ }
+ }
+ //Default behaviour will always generate all classes in the SEI package only
+ return packageName;
+ }
}
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/ToolsHelper.java
===================================================================
---
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/ToolsHelper.java 2008-08-04
11:57:40 UTC (rev 7996)
+++
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/helpers/ToolsHelper.java 2008-08-04
11:59:00 UTC (rev 7997)
@@ -310,7 +310,8 @@
if (w2jc.mappingFileNeeded)
{
MappingFileGenerator mgf = new MappingFileGenerator(wsdl, new
LiteralTypeMapping());
- mgf.setPackageName(getPackageName(wsdl, glc));
+ if (glc != null && glc.packageNamespaceMap != null)
+ mgf.setNamespacePackageMap(glc.packageNamespaceMap);
mgf.setServiceName(wsdl.getServices()[0].getName().getLocalPart());
mgf.setParameterStyle(w2jc.parameterStyle);
@@ -399,21 +400,16 @@
private String getPackageName(WSDLDefinitions wsdl, GlobalConfig glc)
{
String targetNamespace = wsdl.getTargetNamespace();
- //Get it from global config
+ //Get it from global config if it is overriden
if (glc != null && glc.packageNamespaceMap != null)
{
- Map<String, String> map = glc.packageNamespaceMap;
- Iterator<String> iter = map.keySet().iterator();
- while (iter.hasNext())
+ String pkg = glc.packageNamespaceMap.get(targetNamespace);
+ if (pkg != null)
{
- String pkg = (String)iter.next();
- String ns = map.get(pkg);
- if (ns.equals(targetNamespace))
- return pkg;
+ return pkg;
}
}
-
- return NamespacePackageMapping.getJavaPackageName(wsdl.getTargetNamespace());
+ return NamespacePackageMapping.getJavaPackageName(targetNamespace);
}
private void createDir(String path)
Modified:
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java
===================================================================
---
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java 2008-08-04
11:57:40 UTC (rev 7996)
+++
stack/native/branches/dlofthouse/JBPAPP-904/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java 2008-08-04
11:59:00 UTC (rev 7997)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import javax.xml.rpc.encoding.TypeMapping;
@@ -42,6 +43,7 @@
import org.jboss.ws.metadata.wsdl.WSDLUtils;
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
import org.jboss.ws.tools.JavaWriter;
+import org.jboss.ws.tools.NamespacePackageMapping;
import org.jboss.ws.tools.XSDTypeToJava;
import org.jboss.ws.tools.XSDTypeToJava.VAR;
import org.jboss.ws.tools.helpers.MappingFileGeneratorHelper;
@@ -68,9 +70,9 @@
protected WSDLDefinitions wsdlDefinitions;
/**
- * Package Name to override
+ * Package Names to override
*/
- protected String packageName;
+ protected Map<String, String> namespacePackageMap;
/**
* Service Name
@@ -78,6 +80,11 @@
protected String serviceName;
/**
+ * SEI Package Name to override
+ */
+ protected String packageName;
+
+ /**
* Service Endpoint Interface (if available).
* <br/> Will be available for server side generation (Java -> WSDL)
*/
@@ -93,6 +100,8 @@
public MappingFileGenerator(WSDLDefinitions wsdl, TypeMapping typeM)
{
this.wsdlDefinitions = wsdl;
+ String targetNS = wsdl.getTargetNamespace();
+ packageName = NamespacePackageMapping.getJavaPackageName(targetNS);
this.typeMapping = (LiteralTypeMapping)typeM;
}
@@ -122,6 +131,17 @@
this.packageName = packageName;
}
+ public Map<String, String> getNamespacePackageMap()
+ {
+ return namespacePackageMap;
+ }
+
+
+ public void setNamespacePackageMap(Map<String, String> map)
+ {
+ namespacePackageMap = map;
+ }
+
/**
* @return @see #serviceName
*/
@@ -156,7 +176,7 @@
*/
public JavaWsdlMapping generate() throws IOException
{
- MappingFileGeneratorHelper helper = new
MappingFileGeneratorHelper(this.wsdlDefinitions, this.serviceName, this.packageName,
this.serviceEndpointInterface,
+ MappingFileGeneratorHelper helper = new
MappingFileGeneratorHelper(this.wsdlDefinitions, this.serviceName,
this.namespacePackageMap, this.serviceEndpointInterface,
this.typeMapping, this.parameterStyle);
JavaWsdlMapping jwm = new JavaWsdlMapping();
@@ -182,8 +202,8 @@
//Construct package mapping
//Check if the user has provided a typeNamespace
if (typeNamespace != null && typeNamespace.equals(targetNS) == false ||
isServerSideGeneration())
- jwm.addPackageMapping(helper.constructPackageMapping(jwm, packageName,
typeNamespace));
- jwm.addPackageMapping(helper.constructPackageMapping(jwm, packageName, targetNS));
+ jwm.addPackageMapping(helper.constructPackageMapping(jwm,
getPackageName(typeNamespace), typeNamespace));
+ jwm.addPackageMapping(helper.constructPackageMapping(jwm, getPackageName(targetNS),
targetNS));
return jwm;
}
@@ -193,4 +213,19 @@
{
return this.serviceEndpointInterface != null;
}
+
+ private String getPackageName(String targetNamespace)
+ {
+ //Get it from global config
+ if (namespacePackageMap != null)
+ {
+ String pkg = namespacePackageMap.get(targetNamespace);
+ if (pkg != null)
+ {
+ return pkg;
+ }
+ }
+ //Default behaviour will always generate all classes in the SEI package only
+ return packageName;
+ }
}