tomj 02/02/27 15:46:32 Modified: java/src/org/apache/axis/wsdl/fromJava Emitter.java java/src/org/apache/axis/wsdl/toJava JavaDeployWriter.java java/src/org/apache/axis/encoding/ser SimpleSerializer.java java/src/org/apache/axis/deployment/wsdd WSDDBeanMapping.java WSDDService.java WSDDTypeMapping.java Log: Changes to support document/literal WSDL generation and generation of simpleContent type schema. Get the encoding style of a type mapping from the service style. For now, style="document" in the service, means literal encoding. Revision Changes Path 1.22 +14 -3 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java Index: Emitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Emitter.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- Emitter.java 27 Feb 2002 20:31:10 -0000 1.21 +++ Emitter.java 27 Feb 2002 23:46:32 -0000 1.22 @@ -679,7 +679,13 @@ // Input SOAP Body SOAPBody soapBodyIn = new SOAPBodyImpl(); - soapBodyIn.setUse("encoded"); + // for now, if its document, it literal use. + if (mode == MODE_RPC) { + soapBodyIn.setUse("encoded"); + soapBodyIn.setEncodingStyles(encodingList); + } else { + soapBodyIn.setUse("literal"); + } if (targetService == null) soapBodyIn.setNamespaceURI(intfNS); else @@ -693,7 +699,13 @@ // Output SOAP Body SOAPBody soapBodyOut = new SOAPBodyImpl(); - soapBodyOut.setUse("encoded"); + // for now, if its document, it literal use. + if (mode == MODE_RPC) { + soapBodyOut.setUse("encoded"); + soapBodyOut.setEncodingStyles(encodingList); + } else { + soapBodyOut.setUse("literal"); + } if (targetService == null) soapBodyOut.setNamespaceURI(intfNS); else @@ -702,7 +714,6 @@ if (namespace != null) { soapBodyOut.setNamespaceURI(namespace); } - soapBodyOut.setEncodingStyles(encodingList); bindingOutput.addExtensibilityElement(soapBodyOut); bindingOper.setBindingInput(bindingInput); 1.18 +15 -5 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java Index: JavaDeployWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- JavaDeployWriter.java 13 Feb 2002 21:07:15 -0000 1.17 +++ JavaDeployWriter.java 27 Feb 2002 23:46:32 -0000 1.18 @@ -140,7 +140,7 @@ /** * Write out bean mappings for each type */ - protected void writeDeployTypes() throws IOException { + protected void writeDeployTypes(boolean hasLiteral) throws IOException { Vector types = symbolTable.getTypes(); pw.println(); @@ -148,7 +148,8 @@ TypeEntry type = (TypeEntry) types.elementAt(i); if (type.getBaseType() == null && type.isReferenced() && !type.isOnlyLiteralReferenced() - && !(type instanceof CollectionType)) { + && !(type instanceof CollectionType) + && !(type instanceof DefinedElement)) { pw.println(" <typeMapping"); pw.println(" xmlns:ns=\"" + type.getQName().getNamespaceURI() + "\""); pw.println(" qname=\"ns:" + type.getQName().getLocalPart() + '"'); @@ -161,11 +162,18 @@ type.getNode(), emitter.getSymbolTable()) != null) { pw.println(" serializer=\"org.apache.axis.encoding.ser.EnumSerializerFactory\""); pw.println(" deserializer=\"org.apache.axis.encoding.ser.EnumDeserializerFactory\""); + } else if (type.isSimpleType()) { + pw.println(" serializer=\"org.apache.axis.encoding.ser.SimpleNonPrimitiveSerializerFactory\""); + pw.println(" deserializer=\"org.apache.axis.encoding.ser.SimpleDeserializerFactory\""); } else { pw.println(" serializer=\"org.apache.axis.encoding.ser.BeanSerializerFactory\""); pw.println(" deserializer=\"org.apache.axis.encoding.ser.BeanDeserializerFactory\""); } - pw.println(" encodingStyle=\""+ Constants.URI_CURRENT_SOAP_ENC+"\""); + if (hasLiteral) + pw.println(" encodingStyle=\"\""); + else + pw.println(" encodingStyle=\"" + Constants.URI_CURRENT_SOAP_ENC + "\""); + pw.println(" />"); } } @@ -180,13 +188,15 @@ String serviceName = port.getName(); boolean isRPC = (bEntry.getBindingStyle() == BindingEntry.STYLE_RPC); + boolean hasLiteral = bEntry.hasLiteral(); String prefix = Constants.NSPREFIX_WSDD_JAVA; pw.println(" <service name=\"" + serviceName - + "\" provider=\"" + (isRPC ? prefix +":RPC" : prefix +":MSG") + "\">"); + + "\" provider=\"" + (isRPC ? prefix +":RPC" : prefix +":MSG") + + "\"" + (hasLiteral ? " style=\"literal\"" : "") + ">"); writeDeployBinding(binding); - writeDeployTypes(); + writeDeployTypes(hasLiteral); pw.println(" </service>"); 1.4 +86 -8 xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java Index: SimpleSerializer.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SimpleSerializer.java 27 Feb 2002 13:41:27 -0000 1.3 +++ SimpleSerializer.java 27 Feb 2002 23:46:32 -0000 1.4 @@ -63,9 +63,13 @@ import java.io.IOException; import java.util.Vector; import java.lang.reflect.Method; +import java.lang.reflect.Field; import org.apache.axis.Constants; +import org.apache.axis.AxisFault; import org.apache.axis.wsdl.fromJava.Types; +import org.apache.axis.wsdl.fromJava.ClassRep; +import org.apache.axis.wsdl.fromJava.FieldRep; import org.apache.axis.wsdl.toJava.Utils; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.XMLUtils; @@ -88,9 +92,19 @@ public QName xmlType; public Class javaType; + + private BeanPropertyDescriptor[] propertyDescriptor = null; + private Vector beanAttributeNames = null; + public SimpleSerializer(Class javaType, QName xmlType) { this.xmlType = xmlType; this.javaType = javaType; + + if (SimpleType.class.isAssignableFrom(javaType)) { + // get the bean properties and the list of attributes from the bean + propertyDescriptor = BeanSerializer.getPd(javaType); + beanAttributeNames = BeanSerializer.getBeanAttributes(javaType); + } } /** * Serialize a primitive or simple value. @@ -147,10 +161,6 @@ private Attributes getObjectAttributes(Object value, Attributes attributes) { - // get the list of attributes from the bean - Vector beanAttributeNames = - BeanSerializer.getBeanAttributes(value.getClass()); - // if nothing, return if (beanAttributeNames.isEmpty()) return attributes; @@ -161,9 +171,6 @@ else attrs = new AttributesImpl(); - BeanPropertyDescriptor propertyDescriptor[] = - BeanSerializer.getPd(value.getClass()); - try { // Find each property that is an attribute // and add it to our attribute list @@ -207,6 +214,77 @@ * @see org.apache.axis.wsdl.fromJava.Types */ public boolean writeSchema(Types types) throws Exception { - return false; + // Let the caller generate WSDL if this is not a SimpleType + if (!SimpleType.class.isAssignableFrom(javaType)) + return false; + + // Emit WSDL for simpleContent + javax.wsdl.QName qName = types.getWsdlQName(xmlType); + + // ComplexType representation of SimpleType bean class + Element complexType = types.createElement("complexType"); + types.writeSchemaElement(qName, complexType); + complexType.setAttribute("name", qName.getLocalPart()); + + // Produce simpleContent extending base type. + Element simpleContent = types.createElement("simpleContent"); + complexType.appendChild(simpleContent); + Element extension = types.createElement("extension"); + simpleContent.appendChild(extension); + + // Get the base type from the "value" element of the bean + String base = "string"; + for (int i=0; i<propertyDescriptor.length; i++) { + if (! propertyDescriptor[i].getName().equals("value")) + continue; + + BeanPropertyDescriptor bpd = propertyDescriptor[i]; + Class type = bpd.getType(); + // Attribute must extend a simple type. + if (!types.isSimpleSchemaType(type)) + throw new AxisFault(JavaUtils.getMessage("AttrNotSimpleType01", + type.getName())); + + base = types.writeType(type); + } + extension.setAttribute("base", base); + + // Build a ClassRep that represents the bean class. This + // allows users to provide their own field mapping. + ClassRep clsRep = types.getBeanBuilder().build(javaType); + + // Write out fields + Vector fields = clsRep.getFields(); + for (int i=0; i < fields.size(); i++) { + FieldRep field = (FieldRep) fields.elementAt(i); + + String fieldName = field.getName(); + + // if bean fields are attributes, write attribute element + if (!beanAttributeNames.contains(fieldName)) { + continue; + } + // write attribute element + Class fieldType = field.getType(); + + // Attribute must be a simple type. + if (!types.isSimpleSchemaType(fieldType)) + throw new AxisFault(JavaUtils.getMessage("AttrNotSimpleType00", + fieldName, + fieldType.getName())); + + // write attribute element + // TODO the attribute name needs to be preserved from the XML + String elementType = types.writeType(fieldType); + Element elem = types.createAttributeElement(fieldName, + elementType, + false, + extension.getOwnerDocument()); + extension.appendChild(elem); + } + + // done + return true; + } } 1.5 +1 -1 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDBeanMapping.java Index: WSDDBeanMapping.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDBeanMapping.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WSDDBeanMapping.java 28 Jan 2002 18:23:00 -0000 1.4 +++ WSDDBeanMapping.java 27 Feb 2002 23:46:32 -0000 1.5 @@ -96,7 +96,7 @@ serializer = "org.apache.axis.encoding.ser.BeanSerializerFactory"; deserializer = "org.apache.axis.encoding.ser.BeanDeserializerFactory"; - encodingStyle = Constants.URI_CURRENT_SOAP_ENC; + encodingStyle = null; } protected QName getElementName() { 1.41 +12 -7 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java Index: WSDDService.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- WSDDService.java 20 Feb 2002 18:59:20 -0000 1.40 +++ WSDDService.java 27 Feb 2002 23:46:32 -0000 1.41 @@ -330,16 +330,21 @@ tmr = new TypeMappingRegistryImpl(); } try { - TypeMapping tm = (TypeMapping) tmr.getTypeMapping(mapping.getEncodingStyle()); + // Get the encoding style from the mapping, if it isn't set + // use the style of the service to map doc/lit or rpc/enc + String encodingStyle = mapping.getEncodingStyle(); + if (encodingStyle == null) { + if (style == SOAPService.STYLE_RPC) + encodingStyle =Constants.URI_CURRENT_SOAP_ENC; + else + encodingStyle = ""; // literal + } + TypeMapping tm = (TypeMapping) tmr.getTypeMapping(encodingStyle); TypeMapping df = (TypeMapping) tmr.getDefaultTypeMapping(); if (tm == null || tm == df) { tm = (TypeMapping) tmr.createTypeMapping(); - String namespace = mapping.getEncodingStyle(); - if (mapping.getEncodingStyle() == null) { - namespace = Constants.URI_CURRENT_SOAP_ENC; - } - tm.setSupportedNamespaces(new String[] {namespace}); - tmr.register(namespace, tm); + tm.setSupportedNamespaces(new String[] {encodingStyle}); + tmr.register(encodingStyle, tm); } SerializerFactory ser = null; 1.25 +1 -1 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTypeMapping.java Index: WSDDTypeMapping.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTypeMapping.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- WSDDTypeMapping.java 21 Feb 2002 14:33:58 -0000 1.24 +++ WSDDTypeMapping.java 27 Feb 2002 23:46:32 -0000 1.25 @@ -101,7 +101,7 @@ serializer = e.getAttribute("serializer"); deserializer = e.getAttribute("deserializer"); encodingStyle = e.getAttribute("encodingStyle"); - if (encodingStyle == null || encodingStyle.equals("")) { + if (encodingStyle == null) { encodingStyle = Constants.URI_CURRENT_SOAP_ENC; }