Hi, can you please have a look at
http://castor.org/xml-mapping.html#5.-xsi:type and especially the 'auto-naming' attribute discussed therein. I think that this could (and should) be the solution to your problem. Werner Chuck Kring wrote: > Hello, > > I have application that has a variety of alarms. For now consider > Alarm to be an abstract class that is extended by UpdownAlarm and > JitterAlarm. Note that UpdownAlarm and JitterAlarm can have different > parameters - UpDownAlarm could have parameters that describe the allowed > range of motion and JitterAlarm could have parameters that describe the > allowed acceleration. These alarms are created with an alarm factory. > > There is an object called Monitor that contains a field Alarm which can > either be UpdownAlarm or JitterAlarm. My mapping file looks like the > one below. > > <?xml version="1.0"?> > <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version > 1.0//EN" > "http://castor.exolab.org/mapping.dtd"> > <mapping> > <class name="x.y.z.Alarm" auto-complete="false"> > <field name="type" type="string" required="true"><bind-xml > name="type" node="attribute"/></field> > </class> > <class name="x.y.z.UpdownAlarm" extends="x.y.z.Alarm" > auto-complete="false"> > <field name="maxRange" type="string" required="true"><bind-xml > name="maxRange" node="attribute"/></field> > </class> > <class name="x.y.z.JitterAlarm" extends="x.y.z.Alarm" > auto-complete="false"> > <field name="maxAccel" type="string" required="true"><bind-xml > name="maxAccel" node="attribute"/></field> > </class> > <class name="x.y.z.Monitor" auto-complete="false" > > <field name="name" type="String" required="true"><bind-xml > name="name" node="attribute"/> </field> > <field name="alarm" type="x.y.z.Alarm" required="true"> </field> > </class> > </mapping> > > Mapping works fine and produces the following xml: > > <?xml version="1.0" encoding="UTF-8"?> > <config> > <monitor name="test"> > <alarm type="UpdownAlarm" maxRange="45"/> > </monitor> > <monitor name="test2"> > <alarm type="JitterAlarm" maxAccel="95"/> > </monitor> > </config> > > At this point I'm stuck. I don't know how to reliably unmarshal the > alarm fields back to UpdownAlarm and JitterAlarm. > Based upon the documentation, I can use a customFieldHandler to > reference my Alarm factory with a valueOf() method, but what about > the extra parameters like 'maxRange' and 'maxAccel'. These are not > defined for the abstract Alarm so I'm sure Castor will throw a parsing > error (I haven't tried that yet). > > Can anybody give me some guidance about how to proceed? I'd appreciate > examples or suggestions. > Thanks! > > Chuck Kring > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

