Tom and I discussed this yesterday, and I like this approach a little better:
Have the custom type directly extend the simple type which is being extended. So in the example below, you'd have: public class InternationalPrice extends String implements TypeWithAttributes { public static String [] getAttributeFields() { return new String [] { "currency" }; } private String currency; public void setCurrency(String currency) { this.currency = currency; } public InternationalPrice(String val) { super(val); } ....etc.... } This lets you use the new type exactly as if it were a String, which matches the semantics defined by the schema type extension. This type would still be serialized by the SimpleSerializer, only it would now notice that the thingy it was serializing implemented "TypeWithAttributes" and know to ask it about its attributes before writing the element. This logic (as we just discussed on IRC) could actually move up to the Serializer level so that both Bean and Simple types get to use it. Same pattern for complex type extension with attributes, just extend the bean class of the base type, add the attribute accessors, and implement the TypeWithAttributes marker. --Glen > -----Original Message----- > From: R J Scheuerle Jr [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 21, 2002 4:12 PM > To: [EMAIL PROTECTED] > Subject: complexType extending a simpleType > > > According to XML Schema Primer 0 Chapter 2.5.1, a complexType can be > derived from a simple type to add attribute information. > > > Lets say you had the following schema: > > <complexType name="purchaseItem"> > <complexContent> > <sequence> > <element name="itemName" type="xsd:string" /> > <element name="price" type="xsd:string" /> > </sequence> > </complexContent> > </complexType> > > The above could be sent over the wire as: > > <purchaseItem> > <itemName> > Widget > </item> > <price> > 1.00 > </price> > <purchaseItem> > > And the above would be modeled as a java bean named > PurchaseItem with two > String properties. > > > Now let's say you extend this for an international market, > thus the price > needs to know the > currency. Since it is closely tied to the price, you want to > represent > currency as an > attribute on price. Here's how to represent this in xml schema. > > <complexType name="internationalPrice"> > <complexContent> > <simpleContent> > <extension base="xsd:string"/> > <attribute name="currency" type="xsd:string"> > </extension> > </simpleContent> > <complexContent> > </complexType> > > <complexType name="purchaseItem"> > <complexContent> > <sequence> > <element name="itemName" type="xsd:string" /> > <element name="price" type="tns:internationalPrice" /> > </sequence> > </complexContent> > </complexType> > > So this means that price is an element whose value is a > string and has a > currency attribute. > > Here is an example over the wire: > > <purchaseItem> > <itemName> > Widget > </item> > <price currency="USDollars"> > 1.00 > </price> > <purchaseItem> > > > We don't support extension of simpleTypes yet. When we do, we need > to generate a PurchaseItem bean (as before) and a > InternationalPrice bean. > > However, note that the InternationalPrice has a "raw" value that is > serialized > directly...not within an element and not as an attribute value. The > serializer and deserializer need to know about this raw > value, and the bean > requires > a special property name to get to the raw value. (I propose > getValue and > setValue > accessors, which match what we do with enumeration > classes...our other kind > of simpleType). > > So both emitters, bean serializer, and bean deserializer will > need to have > extra code to support this feature. (Note that this is an > optional JAX-RPC > feature). > > > Comments? > > > > > > > Rich Scheuerle > XML & Web Services Development > 512-838-5115 (IBM TL 678-5115) >