Author: mmerz Date: Fri Jan 7 11:38:07 2005 New Revision: 124563 URL: http://svn.apache.org/viewcvs?view=rev&rev=124563 Log: The XmlBeanWSDLProcessor now will use Doc/Lit - BARE if it can resolve the request and response elements as know classes (usually XmlBeans).
The XmlBeanTypeMappingUtil resolves elements containing an anonymous complex type in addition to just getting the type directly. Since the WSDL processor can now generate an legitimate object model having a BARE ParameterStyle from a server model that was using WRAPPED, the drt test has been changed to allow this difference. Contributor: Jonathan Colwell Modified: incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java Modified: incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java?view=diff&rev=124563&p1=incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java&r1=124562&p2=incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java&r2=124563 ============================================================================== --- incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java (original) +++ incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessorTest.java Fri Jan 7 11:38:07 2005 @@ -63,7 +63,7 @@ XmlBeanWSDLProcessor xbwp = new XmlBeanWSDLProcessor(); clientModel = xbwp.createObjectModel(new FileInputStream(f)); - } + } public void tearDown() { } @@ -75,7 +75,10 @@ clientModel.getWsServiceName()); assertEquals(serverModel.getWsTargetNamespace(), clientModel.getWsTargetNamespace()); - assertEquals(serverModel.getSoapBinding(), clientModel.getSoapBinding()); + // NOTE [EMAIL PROTECTED] 2005-Jan-07 -- not checking equivalence of Parameter style since the + // client can use BARE even if the server uses WRAPPED + assertEquals(serverModel.getSoapBinding().getStyle(), clientModel.getSoapBinding().getStyle()); + assertEquals(serverModel.getSoapBinding().getUse(), clientModel.getSoapBinding().getUse()); /* * NOTE [EMAIL PROTECTED] 2004-Nov-09 -- add tests for SOAPHandlers, * HandlerChains and other JSR-181 features. @@ -100,16 +103,24 @@ Jsr181MethodMetadata clientMethod = clientModel .getMethod(wmm.getWmOperationName(), paramClasses); - - compareMethodMetadata(wmm, clientMethod); - compareParameterMetadata(params, clientMethod.getParams()); + boolean paramStylesMatch = (clientModel.getSoapBinding().getParameterStyle() + == serverModel.getSoapBinding().getParameterStyle()); + if (clientMethod != null && paramStylesMatch) { + compareMethodMetadata(wmm, clientMethod); + compareParameterMetadata(params, clientMethod.getParams()); + } + else { + assertFalse("a matching client method for " + wmm.getWmOperationName() + + " could not be found and the Soap bindings match.", + paramStylesMatch); + } } } private void compareMethodMetadata(Jsr181MethodMetadata server, Jsr181MethodMetadata client) throws Exception { - + assertEquals(server.getWmOperationName(), client.getWmOperationName()); assertEquals(server.isOneWay(), client.isOneWay()); // FIXME [EMAIL PROTECTED] 2004-Nov-10 -- see FIXME below Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java?view=diff&rev=124563&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java&r1=124562&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java&r2=124563 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/util/XmlBeanTypeMappingUtil.java Fri Jan 7 11:38:07 2005 @@ -25,6 +25,7 @@ import javax.xml.namespace.QName; +import org.apache.xmlbeans.SchemaField; import org.apache.xmlbeans.SchemaType; import org.apache.xmlbeans.SchemaTypeLoader; import org.apache.xmlbeans.XmlBeans; @@ -63,8 +64,16 @@ SchemaTypeLoader stl = XmlBeans.getContextTypeLoader(); SchemaType st = stl.findType(qType); + if (st == null) { + SchemaField sf = stl.findElement(qType); + if (sf != null) { + st = sf.getType(); + } + } + if (st != null) { Class xmlClass = st.getJavaClass(); + //String clName = xmlClass.getName(); if (st.isBuiltinType()) { Method[] declared = xmlClass.getDeclaredMethods(); @@ -111,6 +120,7 @@ // NOTE [EMAIL PROTECTED] 2004-Nov-30 -- // keep in mind that a real TMU based on a viable SOAP stack should // be used and this pure XmlBean implementation is just a fallback. + System.out.println("no schematype found for " + qType); return Object.class; } } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java?view=diff&rev=124563&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java&r1=124562&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java&r2=124563 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/XmlBeanWSDLProcessor.java Fri Jan 7 11:38:07 2005 @@ -212,92 +212,112 @@ Map<String, TPart[]> messageMap, TTypes types) throws Exception { String opName = op.getName(); - TParam outputParam = op.getOutput(); + TParam outputParam = op.getOutput(); - ClientParameterMetadata[] paraMeta = + Map<String,ClientParameterMetadata> outParamMap = null; + + ClientParameterMetadata[] paraMeta = processParameters(outputParam, types, messageMap, wsm); - Class returnType; - QName returnXMLType; - - if(paraMeta == null) { + Class returnType; + QName returnXMLType; + + if(paraMeta == null) { // Should not happen, may be need to send runtime exception, or // define a new type of exception! throw new Exception("Can't resolve the return type"); - } else if (paraMeta.length == 0 ) { // no return type - returnType=Void.TYPE; - returnXMLType = null; // correct? - } else if (paraMeta.length == 1 ) { + } else if (paraMeta.length == 1 ) { returnType = paraMeta[0].getJavaType(); returnXMLType = paraMeta[0].getXmlType(); - } else { - // Should not happen, may be need to send runtime exception, or - // define a new type of exception! - throw new Exception("Return type is resolved into multiple parameters!"); - - } - - ClientMethodMetadata wmm = - new ClientMethodMetadataImpl(opName, + } else { + // either there is no return value or there are multiple so make this a + // void function and later set OUT parameters if needed. + returnType=Void.TYPE; + returnXMLType = null; // correct? + if (paraMeta.length > 1) { + outParamMap = new HashMap<String, ClientParameterMetadata>(paraMeta.length); + for (ClientParameterMetadata cpm : paraMeta) { + outParamMap.put(cpm.getWpName(), cpm); + } + } + } + ClientMethodMetadata wmm = + new ClientMethodMetadataImpl(opName, returnType, returnXMLType); + + wmm.setWmOperationName(opName); + // FIXME [EMAIL PROTECTED] 2004-Nov-10 -- + // do something better with the action + wmm.setWmAction(opName); + if (Void.TYPE.equals(returnType)) { - wmm.setWmOperationName(opName); - // FIXME [EMAIL PROTECTED] 2004-Nov-10 -- - // do something better with the action - wmm.setWmAction(opName); - if (Void.TYPE.equals(returnType)) { + if (paraMeta.length == 0) { // FIXME [EMAIL PROTECTED] 2004-Nov-22 -- - // check for faults before setting as oneway. + // also check for faults before setting as oneway. wmm.setOneWay(true); } - else { - wmm.setWrName(paraMeta[0].getWpName()); - wmm.setWrTargetNamespace(paraMeta[0].getWpTargetNamespace()); - } + } + else { + wmm.setWrName(paraMeta[0].getWpName()); + wmm.setWrTargetNamespace(paraMeta[0].getWpTargetNamespace()); + } - methodMap.put(opName, wmm); + methodMap.put(opName, wmm); - List paramOrder = op.getParameterOrder(); - TParam inputParam = op.getInput(); - if (inputParam != null) { + List paramOrder = op.getParameterOrder(); + TParam inputParam = op.getInput(); + if (inputParam != null) { - ClientParameterMetadata[] params = - processParameters(inputParam, types, messageMap, wsm); + ClientParameterMetadata[] params = + processParameters(inputParam, types, messageMap, wsm); - if (paramOrder != null) { - for (Object ord : paramOrder) { - for (ClientParameterMetadata wpm : params) { - if (ord.equals(wpm.getWpName())) { + if (paramOrder != null) { + for (Object ord : paramOrder) { + for (ClientParameterMetadata wpm : params) { + if (ord.equals(wpm.getWpName())) { - wpm.setWpMode(WebParam.Mode.IN); - wmm.addParam(wpm); - break; - } + wpm.setWpMode(WebParam.Mode.IN); + wmm.addParam(wpm); + break; } } - } - else if (params.length > 0) { - for (ClientParameterMetadata wpm : params) { - // FIXME [EMAIL PROTECTED] 2004-Nov-09 -- - // handle INOUT and OUT Params and Double check DOC/Lit rules + } + } + else if (params.length > 0) { + for (ClientParameterMetadata wpm : params) { + // FIXME [EMAIL PROTECTED] 2005-Jan-04 -- + // Double check DOC/Lit rules + if (outParamMap != null && outParamMap.containsKey(wpm.getWpName())) { + outParamMap.remove(wpm.getWpName()); + wpm.setWpMode(WebParam.Mode.INOUT); + } + else { wpm.setWpMode(WebParam.Mode.IN); - wmm.addParam(wpm); } + wmm.addParam(wpm); } } - - List<Jsr181ParameterMetadata> params = wmm.getParams(); - /* - System.out.println("adding method " + wmm.getWmOperationName() - + " returning " + wmm.getJavaReturnType() - + " with the following " + params.size() - + " parameters"); + } - for (Jsr181ParameterMetadata wpm : params) { - System.out.println(wpm.getWpName() + ':' + wpm.getJavaType()); + if (outParamMap != null && outParamMap.size() > 0) { + for (ClientParameterMetadata wpm : outParamMap.values()) { + wpm.setWpMode(WebParam.Mode.OUT); + wmm.addParam(wpm); } - */ - wsm.addMethod(wmm); + } + + List<Jsr181ParameterMetadata> params = wmm.getParams(); + /* + System.out.println("adding method " + wmm.getWmOperationName() + + " returning " + wmm.getJavaReturnType() + + " with the following " + params.size() + + " parameters"); + + for (Jsr181ParameterMetadata wpm : params) { + System.out.println(wpm.getWpName() + ':' + wpm.getJavaType()); + } + */ + wsm.addMethod(wmm); } @@ -320,82 +340,117 @@ QName paramXmlType; if (messagePart.isSetElement()) { QName element = messagePart.getElement(); - if (types != null) { - try { - Schema[] schemas = selectChildren(types, - Schema.class); - - for (Schema s : schemas) { - if (s.getTargetNamespace() - .equals(element.getNamespaceURI())) { - Element[] elements = s.getElementArray(); - for (Element e : elements) { - if (e.getName() - .equals(element.getLocalPart())) { + Class javaType = getTypeMappingUtil().q2Class(element); + if (Object.class.equals(javaType)) { + if (types != null) { + try { + Schema[] schemas = selectChildren(types, + Schema.class); + + for (Schema s : schemas) { + if (s.getTargetNamespace() + .equals(element.getNamespaceURI())) { + Element[] elements = s.getElementArray(); + for (Element e : elements) { + if (e.getName() + .equals(element.getLocalPart())) { - if (e.isSetType()) { - ClientParameterMetadata wpm = - new ClientParameterMetadataImpl(); + if (e.isSetType()) { + ClientParameterMetadata wpm = + new ClientParameterMetadataImpl(); - // NOTE [EMAIL PROTECTED] 2004-Nov-09 -- - // DOC/BARE case - wpm.setWpName(e.getName()); - // FIXME [EMAIL PROTECTED] 2004-Nov-09 -- double check the namespace stuff - wpm.setWpTargetNamespace - (s.getTargetNamespace()); - QName type = e.getType(); - wpm.setXmlType(type); - wpm.setJavaType(getTypeMappingUtil() - .q2Class(type)); - - /* - System.out.println(wpm.getWpName() - + " of type " - + wpm.getJavaType()); - */ - paramList.add(wpm); - } - else { - ComplexType ct = e.getComplexType(); - if (ct != null - && ct.isSetSequence()) { - // DOC/LIT WSDL - Group g = ct.getSequence(); - for (Element el : g.getElementArray()) { + wpm.setWpName(e.getName()); + // FIXME [EMAIL PROTECTED] 2004-Nov-09 -- double check the namespace stuff + wpm.setWpTargetNamespace + (s.getTargetNamespace()); + QName type = e.getType(); + wpm.setXmlType(type); + wpm.setJavaType(getTypeMappingUtil() + .q2Class(type)); + + /* + System.out.println(wpm.getWpName() + + " of type " + + wpm.getJavaType()); + */ + paramList.add(wpm); + } + else { + ComplexType ct = e.getComplexType(); + if (ct != null + && ct.isSetSequence()) { + // DOC/LIT WSDL + Group g = ct.getSequence(); + for (Element el : g.getElementArray()) { - if (el.isSetName() - && el.isSetType()) { ClientParameterMetadata wpm = new ClientParameterMetadataImpl(); - - wpm.setWpName(el.getName()); - // FIXME [EMAIL PROTECTED] 2004-Nov-09 -- double check the namespace stuff + + // FIXME [EMAIL PROTECTED] 2004-Nov-09 + // double check the namespace stuff wpm.setWpTargetNamespace (s.getTargetNamespace()); - QName type = el.getType(); - wpm.setXmlType(type); - wpm.setJavaType(getTypeMappingUtil().q2Class(type)); - /* - System.out.println(wpm.getWpName() - + " of type " - + wpm.getJavaType()); - */ - paramList.add(wpm); + if (el.isSetName() + && el.isSetType()) { + + wpm.setWpName(el.getName()); + + QName type = el.getType(); + wpm.setXmlType(type); + wpm.setJavaType(getTypeMappingUtil().q2Class(type)); + /* + System.out.println(wpm + .getWpName() + + " of type " + + wpm.getJavaType()); + */ + paramList.add(wpm); + } + else if (el.isSetRef()) { + QName ref = el.getRef(); + /* + System.out.println + ("ref is set to: " + ref);*/ + wpm.setWpName(ref.getLocalPart()); + wpm.setXmlType(ref); + Class cl = getTypeMappingUtil() + .q2Class(ref); + /*System.out.println + ("resulting java type: " + + cl.getName());*/ + wpm.setJavaType(cl); + + paramList.add(wpm); + } } } } + break; } - break; } + break; } - break; } } + catch (Exception e) { + e.printStackTrace(); + } } - catch (Exception e) { - e.printStackTrace(); - } + } + else { + + // NOTE [EMAIL PROTECTED] 2005-Jan-07 -- Doc/Lit Bare + wsm.getSoapBinding().setParameterStyle(SOAPBinding.ParameterStyle.BARE); + + ClientParameterMetadata wpm = + new ClientParameterMetadataImpl(); + + wpm.setWpTargetNamespace(element.getNamespaceURI()); + wpm.setWpName(element.getLocalPart()); + wpm.setXmlType(element); + wpm.setJavaType(javaType); + paramList.add(wpm); } } else {
