Author: darran.lofthouse(a)jboss.com
Date: 2006-12-10 08:47:51 -0500 (Sun, 10 Dec 2006)
New Revision: 1618
Modified:
branches/dlofthouse/JBWS-1260/src/main/java/org/jboss/ws/tools/WSDLToJava.java
branches/dlofthouse/JBWS-1260/src/test/java/org/jboss/test/ws/tools/jbws1260/JBWS1260TestCase.java
Log:
JBWS-1260 - Source generation complete, all tests pass
Modified: branches/dlofthouse/JBWS-1260/src/main/java/org/jboss/ws/tools/WSDLToJava.java
===================================================================
---
branches/dlofthouse/JBWS-1260/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2006-12-08
16:01:30 UTC (rev 1617)
+++
branches/dlofthouse/JBWS-1260/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2006-12-10
13:47:51 UTC (rev 1618)
@@ -222,7 +222,8 @@
{
public XSTypeDefinition xt;
- public XSElementDeclaration unwrapped;
+ public XSAttributeDeclaration unwrappedAttribute;
+ public XSElementDeclaration unwrappedElement;
public String suffix = "";
public WrappedType(XSTypeDefinition xt)
@@ -240,9 +241,11 @@
XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
- if (wrapper.getAttributeUses().getLength() > 0)
- return false;
+ boolean unwrappedAttribute = false;
+ boolean unwrappedElement = false;
+ unwrappedAttribute = unwrapAttributeUses(wrapper.getAttributeUses());
+
XSParticle particle = wrapper.getParticle();
if (particle != null)
{
@@ -253,10 +256,11 @@
XSModelGroup group = (XSModelGroup)term;
- return unwrapModelGroup(group);
+ unwrappedElement = unwrapModelGroup(group);
}
- return false;
+ // We can only say we unwrapped if we only unwrapped one.
+ return unwrappedAttribute ^ unwrappedElement;
}
private boolean unwrapModelGroup(XSModelGroup group)
@@ -274,7 +278,7 @@
}
else if (term instanceof XSElementDeclaration)
{
- unwrapped = (XSElementDeclaration)term;
+ unwrappedElement = (XSElementDeclaration)term;
if (array)
{
suffix = "[]";
@@ -283,9 +287,24 @@
}
- return unwrapped != null;
+ return unwrappedElement != null;
}
+ private boolean unwrapAttributeUses(XSObjectList attributeUses)
+ {
+ if (attributeUses.getLength() == 1)
+ {
+ XSObject object = attributeUses.item(0);
+ if (object instanceof XSAttributeUse)
+ {
+ XSAttributeUse attributeUse = (XSAttributeUse)object;
+ unwrappedAttribute = attributeUse.getAttrDeclaration();
+ }
+ }
+
+ return unwrappedAttribute != null;
+ }
+
}
//***************************************************************************
@@ -463,30 +482,45 @@
StringBuilder tempBuf = new StringBuilder();
XSComplexTypeDefinition wrapper = (XSComplexTypeDefinition)xt;
- appendParameters(tempBuf, wrapper.getAttributeUses());
+ boolean appendedAttribute = appendParameters(tempBuf, wrapper.getAttributeUses());
+ boolean unwrappedElement = false;
XSParticle particle = wrapper.getParticle();
if (particle == null)
+ {
+ if (appendedAttribute)
+ {
+ buf.append(tempBuf);
+ }
+
return true;
+ }
+ else
+ {
+ XSTerm term = particle.getTerm();
+ if (term instanceof XSModelGroup)
+ {
+ unwrappedElement = unwrapGroup(tempBuf, containingElement,
(XSModelGroup)term);
+ }
+ }
- XSTerm term = particle.getTerm();
- if (term instanceof XSModelGroup == false)
- return false;
+ if ((appendedAttribute && unwrappedElement) || unwrappedElement)
+ {
+ buf.append(tempBuf);
- if (unwrapGroup(tempBuf, containingElement, (XSModelGroup)term) == false)
- return false;
+ // We need a wrapper class generated
+ generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
containingElement);
- buf.append(tempBuf);
+ return true;
+ }
- // We need a wrapper class generated
- generateJavaSource(wrapper, WSDLUtils.getSchemaModel(wsdl.getWsdlTypes()),
containingElement);
-
- return true;
+ return false;
}
- private void appendParameters(StringBuilder buf, XSObjectList attributes) throws
IOException
+ private boolean appendParameters(StringBuilder buf, XSObjectList attributes) throws
IOException
{
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
+ boolean appendedParameter = false;
for (int i = 0; i < attributes.getLength(); i++)
{
@@ -502,8 +536,12 @@
QName xmlType = new QName(type.getNamespace(), type.getName());
generateParameter(buf, null, "", xmlType, xsmodel, type, false,
true);
buf.append(" ").append(getMethodParam(declaration.getName()));
+
+ appendedParameter = true;
}
}
+
+ return appendedParameter;
}
private void appendParameters(StringBuilder buf, WSDLInterfaceOperationInput in,
String containingElement, QName xmlType, XSTypeDefinition xt) throws IOException
@@ -632,6 +670,7 @@
QName xmlType = out.getXMLType();
QName xmlName = out.getElement();
String containingElement = xmlName.getLocalPart();
+ String arraySuffix = "";
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
@@ -639,15 +678,20 @@
WrappedType wt = new WrappedType(xt);
if (wt.unwrap())
{
- XSElementDeclaration element = wt.unwrapped;
-
- xt = element.getTypeDefinition();
- containingElement = containingElement + element.getName();
+ if (wt.unwrappedElement != null)
+ {
+ xt = wt.unwrappedElement.getTypeDefinition();
+ containingElement = containingElement + wt.unwrappedElement.getName();
+ arraySuffix = wt.suffix;
+ }
+ else if (wt.unwrappedAttribute != null)
+ {
+ xt = wt.unwrappedAttribute.getTypeDefinition();
+ }
}
boolean primitive = true;
WrappedArray wrappedArray = new WrappedArray(xt);
- String arraySuffix = wt.suffix;
if (wrappedArray.unwrap())
{
xt = wrappedArray.xt;
Modified:
branches/dlofthouse/JBWS-1260/src/test/java/org/jboss/test/ws/tools/jbws1260/JBWS1260TestCase.java
===================================================================
---
branches/dlofthouse/JBWS-1260/src/test/java/org/jboss/test/ws/tools/jbws1260/JBWS1260TestCase.java 2006-12-08
16:01:30 UTC (rev 1617)
+++
branches/dlofthouse/JBWS-1260/src/test/java/org/jboss/test/ws/tools/jbws1260/JBWS1260TestCase.java 2006-12-10
13:47:51 UTC (rev 1618)
@@ -549,7 +549,7 @@
{
generateScenario('W');
}
-
+
/**
* Test scenario where the element referenced as the message
* parts references a complex type which contains an anonymous
@@ -572,7 +572,7 @@
{
generateScenario('X');
}
-
+
protected void generateScenario(final char scenario) throws Exception
{
if (tests.contains(scenario) == false)