Java object vs xml parse stack
starksm64 Jul 20, 2005 7:04 PMSo in going through the some debugging of the attribute defaults issue, I have a problem understanding the current relationship between the java object stack and the xml document parse stack. Let's start with the xsd for the element that is causing me trouble:
... <xs:element name="binding" minOccurs="1" maxOccurs="unbounded"> <xs:annotation> <xs:appinfo> <jbxb:class impl="org.jboss.naming.JNDIBinding"/> <jbxb:property name="Bindings" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:choice minOccurs="1" maxOccurs="1"> <xs:element name="value"> <xs:annotation> <xs:appinfo> <jbxb:property name="text"/> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="type" type="xs:string" use="optional" default="java.lang.String"> </xs:attribute> <xs:attribute name="editor" type="xs:string" use="optional"> </xs:attribute> <xs:attribute name="replace" type="xs:boolean" default="true"> </xs:attribute> <xs:attribute name="trim" type="xs:boolean" default="true"> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:any namespace="##other"> <xs:annotation> <xs:documentation>An extension point for arbitrary xml value fragments</xs:documentation> </xs:annotation> </xs:any> </xs:choice> <xs:attribute name="name" type="xs:string" use="required"> <xs:annotation> <xs:documentation>The JNDI name of the binding</xs:documentation> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element> ...
A binding element maps to a org.jboss.naming.JNDIBinding object, and the collection of binding elements maps to the Bindings property of the associated parent element java object.
A binding is either a value element with text content and 4 attributes, or an arbitrary xml fragment from another namespace. The text of the value element maps to the "text" property of the JNDIBinding class. The any extension point would map to the "value" Object property of the JNDIBinding class.
So one disconnect I have is that in the default parse mode, the value element has no associated class specified, and there is no org.jboss.naming.Value class that can be selected automatically. When I look at this schema I'm expecting that in the absence of an explicit or automatic mapping of the value element to an object, it will simply inherit its parent element's object. Is this a meaningful mode of behavior in general? To achieve this affect, Alexey corrected the above schema fragment to:
<xs:element name="binding" minOccurs="1" maxOccurs="unbounded"> <xs:annotation> <xs:appinfo> <jbxb:class impl="org.jboss.naming.JNDIBinding"/> <jbxb:property name="Bindings" /> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:choice minOccurs="1" maxOccurs="1"> <xs:element name="value"> <xs:annotation> <xs:appinfo> <jbxb:skip/> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:annotation> <xs:appinfo> <jbxb:characters> <jbxb:property name="text"/> </jbxb:characters> </xs:appinfo> </xs:annotation> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="type" type="xs:string" use="optional" default="java.lang.String"> </xs:attribute> <xs:attribute name="editor" type="xs:string" use="optional"> </xs:attribute> <xs:attribute name="replace" type="xs:boolean" default="true"> </xs:attribute> <xs:attribute name="trim" type="xs:boolean" default="true"> </xs:attribute> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:any namespace="##other"> <xs:annotation> <xs:documentation>An extension point for arbitrary xml value fragments</xs:documentation> </xs:annotation> </xs:any> </xs:choice> <xs:attribute name="name" type="xs:string" use="required"> <xs:annotation> <xs:documentation>The JNDI name of the binding</xs:documentation> </xs:annotation> </xs:attribute> </xs:complexType> </xs:element>
The jbxb:skip essentially removes the value element and merges the content into the binding element along with the attributes. I can understand this mapping fine. I guess my issue is why this was not the natural choice for me. I think the problem is that we don't have an overview of xml to java mapping that clearly shows how elements in a xml tree map to elements in a java object model tree.
This should be done from the default jaxb rules as well as from how the various jaxb/jbxb annotations can be used to manipulate the element mapping to a java object model that is increasingly removed from the expected default. The point is we start with the defaults to show the fine-grained object model that is expected, and then illustrate how customizations can be used to map the same xml document onto a much more compact, preexisting object model graph. I'll work with the documentation team to get this fleshed out.
In terms of the default behavior, the question is whether or not it makes sense for the jbxb:skip to be implicitly present for any element that does not have an explicit or automatic class specification? This could be another jbxb:schemaBindings setting.