Author: mageshbk(a)jboss.com
Date: 2008-02-23 17:05:55 -0500 (Sat, 23 Feb 2008)
New Revision: 5787
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/WSDLToJava.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDToJava.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java
stack/native/trunk/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java
Log:
[JBWS-1217] Added multiple package support for base types too.
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/WSDLToJava.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2008-02-23
10:45:44 UTC (rev 5786)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2008-02-23
22:05:55 UTC (rev 5787)
@@ -315,7 +315,6 @@
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
QName faultXMLName = intfFault.getElement();
QName faultXMLType = intfFault.getXmlType();
-
XSElementDeclaration xe =
xsmodel.getElementDeclaration(faultXMLName.getLocalPart(),
faultXMLName.getNamespaceURI());
XSTypeDefinition xt = xe.getTypeDefinition();
if (!xt.getAnonymous())
@@ -524,7 +523,6 @@
if (unwrappedElement)
{
buf.append(tempBuf);
-
// We need a wrapper class generated
generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
containingElement);
@@ -810,7 +808,7 @@
private void generateJavaSource(XSComplexTypeDefinition xt, JBossXSModel xsmodel,
String containingElement, boolean exception) throws IOException
{
- XSDTypeToJava xtj = new XSDTypeToJava();
+ XSDTypeToJava xtj = new XSDTypeToJava(namespacePackageMap);
xtj.setTypeMapping(this.typeMapping);
String targetNS = wsdl.getTargetNamespace();
String tgtNS = xt.getNamespace();
@@ -819,7 +817,7 @@
{
File dir = utils.createPackage(this.directoryToGenerate, packName);
}
- xtj.createJavaFile((XSComplexTypeDefinition)xt, containingElement,
getLocationForJavaGeneration(packName), packName, xsmodel, exception);
+ xtj.createJavaFile((XSComplexTypeDefinition)xt, containingElement,
this.directoryToGenerate, packName, xsmodel, exception);
}
public void setParameterStyle(String paramStyle)
@@ -838,7 +836,6 @@
return pkg;
}
}
-
//return NamespacePackageMapping.getJavaPackageName(targetNamespace);
//Default behaviour will always generate all classes in the SEI package only
return seiPkgName;
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDToJava.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDToJava.java 2008-02-23 10:45:44
UTC (rev 5786)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDToJava.java 2008-02-23 22:05:55
UTC (rev 5787)
@@ -55,7 +55,7 @@
/**
* Utility class that converts a XSD Type into a Java class
*/
- protected XSDTypeToJava xsdJava = new XSDTypeToJava();
+ protected XSDTypeToJava xsdJava = new XSDTypeToJava(null);
private LiteralTypeMapping typeMapping = null;
@@ -69,9 +69,7 @@
{
XSLoader xsloader = SchemaUtils.getInstance().getXSLoader();
XSModel xsmodel = xsloader.loadURI(schemaFile);
-
- if (createPackageDir) dirloc = utils.createPackage(dirloc.getAbsolutePath(),
packageName);
- generateJavaSource(xsmodel, dirloc, packageName);
+ generateJavaSource(xsmodel, dirloc, packageName, createPackageDir);
}
@@ -82,7 +80,10 @@
boolean createPackageDir)
throws IOException
{
- if (createPackageDir) dirloc = utils.createPackage(dirloc.getAbsolutePath(),
packageName);
+ if (createPackageDir)
+ {
+ utils.createPackage(dirloc.getAbsolutePath(), packageName);
+ }
generateJavaSource(xsmodel, dirloc, packageName);
}
@@ -106,7 +107,7 @@
String tname = type.getName();
if (Constants.NS_SCHEMA_XSD.equals(nsuri) &&
"anyType".equals(tname)) continue;
checkXSDTypeToJava();
- xsdJava.createJavaFile(ctype, dirloc, packageName, xsmodel);
+ xsdJava.createJavaFile(ctype, dirloc.getPath(), packageName, xsmodel);
}
else if (type instanceof XSSimpleTypeDefinition)
{
@@ -116,7 +117,7 @@
String tname = type.getName();
if (Constants.NS_SCHEMA_XSD.equals(nsuri) &&
"anyType".equals(tname)) continue;
checkXSDTypeToJava();
- xsdJava.createJavaFile(stype, dirloc, packageName, xsmodel);
+ xsdJava.createJavaFile(stype, dirloc.getPath(), packageName, xsmodel);
}
}
@@ -158,13 +159,13 @@
if (type.getName() != null)
throw new IllegalArgumentException(str);
checkXSDTypeToJava();
- xsdJava.createJavaFile(type,outerElementName, loc,pkgname,schema, false);
+ xsdJava.createJavaFile(type,outerElementName,loc.getPath(),pkgname,schema, false);
}
private void checkXSDTypeToJava()
{
if(xsdJava == null)
- xsdJava = new XSDTypeToJava();
+ xsdJava = new XSDTypeToJava(null);
xsdJava.setTypeMapping(typeMapping);
}
}
Modified: stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java 2008-02-23
10:45:44 UTC (rev 5786)
+++ stack/native/trunk/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java 2008-02-23
22:05:55 UTC (rev 5787)
@@ -71,11 +71,13 @@
//Additional variables
protected String containingElement = "";
protected String fname = "";
- protected File loc = null;
+ protected String loc = null;
protected String pkgname = "";
private Set<String> generatedFiles = new HashSet<String>();
+ protected Map<String, String> namespacePackageMap = null;
+
/**
* List that is used for exception inheritance case wherein the variables
* obtained from the base class go into the generated constructor alone and
@@ -83,11 +85,12 @@
*/
private Map<String, List> typeNameToBaseVARList = new HashMap<String,
List>();
- public XSDTypeToJava()
+ public XSDTypeToJava(Map<String, String> map)
{
+ this.namespacePackageMap = map;
}
- public void createJavaFile(XSComplexTypeDefinition type, File loc, String pkgname,
XSModel schema) throws IOException
+ public void createJavaFile(XSComplexTypeDefinition type, String loc, String pkgname,
XSModel schema) throws IOException
{
if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
@@ -100,7 +103,7 @@
createJavaFile(type, schema, false);
}
- public void createJavaFile(XSComplexTypeDefinition type, String containingElement,
File loc, String pkgname, XSModel schema, boolean isExceptionType)
+ public void createJavaFile(XSComplexTypeDefinition type, String containingElement,
String loc, String pkgname, XSModel schema, boolean isExceptionType)
throws IOException
{
if (typeMapping == null)
@@ -115,7 +118,7 @@
createJavaFile(type, schema, isExceptionType);
}
- public void createJavaFile(XSSimpleTypeDefinition type, File loc, String pkgname,
XSModel schema) throws IOException
+ public void createJavaFile(XSSimpleTypeDefinition type, String loc, String pkgname,
XSModel schema) throws IOException
{
if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
@@ -153,8 +156,15 @@
vars = this.getVARList(type, schema, isExceptionType);
if (baseName == null && isExceptionType)
+ {
baseName = "Exception";
- jwriter.createJavaFile(loc, fname, pkgname, vars, null, baseName, isExceptionType,
typeNameToBaseVARList);
+ }
+ else if (baseName != null)
+ {
+ baseName = getPackageName(baseType.getNamespace()) + "." + baseName;
+ }
+ String packageName = getPackageName(type.getNamespace());
+ jwriter.createJavaFile(getLocationForJavaGeneration(packageName), fname,
packageName, vars, null, baseName, isExceptionType, typeNameToBaseVARList);
}
public void createJavaFile(XSSimpleTypeDefinition xsSimple, XSModel schema) throws
IOException
@@ -171,7 +181,8 @@
if (slist != null && slist.getLength() > 0)
{
//Enumerated List
- jwriter.createJavaFileForEnumeratedValues(fname, slist, loc, pkgname,
xsSimple);
+ String packageName = getPackageName(xsSimple.getNamespace());
+ jwriter.createJavaFileForEnumeratedValues(fname, slist,
getLocationForJavaGeneration(packageName), packageName, xsSimple);
}
else
{
@@ -268,6 +279,16 @@
this.typeMapping = tm;
}
+ public Map<String, String> getNamespacePackageMap()
+ {
+ return namespacePackageMap;
+ }
+
+ public void setNamespacePackageMap(Map<String, String> map)
+ {
+ this.namespacePackageMap = map;
+ }
+
//PRIVATE METHODS
private void
handleContentTypeElementsWithDerivationRestriction(XSComplexTypeDefinition type, XSModel
schema, List vars, XSParticle xsparticle) throws IOException
@@ -425,7 +446,7 @@
XSSimpleTypeDefinition xstype = att.getTypeDefinition();
QName qn = SchemaUtils.handleSimpleType(xstype);
boolean primitive = obj.getRequired();
- VAR v = createVAR(qn, att.getName(), pkgname, primitive);
+ VAR v = createVAR(qn, att.getName(), getPackageName(xstype.getNamespace()),
primitive);
if (vars == null)
vars = new ArrayList();
vars.add(v);
@@ -565,7 +586,7 @@
{
// it is a composite type
QName qn = new QName(origType.getNamespace(), origType.getName());
- VAR vr = createVAR(qn, elem, (XSComplexTypeDefinition)xstypedef, tname, pkgname,
arrayType);
+ VAR vr = createVAR(qn, elem, (XSComplexTypeDefinition)xstypedef, tname,
getPackageName(origType.getNamespace()), arrayType);
vars.add(vr);
return vars;
}
@@ -604,7 +625,7 @@
this.fname = tempfname;
// Bypass rest of processing
QName anonqn = new QName(anonName);
- VAR vr = createVAR(anonqn, elem, xsc, tname, pkgname, arrayType);
+ VAR vr = createVAR(anonqn, elem, xsc, tname, getPackageName(xsc.getNamespace()),
arrayType);
vars.add(vr);
return vars;
}
@@ -643,7 +664,7 @@
this.fname = temp;
}
- VAR v = createVAR(qn, elem, xstypedef, tname, pkgname, arrayType);
+ VAR v = createVAR(qn, elem, xstypedef, tname,
getPackageName(xstypedef.getNamespace()), arrayType);
vars.add(v);
}
return vars;
@@ -764,4 +785,25 @@
isArrayType = arrayType;
}
}
+
+ private File getLocationForJavaGeneration(String packageName)
+ {
+ File locdir = new File(this.loc);
+ locdir = wsdlUtils.createPackage(locdir.getAbsolutePath(), packageName);
+ return locdir;
+ }
+
+ private String getPackageName(String targetNamespace)
+ {
+ //Get it from global config
+ if (namespacePackageMap != null)
+ {
+ String pkg = namespacePackageMap.get(targetNamespace);
+ if (pkg != null)
+ {
+ return pkg;
+ }
+ }
+ return this.pkgname;
+ }
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java 2008-02-23
10:45:44 UTC (rev 5786)
+++
stack/native/trunk/src/main/java/org/jboss/ws/tools/helpers/MappingFileGeneratorHelper.java 2008-02-23
22:05:55 UTC (rev 5787)
@@ -947,7 +947,7 @@
String targetNS = wsdlDefinitions.getTargetNamespace();
MethodParamPartsMapping mppm = new MethodParamPartsMapping(semm);
mppm.setParamPosition(paramPosition);
- String javaType = getJavaTypeAsString(xmlName, xmlType, targetNS, array,
primitive);
+ String javaType = getJavaTypeAsString(xmlName, xmlType, xmlType.getNamespaceURI(),
array, primitive);
mppm.setParamType(javaType);
//WSDL Message Mapping
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java 2008-02-23
10:45:44 UTC (rev 5786)
+++
stack/native/trunk/src/main/java/org/jboss/ws/tools/mapping/MappingFileGenerator.java 2008-02-23
22:05:55 UTC (rev 5787)
@@ -212,7 +212,7 @@
throws IOException
{
WSDLUtils utils = WSDLUtils.getInstance();
- XSDTypeToJava xst = new XSDTypeToJava();
+ XSDTypeToJava xst = new XSDTypeToJava(namespacePackageMap);
xst.setTypeMapping(this.typeMapping);
xst.setPackageName(getPackageName(typeNamespace));
ServiceEndpointMethodMapping[] mapArr = seim.getServiceEndpointMethodMappings();