01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.models.impl.metabossmodel.statemachinemodel;
16:
17: import java.util.Iterator;
18:
19: import org.netbeans.mdr.storagemodel.StorableObject;
20:
21: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
22: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
23: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
24: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
25:
26: public abstract class StateMachineImpl extends ModelElementImpl
27: implements StateMachine {
28: // Required constructor
29: protected StateMachineImpl(StorableObject storable) {
30: super (storable);
31: }
32:
33: /**
34: * @param pStateName
35: * @return State owned by specified state machine element or throws exception if none found
36: */
37: public State getState(String pStateName) {
38: State lFoundState = findState(pStateName);
39: // Throw exception if nothing found
40: if (lFoundState == null)
41: throw new IllegalArgumentException(
42: "Unable to locate State named '" + pStateName
43: + "'. StateMachineRef: " + getRef());
44: return lFoundState;
45: }
46:
47: /**
48: * @param pStateName
49: * @return State owned by specified state machine element or throws exception if none found
50: */
51: public State findState(String pStateName) {
52: for (Iterator lStatesIterator = getStates().iterator(); lStatesIterator
53: .hasNext();) {
54: State lState = (State) lStatesIterator.next();
55: if (lState.getName().equals(pStateName))
56: return lState;
57: }
58: return null;
59: }
60:
61: /**
62: * @param pTransitionName
63: * @return Transition owned by specified Transition machine element or throws exception if none found
64: */
65: public Transition getTransition(String pTransitionName) {
66: Transition lFoundTransition = findTransition(pTransitionName);
67: // Throw exception if nothing found
68: if (lFoundTransition == null)
69: throw new IllegalArgumentException(
70: "Unable to locate Transition named '"
71: + pTransitionName
72: + "'. TransitionMachineRef: " + getRef());
73: return lFoundTransition;
74: }
75:
76: /**
77: * @param pTransitionName
78: * @return Transition owned by specified Transition machine element or throws exception if none found
79: */
80: public Transition findTransition(String pTransitionName) {
81: for (Iterator lTransitionsIterator = getTransitions()
82: .iterator(); lTransitionsIterator.hasNext();) {
83: Transition lTransition = (Transition) lTransitionsIterator
84: .next();
85: if (lTransition.getName().equals(pTransitionName))
86: return lTransition;
87: }
88: return null;
89: }
90: }
|