Open topic with navigation

TIBCO Business Studio™ - BPM Edition 5.4.0

# Scripting Containment Relationships

The BOM editor allows you to say that instances of one class are contained within instances of another. For example, if there were classes for Car and Widget, instances of the Widget class can be said to be contained by a Car instance. For the contained relationship, the contained objects are affected by the container’s lifecycle events. So, when the container (Car in our example) is destroyed, all the contained (Widget in our example) objects are destroyed too.

The diagram below shows that Widget objects can be contained by a Car or a Bike. However, for an individual Widget object instance, it can only belong to a Car or a Bike instance, not both at once.

There are two ways to model this in the BOM editor. First, a Composition link can be drawn between the two classes, like this:

Alternatively, the Car and Bike class can be given an attribute called widgets of type Widget, as shown below:

Both of these two Car/Widget relationships appear the same when scripting.

There is an attribute of the Car object called widgets, which is an Array, that can contain Widget objects. This would be processed in a similar way to the Array processing examples already covered.

For example, to create a Car and add two Widgets, we can write:

    var car = factory.com_example_data_containment_createCar();
    data.car.model = "Saloon";
    var widget = factory.com_example_data_containment_createWidget();
    data.widget.description = "M8 Bolt";
    data.car.widgets.push(widget);
    widget = factory.com_example_data_containment_createWidget ();
    data.widget.description = "M8 Nut";
    car.widgets.push(widget);

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO Business Studio™ - BPM Edition

Copyright © 2015-2023. Cloud Software Group, Inc. All Rights Reserved.