Apply rule based grouping on Java enum -


(this question not require knowledge of xstream such)

below request xml structure unmarshalled root java bean using xstream -

<root>   <entity>      <action>...</action>      <type>...</type>      <data>...</data>   </entity> </root> 

since data node polymorphic can map either of beans i.e. dataabc, datapqr, dataxyz , on :

<data>    <a>aaa</a>    <b>bbb</b>    <c>ccc</c>  </data> or  <data>    <p>ppp</p>    <q>qqq</q>    <r>rrr</r>  </data> or  <data>    <x>xxx</x>    <y>yyy</y>    <z>zzz</z>  </data> 

xstream helps in umarshaling bean :

root root = xstream.fromxml(rootxml)

there configurer interface helps in configure xstream object mapping xml tags of section actual pojo bean :

interface configurer<t> {     public void configure(t t); }  enum configurerslib implements configurer<xstream> {     root("root", root.class),     entity("entity", entity.class),     type("type", type.class),     action("action", action.class),     // polymorphic data tag configurers     data_abc("data", dataabc.class),     data_pqr("data", datapqr.class),     data_xyz("data", dataxyz.class),     ;     @override    public void configure(xstream xs){      xs.alias(this.xmltag, this.classtype);    }    //constructor    private configurerslib(string tag, class classtype){     this.xmltag = tag;     this.classtype = classtype;    }    ... } 

for given request type - can group configurers make chain-of-responsibility, 1 chain enumset :

if type = abc invoke chain -- {root, entity, action, type, data_abc}

if type = pqr invoke chain -- {root, entity, action, type, data_pqr}

if type = xyz invoke chain -- {root, entity, action, type, data_xyz}

above illustration simpler unfortunately these configurers large in number (50-100+) there possibility of missing configurer enum elements while creating such groups. might reduce clarity too.

question best way (pattern/trick/standards) make sure -

  1. how define completeness (configurer set complete iff have tags covered given incoming request)

  2. how make grouping overridable (for special case may want use pqr instead of abc. or default xyz etc)


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -