7 Replies Latest reply on Jan 25, 2008 10:06 AM by aloubyansky

    Map annotations

    aloubyansky

      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; }
      


        • 1. Re: Map annotations
          aloubyansky

          I've done what I had in mind. There are some other things that are not mentioned in the first post.
          All the tests are here jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntryUnitTestCase.java

          • 2. Re: Map annotations
            alesj

            Can you update the MC with your changes once you've released the update?
            So that we close the MC+JAXB issue. :-)

            • 3. Re: Map annotations
              aloubyansky

              Ok, I'll have a look. Let me know if there is a jira issue for that.

              • 4. Re: Map annotations
                alesj

                 

                "alex.loubyansky@jboss.com" wrote:
                Let me know if there is a jira issue for that.

                http://jira.jboss.com/jira/browse/JBMICROCONT-219

                • 5. Re: Map annotations
                  aloubyansky

                  I had to fix some issues based on the MC tests. I've updated the XB snapshot in the maven2 repository.

                  "mvn" wrote:
                  https://snapshots.jboss.org/maven2/org/jboss/jbossxb/2.0.0-SNAPSHOT/jbossxb-2.0.0-20080125.124437-7.jar


                  But I haven't updated the MC since it uses 2.0.0.CR5. This is what I did to make sure the MC tests pass
                  Index: kernel/src/main/org/jboss/beans/metadata/plugins/MapEntry.java
                  ===================================================================
                  --- kernel/src/main/org/jboss/beans/metadata/plugins/MapEntry.java (revision 69169)
                  +++ kernel/src/main/org/jboss/beans/metadata/plugins/MapEntry.java (working copy)
                  @@ -24,6 +24,8 @@
                   import javax.xml.bind.annotation.XmlType;
                  
                   import org.jboss.beans.metadata.spi.ValueMetaData;
                  +import org.jboss.xb.annotations.JBossXmlMapKey;
                  +import org.jboss.xb.annotations.JBossXmlMapValue;
                  
                  
                   /**
                  @@ -41,6 +43,7 @@
                   /** The value */
                   private ValueMetaData value;
                  
                  + @JBossXmlMapKey
                   public ValueMetaData getKey()
                   {
                   return key;
                  @@ -51,6 +54,7 @@
                   this.key = key;
                   }
                  
                  + @JBossXmlMapValue
                   public ValueMetaData getValue()
                   {
                   return value;
                  Index: kernel/src/main/org/jboss/beans/metadata/plugins/AbstractMapMetaData.java
                  ===================================================================
                  --- kernel/src/main/org/jboss/beans/metadata/plugins/AbstractMapMetaData.java (revision 69169)
                  +++ kernel/src/main/org/jboss/beans/metadata/plugins/AbstractMapMetaData.java (working copy)
                  @@ -29,6 +29,7 @@
                   import java.util.Map;
                   import java.util.Set;
                   import javax.xml.bind.annotation.XmlAttribute;
                  +import javax.xml.bind.annotation.XmlTransient;
                   import javax.xml.bind.annotation.XmlType;
                  
                   import org.jboss.beans.metadata.spi.MetaDataVisitor;
                  @@ -36,9 +37,7 @@
                   import org.jboss.beans.metadata.spi.ValueMetaData;
                   import org.jboss.reflect.spi.ClassInfo;
                   import org.jboss.reflect.spi.TypeInfo;
                  -import org.jboss.xb.annotations.JBossXmlChild;
                  -import org.jboss.xb.annotations.JBossXmlChildren;
                  -import org.jboss.xb.annotations.JBossXmlNoElements;
                  +import org.jboss.xb.annotations.JBossXmlMapEntry;
                  
                   /**
                   * Map metadata.
                  @@ -48,11 +47,12 @@
                   * @version $Revision$
                   */
                   @XmlType
                  -@JBossXmlNoElements
                  -@JBossXmlChildren
                  -({
                  - @JBossXmlChild(name="entry", type=MapEntry.class)
                  -})
                  +@JBossXmlMapEntry(name = "entry", type=MapEntry.class)
                  +//@JBossXmlNoElements
                  +//@JBossXmlChildren
                  +//({
                  +// @JBossXmlChild(name="entry", type=MapEntry.class)
                  +//})
                   public class AbstractMapMetaData extends AbstractTypeMetaData
                   implements Map<MetaDataVisitorNode, MetaDataVisitorNode>, Serializable
                   {
                  @@ -199,6 +199,7 @@
                   return map.values();
                   }
                  
                  + @XmlTransient
                   public Iterator<? extends MetaDataVisitorNode> getChildren()
                   {
                   ArrayList<MetaDataVisitorNode> children = new ArrayList<MetaDataVisitorNode>(keySet());
                  @@ -236,11 +237,13 @@
                   *
                   * @return the class instance
                   */
                  + @XmlTransient
                   protected Object getDefaultInstance()
                   {
                   return new HashMap<Object, Object>();
                   }
                  
                  + @XmlTransient
                   protected Class<? extends Map> getExpectedClass()
                   {
                   return Map.class;


                  • 6. Re: Map annotations
                    alesj

                    Is this ready for CR6?
                    Or what should the release be named?

                    I guess this can wait, for us to completely change the MC's metadata parsing with JAXB.
                    But on the other hand it would be nice to have this already in AS5_beta4, if people want to fully (including Maps) experiment with our JAXB support.
                    e.g. the JMS config could be reduced to simple <queue) or <topic) elements.

                    • 7. Re: Map annotations
                      aloubyansky

                      Yes, we can release CR6.