You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

First Class Object

An OMS simulation instantiates a POJO (plain java object) and passes it as a parameter to an OMS component, which acts on it.

Concept

For OMS a first class object is differentiated from second and third class objects as follows:

ManipulationFirst ClassSecond ClassThird Class
Pass value as a parameteryesyesno
Return value from a methodyesnono
Assign value into a variableyesnono

OMS model simulation could be part of a workflow in which objects are created during earlier steps in the workflow. This example demonstrates they can be used by the simulation.

Implementation

Java class 'Point' provides for instantiating an object containing integers x and y.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package ex02;

/**
 *
 * @author od
 */
public class Point {

    int x;
    int y;

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

}

OMS component 'Comp' consumes 'Point' object as a parameter and prints the values of integers x and y in a readable format.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
package ex02;

import oms3.annotations.*;

public class Comp {

 @In public Point point;

 @Execute
 public void run() {
 System.out.println("x: " + point.x);
 System.out.println("y: " + point.y);
 }
}

In OMS simulation ex02_FirstClassObjectParameter.sim, the model component is specified (line 12), the 'Point' POJO is included (line 2), instantiated and declared a parameter (line 16) passed to the component.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import static oms3.SimBuilder.instance as OMS3
import ex02.Point

/* 
 * Passing a "first class" object as a parameter into a component.
 * The "Point" class is a POJO that gets instantiated in the sim script
 * and passed to to the component. The component then prints it.
 */
OMS3.sim {
    model {
        components {
          "c1" "ex02.Comp"
        }
        parameter {
            // instantiate the Point object within this script
          "c1.point" new Point(x:2, y:5)
        }
    }
}