users@jaxb.java.net

Customisation of ID/IDREF and compatibility with java 5.0

From: Francois Le Fevre <francois.lefevre_at_genoscope.cns.fr>
Date: Tue, 11 Jan 2005 11:11:21 +0100

Dear Jaxb community members,

I am new to java community, I have studied biology, genomics etc ... and
I hope there is no problem I ask a question on this mailing list.

It is about:

1) ID/IDREF mapping
2) Compatibility with java 1.5: Generic types in collection.

BRIEFLY---------------------------------------

I am actually using hyperjaxb (https://hyperjaxb.dev.java.net/) and so
Jaxb.
I have some difficulties in order to customize generated code by Jaxb
for ID/IDREF mapping.
The getter/setter methods are dealing with java.lang.Object and not with
my own complex type defined in the xml schema.
I have found old posts (
https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgId=214897 /
https://jaxb.dev.java.net/servlets/ReadMsg?list=users&msgId=77061 )
which gives the answer : xjc:idSymbolSpace.
But when I try to compile the generated source, there is an error with
method fromString(), which was not generated by hyperjaxb-jaxb.

Do you have any idea why and how to correct my mistake?

ERROR MESSAGE--------------------------
[mkdir] Created dir:
/env/cns/home/flefevre/PROGRAMMATION/workspace/ProofOfConcept/tests/ididref/classes

   [javac] Compiling 39 source files to
/env/cns/home/flefevre/PROGRAMMATION/workspace/ProofOfConcept/tests/ididref/classes

   [javac]
/env/cns/home/flefevre/PROGRAMMATION/workspace/ProofOfConcept/tests/ididref/generated.sources/generated/DogType.java:115:
cannot resolve symbol
   [javac] symbol : method fromString (java.lang.String)
   [javac] location: interface generated.DogType
   [javac] return
(resultSet.wasNull()?null:generated.DogType.fromString(name));
   [javac] ^
   [javac] 1 error

IN DETAILS-----------------------------------

I have sent to You, a xml schema and xml sample files at this end of
this email.
It is a example, it has nothing to deal with my research, as You will
see. ( I am working a biotechnology field )

In this example, I formalize the object "Man" { first and last name }
and the possibility to him to have a dog. {IDREF}
The object "Dog" { nickname, age, id}.

GENERATED CODE WITHOUT CUSTOMISATION
====
.....

protected java.lang.Object _Dog;
......

....

/**
    *
    * @hibernate.any id-type="string" cascade="all"
    * @hibernate.any-column name="Dog_class"
    * @hibernate.any-column name="Dog_id" length="32"
    *
    */
   public java.lang.Object getDog() {
       return _Dog;
   }

   public void setDog(java.lang.Object value) {
       _Dog = value;
   }

====

SCHEMA CUSTOMISATION
===
<xs:annotation>
                <xs:appinfo>
                    <xjc:idSymbolSpace name="dogSpace"/>
                </xs:appinfo>
</xs:annotation>


GENERATED CODE WITH CUSTOMISATION
====
/**
     *
     * @hibernate.property type="generated.DogType$Type"
     *
     */
    public generated.DogType getDog() {
        return _Dog;
    }

    public void setDog(generated.DogType value) {
        _Dog = value;
    }
=====

But now no way to compile the code.... because of the non generation of
method fromString.

Do you any idea, how to do it?

Moreover if I authorize, a man to have more than 1 dog, I would like to
customize the java generated code with the new feature of java 1.5 =
Generic types for collection.
ArrayList<Dog> list = new ArrayList<Dog>();
 

I have tried to be short and precise. So don't hesitate to ask me some
additional informations.

Thanks again for your advice.

Francois

=========
Schema
=========
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2005 sp1 U (http://www.xmlspy.com) by GENOSCOPE
(GENOSCOPE) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
elementFormDefault="unqualified" attributeFormDefault="unqualified"
version="1.0" jaxb:version="1.0" jaxb:extensionBindingPrefixes="xjc">
    <xs:element name="Root">
        <xs:annotation>
            <xs:documentation>Comment describing your root
element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Man" type="ManType" minOccurs="0"
maxOccurs="unbounded"/>
                <xs:element name="Dog" type="DogType" minOccurs="0"
maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="ManType">
        <xs:sequence>
            <xs:element name="dog" type="xs:IDREF" minOccurs="0">
                <xs:annotation>
                    <xs:appinfo>
                        <xjc:idSymbolSpace name="dogSpace"/>
                    </xs:appinfo>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="first_name" type="xs:string"/>
        <xs:attribute name="last_name" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="DogType">
        <xs:attribute name="nickname" type="xs:string"/>
        <xs:attribute name="age" type="xs:int"/>
        <xs:attribute name="id_dog" type="xs:ID">
            <xs:annotation>
                <xs:appinfo>
                    <xjc:idSymbolSpace name="dogSpace"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
</xs:schema>


========
Sample
========
<?class generated.impl.RootImpl?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="dog.xsd">
<Man first_name="Francois" last_name="Le Fevre">
    <dog>dog1</dog>
  </Man>
  <Dog nickname="Platon" age="2" id_dog="dog1">
  </Dog>
</Root>
-- 
-- 
------------------------------------------------------------------------
Genoscope CNS - Bio-Informatic Team
2, rue Gaston Crémieux , CP 5706
91057 EVRY cedex, FRANCE
Phone: (+33) 0 1 60 87 45 83
Fax: (+33) 0 1 60 87 25 14
Web: http://www.genoscope.cns.fr/
E-mail: francois.lefevre_at_genoscope.cns.fr
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net