users@jaxb.java.net

Intervening with jaxb marshalling

From: liorchaga <lior.chaga_at_modelity.com>
Date: Mon, 5 May 2008 05:57:19 -0700 (PDT)

I have declared a complex type that contains 2 element (in a choice) and
another enumeration element to determine which choice is selected, as in the
following example:

<xs:complexType name="RecurrentEvents">
    <xs:complexContent>
        <xs:sequence>
            <xs:element name="selection">
            <xs:restriction base="xs:string">
                <xs:enumeration value="last"></xs:enumeration>
                <xs:enumeration value="count"></xs:enumeration>
            </xs:restriction>
            </xs:element>
        <xs:choice>
                <xs:element name="last" type="xs:date"></xs:element>
                <xs:element name="count" type="xs:int"></xs:element>
        </xs:choice>
        </xs:sequence>
    </xs:complexContent>
</xs:complexType>

Now, suppose I have a web page in which both options are alternative to each
other (meaning, if the user sets "last", "count" is derived from it and vice
versa). Both properties, therefore, are bound to input boxes.
Once the user has set one value, the other value is calculated and kept in
the other input box.

But when I marshal the object, I want only the option that was explicitly
set by the user to be saved (keeping my xml correspondent with the schema).
I've thought of using JAXB's SUBCLASS_REPLACEMENTS to derive a class from
"RecurrentEvents" in which the setters will be overloaded and when "last" is
set, it will set null to "count" in the super class, and vise versa.
However, because regardless of what the user typed, both input boxes are
affected in the client, both setters would be initiated during post back,
and the last setter that would be activated is not necessarily the same one
the user has set.

Alternatively, assuming I have the "selection" that indicates which value
the user typed (I can know it by the "onChange" event), I can allow both
values to be set, and than set one of them to null according to the
selection. But nothing assures me, again, that the selection setter would
occur after the values setters.

Is there a way to guarantee that one setter would be invoked after another?
Or, is there a way to extend the classes some how, or the JAXB marshaller
itself, so when marshalling an object would invoke specific functions that
would "correct" the object so it would conform to the schema?

Thanks,
Lior.
-- 
View this message in context: http://www.nabble.com/Intervening-with-jaxb-marshalling-tp17061104p17061104.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.