Thanks Dennis. That all makes sense... however I still am confused about the
right approach is for doing what I want to do.

In my particular application I have a Java class hierarchy and am modeling
it in XML pretty much directly using JiBX. Classes correspond pretty much to
XML elements. For each class, for example FooBar.java I create an abstract
mapping

 <include path="janFoo.xml"/>
<mapping abstract="true" type-name="fooBar" class="com.example.FooBar">

    <value name="color" field="color"/>
    <structure name="JanFoo" field="janFoo" map-as="janFoo"/>
    ...
</mapping>

 in a separate file fooBar.xml.

The problem comes in a situation where FooBar has a Vehicle property where
Vehicle is abstract .. e.g. I have these classes:

abstract class Vehicle
class Car extends Vehicle
class Truck extends Vehicle

So the vehicle property is always a Car or a Truck and in XML should appear
as either a <Car> or <Truck> element.

I want to do something like this but can't figure out exactly how:

<include path="vehicle.xml"/>
 <mapping abstract="true" type-name="fooBar" class="com.example.FooBar">

    <value name="color" field="color"/>
    <structure field="vehicle" map-as="vehicle"/>   <!-- name="Car" or
name="Truck" ?? -->
    ...
</mapping>

How would I model this property like the example above in without using
extends and yet still use type-names to reference all my mappings instead of
class names?

What I end up having to do is making special cases for all these cases where

   - Must define concrete mappings, whereas all other structures (except the
   topmost one) can have abstract mappings
   - Can't use type-name, have to use class name and extends

This messes up the nice modularity of the abstract-mapping-per-Java-class
approach.

Thanks,
-Archie


On Fri, Mar 11, 2011 at 8:49 PM, Dennis Sosnoski <d...@sosnoski.com> wrote:

>  Hi Archie,
>
> The "extends" attribute is mostly just a left-over from the earlier days of
> JiBX. The only time it's important is when you're using substitution groups
> in your XML documents (which allow you to substitute an extension element
> for a base element in a document - such as <vehicle> for the base element,
> <automobile> for the extension) - and since substitution groups are made of
> elements it makes sense to require a class with a concrete mapping as the
> base.
>
> I personally think substitution groups are the best way of handling
> polymorphism in XML documents, since the element name tells you the
> structure. The alternative of type substitution, where you keep the same
> element name and just add an xsi:type attribute to say what you're really
> doing, seems kludgy to me.
>
> In terms of the mappings, just using <structure map-as="..."/> gives you
> the equivalent of type extension. Though it's not a direct equivalent of
> schema type extension, since it allows you to reference the base type
> anywhere within the structure of the extension (so really a combination of
> schema type extension, group references, and attributeGroup references).
>
>   - Dennis
>
> Dennis M. Sosnoski
> Java SOA and Web Services Consulting<http://www.sosnoski.com/consult.html>
> Axis2/CXF/Metro SOA and Web Services 
> Training<http://www.sosnoski.com/training.html>
> Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
>
> On 03/11/2011 07:56 AM, Archie Cobbs wrote:
>
> I always get confused when trying to use the "extends" attribute...
>
> Here's a simple question: whereas "map-as" allows either a class name or a
> type name, "extends" only allows a class name. Why?
>
> As it stands now, there's no way to extend a mapping that has a type-name.
>
> Thanks,
> -Archie
>
> --
> Archie L. Cobbs
>
>
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the 
> future.http://p.sf.net/sfu/internap-sfd2d
>
>
> _______________________________________________
> jibx-users mailing 
> listjibx-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/jibx-users
>
>


-- 
Archie L. Cobbs
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to