KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > mbtf > v1 > assembler > AsmblState


1 /*
2  * @(#)AsmblState.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Part of the GroboUtils package at:
9  * http://groboutils.sourceforge.net
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */

29 package net.sourceforge.groboutils.mbtf.v1.assembler;
30
31
32 import net.sourceforge.groboutils.mbtf.v1.IState;
33 import net.sourceforge.groboutils.mbtf.v1.IValidate;
34 import net.sourceforge.groboutils.mbtf.v1.ITransition;
35
36 import net.sourceforge.groboutils.mbtf.v1.engine.StateImpl;
37
38 import java.util.Vector JavaDoc;
39
40
41 /**
42  *
43  *
44  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
45  * @version $Date: 2003/02/10 22:52:25 $
46  * @since June 12, 2002
47  */

48 public class AsmblState
49 {
50     private String JavaDoc name;
51     private Vector JavaDoc validates = new Vector JavaDoc();
52     private Vector JavaDoc transNames = new Vector JavaDoc();
53     private boolean startState;
54     private boolean endState;
55     
56     /**
57      *
58      */

59     public AsmblState()
60     {
61         // do nothing
62
}
63     
64     
65     public void setName( String JavaDoc name )
66     {
67         if (name == null)
68         {
69             throw new IllegalArgumentException JavaDoc("no null args");
70         }
71         this.name = name;
72     }
73     
74     
75     public String JavaDoc getName()
76     {
77         return this.name;
78     }
79     
80     
81     public void addValidate( IValidate v )
82     {
83         if (v != null)
84         {
85             this.validates.addElement( v );
86         }
87     }
88     
89     
90     public void addTransitionName( String JavaDoc n )
91     {
92         if (n != null)
93         {
94             this.transNames.addElement( n );
95         }
96     }
97     
98     
99     public IValidate[] getValidates()
100     {
101         IValidate v[] = new IValidate[ this.validates.size() ];
102         this.validates.copyInto( v );
103         return v;
104     }
105     
106     
107     public String JavaDoc[] getTransitionNames()
108     {
109         String JavaDoc s[] = new String JavaDoc[ this.transNames.size() ];
110         this.transNames.copyInto( s );
111         return s;
112     }
113     
114     
115     public void setIsStartState( boolean on )
116     {
117         this.startState = on;
118     }
119     
120     
121     public boolean isStartState()
122     {
123         return this.startState;
124     }
125     
126     
127     public void setIsFinalState( boolean on )
128     {
129         this.endState = on;
130     }
131     
132     
133     public boolean isFinalState()
134     {
135         return this.endState;
136     }
137     
138     
139     /**
140      * Use the given transition set to create this state.
141      *
142      * @exception IllegalArgumentException if one of the transition names in
143      * this state is not in the transition set.
144      */

145     public IState createState( AsmblTransitionSet set )
146     {
147         // Find all the transitions
148
String JavaDoc transNames[] = getTransitionNames();
149         int len = transNames.length;
150         ITransition t[] = new ITransition[ len ];
151         
152         for (int i = len; --i >= 0;)
153         {
154             AsmblTransition at = set.getTransition( transNames[i] );
155             if (at == null)
156             {
157                 throw new IllegalArgumentException JavaDoc("expecting transition '"+
158                     transNames[i]+"'");
159             }
160             t[i] = at.getTransition();
161         }
162         
163         return new StateImpl( getName(), t, getValidates() );
164     }
165 }
166
167
Popular Tags