KickJava   Java API By Example, From Geeks To Geeks.

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


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

60 public abstract class AbstractStateMachineType extends DataType
61 {
62     private static final Logger LOG = Logger.getLogger(
63         AbstractStateMachineType.class );
64     
65     public void execute()
66             throws BuildException
67     {
68         // do nothing
69
}
70
71     protected Location location = Location.UNKNOWN_LOCATION;
72     /**
73      * Sets the file location where this task was defined.
74      */

75     public void setLocation(Location location) {
76         this.location = location;
77     }
78     
79     
80     private Vector JavaDoc validates = new Vector JavaDoc();
81     private String JavaDoc name;
82     
83     
84     public void setName( String JavaDoc name )
85     {
86         this.name = name;
87     }
88     
89     
90     public String JavaDoc getName()
91     {
92         if (isReference())
93         {
94             return ((AbstractStateMachineType)getCheckedRef(
95                 AbstractStateMachineType.class, "state machine type" )).
96                 getName();
97         }
98         return this.name;
99     }
100     
101     
102     public IValidate[] getValidates()
103     {
104         if (isReference())
105         {
106             return ((AbstractStateMachineType)getCheckedRef(
107                 AbstractStateMachineType.class, "state machine type" )).
108                 getValidates();
109         }
110         IValidate[] v = new IValidate[ this.validates.size() ];
111         this.validates.copyInto( v );
112         if (getProject() != null)
113         {
114             for (int i = 0; i < v.length; ++i)
115             {
116                 IValidate vv = v[i];
117                 if (vv instanceof ProjectComponent)
118                 {
119                     LOG.debug("Setting project of "+vv);
120                     ((ProjectComponent)vv).setProject( getProject() );
121                 }
122                 else
123                 {
124                     LOG.debug("Validator "+vv+" not a ProjectComponent, but "+
125                         vv.getClass().getName());
126                 }
127             }
128         }
129         else
130         {
131             LOG.debug("Ant type "+this+" never had project set");
132         }
133         return v;
134     }
135     
136     
137     public void addConfiguredValidateJava( ValidateJavaType type )
138     {
139         if (type != null)
140         {
141             LOG.debug("Adding ValidateJavaType "+type);
142             this.validates.addElement( type );
143         }
144     }
145     
146     
147     public void addConfiguredValidateAnt( ValidateTaskType type )
148     {
149         if (type != null)
150         {
151             this.validates.addElement( type );
152         }
153     }
154     
155     
156     protected void verifySettings()
157             throws BuildException
158     {
159         if (isReference())
160         {
161             ((AbstractStateMachineType)getCheckedRef(
162                 AbstractStateMachineType.class, "state machine type" )).
163                 verifySettings();
164             return;
165         }
166         if (this.name == null)
167         {
168             throw new BuildException( "name not set", location );
169         }
170         if (this.validates.size() <= 0)
171         {
172             throw new BuildException( "no validation types registered",
173                 location );
174         }
175     }
176 }
177
178
Popular Tags