Advanced Axis2 Databinding Framework Features

The aim of this section is provide an insight into the newly added advanced features of ADB.

Content

xsi:type Support

This is implemented by adding a extension maping class. The code that calls the extension mapper is generated inside the deserialization method of the beans and gets active when the xsi:type attribute is present. The following code fragment shows how the generated type mapper looks like

 public static java.lang.Object getTypeObject(
java.lang.String namespaceURI, java.lang.String typeName,
javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception {
if ("http://new.webservice.namespace/types".equals(namespaceURI) &&                 "derivedType2".equals(typeName)) {
        return namespace.webservice._new.types.DerivedType2Helper.parse(reader);
} 

......

        return namespace.webservice._new.types.BaseTypeHelper.parse(reader);
} else if ("http://new.webservice.namespace/types".equals(namespaceURI) &&                 "derivedType1".equals(typeName)) {
        return namespace.webservice._new.types.DerivedType1Helper.parse(reader);
}

throw new java.lang.RuntimeException("Unsupported type " +
        namespaceURI + " " + typeName);

}

Inside every deserialize method, the extension mapper gets called when a xsi:type attribute is encountered and that type is not the type that is being parsed

The following code fragment shows how the ADB deserialize method calls the mapper class

if (reader.getAttributeValue(
                        "http://www.w3.org/2001/XMLSchema-instance", "type") != null) {
        java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance",
                        "type");
        if (fullTypeName != null) {
                java.lang.String nsPrefix = fullTypeName.substring(0,fullTypeName.indexOf(":"));
                nsPrefix = (nsPrefix == null) ? "" : nsPrefix;
                java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":") + 1);
                if (!"derivedType2".equals(type)) {
                        //find namespace for the prefix
                        java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
                        return (DerivedType2) namespace.webservice._new.types.ExtensionMapper.getTypeObject(nsUri,
                                type, reader);
                }
        }
}

This should make the xsi:type based deserialization possible and should result in proper xsi:type based serializations at runtime

This is automatically done but the package name for the mapper class can be controlled by using the mp flag (with a preceding -E)

 WSDL2Code -uri .... -Emp org.example.web.map

When the mapping package is not specified it is derived from the targetnamespace of the first schema that is encountered

Helper mode

Helper mode is a fairly new feature. In the helper mode, the beans are plain Java beans and all the deserialization/serialization code is moved to a helper class. For example the simple schema mentioned in the ADB-howto document will yield four classes for the two that has been previously seen

  1. MyElement.java
  2. MyElementHelper.java
  3. SOAPStruct.java
  4. SOAPStructHelper.java

The helpers basically contain all the code that went into the ADBBeans. Hence the beans in the helper mode are pretty much readable than the rest. Also note that the helper mode is available only if you are in the unpacked mode. The code generator by default does not expand the classes

Helper mode can be switched on by the h flag (Passed with a -E infront to indicate that it is an extra switch undertood by ADB). Also the -u flag should be present to indicate the unpacking

 WSDL2Code -uri .... -u -Eh

More Stuff on ADB?