Hi Tarek,

Ok, so you want to work with an arbitrary number of separate bindings 
that all use separate classes and are all compiled independently.

You mention that "the Dispatcher finds the service registered to handle 
the object model", so there's some kind of registration going on. Are 
you registering the root object class and the associated handler? If so, 
that gives you a fairly easy way of finding the bindings and XML 
elements for each binding - just start by getting the binding factory 
for each registered class, then use the methods provided by the binding 
factory to find the element name and namespace associated with that root 
class. The frontend sample I linked to shows how you can look at the 
root element of the document, and you can decide which binding to use on 
the basis of that element.

If you're *not* registering the root object classes that does make 
things more difficult. If you know the packages being used you could 
actually look for instances of a JiBX_*Factory class (where * is the 
binding name) and just create instances directly, then lookup the names. 
Otherwise, if you have control over the handler definition I'd suggest 
making it a method with a fixed name but variable parameter type - that 
way you could get the expected parameter class name associated with a 
handler via reflection, and call it the same way to invoke that handler.

Hope that gives you some ideas,

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



[EMAIL PROTECTED] wrote:
> Hi Dennis,
>
> Thanks for your reply.
>
> If I do have multiple bind files, how can I know which bind factory to use? 
> I've added a bit more detail on what I am trying to do below, hope this 
> helps clarify things.
>
>
> XML messages are sent over JMS. A Dispatcher picks up the messages and 
> creates the object model from the xml. The messages have different root 
> elements and content. The Dispatcher finds the service registered to handle 
> the object model that is created.
> Therefore the Dispatcher which receives the xml message must be able to 
> either determine the root element of the xml and then use the required bind 
> factory or allow a single bind factory to be able to handle all the xml 
> roots. Different messages will be defined by different people and so there 
> will be separate bind files located in different packages.
>
> One idea I had was to provide the class name that is to be created from the 
> xml as an attribute to the root element. I'd check to see if I had a bind 
> factory already created for this and if not get the factory using 
> reflection.
>
> <PayBill class="com.bills.payment.PayBill">
> ...
> <PayBill>
>
> <AccountStatus class="com.bills.account.AccountStatus">
> ...
> <AccountStatus>
>
>
> Another idea is to find all classes that have a particular annotation and 
> create bind factories for these at the start up of the application. the 
> Dispatcher would then look at the root element and using this get the 
> required bind factory.
>
> If you have any thoughts on these ideas or alternatives please let me know
>
> Regards,
>
> Tarek
>
>
> ----- Original Message ----- 
> From: "Dennis Sosnoski" <[EMAIL PROTECTED]>
> To: "JiBX users" <jibx-users@lists.sourceforge.net>
> Sent: Tuesday, April 17, 2007 9:57 AM
> Subject: Re: [jibx-users] Generic Marshaller and UnMarshaller
>
>
>   
>> If you're using multiple bindings for unmarshalling you first need to
>> determine the appropriate binding to be used for a particular document.
>> There are ways of doing this at runtime based on the actual content
>> (such as an attribute of the root element - see
>> http://jibx.sourceforge.net/tutorial/binding-custom.html#frontend for
>> code to do this).
>>
>> If you just want to allow different root elements for a document, that's
>> a simpler case - you just include <mapping> definitions for all the
>> possible root elements in a single binding, then JiBX uses whichever one
>> is appropriate for the actual root element of the supplied document.
>>
>> You only need to call the getFactory method when you're looking up a
>> particular binding. If there's only one binding you can just use the
>> returned IBindingFactory over and over; if there are multiple bindings,
>> you can either look up the binding factory for a binding each time you
>> use it, or just cache the factory for each binding you're using.
>>
>>  - Dennis
>>
>> Dennis M. Sosnoski
>> SOA and Web Services in Java
>> Training and Consulting
>> http://www.sosnoski.com - http://www.sosnoski.co.nz
>> Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
>>
>>
>>
>> [EMAIL PROTECTED] wrote:
>>     
>>> Hi All,
>>>
>>> I was after some advice on creating a generic marshaller/unmarshaller
>>> using Jibx and specifically the BindFactory
>>>
>>> Marshalling is fine as in this case I can take the passed in Object
>>> and call getClass() for the BindFactory i.e
>>>
>>> IBindingFactory fact = BindingDirectory. getFactory(obj.getClass());
>>>
>>> For UnMarshalling, I don't know what the xml contains to know what
>>> Object Model to create from it. For the different object models, there
>>> is going to be a different bind file. Can multiple classes be registered?
>>>
>>> Also Each time I want to marshal/unmarshal, do I need to do a
>>> BindingDirectory. getFactory?
>>>
>>> Any advice is welcome
>>>
>>> Regards,
>>>       
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> jibx-users mailing list
>> jibx-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jibx-users
>>
>>     
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>
>   

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to