Hi,
I have written a java service in wM 8.2 to modify the Document (with complex structure) at run time.
e.g. Say input to the service is “inputDoc” with complex structure
inputDoc (Document - IData Object)
-----strField1 (String)
-----strField2 (String)
-----internalDoc1 (Document - IData Object)
----------internalDoc1StrField1 (String)
----------internalDoc1StrField2 (String)
-----internalDoc2 (Document - IData Object)
----------doubleInternalDoc1 (Document - IData Object)
---------------doubleInternalDoc1StrField1 (String)
---------------doubleInternalDoc1StrField2 (String)
I would like to convert each leaf node i.e. strField1, strField2, internalDoc1StrField1… to a Document “info” and add three fields in it “key”, “value” and “type”
Here is the code I am using:
--------------------- Code Starts --------------------
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
package
[/color][/size][/COLOR][/SIZE][/b]
DevTeam.Java;
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
import
[/color][/size][/COLOR][/SIZE][/b]
com.wm.data.*;
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
import
[/color][/size][/COLOR][/SIZE][/b]
com.wm.util.Values;
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
import
[/color][/size][/COLOR][/SIZE][/b]
com.wm.app.b2b.server.Service;
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
import
[/color][/size][/COLOR][/SIZE][/b]
com.wm.app.b2b.server.ServiceException;
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
public
[/color][/size][/COLOR][/SIZE][/b]
finalclass documentToModifiedDoc_SVC{/** * The primary method for the Java service** @param pipeline* The IData pipeline* @throws ServiceException*/
publicstaticfinalvoid documentToModifiedDoc(IData pipeline) throws ServiceException {IDataCursor pipelineCursor = pipeline.getCursor();IData idataObj = IDataUtil.getIData(pipelineCursor, “inputDoc”);Values obj = getDocumentKeys(idataObj, pipelineCursor);IData resultIData = obj.getIData();IDataUtil.put(pipelineCursor, “Keys”, obj);IDataUtil.put(pipelineCursor, “idataObj”, resultIData);}// — <> —
publicstatic IData outputIData;publicstatic IDataCursor outCursor;publicstatic Values getDocumentKeys(IData _idata, IDataCursor pipelineCursor){outputIData = IDataFactory.create();IDataCursor _idataCursor = _idata.getCursor();outCursor = outputIData.getCursor();_idataCursor.first();//Values internalKeys;
[SIZE=2]
Values keysObj =
[/size]
new Values();IData info = IDataFactory.create();// IDataCursor infoCursor = info.getCursor();
do{// info = IDataFactory.create();
[SIZE=2]
IDataCursor infoCursor = info.getCursor();
[/size]
if (_idataCursor.getValue() instanceof IData){
[SIZE=2]
keysObj.put(_idataCursor.getKey() , getDocumentKeys((IData)_idataCursor.getValue(), pipelineCursor).getIData());
[/size]
// outCursor.insertAfter(_idataCursor.getKey(), newValues);
[SIZE=2]
}
[/size]
else{infoCursor.insertAfter(“key”, _idataCursor.getKey());infoCursor.insertAfter(“value”, _idataCursor.getValue());infoCursor.insertAfter(“type”, “String”);keysObj.putNode(“info”, info);outCursor.insertAfter(“info”, (IData)info);infoCursor.destroy();//info = null;
[SIZE=2]
}}
[/size]
while (_idataCursor.next());IDataUtil.put(pipelineCursor, “valueObject”, keysObj);//pipelineCursor.insertAfter(“outputIData”, outputIData);
[SIZE=2]
IDataUtil.put(pipelineCursor,
[/size]
“outputIData”, outputIData);return keysObj;}// — <> —
}
------------------------ End -------------------------
The output is coming, but not in the way I want, can anyone please suggest me where I am going wrong. The output I am looking for is:
outputDoc (Document - IData Object)
-----info
----------key (String)
----------value (String)
----------type (String)
-----info
----------key (String)
----------value (String)
----------type (String)
-----internalDoc1 (Document - IData Object)
----------info
---------------key (String)
---------------value (String)
---------------type (String)
----------info
---------------key (String)
---------------value (String)
---------------type (String)
-----internalDoc2 (Document - IData Object)
----------doubleInternalDoc1 (Document - IData Object)
---------------info
--------------------key (String)
--------------------value (String)
--------------------type (String)
---------------info
--------------------key (String)
--------------------value (String)
--------------------type (String)
Thanks in advance!