Tuesday, October 26, 2004

Jaba Jaba, Dooo..

Well, I've finally sucumbed to all the criticism and bowed down to learn java. In the past I've dutifully hacked out java as needed for file i/o, and other mundane tasks.

As I've worked side-by-side in the trenches with webMethods' PS folks, invariably, they have all said that while my flow code is great, the use of loops should be and can be avoided if I would only use JAVA.

So, I decided that in an effort to "better" myself, I would apply java in every situation where I thought a switch to java would provide a significant processing savings.

This is my first all out effort to create a java service that actually does something useful besides "Hello World." Remember to create StringList1, StringList2 as inputs and CombinedStringLists as the output. The idea is to input two string lists and combine them as one. Sure I could have used the built-in services to do this, but I wanted to learn how to use vectors.

Also, I don't know how much this will save in processing time, but it was fun to build. Here's the code:

/*

Remember to do your imports:

import java.util.*
import java.lang.reflect.Array

*/

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String[] StringList1 = IDataUtil.getStringArray( pipelineCursor, "StringList1" );
String[] StringList2 = IDataUtil.getStringArray( pipelineCursor, "StringList2" );
pipelineCursor.destroy();

// create new vector to store both of the arrays
Vector v = new Vector();

// add each array to the vector. If you add new inputs, add them here.

v.addAll(Arrays.asList(StringList1));
v.addAll(Arrays.asList(StringList2));

String[] CombinedStringList = new String[Array.getLength(StringList1) + Array.getLength(StringList2)];
v.copyInto(CombinedStringList);

IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "CombinedStringList", CombinedStringList );
pipelineCursor_1.destroy();


0 Comments:

Post a Comment

<< Home