Author: darran.lofthouse(a)jboss.com
Date: 2007-01-09 12:34:38 -0500 (Tue, 09 Jan 2007)
New Revision: 1877
Added:
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/helpers/ReturnTypeUnwrapper.java
Modified:
branches/dlofthouse/JBWS-1260/
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/WSDLToJava.java
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java
Log:
JBWS-1260 - Source generation.
Property changes on: branches/dlofthouse/JBWS-1260
___________________________________________________________________
Name: svn:ignore
-
clipboard.xml
output
output-eclipse
thirdparty
ant.properties
version.properties.md5
clipboard.txt
.settings
+
clipboard.xml
output
output-eclipse
thirdparty
ant.properties
version.properties.md5
clipboard.txt
.settings
.metadata
Modified:
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/WSDLToJava.java
===================================================================
---
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2007-01-09
15:21:39 UTC (rev 1876)
+++
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2007-01-09
17:34:38 UTC (rev 1877)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY 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 along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.ws.tools;
import java.io.File;
@@ -58,6 +58,7 @@
import org.jboss.ws.metadata.wsdl.WSDLUtils;
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
import org.jboss.ws.metadata.wsdl.xsd.SchemaUtils;
+import org.jboss.ws.tools.helpers.ReturnTypeUnwrapper;
import org.jboss.ws.tools.interfaces.WSDLToJavaIntf;
import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
import org.w3c.dom.Element;
@@ -95,7 +96,7 @@
//Feature Set
protected boolean annotate = false;
- protected Map<String,String> namespacePackageMap = null;
+ protected Map<String, String> namespacePackageMap = null;
//private String wsdlStyle = Constants.RPC_LITERAL;
@@ -125,39 +126,39 @@
/* (non-Javadoc)
* @see org.jboss.ws.tools.WSDLToJavaIntf#getFeature(java.lang.String)
*/
- public boolean getFeature( String name)
+ public boolean getFeature(String name)
{
- if(name == null)
+ if (name == null)
throw new IllegalArgumentException("Illegal null argument:name");
- if(name.equalsIgnoreCase(WSToolsConstants.WSTOOLS_FEATURE_USE_ANNOTATIONS))
- return annotate ;
+ if (name.equalsIgnoreCase(WSToolsConstants.WSTOOLS_FEATURE_USE_ANNOTATIONS))
+ return annotate;
- throw new WSException("Feature:"+ name + " not recognized");
+ throw new WSException("Feature:" + name + " not recognized");
}
/* (non-Javadoc)
* @see org.jboss.ws.tools.WSDLToJavaIntf#setFeature(java.lang.String, boolean)
*/
- public void setFeature( String name, boolean value)
+ public void setFeature(String name, boolean value)
{
- if(name == null)
+ if (name == null)
throw new IllegalArgumentException("Illegal null argument:name");
- if(name.equalsIgnoreCase(WSToolsConstants.WSTOOLS_FEATURE_USE_ANNOTATIONS))
- annotate = value;
+ if (name.equalsIgnoreCase(WSToolsConstants.WSTOOLS_FEATURE_USE_ANNOTATIONS))
+ annotate = value;
}
/* (non-Javadoc)
* @see org.jboss.ws.tools.WSDLToJavaIntf#generateSEI(java.net.URL, java.io.File,
boolean)
*/
- public void generateSEI( URL wsdlFile, File dir, boolean annotate) throws IOException
+ public void generateSEI(URL wsdlFile, File dir, boolean annotate) throws IOException
{
checkTypeMapping();
- WSDLDefinitions wsdl = convertWSDL2Java( wsdlFile);
+ WSDLDefinitions wsdl = convertWSDL2Java(wsdlFile);
this.annotate = annotate;
this.directoryToGenerate = dir.getAbsolutePath();
- generateSEI( wsdl, dir);
+ generateSEI(wsdl, dir);
}
/* (non-Javadoc)
@@ -170,15 +171,14 @@
this.wsdl = wsdl;
style = utils.getWSDLStyle(wsdl);
-
//TODO: Handle annotations flag, as per JAX-WS 2.0 Spec.
//Given the WSDL Object Tree, generate the SEI
//Also take in the location where the SEI should be written
- // String typeNS = wsdl.getNamespaceURI(WSDLConstants.PREFIX_TNS);
+ // String typeNS = wsdl.getNamespaceURI(WSDLConstants.PREFIX_TNS);
String targetNS = wsdl.getTargetNamespace();
//Check if there is an user override
- String packageName = namespacePackageMap !=
null?namespacePackageMap.get(targetNS):null;
- if(packageName == null || packageName.length() == 0)
+ String packageName = namespacePackageMap != null ?
namespacePackageMap.get(targetNS) : null;
+ if (packageName == null || packageName.length() == 0)
packageName = NamespacePackageMapping.getJavaPackageName(targetNS);
this.seiPkgName = packageName;
@@ -188,7 +188,6 @@
//xsdJava.generateJavaSource(wsdl.getTypes().getSchemaModel(), dir, packageName,
true);
}
-
public Map<String, String> getNamespacePackageMap()
{
return namespacePackageMap;
@@ -199,15 +198,16 @@
*/
public void setNamespacePackageMap(Map<String, String> map)
{
- //Lets convert the package->namespace map to namespace->package map
- Set keys = map.keySet();
- Iterator<String> iter = keys.iterator();
- while(iter != null && iter.hasNext())
- {
- if(namespacePackageMap == null) namespacePackageMap = new
HashMap<String,String>();
- String pkg = iter.next();
- namespacePackageMap.put(map.get(pkg),pkg);
- }
+ //Lets convert the package->namespace map to namespace->package map
+ Set keys = map.keySet();
+ Iterator<String> iter = keys.iterator();
+ while (iter != null && iter.hasNext())
+ {
+ if (namespacePackageMap == null)
+ namespacePackageMap = new HashMap<String, String>();
+ String pkg = iter.next();
+ namespacePackageMap.put(map.get(pkg), pkg);
+ }
}
public void setTypeMapping(LiteralTypeMapping tm)
@@ -229,7 +229,7 @@
public boolean unwrap()
{
- if (! Constants.DOCUMENT_LITERAL.equals(style))
+ if (!Constants.DOCUMENT_LITERAL.equals(style))
{
XSElementDeclaration unwrapped = SchemaUtils.unwrapArrayType(xt);
StringBuilder builder = new StringBuilder();
@@ -252,7 +252,6 @@
}
}
-
//***************************************************************************
// PRIVATE METHODS
//***************************************************************************
@@ -261,113 +260,12 @@
{
return Constants.DOCUMENT_LITERAL.equals(style);
}
-
+
private boolean isWrapped()
{
return "wrapped".equals(parameterStyle) &&
Constants.DOCUMENT_LITERAL.equals(style);
}
- private void unwrapRequest(StringBuilder buf, XSTypeDefinition xt) throws IOException
- {
- if (xt instanceof XSComplexTypeDefinition == false)
- throw new WSException("Tried to unwrap a non-complex type.");
-
- XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
- XSParticle particle = wrapper.getParticle();
- if (particle == null)
- throw new WSException("Attempt to unwrap a request type with no
particles");
- XSTerm term = particle.getTerm();
- if (term instanceof XSModelGroup == false)
- throw new WSException("Expected model group, could not unwrap");
- unwrapRequestParticles(buf, (XSModelGroup)term);
-
- // We need a wrapper class generated
- generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
wrapper.getName());
- }
-
- private int unwrapRequestParticles(StringBuilder buf, XSModelGroup group) throws
IOException
- {
- if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE)
- throw new WSException("Only a sequence type can be unwrapped.");
-
- int elementCount = 0;
- XSObjectList particles = group.getParticles();
- for (int i = 0; i < particles.getLength(); i++)
- {
- XSParticle particle = (XSParticle) particles.item(i);
- XSTerm term = particle.getTerm();
- if (term instanceof XSModelGroup)
- {
- elementCount += unwrapRequestParticles(buf, (XSModelGroup)term);
- }
- else if (term instanceof XSElementDeclaration)
- {
- if (elementCount++ > 0)
- buf.append(", ");
- XSElementDeclaration element = (XSElementDeclaration)term;
- QName xmlName = new QName(element.getNamespace(), element.getName());
- QName xmlType = new QName(element.getTypeDefinition().getNamespace(),
element.getTypeDefinition().getName());
- JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- boolean array = particle.getMaxOccursUnbounded() || particle.getMaxOccurs()
> 1;
- generateParameter(buf, xmlName, xmlType, xsmodel,
element.getTypeDefinition(), array, !element.getNillable(), false);
- buf.append(" ").append(getMethodParam(xmlName));
- }
- }
-
- return elementCount;
- }
-
- private String unwrapResponse(XSTypeDefinition xt) throws IOException
- {
- if (xt instanceof XSComplexTypeDefinition == false)
- throw new WSException("Tried to unwrap a non-complex type.");
-
- XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
- XSParticle particle = wrapper.getParticle();
- if (particle == null)
- throw new WSException("Attempt to unwrap a response type with no
particles");
- XSTerm term = particle.getTerm();
- if (term instanceof XSModelGroup == false)
- throw new WSException("Expected model group, could not unwrap");
- String returnType = unwrapResponseParticles((XSModelGroup)term);
- // We need a wrapper class generated
- generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
wrapper.getName());
- return returnType;
- }
-
- private String unwrapResponseParticles(XSModelGroup group) throws IOException
- {
- if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE)
- throw new WSException("Only a sequence type can be unwrapped.");
-
- XSObjectList particles = group.getParticles();
- String returnType = null;
- for (int i = 0; i < particles.getLength(); i++)
- {
- XSParticle particle = (XSParticle) particles.item(i);
- XSTerm term = particle.getTerm();
- if (term instanceof XSModelGroup)
- {
- returnType = unwrapResponseParticles((XSModelGroup)term);
- if (returnType != null)
- return returnType;
- }
- else if (term instanceof XSElementDeclaration)
- {
- XSElementDeclaration element = (XSElementDeclaration)term;
- QName xmlName = new QName(element.getNamespace(), element.getName());
- QName xmlType = new QName(element.getTypeDefinition().getNamespace(),
element.getTypeDefinition().getName());
- JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- boolean array = particle.getMaxOccursUnbounded() || particle.getMaxOccurs()
> 1;
- StringBuilder buf = new StringBuilder();
- generateParameter(buf, xmlName, xmlType, xsmodel,
element.getTypeDefinition(), array, !element.getNillable(), false);
- return buf.toString();
- }
- }
-
- return null;
- }
-
private void appendMethods(WSDLInterface intf, StringBuilder buf) throws IOException
{
buf.append(newline);
@@ -377,7 +275,6 @@
throw new IllegalArgumentException("Interface " + itfname + "
doesn't have operations");
int len = ops != null ? ops.length : 0;
-
// FIXME - Add support for headers
for (int i = 0; i < len; i++)
{
@@ -402,7 +299,7 @@
returnType = "void";
buf.append(" public " + returnType + " ");
- buf.append(ToolsUtils.firstLetterLowerCase(op.getName().toString()) );
+ buf.append(ToolsUtils.firstLetterLowerCase(op.getName().toString()));
buf.append("(").append(paramBuffer);
buf.append(") throws ");
@@ -419,12 +316,12 @@
QName faultXMLName = intfFault.getElement();
QName faultXMLType = intfFault.getXmlType();
- XSElementDeclaration xe =
xsmodel.getElementDeclaration(faultXMLName.getLocalPart(),faultXMLName.getNamespaceURI());
- XSTypeDefinition xt = xe.getTypeDefinition();
- if (! xt.getAnonymous())
+ XSElementDeclaration xe =
xsmodel.getElementDeclaration(faultXMLName.getLocalPart(),
faultXMLName.getNamespaceURI());
+ XSTypeDefinition xt = xe.getTypeDefinition();
+ if (!xt.getAnonymous())
xt = xsmodel.getTypeDefinition(xt.getName(), xt.getNamespace());
- if(xt instanceof XSComplexTypeDefinition)
- generateJavaSource((XSComplexTypeDefinition)xt,xsmodel,
faultXMLName.getLocalPart(), true);
+ if (xt instanceof XSComplexTypeDefinition)
+ generateJavaSource((XSComplexTypeDefinition)xt, xsmodel,
faultXMLName.getLocalPart(), true);
Class cl = getJavaType(faultXMLType, false);
if (cl == null)
@@ -432,9 +329,8 @@
String faultTypeName = (!xt.getAnonymous()) ? faultXMLType.getLocalPart()
: faultXMLName.getLocalPart();
buf.append(seiPkgName + "." + cleanUpFaultName(faultTypeName));
}
- else
- buf.append( cl.getName());
- buf.append( "," );
+ else buf.append(cl.getName());
+ buf.append(",");
}
buf.append(" java.rmi.RemoteException");
buf.append(";");
@@ -453,17 +349,16 @@
if (first)
first = false;
- else
- paramBuffer.append(", ");
+ else paramBuffer.append(", ");
QName xmlName = new QName(part.getName());
QName xmlType = part.getType();
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- XSTypeDefinition xt =
xsmodel.getTypeDefinition(xmlType.getLocalPart(),xmlType.getNamespaceURI());
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
boolean holder = output != null && output.getChildPart(part.getName())
!= null;
- generateParameter(paramBuffer, xmlName, xmlType, xsmodel, xt, false, true,
holder);
- paramBuffer.append(" ").append(getMethodParam(xmlName));
+ generateParameter(paramBuffer, xmlName.getLocalPart(), xmlType, xsmodel, xt,
false, true, holder);
+ paramBuffer.append("
").append(getMethodParam(xmlName.getLocalPart()));
}
if (signature.returnParameter() != null)
@@ -471,7 +366,7 @@
QName xmlName = new QName(signature.returnParameter().getName());
QName xmlType = signature.returnParameter().getType();
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- XSTypeDefinition xt =
xsmodel.getTypeDefinition(xmlType.getLocalPart(),xmlType.getNamespaceURI());
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
returnType = getReturnType(xmlName, xmlType, xt);
}
@@ -487,40 +382,153 @@
QName xmlName = input.getElement();
QName xmlType = input.getXMLType();
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- XSTypeDefinition xt =
xsmodel.getTypeDefinition(xmlType.getLocalPart(),xmlType.getNamespaceURI());
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
- if (isWrapped())
- {
- unwrapRequest(paramBuffer, xt);
- }
- else
- {
- holder = output != null && xmlName.equals(output.getElement());
- generateParameter(paramBuffer, xmlName, xmlType, xsmodel, xt, false, true,
holder);
- paramBuffer.append(" ").append(getMethodParam(xmlName));
- }
+ appendParameters(paramBuffer, input, output, xmlName.getLocalPart());
}
if (!holder && output != null && output.getElement() != null)
{
QName xmlName = output.getElement();
QName xmlType = output.getXMLType();
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
- XSTypeDefinition xt =
xsmodel.getTypeDefinition(xmlType.getLocalPart(),xmlType.getNamespaceURI());
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
- if (isWrapped())
+ returnType = getReturnType(xmlName, xmlType, xt);
+ }
+
+ return returnType;
+ }
+
+ private void appendParameters(StringBuilder buf, WSDLInterfaceOperationInput in,
WSDLInterfaceOperationOutput output, String containingElement) throws IOException
+ {
+
+ QName xmlType = in.getXMLType();
+ JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
+
+ boolean wrapped = isWrapped();
+
+ if (wrapped)
+ {
+ int inputs = in.getWsdlOperation().getInputs().length;
+ if (inputs > 1)
+ throw new WSException("Can not unwrap parameters for operation with
mutliple inputs. inputs=" + inputs);
+
+ String operationName = in.getWsdlOperation().getName().toString();
+ String elementName = in.getElement().getLocalPart();
+
+ if (elementName.equals(operationName) == false)
+ throw new WSException("Unable to unwrap parameters, wrapper element name
must match operation name. operationName=" + operationName + "
elementName="
+ + elementName);
+
+ wrapped = unwrapElementParameters(buf, containingElement, xt);
+ }
+
+ if (wrapped == false)
+ {
+ QName xmlName = in.getElement();
+ boolean holder = output != null && xmlName.equals(output.getElement());
+ generateParameter(buf, containingElement, xmlType, xsmodel, xt, false, true,
holder);
+ buf.append(" ").append(getMethodParam(containingElement));
+ }
+
+ }
+
+ private boolean unwrapElementParameters(StringBuilder buf, String containingElement,
XSTypeDefinition xt) throws IOException
+ {
+ // If at any point parameter unwrapping can not happen return false so we drop back
to not unwrapping.
+
+ if (xt instanceof XSComplexTypeDefinition == false)
+ return false;
+
+ StringBuilder tempBuf = new StringBuilder();
+ XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
+
+ boolean hasAttributes = wrapper.getAttributeUses().getLength() > 0;
+ if (hasAttributes)
+ throw new WSException("Can not unwrap, complex type contains
attributes.");
+
+ boolean unwrappedElement = false;
+
+ XSParticle particle = wrapper.getParticle();
+ if (particle == null)
+ {
+ unwrappedElement = true;
+ }
+ else
+ {
+ XSTerm term = particle.getTerm();
+ if (term instanceof XSModelGroup)
{
- returnType = unwrapResponse(xt);
+ unwrappedElement = unwrapGroup(tempBuf, containingElement,
(XSModelGroup)term);
}
- else
+ }
+
+ if (unwrappedElement)
+ {
+ buf.append(tempBuf);
+
+ // We need a wrapper class generated
+ generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
containingElement);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean unwrapGroup(StringBuilder buf, String containingElement, XSModelGroup
group) throws IOException
+ {
+ if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE)
+ return false;
+
+ XSObjectList particles = group.getParticles();
+ for (int i = 0; i < particles.getLength(); i++)
+ {
+ XSParticle particle = (XSParticle)particles.item(i);
+ XSTerm term = particle.getTerm();
+ if (term instanceof XSModelGroup)
{
- returnType = getReturnType(xmlName, xmlType, xt);
+ if (unwrapGroup(buf, containingElement, (XSModelGroup)term) == false)
+ return false;
}
+ else if (term instanceof XSElementDeclaration)
+ {
+ if (buf.length() > 0)
+ buf.append(", ");
+
+ XSElementDeclaration element = (XSElementDeclaration)term;
+ XSTypeDefinition type = element.getTypeDefinition();
+ String tempContainingElement = containingElement + element.getName();
+
+ QName xmlType = null;
+ if (type.getAnonymous() == false)
+ xmlType = new QName(type.getNamespace(), type.getName());
+
+ JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
+ boolean array = particle.getMaxOccursUnbounded() || particle.getMaxOccurs()
> 1;
+ generateParameter(buf, tempContainingElement, xmlType, xsmodel, type, array,
!element.getNillable(), false);
+
+ String paramName;
+ if (type.getAnonymous())
+ {
+ paramName = containingElement;
+ }
+ else
+ {
+ paramName = element.getName();
+ }
+
+ buf.append(" ").append(getMethodParam(paramName));
+ }
}
- return returnType;
+ // If we reach here we must have successfully unwrapped the parameters.
+ return true;
}
- private void generateParameter(StringBuilder buf, QName xmlName, QName xmlType,
JBossXSModel xsmodel, XSTypeDefinition xt, boolean array, boolean primitive, boolean
holder) throws IOException
+ private void generateParameter(StringBuilder buf, String containingElement, QName
xmlType, JBossXSModel xsmodel, XSTypeDefinition xt, boolean array,
+ boolean primitive, boolean holder) throws IOException
{
WrappedArray wrappedArray = new WrappedArray(xt);
String arraySuffix = (array) ? "[]" : "";
@@ -533,12 +541,14 @@
}
if (xt instanceof XSSimpleTypeDefinition)
- xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition) xt);
+ xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xt);
- Class cl = getJavaType(xmlType, primitive);
- //Class cl = typeMapping.getJavaType(inqname,true);
+ Class cl = null;
- if(cl != null)
+ if (xmlType != null)
+ cl = getJavaType(xmlType, primitive);
+
+ if (cl != null)
{
if (holder)
cl = utils.getHolder(cl);
@@ -547,15 +557,23 @@
}
else
{
- //buf.append(inqname.getLocalPart() + " " +
inqname.getLocalPart().toLowerCase());
- String className = xmlType.getLocalPart();
+ String className;
+ if (xt == null || xt.getAnonymous())
+ {
+ className = containingElement;
+ }
+ else
+ {
+ className = xmlType.getLocalPart();
+ }
+
if (className.charAt(0) == '>')
className = className.substring(1);
className = utils.firstLetterUpperCase(className);
buf.append(seiPkgName + "." + className + arraySuffix);
- if(xt instanceof XSComplexTypeDefinition)
- generateJavaSource((XSComplexTypeDefinition)xt, xsmodel,
xmlName.getLocalPart());
+ if (xt instanceof XSComplexTypeDefinition)
+ generateJavaSource((XSComplexTypeDefinition)xt, xsmodel, containingElement);
}
}
@@ -610,14 +628,35 @@
private String getReturnType(QName xmlName, QName xmlType, XSTypeDefinition xt) throws
IOException
{
+ String containingElement = xmlName.getLocalPart();
+ String arraySuffix = "";
+
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
+ xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(), xmlType.getNamespaceURI());
- if (isWrapped())
- return unwrapResponse(xt);
+ ReturnTypeUnwrapper unwrapper = new ReturnTypeUnwrapper(xmlType, xsmodel,
isWrapped());
+ if (unwrapper.unwrap())
+ {
+ // Need to generate wrapper class as well.
+ if (xt instanceof XSComplexTypeDefinition)
+ generateJavaSource((XSComplexTypeDefinition)xt, xsmodel, containingElement);
+ if (unwrapper.unwrappedElement != null)
+ {
+ xt = unwrapper.unwrappedElement.getTypeDefinition();
+
+ if (unwrapper.xmlType != null)
+ xmlType = unwrapper.xmlType;
+
+ containingElement = containingElement +
unwrapper.unwrappedElement.getName();
+
+ if (unwrapper.array)
+ arraySuffix = "[]";
+ }
+ }
+
boolean primitive = true;
WrappedArray wrappedArray = new WrappedArray(xt);
- String arraySuffix = "";
if (wrappedArray.unwrap())
{
xt = wrappedArray.xt;
@@ -627,25 +666,34 @@
}
if (xt instanceof XSSimpleTypeDefinition)
- xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition) xt);
+ xmlType = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xt);
Class cls = getJavaType(xmlType, primitive);
- if(xt instanceof XSComplexTypeDefinition)
- generateJavaSource((XSComplexTypeDefinition)xt, xsmodel,
xmlName.getLocalPart());
+ if (xt instanceof XSComplexTypeDefinition)
+ generateJavaSource((XSComplexTypeDefinition)xt, xsmodel, containingElement);
- if(cls == null)
+ if (cls == null)
{
- String className = xmlType.getLocalPart();
+ String className;
+ if (xt.getAnonymous() == true)
+ {
+ className = containingElement;
+ }
+ else
+ {
+ className = xmlType.getLocalPart();
+ }
+
if (className.charAt(0) == '>')
className = className.substring(1);
className = utils.firstLetterUpperCase(className);
return seiPkgName + "." + className + arraySuffix;
}
- if(cls.isArray())
+
+ if (cls.isArray())
return JavaUtils.getSourceName(cls);
-
- return cls.getName() + arraySuffix;
+ return cls.getName() + arraySuffix;
}
/**
@@ -677,7 +725,7 @@
private void checkTypeMapping()
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set.");
}
@@ -688,20 +736,19 @@
* Special case - when qname=xsd:anyType && cls == Element
* then cls has to be javax.xml.soap.SOAPElement
*/
- if( qname.getNamespaceURI().equals(Constants.NS_SCHEMA_XSD)
- && "anyType".equals(qname.getLocalPart()) && cls ==
Element.class)
+ if (qname.getNamespaceURI().equals(Constants.NS_SCHEMA_XSD) &&
"anyType".equals(qname.getLocalPart()) && cls == Element.class)
cls = SOAPElement.class;
return cls;
}
- private String getMethodParam(QName qn)
+ private String getMethodParam(String containingElement)
{
- return ToolsUtils.firstLetterLowerCase(qn.getLocalPart());
+ return ToolsUtils.firstLetterLowerCase(containingElement);
}
private File getLocationForJavaGeneration()
{
- return new File( this.directoryToGenerate + "/" +
seiPkgName.replace(".","/"));
+ return new File(this.directoryToGenerate + "/" +
seiPkgName.replace(".", "/"));
}
private void generateJavaSource(XSComplexTypeDefinition xt, JBossXSModel xsmodel,
String containingElement) throws IOException
Modified:
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java
===================================================================
---
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java 2007-01-09
15:21:39 UTC (rev 1876)
+++
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/XSDTypeToJava.java 2007-01-09
17:34:38 UTC (rev 1877)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY 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 along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.ws.tools;
import java.beans.Introspector;
@@ -67,6 +67,7 @@
protected JavaWriter jwriter = new JavaWriter();
//Additional variables
+ protected String containingElement = "";
protected String fname = "";
protected File loc = null;
protected String pkgname = "";
@@ -78,46 +79,43 @@
* obtained from the base class go into the generated constructor alone and
* not as accessors
*/
- private Map<String,List> typeNameToBaseVARList = new
HashMap<String,List>();
+ private Map<String, List> typeNameToBaseVARList = new HashMap<String,
List>();
public XSDTypeToJava()
{
}
- public void createJavaFile(XSComplexTypeDefinition type, File loc,
- String pkgname, XSModel schema)
- throws IOException
+ public void createJavaFile(XSComplexTypeDefinition type, File loc, String pkgname,
XSModel schema) throws IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
this.fname = type.getName();
- if (fname == null) throw new WSException("File Name is null");
+ if (fname == null)
+ throw new WSException("File Name is null");
this.loc = loc;
this.pkgname = pkgname;
createJavaFile(type, schema, false);
}
- public void createJavaFile(XSComplexTypeDefinition type, String filename, File loc,
- String pkgname, XSModel schema, boolean isExceptionType)
- throws IOException
+ public void createJavaFile(XSComplexTypeDefinition type, String containingElement,
File loc, String pkgname, XSModel schema, boolean isExceptionType)
+ throws IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
this.fname = type.getName();
+ this.containingElement = containingElement;
if (fname == null)
- fname = filename;
+ fname = containingElement;
this.loc = loc;
this.pkgname = pkgname;
- createJavaFile(type, schema,isExceptionType );
+ createJavaFile(type, schema, isExceptionType);
}
- public void createJavaFile(XSSimpleTypeDefinition type, File loc,
- String pkgname, XSModel schema)
- throws IOException
+ public void createJavaFile(XSSimpleTypeDefinition type, File loc, String pkgname,
XSModel schema) throws IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
this.fname = type.getName();
this.loc = loc;
@@ -126,11 +124,9 @@
createJavaFile(type, schema);
}
-
- public void createJavaFile(XSComplexTypeDefinition type, XSModel schema, boolean
isExceptionType)
- throws IOException
+ public void createJavaFile(XSComplexTypeDefinition type, XSModel schema, boolean
isExceptionType) throws IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
XSTypeDefinition baseType = type.getBaseType();
//Ensure that the first character is uppercase
@@ -145,24 +141,21 @@
generatedFiles.add(baseName);
String pushName = fname;
fname = baseName;
- this.createJavaFile((XSComplexTypeDefinition) baseType, schema,
isExceptionType);
+ this.createJavaFile((XSComplexTypeDefinition)baseType, schema,
isExceptionType);
fname = pushName;
}
}
- vars = this.getVARList(type, schema, isExceptionType);
+ vars = this.getVARList(type, schema, isExceptionType);
if (baseName == null && isExceptionType)
baseName = "Exception";
- jwriter.createJavaFile(loc, fname, pkgname, vars, null,
- baseName, isExceptionType, typeNameToBaseVARList);
+ jwriter.createJavaFile(loc, fname, pkgname, vars, null, baseName, isExceptionType,
typeNameToBaseVARList);
}
-
- public void createJavaFile(XSSimpleTypeDefinition xsSimple, XSModel schema)
- throws IOException
+ public void createJavaFile(XSSimpleTypeDefinition xsSimple, XSModel schema) throws
IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
XSTypeDefinition baseType = xsSimple.getBaseType();
@@ -174,23 +167,21 @@
if (slist != null && slist.getLength() > 0)
{
//Enumerated List
- jwriter.createJavaFileForEnumeratedValues(fname, slist,
- loc, pkgname, xsSimple);
+ jwriter.createJavaFileForEnumeratedValues(fname, slist, loc, pkgname,
xsSimple);
}
else
{
- if(Constants.NS_SCHEMA_XSD.equals(xsSimple.getNamespace()) )
- return;
+ if (Constants.NS_SCHEMA_XSD.equals(xsSimple.getNamespace()))
+ return;
//TODO: Take care of other cases
return;
}
}
}
- public List<VAR> getVARList(XSComplexTypeDefinition type, XSModel schema,
boolean isExceptionType)
- throws IOException
+ public List<VAR> getVARList(XSComplexTypeDefinition type, XSModel schema,
boolean isExceptionType) throws IOException
{
- if(typeMapping == null)
+ if (typeMapping == null)
throw new WSException("TypeMapping has not been set");
XSTypeDefinition baseType = type.getBaseType();
List vars = new ArrayList();
@@ -220,7 +211,7 @@
if (XSConstants.DERIVATION_RESTRICTION == der)
{
- vars.addAll(createVARsforXSParticle(type, schema) );
+ vars.addAll(createVARsforXSParticle(type, schema));
}
}
else if (XSComplexTypeDefinition.CONTENTTYPE_ELEMENT == contentType)
@@ -229,7 +220,7 @@
{
short der = type.getDerivationMethod();
- if(XSConstants.DERIVATION_NONE == der)
+ if (XSConstants.DERIVATION_NONE == der)
{
handleContentTypeElementsWithDerivationNone(type, schema, isExceptionType,
vars, type.getParticle());
}
@@ -279,21 +270,19 @@
XSTerm xterm = xspar.getTerm();
if (xterm instanceof XSElementDeclaration)
{
- vars.addAll(createVARforXSElementDeclaration(xterm,
- schemautils.isArrayType(xspar) , schema, type));
+ vars.addAll(createVARforXSElementDeclaration(xterm,
schemautils.isArrayType(xspar), schema, type));
}
else if (xterm instanceof XSModelGroup)
{
XSModelGroup xsmodelgrp = (XSModelGroup)xterm;
- vars.addAll(createVARsforXSModelGroup(xsmodelgrp , schema, type));
+ vars.addAll(createVARsforXSModelGroup(xsmodelgrp, schema, type));
}
}
}
}
- private void handleContentTypeElementsWithDerivationExtension(XSComplexTypeDefinition
type, XSModel schema,
- boolean isExceptionType, List vars, XSParticle xsparticle)
- throws IOException
+ private void handleContentTypeElementsWithDerivationExtension(XSComplexTypeDefinition
type, XSModel schema, boolean isExceptionType, List vars, XSParticle xsparticle)
+ throws IOException
{
if (xsparticle != null)
{
@@ -317,28 +306,25 @@
// HACK - The only way to know what elements are local to the subclass,
and not inherited, is to compare to the base class
// THIS TIES US TO XERCES
- if (baseType instanceof XSComplexTypeDefinition == false ||
((XSComplexTypeDefinition) baseType).getParticle().getTerm() == xsterm)
+ if (baseType instanceof XSComplexTypeDefinition == false ||
((XSComplexTypeDefinition)baseType).getParticle().getTerm() == xsterm)
return;
}
XSParticle xspar = (XSParticle)xparts.item(length - 1);
XSTerm xsparTerm = xspar.getTerm();
- if(xsparTerm instanceof XSModelGroup)
+ if (xsparTerm instanceof XSModelGroup)
{
XSModelGroup xsmodelgrp = (XSModelGroup)xspar.getTerm();
vars.addAll(createVARsforXSModelGroup(xsmodelgrp, schema, type));
}
- else
- if(xsparTerm instanceof XSElementDeclaration)
- vars.addAll(createVARforXSElementDeclaration(xsparTerm,
- schemautils.isArrayType(xspar), schema, type));
+ else if (xsparTerm instanceof XSElementDeclaration)
+ vars.addAll(createVARforXSElementDeclaration(xsparTerm,
schemautils.isArrayType(xspar), schema, type));
}
}
}
- private void handleContentTypeElementsWithDerivationNone(XSComplexTypeDefinition
type,
- XSModel schema, boolean isExceptionType, List vars, XSParticle xsparticle)
- throws IOException
+ private void handleContentTypeElementsWithDerivationNone(XSComplexTypeDefinition type,
XSModel schema, boolean isExceptionType, List vars, XSParticle xsparticle)
+ throws IOException
{
if (xsparticle != null)
{
@@ -347,33 +333,33 @@
{
XSModelGroup xsm = (XSModelGroup)xsterm;
XSObjectList xparts = xsm.getParticles();
- int len = xparts != null ? xparts.getLength():0;
+ int len = xparts != null ? xparts.getLength() : 0;
int diff = len - 0;
- for(int i = 0 ; i < len ; i++)
+ for (int i = 0; i < len; i++)
{
- if(isExceptionType && type.getBaseType() != null )
+ if (isExceptionType && type.getBaseType() != null)
{
List<VAR> baseList = new ArrayList<VAR>();
//The first few xsterms are modelgroups for base class
- for(int j = 0; j < diff -1 ; j++)
+ for (int j = 0; j < diff - 1; j++)
{
XSParticle xspar = (XSParticle)xparts.item(j);
XSTerm xsparTerm = xspar.getTerm();
- if(xsparTerm instanceof XSModelGroup)
+ if (xsparTerm instanceof XSModelGroup)
{
XSModelGroup xsmodelgrp = (XSModelGroup)xspar.getTerm();
baseList.addAll(createVARsforXSModelGroup(xsmodelgrp, schema,
type));
}
}
- if(baseList.size() > 0)
- this.typeNameToBaseVARList.put(type.getName(),baseList);
+ if (baseList.size() > 0)
+ this.typeNameToBaseVARList.put(type.getName(), baseList);
//Now take the modelgroup for the type in question
- XSParticle xspar = (XSParticle)xparts.item(len-1);
+ XSParticle xspar = (XSParticle)xparts.item(len - 1);
XSTerm xsparTerm = xspar.getTerm();
- if(xsparTerm instanceof XSModelGroup)
+ if (xsparTerm instanceof XSModelGroup)
{
XSModelGroup xsmodelgrp = (XSModelGroup)xspar.getTerm();
vars.addAll(createVARsforXSModelGroup(xsmodelgrp, schema, type));
@@ -382,24 +368,20 @@
}
XSParticle xspar = (XSParticle)xparts.item(i);
XSTerm xsparTerm = xspar.getTerm();
- if(xsparTerm instanceof XSModelGroup)
+ if (xsparTerm instanceof XSModelGroup)
{
XSModelGroup xsmodelgrp = (XSModelGroup)xspar.getTerm();
vars.addAll(createVARsforXSModelGroup(xsmodelgrp, schema, type));
}
- else
- if(xsparTerm instanceof XSElementDeclaration)
- vars.addAll(createVARforXSElementDeclaration(xsparTerm,
- schemautils.isArrayType(xspar) , schema, type) );
+ else if (xsparTerm instanceof XSElementDeclaration)
+ vars.addAll(createVARforXSElementDeclaration(xsparTerm,
schemautils.isArrayType(xspar), schema, type));
}
- }else
- if(xsterm instanceof XSElementDeclaration)
- {
- vars.addAll(createVARforXSElementDeclaration(xsterm,
- schemautils.isArrayType(xsparticle) , schema, type) );
- }
- else
- throw new WSException("Unhandled Type");
+ }
+ else if (xsterm instanceof XSElementDeclaration)
+ {
+ vars.addAll(createVARforXSElementDeclaration(xsterm,
schemautils.isArrayType(xsparticle), schema, type));
+ }
+ else throw new WSException("Unhandled Type");
}
}
@@ -417,15 +399,15 @@
XSSimpleTypeDefinition xstype = att.getTypeDefinition();
QName qn = SchemaUtils.handleSimpleType(xstype);
VAR v = createVAR(qn, att.getName(), pkgname);
- if (vars == null) vars = new ArrayList();
+ if (vars == null)
+ vars = new ArrayList();
vars.add(v);
}
}
return vars;
}
- private List createVARsforXSParticle(XSComplexTypeDefinition type, XSModel schema)
- throws IOException
+ private List createVARsforXSParticle(XSComplexTypeDefinition type, XSModel schema)
throws IOException
{
List<VAR> list = new ArrayList<VAR>();
XSParticle xsparticle = type.getParticle();
@@ -448,11 +430,9 @@
return list;
}
- private List<VAR> createVARsforXSModelGroup(XSModelGroup xsm, XSModel schema,
- XSComplexTypeDefinition origType)
- throws IOException
+ private List<VAR> createVARsforXSModelGroup(XSModelGroup xsm, XSModel schema,
XSComplexTypeDefinition origType) throws IOException
{
- List<VAR> vars = new ArrayList<VAR>();
+ List<VAR> vars = new ArrayList<VAR>();
short compositor = xsm.getCompositor();
if (XSModelGroup.COMPOSITOR_SEQUENCE == compositor)
@@ -467,12 +447,11 @@
if (term instanceof XSElementDeclaration)
{
- vars.addAll(createVARforXSElementDeclaration(term,
- schemautils.isArrayType(xsparticle) , schema, origType) );
+ vars.addAll(createVARforXSElementDeclaration(term,
schemautils.isArrayType(xsparticle), schema, origType));
}
else if (term instanceof XSModelGroup)
{
- vars.addAll(createVARsforXSModelGroup((XSModelGroup) term, schema,
origType));
+ vars.addAll(createVARsforXSModelGroup((XSModelGroup)term, schema,
origType));
}
}
}
@@ -480,7 +459,6 @@
return vars;
}
-
private VAR createVAR(QName qn, String varstr, String pkgname)
{
String clname = "";
@@ -503,42 +481,35 @@
return v;
}
- private List createVARsForElements(XSObjectList xsobjlist,
- XSModel schema ,
- XSComplexTypeDefinition origType)
- throws IOException
+ private List createVARsForElements(XSObjectList xsobjlist, XSModel schema,
XSComplexTypeDefinition origType) throws IOException
{
- List<VAR> list = new ArrayList<VAR>();
+ List<VAR> list = new ArrayList<VAR>();
int len = xsobjlist.getLength();
for (int i = 0; i < len; i++)
{
XSParticle xsparticle = (XSParticle)xsobjlist.item(i);
XSTerm xsterm = xsparticle.getTerm();
- list.addAll(createVARforXSElementDeclaration(xsterm,
- schemautils.isArrayType(xsparticle), schema, origType) );
+ list.addAll(createVARforXSElementDeclaration(xsterm,
schemautils.isArrayType(xsparticle), schema, origType));
continue;
}
return list;
}
-
- private List createVARforXSElementDeclaration(XSTerm xsterm,
- boolean arrayType, XSModel schema, XSComplexTypeDefinition origType)
- throws IOException
+ private List createVARforXSElementDeclaration(XSTerm xsterm, boolean arrayType,
XSModel schema, XSComplexTypeDefinition origType) throws IOException
{
- List <VAR> vars = new ArrayList<VAR>();
+ List<VAR> vars = new ArrayList<VAR>();
// Handle xsd:any elements
if (xsterm instanceof XSWildcard)
{
XSWildcard xsw = (XSWildcard)xsterm;
-// if (xsw.getConstraintType() == XSWildcard.NSCONSTRAINT_ANY)
-// {
- VAR v = new VAR("_any", "javax.xml.soap.SOAPElement",
arrayType);
- vars.add(v);
- return vars;
-// }
+ // if (xsw.getConstraintType() == XSWildcard.NSCONSTRAINT_ANY)
+ // {
+ VAR v = new VAR("_any", "javax.xml.soap.SOAPElement",
arrayType);
+ vars.add(v);
+ return vars;
+ // }
}
// Handle xsd:group
@@ -550,8 +521,6 @@
XSElementDeclaration elem = (XSElementDeclaration)xsterm;
-
-
// TODO: Check if the element contains any anon complex type
// TODO: If yes, create class that is ComplexTypeName+ElementName
// TODO: ItemsItem If the elem contains anon simpletype
@@ -562,86 +531,88 @@
String xstypename = xstypedef.getName();
// Check if it is a composite type
- if(xstypename != null && xstypedef.getName().equals(origType.getName())
- && xstypedef.getNamespace().equals(origType.getNamespace()))
+ if (xstypename != null && xstypedef.getName().equals(origType.getName())
&& xstypedef.getNamespace().equals(origType.getNamespace()))
{
// it is a composite type
- QName qn = new QName(origType.getNamespace(),origType.getName());
+ QName qn = new QName(origType.getNamespace(), origType.getName());
VAR vr = createVAR(qn, elem, (XSComplexTypeDefinition)xstypedef, tname, pkgname,
arrayType);
vars.add(vr);
return vars;
}
else
- if (xstypename == null && xstypedef instanceof XSComplexTypeDefinition)
+ if (xstypename == null && xstypedef instanceof XSComplexTypeDefinition)
+ {
+ XSComplexTypeDefinition xsc = (XSComplexTypeDefinition)xstypedef;
+ String subname = utils.firstLetterUpperCase(tname);
+ // Save the fname in a temp var
+ String tempfname = this.fname;
+ // it will be an anonymous type
+ if (containingElement == null || containingElement.length() == 0)
+ containingElement = origType.getName();
+
+ String anonName = containingElement + subname;
+ anonName = utils.firstLetterUpperCase(anonName);
+ this.fname = anonName;
+ this.createJavaFile((XSComplexTypeDefinition)xstypedef, schema, false);
+
+ // Restore the fname
+ this.fname = tempfname;
+ // Bypass rest of processing
+ QName anonqn = new QName(anonName);
+ VAR vr = createVAR(anonqn, elem, xsc, tname, pkgname, arrayType);
+ vars.add(vr);
+ return vars;
+ }
+ else
+ {
+ // Unwrap any array wrappers
+ if (SchemaUtils.isWrapperArrayType(xstypedef))
{
- XSComplexTypeDefinition xsc = (XSComplexTypeDefinition)xstypedef;
- String subname = utils.firstLetterUpperCase(tname);
- // Save the fname in a temp var
- String tempfname = this.fname;
- // it will be an anonymous type
- String anonName = fname + subname;
- this.fname = anonName;
- this.createJavaFile((XSComplexTypeDefinition)xstypedef, schema, false);
+ XSComplexTypeDefinition complex = (XSComplexTypeDefinition)xstypedef;
+ XSModelGroup group = (XSModelGroup)complex.getParticle().getTerm();
+ XSElementDeclaration element =
(XSElementDeclaration)((XSParticle)group.getParticles().item(0)).getTerm();
+ xstypedef = element.getTypeDefinition();
+ xstypename = xstypedef.getName();
+ arrayType = true;
+ }
- // Restore the fname
- this.fname = tempfname;
- // Bypass rest of processing
- QName anonqn = new QName(anonName);
- VAR vr = createVAR(anonqn, elem, xsc, tname, pkgname, arrayType);
- vars.add(vr);
- return vars;
+ QName qn = null;
+ if (xstypedef instanceof XSSimpleTypeDefinition)
+ {
+ qn = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xstypedef);
}
else
{
- // Unwrap any array wrappers
- if (SchemaUtils.isWrapperArrayType(xstypedef))
- {
- XSComplexTypeDefinition complex = (XSComplexTypeDefinition) xstypedef;
- XSModelGroup group = (XSModelGroup) complex.getParticle().getTerm();
- XSElementDeclaration element = (XSElementDeclaration)
((XSParticle)group.getParticles().item(0)).getTerm();
- xstypedef = element.getTypeDefinition();
- xstypename = xstypedef.getName();
- arrayType = true;
- }
+ qn = new QName(xstypedef.getNamespace(), xstypename);
+ }
- QName qn = null;
- if (xstypedef instanceof XSSimpleTypeDefinition)
- {
- qn = SchemaUtils.handleSimpleType((XSSimpleTypeDefinition)xstypedef);
- }
- else
- {
- qn = new QName(xstypedef.getNamespace(), xstypename);
- }
+ String temp = this.fname;
- String temp = this.fname;
-
- if (xstypename != null && xstypedef instanceof
XSComplexTypeDefinition)
+ if (xstypename != null && xstypedef instanceof XSComplexTypeDefinition)
+ {
+ this.fname = utils.firstLetterUpperCase(xstypename);
+ if (!generatedFiles.contains(this.fname))
{
- this.fname = utils.firstLetterUpperCase(xstypename);
- if (! generatedFiles.contains(this.fname))
- {
- generatedFiles.add(this.fname);
- this.createJavaFile((XSComplexTypeDefinition)xstypedef, schema,
false);
- }
- this.fname = temp;
+ generatedFiles.add(this.fname);
+ this.createJavaFile((XSComplexTypeDefinition)xstypedef, schema, false);
}
-
- VAR v = createVAR( qn , elem, xstypedef, tname, pkgname, arrayType);
- vars.add(v);
+ this.fname = temp;
}
+
+ VAR v = createVAR(qn, elem, xstypedef, tname, pkgname, arrayType);
+ vars.add(v);
+ }
return vars;
}
-
- private VAR createVAR(QName qn, XSElementDeclaration elem,
- XSTypeDefinition t, String varstr, String pkgname, boolean
arrayType)
+ private VAR createVAR(QName qn, XSElementDeclaration elem, XSTypeDefinition t, String
varstr, String pkgname, boolean arrayType)
{
if (t instanceof XSSimpleTypeDefinition)
{
QName tempqn = schemautils.handleSimpleType((XSSimpleTypeDefinition)t);
- if (tempqn != null) qn = tempqn;
+ if (tempqn != null)
+ qn = tempqn;
}
String clname = "";
Class cls = typeMapping.getJavaType(qn);
@@ -650,7 +621,7 @@
{
clname = JavaUtils.getSourceName(cls);
String primitive = utils.getPrimitive(clname);
- if ((! elem.getNillable()) && primitive != null)
+ if ((!elem.getNillable()) && primitive != null)
clname = primitive;
}
else
@@ -659,8 +630,7 @@
if (t.getName() == null)
typename = qn;
- else
- typename = new QName(t.getName());
+ else typename = new QName(t.getName());
if (typename != null)
{
String nsuri = typename.getNamespaceURI();
@@ -668,7 +638,8 @@
clname = pkgname + ".";
clname += typename.getLocalPart();
}
- else if (qn != null) clname = qn.getLocalPart();
+ else if (qn != null)
+ clname = qn.getLocalPart();
}
v = new VAR(Introspector.decapitalize(varstr), clname, arrayType);
@@ -687,8 +658,7 @@
//Check baseType is xsd:anyType
if (baseType != null)
{
- if (baseType.getNamespace() == Constants.NS_SCHEMA_XSD &&
- baseType.getName().equals("anyType"))
+ if (baseType.getNamespace() == Constants.NS_SCHEMA_XSD &&
baseType.getName().equals("anyType"))
baseType = null; //Ignore this baseType
}
if (XSComplexTypeDefinition.CONTENTTYPE_SIMPLE == t.getContentType())
@@ -697,7 +667,7 @@
}
}
- if(baseName == null && baseType != null)
+ if (baseName == null && baseType != null)
baseName = baseType.getName();
return baseName;
Added:
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/helpers/ReturnTypeUnwrapper.java
===================================================================
---
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/helpers/ReturnTypeUnwrapper.java 2007-01-09
15:21:39 UTC (rev 1876)
+++
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/helpers/ReturnTypeUnwrapper.java 2007-01-09
17:34:38 UTC (rev 1877)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.tools.helpers;
+
+import javax.xml.namespace.QName;
+
+import org.apache.xerces.xs.XSComplexTypeDefinition;
+import org.apache.xerces.xs.XSElementDeclaration;
+import org.apache.xerces.xs.XSModelGroup;
+import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSParticle;
+import org.apache.xerces.xs.XSTerm;
+import org.apache.xerces.xs.XSTypeDefinition;
+import org.jboss.ws.WSException;
+import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
+
+/**
+ * A helper class to unwrap a return type is possible.
+ *
+ * @author darran.lofthouse(a)jboss.com
+ * @since 10 Dec 2006
+ */
+public class ReturnTypeUnwrapper
+{
+
+ public JBossXSModel xsmodel;
+ public QName xmlType;
+ public XSElementDeclaration unwrappedElement;
+ public boolean array = false;
+ private boolean wrapped;
+
+ public ReturnTypeUnwrapper(QName xmlType, JBossXSModel xsmodel, boolean wrapped)
+ {
+ this.xmlType = xmlType;
+ this.xsmodel = xsmodel;
+ this.wrapped = wrapped;
+ }
+
+ public boolean unwrap()
+ {
+ if (wrapped == false)
+ return false;
+
+ XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
+
+ if (xt instanceof XSComplexTypeDefinition == false)
+ throw new WSException("Tried to unwrap a non-complex type.");
+
+ XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
+
+ boolean hasAttributes = wrapper.getAttributeUses().getLength() > 0;
+ if (hasAttributes)
+ throw new WSException("Can not unwrap, complex type contains
attributes.");
+
+ boolean unwrapped = false;
+
+ XSParticle particle = wrapper.getParticle();
+ if (particle != null)
+ {
+ XSTerm term = particle.getTerm();
+
+ if (term instanceof XSModelGroup == false)
+ throw new WSException("Expected model group, could not unwrap");
+
+ XSModelGroup group = (XSModelGroup)term;
+
+ unwrapped = unwrapModelGroup(group);
+ }
+
+ return unwrapped;
+ }
+
+ private boolean unwrapModelGroup(XSModelGroup group)
+ {
+ XSObjectList particles = group.getParticles();
+ if (particles.getLength() == 1)
+ {
+ XSParticle particle = (XSParticle)particles.item(0);
+ boolean array = particle.getMaxOccursUnbounded() || particle.getMaxOccurs() >
1;
+ XSTerm term = particle.getTerm();
+
+ if (term instanceof XSModelGroup)
+ {
+ return unwrapModelGroup((XSModelGroup)term);
+ }
+ else if (term instanceof XSElementDeclaration)
+ {
+ unwrappedElement = (XSElementDeclaration)term;
+ XSTypeDefinition type = unwrappedElement.getTypeDefinition();
+ if (type.getAnonymous() == false)
+ xmlType = new QName(unwrappedElement.getTypeDefinition().getNamespace(),
unwrappedElement.getTypeDefinition().getName());
+
+ this.array = array;
+ }
+
+ }
+ else
+ {
+ throw new WSException("Unable to unwrap model group with multiple
particles.");
+ }
+
+ return unwrappedElement != null;
+ }
+
+}
Property changes on:
branches/dlofthouse/JBWS-1260/jbossws-core/src/main/java/org/jboss/ws/tools/helpers/ReturnTypeUnwrapper.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF