scheu 02/04/02 13:24:40
Modified: java/src/org/apache/axis/description TypeDesc.java
java/src/org/apache/axis/encoding/ser BeanDeserializer.java
java/src/org/apache/axis/utils JavaUtils.java
java/src/org/apache/axis/wsdl/toJava
JavaBeanHelperWriter.java SchemaUtils.java
Log:
A couple of minor fixes (Glen you may want to review these).
Given the discussion on the chat, the stuff in (2) probably needs
to be done for attributes.
1) JavaUtils.xmlNameToJavaName code was broken if the xmlName is a single
character capitalized name (reported by Ravi Kumar).
2) SchemaUtils. Changed the code slightly to set the ElementDecl's name
qname to either a qualified or unqualified name. For example:
<xsd:simpleType name="enum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="one"/>
<xsd:enumeration value="two"/>
<xsd:enumeration value="three"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="complexAll">
<xsd:all>
<xsd:element name="foo" type="simpleType"/>
<xsd:element ref="simpleType"/>
</xsd:all>
</xsd:complexType>
There are two elements inside complexAll. The first one is named "foo".
"foo" is an unqualified name and so would be serialized as <foo>"bar"<foo>.
The second element is a reference to a defined root element named "simpleType",
so
"simpleType" is a qualified name whose namespace context is the target
namespace.
"simpleType" could be serialized without a prefix (if the default namespace is
set correctly) or it could be serialized with a prefix the corresponds to the
target namespace.
3) Slight change to the JavaBeanHelperWriter to write meta data if:
java name and xml names are different.
java name begins with a cap (we have run into too many problems with the
reverse mapping of such things).
element has a qualified name (namespace uri is set).
4) Changed the BeanDeserializer to first look for the qualified xml name. If not
found and there is no prefix, search for an unqualified xml name.
5) Temporary change to BeanDeserializer to get meta data from a base class.
Revision Changes Path
1.8 +8 -3 xml-axis/java/src/org/apache/axis/description/TypeDesc.java
Index: TypeDesc.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TypeDesc.java 22 Mar 2002 14:38:45 -0000 1.7
+++ TypeDesc.java 2 Apr 2002 21:24:40 -0000 1.8
@@ -86,14 +86,19 @@
public static TypeDesc getTypeDescForClass(Class cls)
{
try {
- Method getTypeDesc =
+ Method getTypeDesc = null;
+ try {
+ getTypeDesc =
cls.getMethod("getTypeDesc", noClasses);
+ } catch (NoSuchMethodException e) {}
if (getTypeDesc == null) {
// Look for a Helper Class
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class helper = Class.forName(cls.getName() + "_Helper", true, cl);
- getTypeDesc =
- helper.getMethod("getTypeDesc", noClasses);
+ try {
+ getTypeDesc =
+ helper.getMethod("getTypeDesc", noClasses);
+ } catch (NoSuchMethodException e) {}
}
if (getTypeDesc != null) {
return (TypeDesc)getTypeDesc.invoke(null,
1.18 +41 -7
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- BeanDeserializer.java 2 Apr 2002 14:22:11 -0000 1.17
+++ BeanDeserializer.java 2 Apr 2002 21:24:40 -0000 1.18
@@ -167,15 +167,19 @@
prevQName = elemQName;
if (typeDesc != null) {
- // IF we're SOAP-encoded AND this is an unprefixed element,
- // ignore the actual namespace context for the element, and
- // just compare local names.
- boolean ignoreNS = ((prefix == null || prefix.equals("")) &&
- context.getMessageContext().isEncoded());
+ // First lookup the field using the target namespace context
+ // and local name. If this fails and the incoming element
+ // name is not prefixed, lookup the name assuming an unqualified
+ // name.
String fieldName = typeDesc.getFieldNameForElement(elemQName,
- ignoreNS);
-
+ false);
+ if (fieldName == null && (prefix == null || prefix.equals(""))) {
+ fieldName =
+ typeDesc.getFieldNameForElement(
+ new QName("", elemQName.getLocalPart()), false);
+ }
+
propDesc = (BeanPropertyDescriptor)propertyMap.get(fieldName);
}
@@ -183,6 +187,36 @@
// look for a field by this name.
propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);
}
+
+ // Currently the meta data does not consider inheritance.
+ // Glen is working on a fix. In the meantime, the following
+ // code attempts to get the meta data from the base class.
+ // (this fix does not work in all cases, but is necessary to
+ // get comprehensive tests Animal - Cat inheritance to work).
+ if (propDesc == null) {
+ Class superClass = javaType;
+ while (superClass != null && propDesc == null) {
+ superClass = superClass.getSuperclass();
+ if (superClass != null) {
+ TypeDesc td = TypeDesc.getTypeDescForClass(superClass);
+ if (td != null) {
+ String fieldName =
+ td.getFieldNameForElement(elemQName,
+ false);
+ if (fieldName == null &&
+ (prefix == null || prefix.equals(""))) {
+ fieldName =
+ td.getFieldNameForElement(
+ new QName("", elemQName.getLocalPart()), false);
+ }
+
+ propDesc =
+ (BeanPropertyDescriptor)propertyMap.get(fieldName);
+ }
+ }
+ }
+ }
+
if (propDesc == null) {
// No such field
throw new SAXException(
1.40 +1 -0 xml-axis/java/src/org/apache/axis/utils/JavaUtils.java
Index: JavaUtils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- JavaUtils.java 2 Apr 2002 19:07:17 -0000 1.39
+++ JavaUtils.java 2 Apr 2002 21:24:40 -0000 1.40
@@ -575,6 +575,7 @@
// character is also uppercase, to follow Introspector rules.
if (Character.isUpperCase(nameArray[i]) &&
((i != firstRealChar) ||
+ (nameLen == 1) ||
(nameLen > 1 && Character.isLowerCase(nameArray[1])))) {
result.append(Character.toLowerCase(nameArray[i]));
}
1.4 +12 -1
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java
Index: JavaBeanHelperWriter.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JavaBeanHelperWriter.java 29 Mar 2002 22:13:05 -0000 1.3
+++ JavaBeanHelperWriter.java 2 Apr 2002 21:24:40 -0000 1.4
@@ -128,7 +128,18 @@
TypeEntry type = elem.getType();
String elemName = elem.getName().getLocalPart();
String javaName = Utils.xmlNameToJava(elemName);
- if (!javaName.equals(elemName)) {
+
+ // Meta data is needed if the default serializer
+ // action cannot map the javaName back to the
+ // element's qname. This occurs if:
+ // - the javaName and element name local part are different.
+ // - the javaName starts with uppercase char (this is a wierd
+ // case and we have several problems with the mapping rules.
+ // Seems best to gen meta data in this case.)
+ // - the element name is qualified (has a namespace uri)
+ if (!javaName.equals(elemName) ||
+ Character.isUpperCase(javaName.charAt(0)) ||
+ !elem.getName().getNamespaceURI().equals("")) {
// If we did some mangling, make sure we'll write out the XML
// the correct way.
if (elementMappings == null)
1.18 +15 -1 xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java
Index: SchemaUtils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/SchemaUtils.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- SchemaUtils.java 26 Mar 2002 22:51:24 -0000 1.17
+++ SchemaUtils.java 2 Apr 2002 21:24:40 -0000 1.18
@@ -341,10 +341,24 @@
QName nodeName = Utils.getNodeNameQName(elementNode);
BooleanHolder forElement = new BooleanHolder();
QName nodeType = Utils.getNodeTypeRefQName(elementNode, forElement);
- if (nodeType == null) { // The element may use an anonymous type
+
+
+ // An element inside a complex type is either qualified or unqualified.
+ // If the ref= attribute is used, the name of the ref'd element is used
+ // (which must be a root element). If the ref= attribute is not
+ // used, the name of the element is unqualified.
+
+ if (!forElement.value) {
+ // Unqualified nodeName
+ nodeName = new QName("", nodeName.getLocalPart());
+ } else {
+ nodeName = nodeType;
+ }
+ if (nodeType == null) {
nodeType = getElementAnonQName(elementNode);
forElement.value = false;
}
+
TypeEntry type = (TypeEntry)symbolTable.getTypeEntry(nodeType,
forElement.value);