users@jaxb.java.net

Re: Getting JAXB to instantiate your subclasses

From: Allister Bertram <abertram_at_checkfree.com>
Date: Thu, 03 Apr 2003 22:20:19 -0500

In my example, "owned" elements can be positioned in an XML document within
the context of an "owning" element, or can be positioned under the root of
the document with a reference to the "owning" element.

Here's a doctored schema for simplicity. "A" can own AA, BB, and CC
elements. "AA" can own BB and CC elements, and needs an "A" reference if
it isn't positioned under the owning "A".

I'd like to subclass all of A, AA, BB, CC to add business logic to the
content.

When I inline binding customizations to specify an implementation class for
all of A, AA, BB, CC, the generated classes give me subclass instances only
when the elements are positioned directly under the document root. When
the elements are positioned under owning elements, the implClass
customization doesn't seem to apply.

   <xs:element name="DocumentRoot">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="ElementA" />
      <xs:element ref="ElementAA" />
      <xs:element ref="ElementBB" />
      <xs:element ref="ElementCC" />
      </xs:choice>
    </xs:complexType>
  </xs:element>

  <xs:element name="ElementA">
    <xs:complexType>
      <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" ref="ElementAA" />
      <xs:element minOccurs="0" maxOccurs="unbounded" ref="ElementBB" />
      <xs:element minOccurs="0" maxOccurs="unbounded" ref="ElementCC" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="ElementARef">
    <xs:complexType>
      <xs:attribute name="Key" type="xs:string" />
    </xs:complexType>
  </xs:element>

  <xs:element name="ElementAA">
    <xs:complexType>
      <xs:sequence>
      <xs:element minOccurs="0" ref="ElementARef" />
      <xs:element minOccurs="0" maxOccurs="unbounded" ref="ElementBB" />
      <xs:element minOccurs="0" maxOccurs="unbounded" ref="ElementCC" />
      </xs:sequence>
      <xs:attribute name="Type" type="xs:string" use="required" />
      <xs:attribute name="Description" type="xs:string" />
    </xs:complexType>
  </xs:element>

etc.




Allister Bertram
Software Engineer
CheckFree i-Solutions
abertram_at_checkfree.com
Phone: (519) 883-8487 x33480

The #1 Way to Pay Online
http://www.checkfree.com/paybillsonline



|---------+---------------------------->
| | Ryan Shoemaker - |
| | JavaSoft East |
| | <Ryan.Shoemaker_at_S|
| | un.COM> |
| | Sent by: |
| | Discussion list |
| | for the Java |
| | Architecture for |
| | XML Binding |
| | <JAXB-INTEREST_at_JA|
| | VA.SUN.COM> |
| | |
| | |
| | 04/03/2003 04:24 |
| | PM |
| | Please respond to|
| | Discussion list |
| | for the Java |
| | Architecture for |
| | XML Binding |
| | |
|---------+---------------------------->
>------------------------------------------------------------------------------------------------------------------------------|
  | |
  | To: JAXB-INTEREST_at_JAVA.SUN.COM |
  | cc: |
  | Subject: Re: Getting JAXB to instanciate your subclasses |
>------------------------------------------------------------------------------------------------------------------------------|




Allister Bertram wrote:
> I'm seeing some success using the discussed method, but it's failing to
properly instantiate from
> my specified impl subclass when the element is a child of another
element.
>
> In my schema, certain elements can appear under the root, with a
reference to related entities,
> or they can appear as child elements of those related entities. In the
former case, the
> implClass binding is working for me, but in the latter, it is not.
>

I think I follow you, but a simple schema fragment would help me answer
your
question. Can you provide one?

> I hope the upcoming FAQ will either offer a solution to this extension of
the original problem,
> or articulate that I'm out of luck until a future release.
>

I apologize that the FAQ is not out yet - it is complete, but hung-up in
some
internal processes to get it on the web. I'll be sure to send an
announcement
as soon as it is published.

Thanks,

--Ryan