Hi Søren,
The "extends" attribute is actually rarely needed, and perhaps was an
unfortunate choice of name. Partially this is because the meaning of the
attribute has evolved somewhat over time, as JiBX has been extended and
new features added. Unfortunately the tutorial may give this more
emphasis than it deserves (because that has also evolved over time, and
retains some parts which are no longer very relevant), so people think
it's important and try to make use of it.
What "extends" really does is tell JiBX that certain XML elements can
substitute for another element, defining a "substitution group" in
schema terms. This is a pretty specific behavior, and one that's not
really widely used in documents. In particular, you never need to use
extends just because of an inheritance or implements relationship in the
Java classes. The only time you really need it is when the base class is
treated as a standalone element, which can be used on its own.
For the case you mentioned, if you don't use extends at all you can
still marshal/unmarshal a Baz as either a Foo or a Bar. It's only if you
want a separate element name for a Baz, as opposed to some other sort of
Foo or Bar, that you'd need to use extends.
I'll try to deemphasize "extends" in the 1.2 documentation, and also
state the very limited situations where it needs to be used. In the
meantime, if you look at the tutorial Example 16 which shows extends
being used, consider that the following binding (which eliminates
extends) also works fine for this case:
<binding>
<mapping name="customer" class="example16.Customer">
<structure field="identity"/>
<value name="street" field="street" usage="optional"/>
<value name="city" field="city" usage="optional"/>
<value name="state" field="state" usage="optional"/>
<value name="zip" field="zip" usage="optional"/>
<value name="phone" field="phone" usage="optional"/>
</mapping>
<mapping type-name="identity" class="example16.Identity" abstract="true">
<value name="cust-num" field="customerNumber"/>
</mapping>
<mapping name="person" class="example16.Person">
<structure map-as="identity"/>
<value name="first-name" field="firstName"/>
<value name="last-name" field="lastName"/>
</mapping>
<mapping name="company" class="example16.Company">
<value name="name" field="name"/>
<value name="tax-id" field="taxId"/>
<structure map-as="identity"/>
</mapping>
</binding>
Cheers,
- Dennis
Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
Søren Andersen wrote:
> I'm currently working on taking a rather large piece of Java-code and
> using Jibx to serialize / deserialize it.
>
> However, I've stumbled upon a problem that I'm not sure how to attack.
>
> I have the following situation:
>
> interface Foo {
> //methods
> }
>
> abstract class Bar {
> //metods and lots of fields
> }
>
> class Baz extends Bar implements Foo {
> //more stuff
> }
>
> Now, I need to use both the property that Baz is-a Bar in one context,
> and that Baz is-a Foo in another. However, as far as I can see Jibx
> only allows single inheritance via the extends keyword on mappings?
>
> Is there some standard solution to this? Any tips would be welcome.
>
> Regards,
>
> Søren Andersen
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users