[jboss-dev-forums] [Design of JBossXB] - Re: Using annotations to define schema mappings

scott.stark@jboss.org do-not-reply at jboss.com
Sun Oct 8 18:40:47 EDT 2006


Yes, and we also need to support the ability to pickup the schema annotations from an external file. The jaxb mechanism for this has an xpath syntax where 

An example from the jaxb2 spec, consider the following schema and external binding file.
Source Schema: A.xsd:

  | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  |    xmlns:ens="http://example.com/ns"
  |    targetNamespace="http://example.com/ns">
  |    <xs:complexType name="aType">
  |       <xs:sequence>
  |          <xs:element name="foo" type="xs:int"/>
  |       </xs:sequence>
  |       <xs:attribute name="bar" type="xs:int"/>
  |    </xs:complexType>
  |    <xs:element name="root" type="ens:aType"/>
  | </xs:schema>
  | 

External binding declarations file:

  | <jaxb:bindingsxmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  |    xmlns:xs="http://www.w3.org/2001/XMLSchema"
  |    version="1.0">
  |    <jaxb:bindings schemaLocation='A.xs'>
  |       <jaxb:bindings node="//xs:complexType[@name=?aType?]?>
  |          <jaxb:class name="customNameType"/>
  |          <jaxb:bindings node=?.//xs:element[@name=?foo?]?>
  |             <jaxb:property name="customFoo"/>
  |          </jaxb:bindings>
  |          <jaxb:bindings node=?./xs:attribute[@name=?bar?]?>
  |             <jaxb:property name="customBar"/>
  |          </jaxb:bindings>
  |       </jaxb:bindings>
  |    </jaxb:bindings>
  | </jaxb:bindings>
  | 

Conceptually, the combination of the source schema and external binding file above are the equivalent of the following inline annotated schema.

  | <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  |    xmlns:ens="http://example.com/ns"
  |    targetNamespace="http://example.com/ns"
  |    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  |    jaxb:version="1.0">
  |    <xs:complexType name="aType">
  |       <xs:annotation>
  |          <xs:appinfo>
  |             <jaxb:class name="customNameType"/>
  |          </xs:appinfo>
  |       </xs:annotation>
  |       <xs:sequence>
  |          <xs:element name="foo" type="xs:int">
  |             <xs:annotation>
  |                <xs:appinfo>
  |                   <jaxb:property name="customFoo"/>
  |                </xs:appinfo>
  |             </xs:annotation>
  |          </xs:element>
  |       </xs:sequence>
  |       <xs:attribute name="bar" type="xs:int">
  |          <xs:annotation>
  |             <xs:appinfo>
  |                <jaxb:property name="customBar"/>
  |             </xs:appinfo>
  |          </xs:annotation>
  |       </xs:attribute>
  |    </xs:complexType>
  |    <xs:element name="root" type="ens:aType"/>
  | </xs:schema>
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976856#3976856

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976856



More information about the jboss-dev-forums mailing list