users@jaxb.java.net

Re: Customizing IDREF target type?

From: Dennis Sosnoski <dms_at_sosnoski.com>
Date: Thu, 12 Jun 2003 01:48:43 -0700

I don't think this is going to do any good. Right now I've got ID/IDREF
links handling by JAXB using a Schema along these lines:
  ...
  <xsd:element name="carrier">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="rating" type="xsd:int"/>
        <xsd:element name="URL" type="xsd:string"/>
        <xsd:element name="name" type="xsd:string"/>
      </xsd:sequence>
      <xsd:attribute name="ident" type="xsd:ID" use="required"/>
    </xsd:complexType>
  </xsd:element>
  ...
  <xsd:element name="flight">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="number" type="xsd:int"/>
        <xsd:element name="depart" type="xsd:string"/>
        <xsd:element name="arrive" type="xsd:string"/>
      </xsd:sequence>
      <xsd:attribute name="carrier" type="xsd:IDREF" use="required"/>
    </xsd:complexType>
  </xsd:element>

Where the "carrier" attribute of a "flight" element always links to a
"carrier" element. I'd like to have the generated methods take the form:

    java.lang.Object getCarrier();
    void setCarrier(java.lang.Object value);

rather than what I'm getting now, which is:

    java.lang.Object getCarrier();
    void setCarrier(java.lang.Object value);

I'm probably missing something here, but I don't see how to do this
using the <jaxb:property> customization you outlined below without
writing some sort of custom converters for the IDREFs to <carrier>
elements. Even if I did this, I don't see how to use custom converters
with ID/IDREF pairs unless I handle them completely on my own and
maintain my own maps of ID to object. Any suggestions?

Thanks again,

  - Dennis

Ed Mooney wrote:

>Hi Dennis,
>
>Use a <baseType> customization. For example:
>
> <xs:attribute name="Idref" type="xs:IDREF">
> <xs:annotation>
> <xs:appinfo>
> <jaxb:property>
> <jaxb:baseType>
> <jaxb:javaType name="java.lang.String"
>parseMethod="javax.xml.bind.DatatypeConverter.parseString"
>printMethod="javax.xml.bind.DatatypeConverter.printString" />
> </jaxb:baseType>
> </jaxb:property>
> </xs:appinfo>
> </xs:annotation>
> </xs:attribute>
>
>binds to:
>
> java.lang.String getIdref();
> void setIdref(java.lang.String value);
>
>Regards,
>--
>Ed Mooney |Sun Microsystems, Inc.|Time flies like
>Java Web Services |UBUR02-201 |an arrow, but
>Ed.Mooney_at_Sun.COM |1 Network Drive |fruit flies like
>781-442-0459 |Burlington, MA 01803 |a banana. Groucho
>
>Dennis Sosnoski wrote:
>
>
>>Is there anyway to specify that the target of an IDREF attribute is
>>always going to be a specific type of element/object? I'd like the
>>generated code to supply the appropriate object type for the get and set
>>methods, rather than just "java.lang.Object getXXX()" and "void
>>setXXX(java.lang.Object)". Thanks,
>>
>> - Dennis
>>
>>
>
>
>