001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.model;
018:
019: import java.io.Serializable;
020:
021: /**
022: * An abstract base class for elements in SCXML that can serve as a
023: * <target> for a <transition>, such as State or Parallel.
024: *
025: */
026: public abstract class TransitionTarget implements Serializable {
027:
028: /**
029: * Identifier for this transition target. Other parts of the SCXML
030: * document may refer to this <state> using this ID.
031: */
032: private String id;
033:
034: /**
035: * Optional property holding executable content to be run upon
036: * entering this transition target.
037: */
038: private OnEntry onEntry;
039:
040: /**
041: * Optional property holding executable content to be run upon
042: * exiting this transition target.
043: */
044: private OnExit onExit;
045:
046: /**
047: * Optional property holding the data model for this transition target.
048: */
049: private Datamodel datamodel;
050:
051: /**
052: * The parent of this transition target (may be null, if the parent
053: * is the SCXML document root).
054: */
055: private TransitionTarget parent;
056:
057: /**
058: * Constructor.
059: */
060: public TransitionTarget() {
061: super ();
062: onEntry = new OnEntry(); //empty defaults
063: onEntry.setParent(this );
064: onExit = new OnExit(); //empty defaults
065: onExit.setParent(this );
066: parent = null;
067: }
068:
069: /**
070: * Get the identifier for this transition target (may be null).
071: *
072: * @return Returns the id.
073: */
074: public final String getId() {
075: return id;
076: }
077:
078: /**
079: * Set the identifier for this transition target.
080: *
081: * @param id The id to set.
082: */
083: public final void setId(final String id) {
084: this .id = id;
085: }
086:
087: /**
088: * Get the onentry property.
089: *
090: * @return Returns the onEntry.
091: */
092: public final OnEntry getOnEntry() {
093: return onEntry;
094: }
095:
096: /**
097: * Set the onentry property.
098: *
099: * @param onEntry The onEntry to set.
100: */
101: public final void setOnEntry(final OnEntry onEntry) {
102: this .onEntry = onEntry;
103: }
104:
105: /**
106: * Get the onexit property.
107: *
108: * @return Returns the onExit.
109: */
110: public final OnExit getOnExit() {
111: return onExit;
112: }
113:
114: /**
115: * Set the onexit property.
116: *
117: * @param onExit The onExit to set.
118: */
119: public final void setOnExit(final OnExit onExit) {
120: this .onExit = onExit;
121: }
122:
123: /**
124: * Get the data model for this transition target.
125: *
126: * @return Returns the data model.
127: */
128: public final Datamodel getDatamodel() {
129: return datamodel;
130: }
131:
132: /**
133: * Set the data model for this transition target.
134: *
135: * @param datamodel The Datamodel to set.
136: */
137: public final void setDatamodel(final Datamodel datamodel) {
138: this .datamodel = datamodel;
139: }
140:
141: /**
142: * Get the parent TransitionTarget.
143: *
144: * @return Returns the parent state
145: * (null if parent is <scxml> element)
146: */
147: public final TransitionTarget getParent() {
148: return parent;
149: }
150:
151: /**
152: * Set the parent TransitionTarget.
153: *
154: * @param parent The parent state to set
155: */
156: public final void setParent(final TransitionTarget parent) {
157: this .parent = parent;
158: }
159:
160: /**
161: * Get the parent State.
162: *
163: * @return The parent State
164: */
165: public final State getParentState() {
166: TransitionTarget tt = this .getParent();
167: if (tt == null) {
168: return null;
169: } else {
170: if (tt instanceof State) {
171: return (State) tt;
172: } else { //tt is Parallel
173: return tt.getParentState();
174: }
175: }
176: }
177:
178: }
|