NVN
NVN

Reputation: 107

Set the attribute value through java method call

I have the Ecore model which has the attribute ID.Now in the Sirius we can set the attribute values through the set operation by specifying the feature name of the attribute and the value Expression in the Sirius design.Now the problem is,i want to set the attribute value id so i want to use the methods given by java to create random numbers so how can i call that method in the value expression such that the feature name has the value of the method return type.

Upvotes: 0

Views: 920

Answers (1)

pcdavid
pcdavid

Reputation: 306

The Set operation in Sirius uses an expression to get the value to set. The expressions can be written in a variety of query languages. Most support calling back to so-called "Java services", which are plain Java methods which must conform to a few rules. See the corresponding documentation section for details.

Basically for your case you need to:

  1. Write a small Java class which exposes the "random number generation" code you want to call in a way that Sirius can invoke as a service.
  2. Register the corresponding class in your VSM (this is described in the documentation).
  3. Finally, invoke the service from the expression in your Set Value operation, with something like service:getRandomId.

The advanced Sirius tutorial also has a section at the end about using Java services which may be usefull.

Upvotes: 1

Related Questions