hi all,
i've been philosophizing about jibx recently, trying to look at it from different angles..
i'd like to share these thoughts because i believe i'm on an interesting path.
topic: jibx binding file definition
statement: i find jibx to have one of the cleanest/simplest (and yet most powerful) binding file grammars
i believe binding files can be very complex because they
must do three things:
1. define an xml structure
2. define a java class structure
3. relate how items in [1] relate to items in [2]jibx does this very cleanly using common elements such
as <mapping> <structure> <element> <value> and <collection> elements
that are common to both the xml and java sides of things.
yet on the other hand, the "name" attribute relates only to the
xml side while attributes such as "field" and "class" relate only
to the java side. to me, that's the essence of the flexible structure mapping
that jibx allows.
now, here are my thoughts:
there already exist a number of xml languages for defining
the xml structure: xml schema, dtd's, relax NG, etc..jibx defines yet another grammar for defining the xml structure. i see this as a negative: because programmers now must learn yet another grammar for defining an xml schema.
thought: why not piggyback on an existing grammar?
suggestion: Relax NGspecifically, i think that jibx could be simplified if it defined only the java mapping aspect on top of Relax NG
example:
1. Java:
class Customer {
String _name;
Address _address;
}
class Address {
String _street, _city, _state, _zip;
}2. xml: <customer name="eitan"> <address> <street>101 x</street> <city>Boston</city> <state>MA</state> <zip>12345</zip> </address> </customer>
3. jibx binding:
<binding>
<mapping name="customer" class="Customer">
<value name="name" field="_name" style="attribute" />
<structure name="address" field="_address">
<value name="street" field="_street" />
<value name="city" field="_city" />
<value name="state" field="_state" />
<value name="zip" field="_zip" />
</structure>
</mapping>
</binding> 4. Relax NG Grammar:
<element name="customer">
<attribute name="name" />
<element name="address">
<element name="street">
<text />
</element>
<element name="city">
<text />
</element>
<element name="state">
<text />
</element>
<element name="zip">
<text />
</element>
</element>
</element>5. possible combined Relax NG - JiBX binding definition:
<grammar xmlns="whatever-the-relaxing-namespace-is" xmlns:jibx="http://jibx.org/jibx-binding-namespace">
<start><ref name="customer-def" /></start>
<define name="customer-def">
<element name="customer" jibx:class="Customer">
<attribute name="name" jibx:field="_name" />
<element name="address" jibx:field="_address">
<element name="street" jibx:field="_street">
<text />
</element>
<element name="city" jibx:field="_city">
<text />
</element>
<element name="state" jibx:field="_state">
<text />
</element>
<element name="zip" jibx:field="_zip">
<text />
</element>
</element>
</element>
</define>
</grammar>
structured mapping could work quite nicely with this as well:
a. structured xml but flattened java:
above, replace this:
<element name="address" jibx:field="_address">
with:
<element name="address">
(leave out the jibx:field attribute)b. flattened xml but structured java:
<element name="customer" jibx:class="Customer">
<attribute name="name" jibx:field="_name" />
<jibx:structure field="_address">
<element name="street" jibx:field="_street">
<text />
</element>
<element name="city" jibx:field="_city">
<text />
</element>
<element name="state" jibx:field="_state">
<text />
</element>
<element name="zip" jibx:field="_zip">
<text />
</element>
</jibx:structure>
</element>relax ng allows this. that is, it's a valid schema document, and the jibx binding
is layered above it.
i know these examples are no way conclusive proof that it's possible to
handle all mapping cases. how would collections be handled? id-idref?
i'm sure there are many more questions.
i'm just eager for feedback at this point.
again, the advantage i see here is being able to define bindings on top of
an existing xml schema definition language instead of a new one:
1. this alleviates the programmer having to learn another schema language
2. in the likely event that an xml schema already exists, defining the jibx
binding would be much less work: just layer the jibx mapping information right on
top of it, in a non-intrusive way
thought: maybe jibx can be made to work with both Relax NG and the XML Schema specification?
feedback?
thanks, eitan
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
