I downloaded the nightly snapshot from CVS and it seems to be able to handle
Maps fine if I use "auto-complete='true'" in my mapping file and let Castor
introspect my object.  

However, I would like Castor to call my getters and setters.  What
attributes do I have to set in the Field element of my mapping file to do
this?
 
Specifically, what do I put for "type" -- the type of the key or the type of
the value?  I assume it wants the type of the value, so where do I specify
the type of the key?

Also, what signatures do the "get-method" and "set-method" expect?

I could not find any documentation on this. If it already exists, I
apologize for asking these questions -- please let me know where the
documentation is instead.

Thank you,
Gary 


-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 04, 2004 10:49 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Field Handler is not invoked in 0.9.5.2


Hi Sudhir,

Map/Hashtable support has been upgraded for Castor XML in the CVS. If
you can, you should try that version (by using either CVS or a nightly
snapshot) and see if it fits your needs. The keys are now output by
default.

--Keith

SUDHIR KULKARNI wrote:
> 
> Hi
>        I am trying to Marshal java.util.Map  by
> implementing FieldHandler interface.
> Problem: No exception thrown- Map is marshalled with
> no keys but only values.
> I am using castor 0.9.5.2 and marshalling Map object
> on an event in web application which is
> running on IBM Websphere. I tried other ways like
> using GeneralizedFieldHandler. Didn't work.
> It would be great anybody tells me why field handler
> is never invoked.
> If anybody knows link/mail which has working example
> of Map marshalling let me know.
> 
> Thanks
> Sudhir
> -------------------------------------------------------
> 
> Main Object
> ---------------
> Location. java
> {
>    .....
> 
>   java.util.Map LocationDetails;
> 
> }
> 
> The Wrapper class to hold LocationDetails
> --------------------------------------------------------
> public class MapFieldWrapper {
> 
> 
>         private   Object[] keyvalue;
>         private   Object[] objvalue;
> 
> public Object[] getKeyvalue(){
>            return keyvalue;
>   }
>   public void setKeyvalue(Object[] valtoset) {
>           keyvalue = valtoset;
>   }
> 
>   public Object[] getObjvalue(){
>                    return objvalue;
>                    }
>   public void setObjvalue(Object[] valtoset) {
>                   objvalue = valtoset;
>   }
> 
> }
> 
> The field Handler
> --------------------
> public class MapFieldWrapperHandler  implements
> FieldHandler{
> 
>         MapFieldWrapper mapWrap;
> 
>         public MapFieldWrapperHandler() {
> 
>                 mapWrap = new MapFieldWrapper();
> 
>         }
> 
>  public void checkValidity(Object object) {
>        //deprecated doing nothing
>         }
>         public Object getValue(Object passedObject) throws
> IllegalStateException {
> 
>                 System.out.println(" I am in getValue");
>                 //
> mapWrap.setKeyvalue((Map(passedObject)).keySet().toArray());
> 
> 
> mapWrap.setKeyvalue(((HashMap)(passedObject)).keySet().toArray());
> 
> mapWrap.setObjvalue(((HashMap)(passedObject)).values().toArray());
> 
>                 return mapWrap;
>         }
> 
>    public Object newInstance(Object passedObject,
> Object passedObjArray[]){
> 
>                 System.out.println(" I am in newInstance 2");
>               // Map newObj = new HashMap();
>                //newObj= (Map)passedObject;
>                         // return newObj;
>                         return null;
>    }
>    public Object newInstance(Object passedObject){
> 
>                   System.out.println(" I am in newInstance1 ");
>                         // Map newObj = new HashMap();
>                          //newObj= (Map)passedObject;
>                           // return newObj;
>                           return null;
>          }
> 
>    public void resetValue(Object passedObject) {
> 
>         System.out.println(" I am in resetValue");
> 
>    }
> 
>    public void setValue(Object passedObject, Object
> passedValue) {
>         System.out.println(" I am in setValue");
> 
>    }
> 
> Map file
> ----------
> <mapping xmlns="http://castor.exolab.org/";
> xmlns:cst="http://castor.exolab.org/";>
>         <description>Castor generated mapping file-Sudhir 18
> DEC2003</description>
>         <class cst:name="Location" auto-complete="false">
>                 <description>Default mapping for class
> Location</description>
>                 <map-to cst:xml="location"/>
>         <field
> cst:name="LocationDetail"cst:type="MapFieldWrapper"
> handler="MapFieldWrapperHandler" >
>                         <bind-xml name="location-detail" node="element"/>
>                 </field>
>                 </class>
>         <class name="MapFieldWrapper" auto-complete="false">
>                 <field cst:name="keyvalue"
> cst:type="java.lang.Object" collection="array">
>                         <bind-xml name="keyvalue" node="element"/>
>                 </field>
>                 <field cst:name="objvalue"
> cst:type="java.lang.Object" collection="array">
>                         <bind-xml name="objvalue" node="element"/>
>                 </field>
>     </class>
> </mapping>
> 
> --------------------------------------------------
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free web site building tool. Try it!
> http://webhosting.yahoo.com/ps/sb/
> 
> -----------------------------------------------------------
> 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

Reply via email to