On Sat, Mar 12, 2011 at 10:05 PM, Dennis Sosnoski <d...@sosnoski.com> wrote:

> From your response I'm not sure if you're just saying that you don't like
> having to use concrete mappings in this case, or if there's an actual
> problem with using the concrete mappings. If it's the former, can you
> suggest a cleaner way of representing substitution groups? I don't think
> it's likely to change in the current codebase, but perhaps I can implement a
> different approach for JiBX 2.
>

I'm realizing it's easier to complain than come up with consructive
solutions :-)

Anyway, I'll try to separate out the issues.

First, there doesn't seem to be any reason why you can't use type-names with
substitution groups (i.e., extends="typename"). This seems like a relatively
simple limitation that could be fixed in the JiBX parsing engine. In other
words, you should be able to do this:

<mapping abstract="true" class="com.example.Vehicle" type-name="vehicle">
<mapping class="com.example.Car" name="Car" extends="vehicle">
<mapping class="com.example.Truck" name="Truck" extends="vehicle">

Next issue: requiring concrete mappings with substitution groups. With
substitution groups, somewhere you have to specify the set of valid XML tags
(and corresponding Java classes) that are allowed for the group. Call this
the "group specification'. With the current JiBX, the concrete mappings
implicitly provide the group specification -- and I'm guessing that's
probably the main reason why they are required.

But it might be simpler and more modular if the "group specification" was
declared explicitly at the point of use. This would then allow us to relax
the requirement for concrete mappings. For example:

 <mapping abstract="true" class="com.example.Vehicle" type-name="vehicle">
<mapping abstract="true" class="com.example.Car" type-name="car"
extends="vehicle">
<mapping abstract="true" class="com.example.Truck" type-name="truck"
extends="vehicle">
...
<mapping abstract="true" class="com.example.FooBar" type-name="fooBar">
    <structure field="vehicle">
        <mapping-option name="Car" map-as="Car"/>
        <mapping-option name="Truck" map-as="Trunk"/>
    </structure>
...

What I like about this is that it's much clearer from looking at the mapping
file what can happen. This also could even be implemented so that it was
backward compatible with existing mapping files.

-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 list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to