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