Here’s an exemple of a wrapper for the HashMap class. I only tried the IDataCodable interface, but it seems to work perfectly:
- The savePipelineToFile/restorePipelineFromFile work as they should
- It will save everything that can be saved, meaning: any java Object that is either already recognized (like IData, String, List instances…) or another implementaion of IDataCodable
- A bonus I hadn’t expected: in step by step mode, the HashMap is now represented not as its toString() representation, but as the IData you built in the getIData method. Meaning its MUUUUUUUCH more readable in debug mode.
Enjoy!
PS: in my implementation, I chose to represent the HashMap as an IData array. Of course, you can do anything you like instead.
public static class WMHashMap extends HashMap implements IDataCodable{
public void setIData(IData idata){
IDataCursor idc = null;
this.clear();
try{
idc = idata.getCursor();
IData[] tab = IDataUtil.getIDataArray(idc, "liste");
for(IData id: tab){
IDataCursor coupleCursor = null;
try{
coupleCursor = id.getCursor();
Object cle = IDataUtil.get(coupleCursor, "cle");
Object valeur = IDataUtil.get(coupleCursor, "valeur");
this.put(cle, valeur);
}
finally{
if(coupleCursor!=null) coupleCursor.destroy();
}
}
}
finally{
if(idc!=null) idc.destroy();
}
}
public IData getIData(){
IData[] tableau = new IData[this.size()];
int index = 0;
for(Object cle: this.keySet()){
IData doc = IDataFactory.create();
IDataCursor idc = null;
try{
idc = doc.getCursor();
IDataUtil.put(idc, "cle", cle );
IDataUtil.put(idc, "valeur", this.get(cle));
tableau[index] = doc;
}
finally{
if(idc!=null) idc.destroy();
}
index++;
}
IData retour = IDataFactory.create();
IDataCursor retourCursor = null;
try{
retourCursor = retour.getCursor();
IDataUtil.put(retourCursor, "liste", tableau);
}
finally{
if(retourCursor!=null) retourCursor.destroy();
}
return retour;
}
}
#webMethods#Flow-and-Java-services#Integration-Server-and-ESB