users@jaxb.java.net

Re: map xsd:restrictions as subclasses

From: Anca Dobrescu <anca.a.dobrescu_at_gmail.com>
Date: Fri, 13 May 2011 10:06:18 +0200

Hi Wolfgang -

Thanks for your answer. Actually, the simpleType Simple_Id is mapped to a
Base_3039 class, like this:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Simple_Id", propOrder = {
    "value"
})
public class SimpeId {

    @XmlValue
    protected Base3039 value;

    /**
     * Gets the value of the value property.
     *
     * @return
     * possible object is
     * {_at_link Base3039 }
     *
     */
    public Base3039 getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     *
     * @param value
     * allowed object is
     * {_at_link Base3039 }
     *
     */
    public void setValue(Base3039 value) {
        this.value = value;
    }

}


And the Base3039 simple type is mapped like this:


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Base_3039", propOrder = {
    "value"
})
public class Base3039 {

    @XmlValue
    protected String value;

    /**
     * Gets the value of the value property.
     *
     * @return
     * possible object is
     * {_at_link String }
     *
     */
    public String getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     *
     * @param value
     * allowed object is
     * {_at_link String }
     *
     */
    public void setValue(String value) {
        this.value = value;
    }

}

In this case, I don't understand why the Simple_S class for example is
mapped likes this, instead of extending SimpleId:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Simple_S", propOrder = {
    "value"
})
public class SimpleS {

    @XmlValue
    protected SimpleId value;

    /**
     * Gets the value of the value property.
     *
     * @return
     * possible object is
     * {_at_link SimpleId }
     *
     */
    public SimpleId getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     *
     * @param value
     * allowed object is
     * {_at_link SimpleId }
     *
     */
    public void setValue(SimpleId value) {
        this.value = value;
    }

}

Thanks!

-Anca


On Thu, May 12, 2011 at 7:31 PM, Wolfgang Laun <wolfgang.laun_at_gmail.com>wrote:

> If the simpleType Simple_Id is mapped to xs:string, you cannot expect
> subclasses, because java.lang.String is final.
> -W
>
>
>
> On 12 May 2011 17:48, <anca.a.dobrescu_at_gmail.com> wrote:
>
>> Hi everyone -
>>
>> I have been doing a lot of research trying to figure this out, but am
>> still unsuccessful.
>>
>> Here's what I'm trying to do. I have a number of XSD that follow this
>> pattern:
>>
>> Simple_Id.xsd
>>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>> <xsd:include schemaLocation="./Base_3039.xsd"/>
>> <xsd:include schemaLocation="./Simple_A.xsd"/>
>> <xsd:include schemaLocation="./Simple_S.xsd"/>
>> <xsd:include schemaLocation="./Simple_N.xsd"/>
>> <xsd:include schemaLocation="./Simple_V1.xsd"/>
>> <xsd:include schemaLocation="./Simple_L.xsd"/>
>> <xsd:include schemaLocation="./Simple_V.xsd"/>
>> <xsd:include schemaLocation="./Simple_C.xsd"/>
>> <xsd:simpleType name="Simple_Id">
>> <xsd:restriction base="Base_3039"/>
>> </xsd:simpleType>
>> </xsd:schema>
>>
>> where for example Simple_S.xsd looks like this:
>>
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>>
>> <xsd:include schemaLocation="./Simple_Id.xsd"/>
>>
>> <xsd:simpleType name="Simple_S">
>> <xsd:restriction base="Simple_Id">
>>
>> <xsd:minLength value="14"/>
>> <xsd:maxLength value="14"/>
>>
>> </xsd:restriction>
>> </xsd:simpleType>
>>
>> </xsd:schema>
>>
>> Eventually, I would like to be able to generate XML files that contain
>> tags looking like this:
>>
>> <Id xsi:type="Simple_S">XYZUVW</Id>
>>
>> For now, without enabling mapSimpleTypeDef, I am able to
>> marshall/unmarshall XML files but without the xsi:types.
>>
>> After enabling mapSimpleTypeDef classes are generated for the simple
>> types. Nevertheless, the classes for the different types of Simple_Ids
>> do not extend Simple_Id but only contain a field of type Simple_Id.
>>
>> So, basically, my question is how can I make JAXB map my restrictions
>> as subclasses of the restricted type. Note that the XSDs are not mine
>> to modify, just have to work with them.
>>
>> Thanks for taking the time to help me figure this out!
>>
>> -Anca
>>
>
>