collections - Castor Hashtable polymorphism -


good day

i attempting use castor construct hashtable has multiple implementations of abstract class. here parent "config"

<class name="com.config">     <map-to xml="config" />     <field name="rulesmap" collection="hashtable">         <bind-xml  auto-naming="derivebyclass"  >             <class name="org.exolab.castor.mapping.mapitem">                 <field name="key" type="java.lang.string">                     <bind-xml name="name" node="attribute" />                 </field>                 <field name="value" type=com.rule">                  </field>             </class>         </bind-xml>     </field> </class> 

'com.rule' abstract class , @ end of day xml struct looks this

<config> <rule-impl1 name="ruletype1instance1" rulefield="field"  />     <rule-impl2 name="ruletype2instance2" rulefield="field" ruleimpl2field1="..." /> </config> 

i'm not sure there enough detail or question formed here give accurate answer, doing pretty similar , ran roadblocks. thought i'd provide 2 cents. i'm not familiar castor other xml frameworks , in case castor doing it's automatic marshalling/unmarshalling instead of manually writing code decide when want done. if manually doing piece thought have been able make decisions unmarshall specific classes extend abstract class.

with disclaimers out of way, do.

**if can add field request/response create this:

public class rulecontainer {  private ruletype ruletype;  // possibly build enum or other non-java equivalent  private ruleimpl1 ruleimpl1;  private ruleimpl2 ruleimpl2;  private ruleimpl...n ruleimpl...n;  // getters & setters, etc } 

then value of table changed

<field name="value" type="com.rulecontainer"></field> 

and include mapping of rulecontainer

 <class name="com.rulecontainer">    <field name="ruletype" type="com.ruletype"    <field name="ruleimpl1" type="com.ruleimpl1">    <field name="ruleimpl2" type="com.ruleimpl2">    <field name="ruleimpl...n" type="com.ruleimpl...n">  </class> 

also include mappings of each implementation whatever may like. in case i've broken each implementation mapping out separate file , used

<include href="" />  

tag include extraneous mappings in parent file.

all of sets use ruletype field know rule in rulecontainer valid (the rest null castor default required="false"). logic work each implementation of rule simple write there. hope helps.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -