Eitan Suez wrote:


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.

I think this does work well, and I'm glad to see you also find it a clean structure.



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 NG

  specifically, i think that jibx could be simplified if it defined
  only the java mapping aspect on top of Relax NG

This is a very interesting idea, though I think it has some drawbacks. One of the advantages I see of the binding definition is that it acts as a layer of indirection between the Java code and the XML representation. Embedding the mapping into the grammar description would lose this advantage.


One of the beta 4 features I have implemented is schema generation from the combination of a binding definition and Java code. There are limits on this - including things not specified in the binding, such as an untyped collection that can contain any type of element/object defined by a <mapping>. But it does give a decent starting point in most cases. I'm also working the beta 4 code to allow a better correspondence with schema, including support for xsi:type and the whole concept of types in general (as opposed to elements, which is what JiBX was originally designed to support).

That doesn't mean that RelaxNG support (including perhaps embedding the binding definition directly into the grammar) isn't worth pursuing, though. The binding definition model code is implemented and fairly well tested at this point, so I'm planning to finally check that in and make it available for other people to start working with. If you can write a processor for your enhanced RelaxNG grammar that generates the binding definition model it'll be usable with all aspects of JiBX. The binding definition model includes pretty complete validation, so that if you can construct the model and validate it the code generation should be able to turn it into a working binding.

 - Dennis


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



-------------------------------------------------------
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

Reply via email to