001: /*
002: * @(#)AsmblState.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Part of the GroboUtils package at:
009: * http://groboutils.sourceforge.net
010: *
011: * Permission is hereby granted, free of charge, to any person obtaining a
012: * copy of this software and associated documentation files (the "Software"),
013: * to deal in the Software without restriction, including without limitation
014: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
015: * and/or sell copies of the Software, and to permit persons to whom the
016: * Software is furnished to do so, subject to the following conditions:
017: *
018: * The above copyright notice and this permission notice shall be included in
019: * all copies or substantial portions of the Software.
020: *
021: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
022: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
024: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
025: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
026: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
027: * DEALINGS IN THE SOFTWARE.
028: */
029: package net.sourceforge.groboutils.mbtf.v1.assembler;
030:
031: import net.sourceforge.groboutils.mbtf.v1.IState;
032: import net.sourceforge.groboutils.mbtf.v1.IValidate;
033: import net.sourceforge.groboutils.mbtf.v1.ITransition;
034:
035: import net.sourceforge.groboutils.mbtf.v1.engine.StateImpl;
036:
037: import java.util.Vector;
038:
039: /**
040: *
041: *
042: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
043: * @version $Date: 2003/02/10 22:52:25 $
044: * @since June 12, 2002
045: */
046: public class AsmblState {
047: private String name;
048: private Vector validates = new Vector();
049: private Vector transNames = new Vector();
050: private boolean startState;
051: private boolean endState;
052:
053: /**
054: *
055: */
056: public AsmblState() {
057: // do nothing
058: }
059:
060: public void setName(String name) {
061: if (name == null) {
062: throw new IllegalArgumentException("no null args");
063: }
064: this .name = name;
065: }
066:
067: public String getName() {
068: return this .name;
069: }
070:
071: public void addValidate(IValidate v) {
072: if (v != null) {
073: this .validates.addElement(v);
074: }
075: }
076:
077: public void addTransitionName(String n) {
078: if (n != null) {
079: this .transNames.addElement(n);
080: }
081: }
082:
083: public IValidate[] getValidates() {
084: IValidate v[] = new IValidate[this .validates.size()];
085: this .validates.copyInto(v);
086: return v;
087: }
088:
089: public String[] getTransitionNames() {
090: String s[] = new String[this .transNames.size()];
091: this .transNames.copyInto(s);
092: return s;
093: }
094:
095: public void setIsStartState(boolean on) {
096: this .startState = on;
097: }
098:
099: public boolean isStartState() {
100: return this .startState;
101: }
102:
103: public void setIsFinalState(boolean on) {
104: this .endState = on;
105: }
106:
107: public boolean isFinalState() {
108: return this .endState;
109: }
110:
111: /**
112: * Use the given transition set to create this state.
113: *
114: * @exception IllegalArgumentException if one of the transition names in
115: * this state is not in the transition set.
116: */
117: public IState createState(AsmblTransitionSet set) {
118: // Find all the transitions
119: String transNames[] = getTransitionNames();
120: int len = transNames.length;
121: ITransition t[] = new ITransition[len];
122:
123: for (int i = len; --i >= 0;) {
124: AsmblTransition at = set.getTransition(transNames[i]);
125: if (at == null) {
126: throw new IllegalArgumentException(
127: "expecting transition '" + transNames[i] + "'");
128: }
129: t[i] = at.getTransition();
130: }
131:
132: return new StateImpl(getName(), t, getValidates());
133: }
134: }
|