Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61a8c56

Browse files
Initial version, added state machine, etc
1 parent 5f2362f commit 61a8c56

39 files changed

+4770
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package sysmlinjava.statemachine;
2+
3+
import sysmlinjava.events.SysMLCompletionEvent;
4+
5+
/**
6+
* SysMLinJava's representation of the SysML completion event that is submitted
7+
* by a behavior in state, i.e. by the {@code SysMLDoActivity} of the
8+
* {@code SysMLState}. The do-Activity submits the completion event to the state
9+
* machine upon completion of the behavior. Transitions out of the state may/may
10+
* not be triggered by the completion event, as specified by the state machine's
11+
* model.
12+
*
13+
* @author ModelerOne
14+
*
15+
*/
16+
public class DoActivityCompletionEvent extends SysMLCompletionEvent
17+
{
18+
/**
19+
* Constructor
20+
* @param id unique identifier of the event
21+
*/
22+
public DoActivityCompletionEvent(Long id)
23+
{
24+
super("DoActivity", id);
25+
}
26+
27+
@Override
28+
public void createCompletionExpression()
29+
{
30+
completionExpression = String.valueOf(id);
31+
}
32+
33+
@Override
34+
public String toString()
35+
{
36+
return String.format("DoActivityCompletionEvent [completionExpression=%s, name=%s, id=%s]", completionExpression, name, id);
37+
}
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package sysmlinjava.statemachine;
2+
3+
import sysmlinjava.events.SysMLEvent;
4+
5+
/**
6+
* Event indicating transition to the {@code FinalState} is triggered. The
7+
* {@code FinalEvent} is used by transitions to trigger transition to the state
8+
* machine's final state.
9+
*
10+
* @author ModelerOne
11+
*
12+
*/
13+
public final class FinalEvent extends SysMLEvent
14+
{
15+
/**
16+
* Constructor
17+
*/
18+
public FinalEvent()
19+
{
20+
super();
21+
}
22+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package sysmlinjava.statemachine;
2+
3+
import java.util.Optional;
4+
import sysmlinjava.blocks.SysMLBlock;
5+
import sysmlinjava.events.SysMLSignalEvent;
6+
7+
/**
8+
* SysMLinJava representation of a transition to the final state of a state
9+
* machine. The {@code FinalTransition}(s) must be the last transition(s)
10+
* specified for all state machines. The {@code SysMLStateMachine} execution
11+
* terminates with the performance of this transition to the {@code finalState}
12+
* declared in the state machine. The {@code FinalTransition} is triggered by
13+
* the submission of a {@code FinalEvent} to the state machine when the
14+
* transition is "active" for the current state. It's initialization must
15+
* specify the instance of the {@code FinalState} declared in
16+
* {@code SysMLStateMachine} and an instance of a previous state (or
17+
* pseudo-state) to transition from.
18+
* <p>
19+
* <b>Note</b> this is a convenience class for transition to the final state. It
20+
* is optionally triggered by the occurance of the {@code FinalEvent}. If a
21+
* different triggering event and/or guard and/or effect are needed for this
22+
* transition to the {@code FinalState}, an instance of a
23+
* {@code SysMLTransition} should be used for the transition to the final state
24+
* instead.
25+
*
26+
* @author ModelerOne
27+
*
28+
*/
29+
public final class FinalTransition extends SysMLTransition
30+
{
31+
/**
32+
* Constructor for transition from a state to the final state
33+
*
34+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
35+
* the current state machine that contains this transition.
36+
* @param prevState The {@code SysMLState} instance which the
37+
* {@code FinalTransition} is to transition from.
38+
* <b>Note</b> this is a convenience class for transition to
39+
* the final state. It is triggered by the occurance of the
40+
* {@code FinalEvent}. If a different triggering event
41+
* and/or guard and/or effect are needed for this transition
42+
* to the {@code FinalState}, an instance of a
43+
* {@code SysMLTransition} should be used instead.
44+
* @param finalState The {@code FinalState} instance to which this transition
45+
* is to transition to, e.g. {@code finalState} in
46+
* {@code SysMLStateMachine} or other instantiation of
47+
* {@code FinalState}.
48+
* @param name Name of this transition, e.g. {@code OperationalToFinal}
49+
*/
50+
public FinalTransition(Optional<? extends SysMLBlock> contextBlock, SysMLState prevState, SysMLFinalState finalState, String name)
51+
{
52+
super(contextBlock, prevState, finalState, Optional.of(FinalEvent.class), Optional.empty(), Optional.empty(), name, SysMLTransitionKind.external);
53+
}
54+
55+
/**
56+
* Constructor for transition from a junction pseudo-state to the final state
57+
*
58+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
59+
* the current state machine that contains this transition.
60+
* @param prevState The {@code SysMLJunctionPseudoState} instance which the
61+
* {@code FinalTransition} is to transition from.
62+
* <b>Note</b> this is a convenience class for transition to
63+
* the final state from a junction. It assumes the junction
64+
* is of multiple in-transitions to a single out-transition
65+
* in which there is no guard condition on the
66+
* out-transition - a common method of transitioning to the
67+
* final state. If a guard and/or effect are needed on the
68+
* transition to the final state, an instance of a
69+
* {@code SysMLTransition} that specifies these items should
70+
* be used instead.
71+
* @param finalState The {@code FinalState} instance to which this transition
72+
* is to transition to, e.g. {@code finalState} in
73+
* {@code SysMLStateMachine} or other instantiation of
74+
* {@code FinalState}.
75+
* @param name Name of this transition, e.g. {@code JunctionToFinal} or
76+
* {@code ChoiceToFinal}
77+
*/
78+
public FinalTransition(Optional<? extends SysMLBlock> contextBlock, SysMLJunctionPseudoState prevState, SysMLFinalState finalState, String name)
79+
{
80+
super(contextBlock, prevState, finalState, Optional.empty(), Optional.empty(), name);
81+
}
82+
83+
@Override
84+
public boolean guardConditionSatisfied(Optional<? extends SysMLSignalEvent> currentEvent)
85+
{
86+
return true;
87+
}
88+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package sysmlinjava.statemachine;
2+
3+
import sysmlinjava.events.SysMLEvent;
4+
5+
/**
6+
* Event indicating transition from the {@code InitialState} is triggered. The
7+
* {@code InitialEvent} is used by transitions to trigger transition from the
8+
* state machine's initial state.
9+
*
10+
* @author ModelerOne
11+
*
12+
*/
13+
public final class InitialEvent extends SysMLEvent
14+
{
15+
/**
16+
* Constructor
17+
*/
18+
public InitialEvent()
19+
{
20+
super("InitialEvent");
21+
}
22+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package sysmlinjava.statemachine;
2+
3+
import java.util.Optional;
4+
import sysmlinjava.blocks.SysMLBlock;
5+
import sysmlinjava.events.SysMLSignalEvent;
6+
7+
/**
8+
* SysMLinJava representation of the initial transition of a SysML state
9+
* machine, i.e. of the transition from the initial state to a state of the
10+
* state machine. The {@code InitialTransition} must be the first transition to
11+
* occur for all state machines.
12+
* <p>
13+
* The {@code SysMLStateMachine} execution commences with the performance of
14+
* this transition to a state of the specialized state machine. The
15+
* {@code InitialTransition} is triggered by the {@code InitialEvent} and has no
16+
* guard nor effect. It's initialization must specify the instance of the
17+
* {@code InitialState} specified in the {@code SysMLStateMachine} and a
18+
* specified next state to transition to. An example follows.
19+
*
20+
* <pre>
21+
public void createTransitions()
22+
{
23+
:
24+
initialToPowerOff = new InitialTransition(contextBlock, initialState, powerOffState, initialToPowerOffEffect, "InitialToPowerOff");
25+
:
26+
}
27+
* </pre>
28+
*
29+
* @author ModelerOne
30+
*
31+
*/
32+
public final class InitialTransition extends SysMLTransition
33+
{
34+
/**
35+
* Constructor for base initial transition to state and no effect.
36+
*
37+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
38+
* the current state machine
39+
* @param initialState The {@code InitialState} instance from which this
40+
* transition is to transition from, e.g.
41+
* {@code initialState} in {@code
42+
* SysMLStateMachine}
43+
* @param nextState The {@code SysMLState} instance which this transition is
44+
* to transition to
45+
* @param name Name of this transition, e.g. "InitialToOperational"
46+
*/
47+
public InitialTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState initialState, SysMLState nextState, String name)
48+
{
49+
super(contextBlock, initialState, nextState, Optional.empty(), name);
50+
}
51+
52+
/**
53+
* Constructor for base initial transition to pseudo-state and no effect.
54+
*
55+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
56+
* the current state machine
57+
* @param initialState The {@code InitialState} instance from which this
58+
* transition is to transition from, e.g.
59+
* {@code initialState} in {@code
60+
* SysMLStateMachine}
61+
* @param nextState The {@code SysMLPseudoState} instance which this
62+
* transition is to transition to
63+
* @param name Name of this transition, e.g.
64+
* "InitialToOperationalChoice"
65+
*/
66+
public InitialTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState initialState, SysMLPseudoState nextState, String name)
67+
{
68+
super(contextBlock, initialState, nextState, Optional.empty(), name);
69+
}
70+
71+
/**
72+
* Constructor for initial transition to a state with an effect.
73+
*
74+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
75+
* the current state machine
76+
* @param initialState The {@code InitialState} instance from which this
77+
* transition is to transition from, e.g.
78+
* {@code initialState} in {@code
79+
* SysMLStateMachine}
80+
* @param nextState The {@code SysMLState} instance which this transition is
81+
* to transition to
82+
* @param effect The {@code SysMLEffect} which this initial transition is
83+
* to perform just before transition to the next (first)
84+
* state
85+
* @param name Name of this transition, e.g. "InitialToOperational"
86+
*/
87+
public InitialTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState initialState, SysMLState nextState, SysMLEffect effect, String name)
88+
{
89+
super(contextBlock, initialState, nextState, Optional.of(effect), name);
90+
}
91+
92+
/**
93+
* Constructor for initial transition to a pseudo-state with an effect.
94+
*
95+
* @param contextBlock Optional {@code SysMLBlock} which provides the context of
96+
* the current state machine
97+
* @param initialState The {@code InitialState} instance from which this
98+
* transition is to transition from, e.g.
99+
* {@code initialState} in {@code
100+
* SysMLStateMachine}
101+
* @param nextState The {@code SysMLPseudoState} instance which this
102+
* transition is to transition to
103+
* @param effect The {@code SysMLEffect} which this initial transition is
104+
* to perform just before transition to the next (first)
105+
* pseudo-state
106+
* @param name Name of this transition, e.g. "InitialToOperational"
107+
*/
108+
public InitialTransition(Optional<? extends SysMLBlock> contextBlock, SysMLInitialState initialState, SysMLPseudoState nextState, SysMLEffect effect, String name)
109+
{
110+
super(contextBlock, initialState, nextState, Optional.of(effect), name);
111+
}
112+
113+
/**
114+
* Boolean operation that is finally overridden to force satisfaction of guard
115+
* condition. (IAW SysML, initial transition cannot have a guard)
116+
*/
117+
@Override
118+
public final boolean guardConditionSatisfied(Optional<? extends SysMLSignalEvent> currentEvent)
119+
{
120+
return true;
121+
}
122+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package sysmlinjava.statemachine;
2+
3+
import sysmlinjava.events.SysMLCompletionEvent;
4+
5+
/**
6+
* SysMLinJava representation of the SysML completion event that is submitted by
7+
* sub-state machines (state machines that execute within a state) to the parent
8+
* state machine to invoke its reaction to the completion of the sub-state
9+
* machine.
10+
*
11+
* @author ModelerOne
12+
*
13+
*/
14+
public class StateMachineCompletionEvent extends SysMLCompletionEvent
15+
{
16+
/**
17+
* Constructor
18+
*
19+
* @param stateMachineID identifier of the sub-state machine that has completed
20+
* its execution, i.e. the sub-state machine that has
21+
* achieved its final state.
22+
*/
23+
24+
public StateMachineCompletionEvent(Long stateMachineID)
25+
{
26+
super(String.format("StateMachine%d", stateMachineID), stateMachineID);
27+
}
28+
29+
@Override
30+
public String toString()
31+
{
32+
return String.format("StateMachineCompletionEvent [completionExpression=%s, name=%s, id=%s]", completionExpression, name, id);
33+
}
34+
35+
@Override
36+
public void createCompletionExpression()
37+
{
38+
completionExpression = String.valueOf(id);
39+
}
40+
41+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package sysmlinjava.statemachine;
2+
3+
import java.util.Optional;
4+
import sysmlinjava.blocks.SysMLBlock;
5+
6+
/**
7+
* SysMLinJava's representation of the SysML choice pseudo-state. As an
8+
* extension of the {@code SysMLPseudoState} which is an extension of the
9+
* {@code SysMLVertex} it is assigned its transitions into and out of the "choice"
10+
* pseudo-state by {@code SysMLTransition} constructors invoked in an override
11+
* of the {@code SysMLStateMachine}'s {@code createTransitions()} operation.
12+
*
13+
* @author ModelerOne
14+
* @see SysMLTransition
15+
* @see SysMLStateMachine#createTransitions()
16+
*/
17+
public final class SysMLChoicePseudoState extends SysMLPseudoState
18+
{
19+
/**
20+
* Constructor
21+
*
22+
* @param contextBlock block in whose context the state machine executes
23+
* @param name name of the "choice" pseudo-state
24+
*/
25+
public SysMLChoicePseudoState(Optional<? extends SysMLBlock> contextBlock, String name)
26+
{
27+
super(contextBlock, name);
28+
}
29+
}

0 commit comments

Comments
 (0)