[jboss-dev-forums] [Design of JBossXB] - Map annotations

alex.loubyansky@jboss.com do-not-reply at jboss.com
Thu Jan 10 08:44:44 EST 2008


I am prototyping map binding annotations. This is what I currently have.

@JBossXmlMapEntry. Used if key-value pairs are wrapped inside an element, i.e. entry element. And/or if the whole entry should be bound to a Java type.

@JBossXmlMapKeyElement. Binds the key to an element.
@JBossXmlMapKeyAttribute. Binds the key to an attribute.
@JBossXmlMapValueElement. Binds the value to an element.
@JBossXmlMapValueAttribute. Binds the value to an attribute.

The target for all annotations is ElementType.TYPE, ElementType.METHOD, ElementType.FIELD.

Some of the possible bindings:

Sequence of key and value elements

  |  <key>key1</key><value>value1</value>
  |  <key>key2</key><value>value2</value>
  |  
  |  @JBossXmlMapKeyElement(name="key")
  |  @JBossXmlMapValueElement(name="value")
  |  public Map getMap(){ return map; }
  | 

Sequence of key and value elements wrapped inside entry element

  |  <entry>
  |    <key>key1</key>
  |    <value>value1</value>
  |  </entry>
  |  <entry>
  |    <key>key2</key>
  |    <value>value2</value>
  |  </entry>
  |  
  |  @JBossXmlMapEntry(name="entry")
  |  @JBossXmlMapKeyElemenet(name="key")
  |  @JBossXmlMapValueElement(name="value")
  |  public Map getMap(){ return map; }
  | 

Key and value attributes in entry element

  |  <entry key='key1' value='value1'/>
  |  <entry key='key2' value='value2'/>
  |  
  |  @JBossXmlMapEntry(name="entry")
  |  @JBossXmlMapKeyAttribute(name="key")
  |  @JBossXmlMapValueAttribute(name="value")
  |  public Map getMap(){ return map; }
  | 

Key is an attribute and the value is the value of entry element

  |  <entry key='key1'>value1</entry>
  |  <entry key='key2'>value2</entry>
  |  
  |  /**
  |   * value binding is not specified, it's supposed to be the value of entry
  |   * element.
  |   * But if the entry is bound to a Java type with JBossXmlMapEntry.type()
  |   * then the value will be the entry itself.
  |   */
  |  @JBossXmlMapEntry(name="entry")
  |  @JBossXmlMapKeyAttribute(name="key")
  |  public Map getMap(){ return map; }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118655#4118655

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118655



More information about the jboss-dev-forums mailing list