Ah, now I understand - when you said "multiple tags to a single class" in the original email I interpreted that as a sequence of elements (partially because that's what you seemed to be showing).

The problem here is that <mapping> is intended as a general rule for how to handle a particular class. Allowing multiple <mapping>s to reference the same class creates a real problem in that JiBX doesn't know which one to apply when an instance of the class is encountered while marshalling. So the only way to do what you want using <mapping> is with a separate base class for the classes corresponding to the <equation> element, as you suggest.

Depending on how you're using these in the XML documents you may be able to use an alternative approach. If you just have a collection of mixed <analysis> and <equation> elements, for instance, you should be able to use a <structure type="AbstractFunction" marshaller="AnalysisMapper" unmarshaller="AnalysisMapper"/> child of the <collection> element to handle both types of elements. Then it'd be up to your custom mar/umar code to create the appropriate subclass when unmarshalling and to output the appropriate element name when marshalling. It doesn't look like I've got a test case for this approach, but I believe I've used it in the past.

 - Dennis

EXT-Moody, Eric W wrote:

   <mapping name="analysis" class="AbstractFunction"
        marshaller="AnalysisMapper" unmarshaller="AnalysisMapper"/>

   <mapping name="equation" class="?????????" extends="AbstractFunction">
        marshaller="EquationMapper" unmarshaller="EquationMapper"/>

There are many different AbstractFunction subclasses that map to <analysis> elements. There are three 
different kinds of equations (AbstractFunction subclasses) that map to the <equation> element. If I 
use "AbstractFunction" as the class for the equation mapping, I get a conflicting mapping error 
when compiling the binding. On the other hand, if I don't specify a class for the mapping, I get a missing 
attribute error.

The only way I could think of to get it to work is to create a thin Equation class 
that is abstract and extends AbstractFunction -- so all the equation types subclass 
this instead of AbstractFunction. There is no other purpose for this Equation class 
though, so it's sortof clutter. Is there an alternative?

Thanks,
Eric Moody




Hi Eric,

If I"m understanding you correctly I don"t think there"s anything to prevent you from doing what you want. JiBX marshaller/unmarshallers generated from a binding definition only deal with a single element, but if you"re writing a custom marshaller/unmarshaller I can"t think of any reason you couldn"t have it handle multiple elements. You could specify your marshaller/unmarshaller as handling AbstractFunction, but the actual type returned by the unmarshaller (or passed to the marshaller) could be any subclass of AbstractFunction.

Does that answer your question?

 - Dennis

EXT-Moody, Eric W wrote:



>I am trying to map multiple tags to a single class. I have an AbstractFunction class, 
a
small number InternalFunction types, and a large/growing number of UserFunction types 
that I
can identify by package name (but I will not necessarily know the actual class names in
advance).
>
>So in:
>
>  <internal-function>...</internal-function>
>  <user-function>...</user-function>
>
>Both of these elements should be handled by the mapper in AbstractFunction. I 
understand
why I can"t specify different marshallers/unmarshallers, but I don"t see any obvious 
reason
why this shouldn"t be possible. The custom mapper can decide at runtime which object 
type to
create when unmarshalling, and which element type to create when marshalling.
>
>Do I need to use a <structure> element somehow in my binding definition? Is there a 
way to
accomplish this? Perhaps this is a newbie question, but I couldn"t find anything 
covering
this specifically, either in the documentation or mailing list.
>
>Thanks,
>Eric Moody



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to