Hello,

I think I'm struggling to map OO concepts to XML schema concepts, and I hope
that someone on this list has seen this problem before.

(All schemas are defined at the bottom of this email)

1. A schema defines two complex types, 'Foo' and 'Bar'.
2. A 'Foo' has an element named 'Bar' of type 'Bar', e.g.

  <Foo>
    <Bar/>
  </Foo>

3. A customer-specific version of this schema extends 'Foo' and 'Bar' with
complex types 'CustomerFoo' and 'CustomerBar'.
4. The complex type 'CustomerFoo' adds a single element to 'Foo'.
5. The complex type 'CustomerBar' adds a single string element to 'Bar'.

My problem is that I need 'CustomerFoo's "inherited" element 'Bar' to be of
type 'CustomerBar', e.g. the following XML must be valid:

  <CustomerFoo>
    <CustomerBar/>
  </CustomerFoo>

and the following code should be generated:

public class CustomerFooImpl extends FooImpl implements CustomerFoo{
  //...


  //Foo.getBar() is satisfied by returning a CustomerBar, which extends Bar
  private CustomerBar customerBar;
  public Bar getBar(){
    return this.customerBar;
  }
}

I can't seem to get this to work.  I've tried two approaches:

1. Use an 'xs:include' or 'xs:import' with 'xs:extension' in the
customer-specific schema.
        - The element 'Bar' in the complex type 'Foo' cannot be redefined by
a simple extension, so the following XML document is not valid:

<CustomerFoo>
        <!-- ... -->

        <!-- Not valid, because although CustomerBar extends Bar, -->
        <!-- this is not sufficient to allow a CustomerBar to replace -->
        <!-- the Bar required by Foo -->
        <CustomerBar>
                <!-- ... -->
        </CustomerBar>
</CustomerFoo>

2. Use an 'xs:redefines' with 'xs:extension' in the customer-specific
schema.
        - This allows the previous XML to validate, but the generated
CustomerBar.java and CustomerFoo.java don't extend Bar.java and Foo.java
(likewise for the Impl classes).

Is there another way to express the fact that, for a customerFoo, the 'Bar'
element should be a 'customerBar'?  Should I be using substitution groups or
xsi:type somewhere?

Thanks for your help.  The XML is below.

Brian Hartin
Pearson Educational Measurement
Iowa City, IA 52245




<!-- foobar.xsd -->
<!-- A 'base' schema which will be 'extended' by customer specific ones
-->
<xs:schema ...>
  <xs:complexType name="Foo">
    <xs:sequence>
      <xs:element name="FooName" type="xs:string"/>
      <xs:element name="Bar" type="bar"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Bar">
    <xs:sequence>
      <xs:element name="BarName" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

<!-- customer-foobar.xsd -->
<!-- A version of the base schema for a customer using include and extension
-->
<xs:schema ...>
  <xs:include schemaLocation="foobar.xsd"/>
  <xs:complexType name="customerFoo">
    <xs:complexContent>
      <xs:extension base="Foo">
        <xs:sequence>
          <xs:element name="FooCode" type="xs:string"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="customerBar">
    <xs:complexContent>
      <xs:extension base="Bar">
        <xs:sequence>
          <xs:element name="BarCode" type="xs:string"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

<!-- customer-foobar.xsd -->
<!-- A version of the base schema for a customer using redefines and
extension -->
<xs:schema ...>
  <xs:redefines schemaLocation="foobar.xsd">
    <xs:complexType name="CustomerFoo">
      <xs:complexContent>
        <xs:extension base="Foo">
          <xs:sequence>
            <xs:element name="FooCode" type="xs:string"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="CustomerBar">
      <xs:complexContent>
        <xs:extension base="Bar">
          <xs:sequence>
            <xs:element name="BarCode" type="xs:string"/>
          </xs:sequence>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:redefines>
</xs:schema>


 

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to