Java API creating arrays

Hi:

I’m access Workflow using the Java API. I’m able to access and set properties and nested documents with any issues.

I’m running into trouble, however, when I attempt to create an array attribute.

WFData[] values = wfData.create(“values”, 4);

The array is created but all the elements in the array are null. How do I populate this array with WFData instances?

Regards,

Jeremy

values[0] = new WFData(); // use the appropriate constructorDo this for each array element (values[1], values[2], etc.).

Hi,

I can’t use:

values[0] = new WFData()

WFData is an interface and cannot be constructed. The API documents don’t contain information on implementing classes or their construction (i.e. can they be created with a constructor or are they created by a factory class).

Any ideas what class I could be creating?

Thanks,

Jeremy

It’s a little obscure (and completely undocumented) but I think I’ve figured it out. If you have a property called “values” that is an array and you want to set it to a new array you do the following:

WFData myDocument = // get your document…
WFData[] values = myDocument.create(“values”, size);
for (int i = 0; i < values.length; i++) {
values[i] = myDocument.create(“values”);
}
myDocument.setValue(“values”, values);

In order for it to work you have to:

  1. Create the array by calling create(attribute, size).
  2. Call create(attribute) on the array attribute with no index to create each value.
  3. Set the original property.

Without going on a rant, I have to say that the API documents are really poor (using webMethods Workflow 6.1). The create(attribute, size) and create(attribute) methods have zero description. Oh well :slight_smile:

Jeremy

Glad you figured it out. I’ve never used WF so my explanation was purely to show how to initialize any type of Java array–I should have explained that in my response.

I’m looking at the WF Client Java API doc now. It is indeed a bit light on description, to put it mildly. It’s a shame that docs simply got the wM branding treatment (WF was acquired) rather than updated to match the normally decent documentation that wM provides with their other products.