Java API

From WeizmannWiki
Revision as of 08:17, 28 October 2011 by Smadar (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Below are code snippets for commonly used operations.

Create LSC


LSCModel topModel;
topModel = (LSCModel) UMLFactory.eINSTANCE.createModel();
topModel.applyProfile();
LSCCollaboration collaboration = topModel.createLSCCollaboration();
LSCInteraction lsc = collaboration.createLSC("LSCName");

Create Lifeline


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
LSCLifeline userLifeline = lsc.createLSCLifeline ("User", "User",LifelineType.USER, Binding.STATIC);
LSCLifeline lifelineA = lsc.createLSCLifeline ("a", "ClassA",LifelineType.SYSTEM, Binding.DYNAMIC);

Create Condition


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
LSCLifeline lifelineA = lsc.createLSCLifeline ("a", "ClassA",LifelineType.SYSTEM, Binding.DYNAMIC);
LSCLifeline lifelineB = lsc.createLSCLifeline ("b", "ClassB",LifelineType.SYSTEM, Binding.DYNAMIC);
ArrayList coveredLifelines = new ArrayList<LSCLifeline>();
coveredLifelines.add(lifelineA);
coveredLifelines.add(lifelineB);
LSCStateInvariant cond = lsc.createLSCOpaqueCondition("a.getState().equals(b.getState())", coveredLifelines, "a.getState().equals(b.getState())");
cond.setTemperature(Temperature.Cold);
...

Create Sync Construct


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
LSCLifeline lifelineA = lsc.createLSCLifeline ("a", "ClassA",LifelineType.SYSTEM, Binding.DYNAMIC);
LSCLifeline lifelineB = lsc.createLSCLifeline ("b", "ClassB",LifelineType.SYSTEM, Binding.DYNAMIC);
ArrayList coveredLifelines = new ArrayList<LSCLifeline>();
coveredLifelines.add(lifelineA);
coveredLifelines.add(lifelineB);
tempDetectLSC.createLSCSyncConstraint(coveredLifelines);
...

Create Assignment


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
LSCLifeline lifelineA = lsc.createLSCLifeline ("a", "ClassA",LifelineType.SYSTEM, Binding.DYNAMIC);
LSCLifeline lifelineB = lsc.createLSCLifeline ("b", "ClassB",LifelineType.SYSTEM, Binding.DYNAMIC);
ArrayList coveredLifelines = new ArrayList<LSCLifeline>();
coveredLifelines.add(lifelineA);
coveredLifelines.add(lifelineB);
LSCStateInvariant assignment1 = lsc.createLSCAssignment("time", "Long", "System.currentTimeMillis()", MessageArgType.OPAQUE_EXPRESSION, coveredLifelines);
...

Create Loop Fragment


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
...
LSCCombinedFragment loop = lsc.createLSCLoopFragment("loop", 3, lifelineA, lifelineB);
InteractionOperand loopOper = loop.getOperand(loop.getLSCLoopOperandName());
LSC.createLSCMessage(lifelineA, lifelineB, "methodY", Temperature.Hot, ExecutionKind.MONITORED, loopOper);
...

Create Alt Fragment


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
LSCLifeline lifelineA = lsc.createLSCLifeline ("a", "ClassA",LifelineType.SYSTEM, Binding.DYNAMIC);
LSCLifeline lifelineB = lsc.createLSCLifeline ("b", "ClassB",LifelineType.SYSTEM, Binding.DYNAMIC);
ArrayList coveredLifelines = new ArrayList<LSCLifeline>();
coveredLifelines.add(lifelineA);
coveredLifelines.add(lifelineB);
// create an alt fragment:
LSCCombinedFragment alt = lsc.createLSCAltFragment("State", coveredLifelines, 0);
// create an operand with opaque expression (serves as a condition, if true then we get into the operand):
LSCInteractionOperand stateOn = alt.createOperand("StateON", "state.equals(State.ON)");
LSCMessage msg1 = lsc.createLSCMessage(lifelineA, lifelineB, "methodX", Temperature.Hot, ExecutionKind.EXECUTE, stateOn);
LSCInteractionOperand stateOff = alt.createOperand("StateOFF", "state.equals(State.OFF)");
LSCMessage msg2 = lsc.createLSCMessage(lifelineA, lifelineB, "methodY", Temperature.Hot, ExecutionKind.EXECUTE, stateOff);

Create Message

Message without arguments


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
...
lsc.createLSCMessage(user, lifelineA, "methodX", Temperature.Cold, ExecutionKind.MONITORED);

Message with arguments


 ...
 LSCInteraction lsc = collaboration.createLSC("LSCName");
 ...
 List<MessageParameter> messageParameters = new ArrayList<MessageParameter>();
 messageParameters.add(new MessageParameter("arg", "String", "Text To Display", MessageArgType.EXACT));
 lsc.createLSCMessage(userLifeline, lifelineA, "setText", messageParameters, "void", Temperature.Hot,
       ExecutionKind.EXECUTE);

Message inside a Fragment


...
LSCInteraction lsc = collaboration.createLSC("LSCName");
...
LSCCombinedFragment loop = lsc.createLSCLoopFragment("loop", 3, lifelineA, lifelineB);
InteractionOperand loopOper = loop.getOperand(loop.getLSCLoopOperandName());
LSC.createLSCMessage(lifelineA, lifelineB, "methodY", Temperature.Hot, ExecutionKind.MONITORED, loopOper);
...