KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > mbtf > v1 > ant > StateType


1 /*
2  * @(#)StateType.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.ant;
30
31 import org.apache.tools.ant.Project;
32 import org.apache.tools.ant.ProjectHelper;
33 import org.apache.tools.ant.Task;
34 import org.apache.tools.ant.BuildException;
35 import org.apache.tools.ant.types.Reference;
36 import org.apache.tools.ant.types.DataType;
37 import org.apache.tools.ant.taskdefs.Definer;
38
39 import java.util.Vector JavaDoc;
40
41 import net.sourceforge.groboutils.mbtf.v1.IValidate;
42 import net.sourceforge.groboutils.mbtf.v1.ISystem;
43
44 import net.sourceforge.groboutils.mbtf.v1.assembler.AsmblState;
45
46
47 /**
48  * An ant datatype encapsulating the IState instance. This includes an
49  * <tt>execute()</tt> method to allow for this to be defined in a
50  * &lt;typedef&gt; declaration, rather than inside a target as a
51  * &lt;datatype&gt; declaration.
52  *
53  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
54  * @version $Date: 2003/02/10 22:52:25 $
55  * @since June 13, 2002
56  */

57 public class StateType extends AbstractStateMachineType
58 {
59     public static final String JavaDoc DEFAULT_ANT_NAME = "mbtf.state";
60     
61     
62     private Vector JavaDoc transitions = new Vector JavaDoc();
63     private boolean startState = false;
64     private boolean finalState = false;
65     
66     
67     public static class RefTransitionType
68     {
69         private String JavaDoc name;
70         
71         public void setName( String JavaDoc name )
72         {
73             this.name = name;
74         }
75         
76         public String JavaDoc getName()
77         {
78             return this.name;
79         }
80     }
81     public void addTransition( RefTransitionType trans )
82     {
83         if (trans != null)
84         {
85             this.transitions.addElement( trans );
86         }
87     }
88     
89     
90     public String JavaDoc[] getTransitionNames()
91     {
92         if (isReference())
93         {
94             return ((StateType)getCheckedRef(
95                 StateType.class, DEFAULT_ANT_NAME )).
96                 getTransitionNames();
97         }
98         
99         String JavaDoc[] s = new String JavaDoc[ this.transitions.size() ];
100         for (int i = s.length; --i >= 0;)
101         {
102             s[i] = ((RefTransitionType)this.transitions.elementAt( i )).
103                 getName();
104         }
105         return s;
106     }
107     
108     
109     public void setStartState( boolean on )
110     {
111         this.startState = on;
112     }
113     
114     
115     public boolean getStartState()
116     {
117         if (isReference())
118         {
119             return ((StateType)getCheckedRef(
120                 StateType.class, DEFAULT_ANT_NAME )).
121                 getStartState();
122         }
123         return this.startState;
124     }
125     
126     
127     public void setFinalState( boolean on )
128     {
129         this.finalState = on;
130     }
131     
132     
133     public boolean getFinalState()
134     {
135         if (isReference())
136         {
137             return ((StateType)getCheckedRef(
138                 StateType.class, DEFAULT_ANT_NAME )).
139                 getFinalState();
140         }
141         return this.finalState;
142     }
143     
144     
145     public AsmblState createState()
146             throws BuildException
147     {
148         if (isReference())
149         {
150             return ((StateType)getCheckedRef(
151                 StateType.class, DEFAULT_ANT_NAME )).
152                 createState();
153         }
154
155         verifySettings();
156         
157         AsmblState as = new AsmblState();
158         as.setName( getName() );
159         as.setIsStartState( getStartState() );
160         as.setIsFinalState( getFinalState() );
161
162         IValidate v[] = getValidates();
163         for (int i = 0; i < v.length; ++i)
164         {
165             as.addValidate( v[i] );
166         }
167         
168         String JavaDoc names[] = getTransitionNames();
169         for (int i = 0; i < names.length; ++i)
170         {
171             as.addTransitionName( names[i] );
172         }
173         
174         return as;
175     }
176 }
177
178
Popular Tags