By the way, note that the mapping.xml syntax I (without too much thought)
proposed would also work very well in XDoclet.  

For example:

@castor.field set-method="setMap" collection="map"
@castor.field-xml node="element"
@castor.map-key name="item.key" type="string" handler="MyHandler"
node="element"
@castor.map-value name="item.value" type="string" handler="MyHandler"
node="element"



On Wed, 25 Feb 2004 16:32:37 -0500, "Jeremy Haile" <[EMAIL PROTECTED]>
said:
> I know that there is support for mapping via the MapItem class, although
> I have yet to try and get this working (I'll explain soon).  However, in
> order to use this method you have to do something like: (excerpted from
> previous post)
> 
> >           <field name="children"
> > type="org.exolab.castor.mapping.MapItem" collection="map"
> >               get-method="getChildren"
> >               set-method="setChildren">
> >               <bind-xml>
> >                   <class name="org.exolab.castor.mapping.MapItem">
> >                      <field name="key" type="string">
> >                          <bind-xml name="item.key" node="element"/>
> >                      </field>
> >                      <field name="value" type="string">
> >                          <bind-xml name="item.value" node="element"/>
> >                      </field>
> >                   </class>
> >               </bind-xml>
> >           </field>
> 
> This is very nice as it also allows you to specify a handler for the
> MapItem fields, etc.  The only thing that would be nicer would be built
> in support for maps in the mapping.xml. Something similar this would be
> nice: *big grin*  
> 
> 
> >           <field name="children"
> > type="org.exolab.castor.mapping.MapItem" collection="map"
> >               get-method="getChildren"
> >               set-method="setChildren">
> >               <bind-xml>
> >                      <map-key name="item.key" type="string" handler="MyHandler" 
> > node="element"/>
> >                      <map-value name="item.value" type="string" 
> > handler="MyHandler" node="element"/>
> >               </bind-xml>
> >           </field>
> 
> 
> My problem however is that I don't think XDoclet yet supports the current
> bind-xml syntax and I use XDoclet to generate my mapping.xml for many
> many objects across my application and to simplify the process of
> developers adding new objects to the castor mapping.  
> 
> So my questions are:
> 1) Does XDoclet support this syntax or will it in the near future?
> 2) Who is the maintainer of the castor XDoclet tags?
> 3) If I am at a dead-end using XDoclet for this syntax, is there an
> alternative way to use maps?  
> 4) If the alternative way of using maps is a huge pain, how hard is it to
> patch castor or XDoclet to add better support for maps?
> 
> 
> Jeremy
> 
> 
> 
> 
> 
> On Thu, 19 Feb 2004 12:23:38 -0600, "Keith Visco" <[EMAIL PROTECTED]>
> said:
> > 
> > 
> > 
> > Hi Till,
> > 
> > My map test cases seem to be working ok, but based on the information
> > you've given below there might be a problem with arrays as values in the
> > map, I'll have to double check that. 
> > 
> > I'll run some additional tests later when I have some free time.
> > 
> > Here's an example that works fine for me:
> > 
> > //class: Root
> > 
> > public class Root {
> > 
> >   HashMap _children = new HashMap();
> > 
> >   public HashMap getChildren() {
> >       return _children;
> >   }
> >   public void setChildren(HashMap m) {
> >       _children = (HashMap)m;
> >   }
> > }
> > 
> > // mapping.xml
> > 
> >       <class name="Root">
> >           <field name="children"
> > type="org.exolab.castor.mapping.MapItem" collection="map"
> >               get-method="getChildren"
> >               set-method="setChildren">
> >               <bind-xml>
> >                   <class name="org.exolab.castor.mapping.MapItem">
> >                      <field name="key" type="java.lang.Object">
> >                          <bind-xml name="item.key" node="element"/>
> >                      </field>
> >                      <field name="value" type="java.lang.Object">
> >                          <bind-xml name="item.value" node="element"/>
> >                      </field>
> >                   </class>
> >               </bind-xml>
> >           </field>
> >       </class>
> > 
> > And the resulting xml which marshals and then unmarshals without any
> > problem:
> > 
> > <?xml version="1.0" encoding="UTF-8"?>
> > <root>
> >     <children>
> >         <item.key xsi:type="java:java.lang.String"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>key1</item.key>
> >         <item.value xsi:type="java:java.lang.String"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>value1</item.value>
> >     </children>
> >     <children>
> >         <item.key xsi:type="java:java.lang.String"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>key2</item.key>
> >         <item.value xsi:type="java:java.lang.String"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>value2</item.value>
> >     </children>
> > </root>
> > 
> > Thanks,
> > 
> > --Keith
> > 
> > [EMAIL PROTECTED] wrote:
> > > 
> > > Hi Keith,
> > > I'm very sorry, but I can't yield the results you are predicting.
> > > First of all I want to say, that I am using JDK 1.2.2, but I don't
> > > think this matters.
> > > I have a simple wrapper class for a hashmap (HashMapWrapper) which
> > > contains a single field hashMap of type java.util.Map and appropriate
> > > getter and setter. The HashMap's keys are Strings, while the values
> > > contain different types (arrays of int, char; BigInteger; ...). When
> > > not specifying a mapping file, I can marshall my wrapper class and get
> > > keys as well as values in the XML. But when unmarshalling, castor
> > > fails at array values with:
> > > ValidationException: element "value" occurs more than once. (parent
> > > class: org.exolab.castor.mapping.MapItem)
> > > 
> > > When specifying a mapping like
> > > <field name="hashMap" type="org.exolab.castor.mapping.MapItem"
> > > collection="map" />
> > > 
> > > keys aren't marshalled anymore (I guess this contradicts your
> > > statement below!)! when unmarshalling the result without the keys
> > > (which is not what I want obviously) I get HashMap entries like
> > > <value>=<value>.
> > > 
> > > So the next thing I tried was to specify a mapping for ....MapItem as
> > > you mentioned it:
> > >         <class name="org.exolab.castor.mapping.MapItem">
> > >                 <field name="key" type="java.lang.Object"/>
> > >                 <field name="value" type="java.lang.Object"/>
> > > 
> > >         </class>
> > > 
> > > doing this doesn't bring me the keys back either, but I get the
> > > following additional error-message when unmarshalling:
> > > #startElement: hash-map
> > > unable to find or create a ClassDescriptor for class: [I
> > > #characters:
> > > 
> > > #startElement: integer
> > > org.xml.sax.SAXException: unable to find FieldDescriptor for 'integer'
> > > in ClassDescriptor of map-item
> > > 
> > > I also tried only using the mapping file during unmarshalling - this
> > > also doesn't help.
> > > So. what are you telling us? ;-)
> > > 
> > > Thanks for any help!
> > > 
> > > kind regards
> > > Till Kothe
> > > 
> > >   [EMAIL PROTECTED]
> > >                                     To:        [EMAIL PROTECTED]
> > >   18.02.2004 22:55                  cc:
> > >   Please respond to                 Subject:        Re: [castor-dev]
> > >   castor-dev                java.util.Map support
> > > 
> > > Hi Jeremy
> > > 
> > > Some upgrades were included in the 0.9.5.3 RC.
> > > 
> > > When using default introspection, you should notice these changes
> > > right
> > > away, as both the key and value are now output by default.
> > > 
> > > When using a mapping file you need to specify this by using Castor's
> > > built-in wrapper:
> > > 
> > > Try the following:
> > > 
> > > <field name="..." type="org.exolab.castor.mapping.MapItem"
> > > collection="map"/>
> > > 
> > > You don't need to put MapItem's in your map. Castor automatically
> > > creates the MapItem  internally for it's own use during
> > > marshalling/unmarshalling.
> > > 
> > > You could also try not specifying the type. I think it defaults to
> > > MapItem.
> > > 
> > > In addition, you can control the names of the element tags by
> > > specifying
> > > a mapping for the MapItem class:
> > > 
> > >      <class name="org.exolab.castor.mapping.MapItem">
> > >         <field name="key" type="java.lang.Object">
> > >              <bind-xml name="id" node="element"/>
> > >         </field>
> > >         <field name="value" type="java.lang.Object"/>
> > >      </class>
> > > 
> > > The above will change the default name from "<key>" to "<id>". for the
> > > key field.
> > > 
> > > If you have more than one map and you want to have different mappings
> > > for each one, you can now also use an inline class mapping directly
> > > inside the bind-xml element as such:
> > > 
> > > <field name="..." type="...MapItem" collection="map">
> > > 
> > >   <bind-xml>
> > >      <class name="org.exolab.castor.mapping.MapItem">
> > >         <field name="key" type="java.lang.Object">
> > >              <bind-xml name="id" node="element"/>
> > >         </field>
> > >         <field name="value" type="java.lang.Object"/>
> > >      </class>
> > >  </bind-xml>
> > > 
> > > </field>
> > > 
> > > Hope that helps,
> > > 
> > > --Keith
> > > 
> > > Jeremy Haile wrote:
> > > >
> > > > OK, so this has been mentioned on the list and there are several
> > > bugzilla
> > > > reports about better support for java.util.Map.  Was this support
> > > added
> > > > in 0.9.5.3?  Is there any approximate schedule for when this support
> > > will
> > > > be added?
> > > >
> > > > Currently the best way to "map" a java.util.Map object is either
> > > using a
> > > > wrapper object in the XML and a custom FieldHandler to convert to
> > > and
> > > > from the Map object, or have the key and value be the same (which
> > > doesn't
> > > > work in most situations) - is that correct?
> > > >
> > > > I simply want to do a string to string mapping using a
> > > java.util.Map.  If
> > > > someone could provide an example of the current best practice for
> > > maps, I
> > > > would appreciate it.
> > > > --
> > > >   Jeremy Haile
> > > >   [EMAIL PROTECTED]
> > > >
> > > > -----------------------------------------------------------
> > > > If you wish to unsubscribe from this mailing, send mail to
> > > > [EMAIL PROTECTED] with a subject of:
> > > >         unsubscribe castor-dev
> > > 
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > >        unsubscribe castor-dev
> > 
> > ----------------------------------------------------------- 
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-dev
> > 
> -- 
>   Jeremy Haile
>   [EMAIL PROTECTED]
-- 
  Jeremy Haile
  [EMAIL PROTECTED]

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to