Author: darran.lofthouse(a)jboss.com
Date: 2006-12-05 10:24:26 -0500 (Tue, 05 Dec 2006)
New Revision: 1554
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 - Stopped all exceptions when generating the return type.
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-05
14:46:04 UTC (rev 1553)
+++
branches/dlofthouse/JBWS-1260/src/main/java/org/jboss/ws/tools/WSDLToJava.java 2006-12-05
15:24:26 UTC (rev 1554)
@@ -274,55 +274,50 @@
return elementCount;
}
- private String unwrapResponse(XSTypeDefinition xt) throws IOException
+ private XSElementDeclaration unwrapType(XSTypeDefinition xt)
{
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;
+ 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;
+
+ return unwrapModelGroup(group);
+ }
+
+ return null;
}
- private String unwrapResponseParticles(XSModelGroup group) throws IOException
+ private XSElementDeclaration unwrapModelGroup(XSModelGroup group)
{
- if (group.getCompositor() != XSModelGroup.COMPOSITOR_SEQUENCE)
- throw new WSException("Only a sequence type can be unwrapped.");
+ XSElementDeclaration unwrapped = null;
XSObjectList particles = group.getParticles();
- String returnType = null;
- for (int i = 0; i < particles.getLength(); i++)
+ if (particles.getLength() == 1)
{
- XSParticle particle = (XSParticle)particles.item(i);
+ XSParticle particle = (XSParticle)particles.item(0);
XSTerm term = particle.getTerm();
+
if (term instanceof XSModelGroup)
{
- returnType = unwrapResponseParticles((XSModelGroup)term);
- if (returnType != null)
- return returnType;
+ unwrapped = unwrapModelGroup((XSModelGroup)term);
}
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, null, xmlName, xmlType, xsmodel,
element.getTypeDefinition(), array, !element.getNillable());
- return buf.toString();
+ unwrapped = (XSElementDeclaration)term;
}
+
}
- return null;
+ return unwrapped;
}
private void appendMethods(WSDLInterface intf, StringBuilder buf) throws IOException
@@ -532,12 +527,20 @@
QName xmlType = out.getXMLType();
QName xmlName = out.getElement();
+ String containingElement = xmlName.getLocalPart();
JBossXSModel xsmodel = WSDLUtils.getSchemaModel(wsdl.getWsdlTypes());
XSTypeDefinition xt = xsmodel.getTypeDefinition(xmlType.getLocalPart(),
xmlType.getNamespaceURI());
if (isWrapped())
- return unwrapResponse(xt);
+ {
+ XSElementDeclaration element = unwrapType(xt);
+ if (element != null)
+ {
+ xt = element.getTypeDefinition();
+ containingElement = containingElement + element.getName();
+ }
+ }
boolean primitive = true;
WrappedArray wrappedArray = new WrappedArray(xt);
@@ -557,11 +560,20 @@
//Class cls = typeMapping.getJavaType(qname,true);
if (xt instanceof XSComplexTypeDefinition)
- generateJavaSource((XSComplexTypeDefinition)xt, xsmodel,
xmlName.getLocalPart());
+ generateJavaSource((XSComplexTypeDefinition)xt, xsmodel, containingElement);
if (cls == null)
{
- String className = xmlType.getLocalPart();
+ String className;
+ if (xt.getAnonymous())
+ {
+ className = containingElement;
+ }
+ else
+ {
+ className = xmlType.getLocalPart();
+ }
+
if (className.charAt(0) == '>')
className = className.substring(1);
className = utils.firstLetterUpperCase(className);
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-05
14:46:04 UTC (rev 1553)
+++
branches/dlofthouse/JBWS-1260/src/test/java/org/jboss/test/ws/tools/jbws1260/JBWS1260TestCase.java 2006-12-05
15:24:26 UTC (rev 1554)
@@ -22,6 +22,8 @@
package org.jboss.test.ws.tools.jbws1260;
import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
import org.jboss.test.ws.JBossWSTest;
import org.jboss.test.ws.tools.fixture.JBossSourceComparator;
@@ -37,6 +39,38 @@
public class JBWS1260TestCase extends JBossWSTest
{
+ private static Set tests = new HashSet();
+
+ static
+ {
+ tests.add('A');
+ tests.add('B');
+ tests.add('C');
+ tests.add('D');
+ tests.add('E');
+ tests.add('F');
+ tests.add('G');
+ tests.add('H');
+ tests.add('I');
+ tests.add('J');
+ tests.add('K');
+ tests.add('L');
+ }
+
+ /**
+ * Test scenario where the element referenced as the message
+ * parts contains an anonymous complex type which contains
+ * a single element.
+ *
+ * <element name='lookupResponse'>
+ * <complexType>
+ * <sequence>
+ * <element name='number' nillable='true'
type='string'/>
+ * </sequence>
+ * </complexType>
+ * </element>
+ *
+ */
public void testScenario_A() throws Exception
{
generateScenario('A');
@@ -99,6 +133,12 @@
protected void generateScenario(final char scenario) throws Exception
{
+ if (tests.contains(scenario) == false)
+ {
+ System.out.println("Skipping test '" + scenario +
"'");
+ return;
+ }
+
String resourceDir = "resources/tools/jbws1260/scenario_" + scenario;
String toolsDir = "tools/jbws1260/scenario_" + scenario;
String[] args = new String[] { "-dest", toolsDir, "-config",
resourceDir + "/wstools-config.xml" };
Show replies by date