Hi Leif,

The cleanest approach for this is probably to define abstract <mapping> definitions with no name for each of the classes which can be extended. Use the new type-name="some-name" attribute to give the abstract mappings names, so that you can define separate mappings for the actual types which use these abstract mappings. So you'd have:

<mapping abstract="true" type-name="A-type">
 ...
</mapping>
<mapping class="A" name="A">
 <structure map-as="A-type"/>
</mapping>
<mapping abstract="true" type-name="B-type">
 <structure map-as="A-type"/>
 ...
</mapping>
<mapping class="B" name="B">
 <structure map-as="B-type"/>
</mapping>

etc. That way you're reusing the structure at each level while only doing the wrapper element that matches the actual class.

 - Dennis

Leif Stainsby wrote:

Hi,

I have read the JiBX documentation (very nice) but the differences
between 'extends' versus 'map-as' is not clear to me.  Perhaps someone
could help me with this.  What is needed seems fairly straightforward,
and I believe JiBX can handle it, I just can't quite figure out what the
mapping should look like.

What would be the best approach to use for mapping this typical class
hierarchy?

Class-A (base class) Class-B extends Class-A
 Class-C extends Class-B
where none of the classes is abstract (they can all occur individually
in the wild) and where the serialized form of a derived class includes
all the properties (elements, attributes etc.) of the extended classes
but does not include the element names of classes that are extended.
Obviously, some form or re-use of the mappings would be useful.  Assume
for now that all properties are simple (i.e. no collections or nested
structures).

I hope this is clear enough, but perhaps an example will help.  I would
expect it to serialize an instance of Class-C (something) like this:

 <element-C attrA1="" attrB1="" attr-C1="" attr-C2="">
   <element-A1/>
   <element-A2/>
   <element-B1/>
   <element-B2/>
   <element-C1/>
   <element-C2/>
 </element-C>
and *not* like this, with wrapping element names from classes higher up
the hierarchy:

 <element-C attr-C1="" attr-C2="">
   <element-A attrA1="">
     <element-A1/>
     <element-A2/>
   </element-A>
   <element-B attrB1="">
     <element-B1/>
     <element-B2/>
   </element-B>
   <element-C1/>
   <element-C2/>
 </element-C>
Are there 'best practices' that cover this issue already written up
somewhere?  Many thanks in advance.

...Leif
--------------------------
 Leif Stainsby
 Galdos Systems Inc.
--------------------------


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to