Difference between revisions of "Java API"
From WeizmannWiki
(New page: Below are code snippets for commonly used operations. === Create LSC === <span style="font-size: larger;"> LSCModel topModel; topModel = (LSCModel) UMLFactory.eINSTANCE.createModel(); ...) |
|||
Line 10: | Line 10: | ||
</span> | </span> | ||
− | === Create | + | === Create lifeline === |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
... | ... | ||
Line 18: | Line 18: | ||
</span> | </span> | ||
− | === Create | + | === Create condition=== |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
... | ... | ||
Line 32: | Line 32: | ||
</span> | </span> | ||
− | === Create | + | === Create sync construct=== |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
... | ... | ||
Line 45: | Line 45: | ||
</span> | </span> | ||
− | === Create | + | === Create assignment=== |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
... | ... | ||
Line 58: | Line 58: | ||
</span> | </span> | ||
− | === Create | + | === Create loop fragment === |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
Line 70: | Line 70: | ||
</span> | </span> | ||
− | === Create | + | === Create alt fragment === |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
Line 109: | Line 109: | ||
</span> | </span> | ||
− | ==== Message inside a | + | ==== Message inside a fragment ==== |
<span style="font-size: larger;"> | <span style="font-size: larger;"> | ||
... | ... |
Latest revision as of 06:18, 28 October 2011
Below are code snippets for commonly used operations.
Contents
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);
...