scheu 02/02/22 15:11:35
Modified: java/src/org/apache/axis/encoding/ser BeanDeserializer.java
BeanSerializer.java
java/src/org/apache/axis/wsdl/fromJava Types.java
java/src/org/apache/axis/wsdl/toJava
JavaComplexTypeWriter.java
java/test/wsdl/roundtrip BondInvestment.java
RoundtripTestSoapBindingImpl.java
java/test/wsdl/types ComprehensiveTypes.wsdl
VerifyTestCase.java
Log:
The following changes were made:
* Changed the comprehensive and roundtrip tests to test the
new complexType attribute support (Thanks Tom and Glen)
* Changed BeanSerializer/BeanDeserializer to use the new attribute
serialization for soap encoding.
* Fixed bug with BeanSerializer/Types related to the generation of the
attribute element in the wsdl file (...the code was generating
<element ...> instead of <attribute ...>)
* Other minor changes
Revision Changes Path
1.5 +48 -44
xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java
Index: BeanDeserializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BeanDeserializer.java 19 Feb 2002 20:50:46 -0000 1.4
+++ BeanDeserializer.java 22 Feb 2002 23:11:34 -0000 1.5
@@ -208,65 +208,69 @@
DeserializationContext context)
throws SAXException {
- // No attributes are allowed for SOAP encoding
- if (Constants.isSOAP_ENC(context.getMessageContext().getEncodingStyle())) {
- return;
- }
// get list of properties that are really attributes
Vector beanAttributeNames = BeanSerializer.getBeanAttributes(javaType);
// loop through the attributes and set bean properties that
// correspond to attributes
- for (int i=0; i < attributes.getLength(); i++) {
- String attrName = attributes.getLocalName(i);
- String attrNameUp = BeanSerializer.format(attrName,
BeanSerializer.FORCE_UPPER);
- String attrNameLo = BeanSerializer.format(attrName,
BeanSerializer.FORCE_LOWER);
- String mangledName = JavaUtils.xmlNameToJava(attrName);
-
- // look for the attribute property
- BeanPropertyDescriptor bpd =
+ if (beanAttributeNames != null &&
+ beanAttributeNames.size() > 0) {
+ for (int i=0; i < attributes.getLength(); i++) {
+ String attrName = attributes.getLocalName(i);
+ String attrNameUp = BeanSerializer.format(attrName,
BeanSerializer.FORCE_UPPER);
+ String attrNameLo = BeanSerializer.format(attrName,
BeanSerializer.FORCE_LOWER);
+ String mangledName = JavaUtils.xmlNameToJava(attrName);
+
+ // See if the attribute is a beanAttribute name
+ if (!beanAttributeNames.contains(attrName) &&
+ !beanAttributeNames.contains(attrNameUp) &&
+ !beanAttributeNames.contains(attrNameLo))
+ continue;
+
+ // look for the attribute property
+ BeanPropertyDescriptor bpd =
(BeanPropertyDescriptor) propertyMap.get(attrNameUp);
- if (bpd == null)
- bpd = (BeanPropertyDescriptor) propertyMap.get(attrNameLo);
- if (bpd == null)
- bpd = (BeanPropertyDescriptor) propertyMap.get(mangledName);
- if (bpd != null) {
- if (bpd.getWriteMethod() == null ) continue ;
-
- // determine the QName for this child element
- TypeMapping tm = context.getTypeMapping();
- Class type = bpd.getType();
- QName qn = tm.getTypeQName(type);
- if (qn == null)
- throw new SAXException(
+ if (bpd == null)
+ bpd = (BeanPropertyDescriptor) propertyMap.get(attrNameLo);
+ if (bpd == null)
+ bpd = (BeanPropertyDescriptor) propertyMap.get(mangledName);
+ if (bpd != null) {
+ if (bpd.getWriteMethod() == null ) continue ;
+
+ // determine the QName for this child element
+ TypeMapping tm = context.getTypeMapping();
+ Class type = bpd.getType();
+ QName qn = tm.getTypeQName(type);
+ if (qn == null)
+ throw new SAXException(
JavaUtils.getMessage("unregistered00",
type.toString()));
- // get the deserializer
- Deserializer dSer = context.getDeserializerForType(qn);
- if (dSer == null)
- throw new SAXException(
+ // get the deserializer
+ Deserializer dSer = context.getDeserializerForType(qn);
+ if (dSer == null)
+ throw new SAXException(
JavaUtils.getMessage("noDeser00", type.toString()));
- if (! (dSer instanceof SimpleDeserializer))
- throw new SAXException(
+ if (! (dSer instanceof SimpleDeserializer))
+ throw new SAXException(
JavaUtils.getMessage("AttrNotSimpleType00",
bpd.getName(),
type.toString()));
- if (bpd.getWriteMethod().getParameterTypes().length == 1) {
- // Success! Create an object from the string and set
- // it in the bean
- try {
- Object val = ((SimpleDeserializer)dSer).
- makeValue(attributes.getValue(i));
- bpd.getWriteMethod().invoke(value, new Object[] {val} );
- } catch (Exception e) {
- throw new SAXException(e);
+ if (bpd.getWriteMethod().getParameterTypes().length == 1) {
+ // Success! Create an object from the string and set
+ // it in the bean
+ try {
+ Object val = ((SimpleDeserializer)dSer).
+ makeValue(attributes.getValue(i));
+ bpd.getWriteMethod().invoke(value, new Object[] {val} );
+ } catch (Exception e) {
+ throw new SAXException(e);
+ }
}
- }
- } // if
- } // attribute loop
-
+ } // if
+ } // attribute loop
+ } // if attributes exist
} // onStartElement
}
1.9 +8 -12
xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
Index: BeanSerializer.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BeanSerializer.java 22 Feb 2002 20:04:43 -0000 1.8
+++ BeanSerializer.java 22 Feb 2002 23:11:34 -0000 1.9
@@ -156,16 +156,11 @@
{
boolean isSOAP_ENC = Constants.
isSOAP_ENC(context.getMessageContext().getEncodingStyle());
- if (isSOAP_ENC) {
- // SOAP encoding doesn't allow attributes
- context.startElement(name, attributes);
- } else {
- // Check for meta-data in the bean that will tell us if any of the
- // properties are actually attributes, add those to the element
- // attribute list
- Attributes beanAttrs = getObjectAttributes(value, attributes);
- context.startElement(name, beanAttrs);
- }
+ // Check for meta-data in the bean that will tell us if any of the
+ // properties are actually attributes, add those to the element
+ // attribute list
+ Attributes beanAttrs = getObjectAttributes(value, attributes);
+ context.startElement(name, beanAttrs);
try {
// Serialize each property
@@ -173,7 +168,8 @@
String propName = propertyDescriptor[i].getName();
if (propName.equals("class"))
continue;
- if (!isSOAP_ENC && beanAttributeNames.contains(propName))
+ //if (!isSOAP_ENC && beanAttributeNames.contains(propName))
+ if (beanAttributeNames.contains(propName))
continue;
propName = format(propName, elementPropertyFormat);
@@ -396,7 +392,7 @@
fieldType.getName()));
String elementType = types.writeType(fieldType);
- Element elem = types.createElement(fieldName,
+ Element elem = types.createAttributeElement(fieldName,
elementType,
false,
where.getOwnerDocument());
1.17 +19 -0 xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
Index: Types.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Types.java 21 Feb 2002 18:51:23 -0000 1.16
+++ Types.java 22 Feb 2002 23:11:34 -0000 1.17
@@ -541,6 +541,25 @@
/**
+ * Create Attribute Element with a given name and type
+ * @param elementName the name of the created element
+ * @param elementType schema type representation of the element
+ * @param nullable nullable attribute of the element
+ * @return the created Element
+ */
+ public Element createAttributeElement(String elementName,
+ String elementType,
+ boolean nullable,
+ Document docHolder) {
+ Element element = docHolder.createElement("attribute");
+ element.setAttribute("name", elementName);
+ if (nullable)
+ element.setAttribute("nillable", "true");
+ element.setAttribute("type", elementType);
+ return element;
+ }
+
+ /**
* convert from JAX-RPC QName to WSDL QName
* @param qName JAX-RPC QName
* @return WSDL QName
1.9 +1 -1
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java
Index: JavaComplexTypeWriter.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaComplexTypeWriter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JavaComplexTypeWriter.java 21 Feb 2002 19:25:07 -0000 1.8
+++ JavaComplexTypeWriter.java 22 Feb 2002 23:11:34 -0000 1.9
@@ -216,7 +216,7 @@
// list of properties that are attributes instead of elements
if (attributes != null) {
pw.println(" // List of fields that are XML attributes");
- pw.println(" public static java.lang.String[] _attrs = new String[]
{");
+ pw.println(" private static java.lang.String[] _attrs = new String[]
{");
for (int i=0; i < attributes.size(); i+=2) {
pw.println(" \"" + Utils.xmlNameToJava((String)
attributes.get(i + 1)) + "\", ");
}
1.2 +13 -0 xml-axis/java/test/wsdl/roundtrip/BondInvestment.java
Index: BondInvestment.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/roundtrip/BondInvestment.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BondInvestment.java 12 Feb 2002 22:10:19 -0000 1.1
+++ BondInvestment.java 22 Feb 2002 23:11:35 -0000 1.2
@@ -154,4 +154,17 @@
return this.wrapperDouble;
} // getWrapperDouble
+ // List of fields that are XML attributes
+ private static java.lang.String[] _attrs = new String[] {
+ "taxIndicator",
+ "docType",
+ "stockBeta"
+ };
+
+ /**
+ * Return list of bean field names that are attributes
+ */
+ public static java.lang.String[] getAttributeElements() {
+ return _attrs;
+ }
} // BondInvestment
1.3 +7 -0
xml-axis/java/test/wsdl/roundtrip/RoundtripTestSoapBindingImpl.java
Index: RoundtripTestSoapBindingImpl.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/test/wsdl/roundtrip/RoundtripTestSoapBindingImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RoundtripTestSoapBindingImpl.java 20 Feb 2002 20:41:14 -0000 1.2
+++ RoundtripTestSoapBindingImpl.java 22 Feb 2002 23:11:35 -0000 1.3
@@ -148,6 +148,13 @@
sendValue.setDocType((short) 45);
sendValue.setTaxIndicator((byte) 8);
+ if ((in0.getStockBeta() == 32) &&
+ (in0.getDocType() == (short) 35) &&
+ (in0.getTaxIndicator() == (byte) 3))
+ ;
+ else
+ throw new RemoteException("Actual attribute values did not match
expected values.");
+
if ((in0.getOptions()[0].getCallDate().equals(new Date(1013441507388L))) &&
(in0.getOptions()[1].getCallDate().equals(new Date(1013441507390L))) &&
(in0.getWrapperShortArray()[0].equals(new Short((short) 23))) &&
1.16 +10 -4 xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl
Index: ComprehensiveTypes.wsdl
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/types/ComprehensiveTypes.wsdl,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ComprehensiveTypes.wsdl 5 Feb 2002 23:11:13 -0000 1.15
+++ ComprehensiveTypes.wsdl 22 Feb 2002 23:11:35 -0000 1.16
@@ -73,20 +73,26 @@
</xsd:complexType>
</xsd:element>
+ <xsd:complexType name="time">
+ <xsd:restriction base="xsd:string">
+ <xsd:attribute name="DST" type="xsd:boolean" />
+ </xsd:restriction>
+ </xsd:complexType>
+
<xsd:complexType name="complexWComplex">
<xsd:sequence>
<xsd:element name="stock_quote">
<xsd:complexType>
+ <xsd:attribute name="symbol" type="xsd:string"/>
<xsd:sequence>
<!-- forward simple type ref -->
- <xsd:element name="symbol" type="typens:simpleFwd"/>
- <xsd:element name="time" type="xsd:string"/>
- <xsd:element name="last" type="xsd:string"/>
- <xsd:element name="change" type="xsd:string"/>
+ <xsd:element name="time" type="typens:time"/>
+ <xsd:element name="change" type="typens:simpleFwd"/>
<xsd:element name="pctchange" type="xsd:string"/>
<xsd:element name="bid" type="xsd:string"/>
<xsd:element name="ask" type="xsd:string"/>
</xsd:sequence>
+ <xsd:attribute name="last" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="outside" type="xsd:int"/>
1.9 +12 -2 xml-axis/java/test/wsdl/types/VerifyTestCase.java
Index: VerifyTestCase.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/types/VerifyTestCase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- VerifyTestCase.java 5 Feb 2002 23:11:13 -0000 1.8
+++ VerifyTestCase.java 22 Feb 2002 23:11:35 -0000 1.9
@@ -55,6 +55,7 @@
import test.wsdl.types.comprehensive_types.EnumShort;
import test.wsdl.types.comprehensive_types.EnumString;
import test.wsdl.types.comprehensive_types.StockQuote;
+import test.wsdl.types.comprehensive_types.Time;
import test.wsdl.types.comprehensive_types2.A;
import test.wsdl.types.comprehensive_types2.B;
@@ -245,8 +246,17 @@
} catch (java.rmi.RemoteException re) {
throw new junit.framework.AssertionFailedError("Remote Exception
caught: " + re );
}
- StockQuote stockQuote = new StockQuote("hi ho!", "hi ho!", "it's off to
work", "we go", "tweet tweet tweet tweet", "tweet tweet tweet tweet", "tweet tweet,
tweet tweet");
- ComplexWComplex complexWComplex = new ComplexWComplex(stockQuote, 22);
+ StockQuote stockQuote = new StockQuote();
+ stockQuote.setTime(new Time());
+ stockQuote.setChange("5");
+ stockQuote.setPctchange("100%");
+ stockQuote.setBid("9");
+ stockQuote.setAsk("11");
+ stockQuote.setSymbol("AXS");
+ stockQuote.setLast("5");
+ ComplexWComplex complexWComplex = new ComplexWComplex();
+ complexWComplex.setStockQuote(stockQuote);
+ complexWComplex.setOutside(22);
try {
binding.complexWComplexIn(complexWComplex);
} catch (java.rmi.RemoteException re) {