An array of IData objects

Hi

I have created a simple java service that will invoke a built-in java service “pub.date.dateTimeFormat”.
I declared a DocumentList(named “date”) having “inString”, “currentPattern”, “newPattern” as fields in DocumentList.
And also another DocumentList(named “dateOut”) having “value” as a field.

Any way i developed the code and it is working properly.
And my doubt is:
“is it the correct way to create an array of IData objects and is there any better approach to do so?”
Here is my code…

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();

// date
IData[]    date = IDataUtil.getIDataArray( pipelineCursor, "date" );
int n=date.length;

IData out[] = new IData[n];// can we create IData objects like this?
String output[] =new String[n];
if ( date != null)
{        
    for ( int i = 0; i < date.length; i++ )
    {
        try{
                out[i] = Service.doInvoke("pub.date","dateTimeFormat", date[i]);
            }catch(Exception ex){}
    }
}
pipelineCursor.destroy();

for ( int i = 0; i <out.length; i++ ) 
{
    IDataCursor outCursor = out[i].getCursor();
    output[i] = IDataUtil.getString( outCursor, "value" );
    outCursor.destroy();
}

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();

// dateOut
IData[]    dateOut = new IData[n];
for ( int i = 0; i <dateOut.length; i++ ) 
{
    dateOut[i] = IDataFactory.create();
    IDataCursor dateOutCursor = dateOut[i].getCursor();
    IDataUtil.put( dateOutCursor, "value", output[i] );
    dateOutCursor.destroy();
}

IDataUtil.put( pipelineCursor_1, “dateOut”, dateOut );
pipelineCursor_1.destroy();

Thanks in advance…
Trinadh

I would suggest doing this with flow service. Java is not necessary for this.

I’m 100% with you. for most of the tasks using already built-in services should resolve it, and Java code SHOULD be used for very few particular things.

However for learning purposes it’s fine this kind of code :smiley: