How to get the data type of an document's element using Java API

Hi Gurus,

I am developing java services to Invoke a Insert service which inserts the data into Oracle 9i database. The java service receives the records in as XML string. The java code loops on each record, extracts elements and sets to the appropriate field. The input to the insert service is document, collection of Objects; Strings, BigInteger, Date etc… Now in java code how do I get the data type of the object? If I know the object’s data type then I can map the read data from the XML and construct the document for insert service. So could anyone help me how to get the data type using Java API.

Thanks in advance
Jo

Hi,
Traverse through the document using the webMethods java API. You can then use the IDataCursor’s getKey()
method to get the key of the document. Then passing the IDataCursor object and the key to the IDataUtil’s get method to obtain the value
of the document element as an object. Then use the java’s instanceof keyword to compare and check the
datatype of the documents element.

Suppose if you document has the following elements with String, Integer, Date, BigInteger datatypes…

doc
Name - (String datatype)
Age - (Integer datatype)
JoinDate - (Date datatype)
Salary - (BigInteger datatype)

Below is a sample code snippet…

[highlight=java]
IDataCursor _cursor = pipeline.getCursor() ;

IData _data = IDataUtil.getIData(_cursor,“doc”) ;

IDataCursor _datacursor = _data.getCursor() ;

//move the cursor to the first element in the document
_datacursor.first();

while(_datacursor.hasMoreData())
{
String _strKey = _datacursor.getKey() ;

Object _obj = IDataUtil.get(_datacursor,_strKey) ;

if(_obj instanceof java.lang.String)
{
//do processing here
}
else if(_obj instanceof java.lang.Integer)
{
//do processing here
}
else if(_obj instanceof java.util.Date)
{
//do processing here
}
else if(_obj instanceof java.math.BigInteger)
{
//do processing here
}

//move the cursor to the next element in the document
_datacursor.next();
}

//Finally destroy the cursor’s at the end of the java service
_datacursor.destroy() ;

_cursor.destroy() ;[/highlight]

Note that java’s instanceof keyword can only be used with the non-primitive datatypes.

Thanks
sivaram

Thank you Sivaram,

With regards
Jo

Would strongly encourage you to not use Java services for this purpose. Integration Server is not a typical application server where everything is in Java code. Try to do things in FLOW and with JDBC adapter services and you’ll find debugging, maintenance and performance to be better.