KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > KillMethodSkeleton


1 /**
2  * $Id: KillMethodSkeleton.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2004-2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx;
30
31 import org.apache.tools.ant.Project;
32
33 import com.idaremedia.antx.apis.ProblemHandler;
34 import com.idaremedia.antx.apis.Responses;
35 import com.idaremedia.antx.helpers.Strings;
36
37 /**
38  * Starter implementation of a fixture cleanup callback. Subclasses should fill in
39  * the specific kill method (context,default,current) that applies.
40  *
41  * @since JWare/AntX 0.4
42  * @author ssmc, &copy;2004-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
43  * @version 0.5
44  * @.safety single
45  * @.group impl,helper
46  **/

47
48 public class KillMethodSkeleton implements KillMethod
49 {
50     /**
51      * Initializes a new silent killer of nothing and everything.
52      **/

53     protected KillMethodSkeleton()
54     {
55     }
56
57
58
59     /**
60      * Initializes a general fixture administrator kill method.
61      * @param FXID the administrator's iteration identifier
62      * @param name a script-facing label for administrator
63      * @see FixtureIds
64      **/

65     public KillMethodSkeleton(String JavaDoc FXID, String JavaDoc name)
66     {
67         m_FXID = FXID;
68         m_name = name;
69     }
70
71
72
73     /**
74      * Return <i>true</i> if this kill method understands target.
75      * @param target symbolic name of thing to be killed
76      **/

77     public boolean canKill(String JavaDoc target)
78     {
79         return true;
80     }
81
82
83
84     /**
85      * Returns the fixture component's FixtureOverlays identifier.
86      **/

87     protected String JavaDoc getComponentId()
88     {
89         AntX.verify_(m_FXID!=null,"Fixture.KillMethod:","nonzro FXId");
90         return m_FXID;
91     }
92
93
94
95     /**
96      * Returns the fixture component's general classification.
97      * By default just returns value of {@linkplain #getComponentId}.
98      **/

99     protected String JavaDoc getComponentName()
100     {
101         return m_name!=null ? m_name : getComponentId();
102     }
103
104
105
106     /**
107      * Calls {@linkplain #kill(String,ProblemHandler) kill(String,Source)}
108      * with symbolic "<span class="src">all</span>" target string.
109      * @param from controlling task (non-null)
110      **/

111     public final boolean kill(ProblemHandler from)
112     {
113         return kill(Strings.ALL,from);
114     }
115
116
117
118     /**
119      * Should unset the default (fall back) fixture component.
120      * This version does nothing by default; subclasses can
121      * customize.
122      * @param from controlling task (non-null)
123      **/

124     protected boolean killDefault(ProblemHandler from)
125     {
126         return true;
127     }
128
129
130
131     /**
132      * Removes all the fixture component's information from the
133      * FixtureOverlays stack. Operation is thread-bound; only affects
134      * the current thread's iteration information.
135      * @param from controlling task (non-null)
136      **/

137     protected boolean killContext(ProblemHandler from)
138     {
139         FixtureOverlays overlays = FixtureOverlays.getContextInstance();
140         overlays.clear(getComponentId());
141         return true;
142     }
143
144
145
146     /**
147      * Removes the frontmost component instance from the
148      * FixtureOverlays stack. Operation is thread-bound; only affects
149      * the current thread's iteration information.
150      * @param from controlling task (non-null)
151      **/

152     protected boolean killCurrent(ProblemHandler from)
153     {
154         Responses.LitmusResult result= new Responses.LitmusResult();
155         FixtureOverlays.uninstallIfIs(getComponentId(),result,getComponentName());
156         if (result.hadProblem) {
157             from.problem(result.what,Project.MSG_WARN);
158         }
159         return !result.hadProblem;
160     }
161
162
163
164     /**
165      * Based on the requested target, removes or resets some aspect
166      * of this method's associated fixture component.
167      * @param target symbolic name of thing to be affected
168      * @param from controlling task or test (non-null)
169      **/

170     public boolean kill(String JavaDoc target, ProblemHandler from)
171     {
172         AntX.require_(from!=null,"Fixture.KillMethod:","kill- nonzro src");
173         if (Strings.ALL.equals(target)) {
174             return killContext(from) && killDefault(from);
175         } else if (Strings.CURRENT.equals(target)) {
176             return killCurrent(from);
177         } else if (Strings.CONTEXT.equals(target)) {
178             return killContext(from);
179         } else if (Strings.DEFAULT.equals(target)) {
180             return killDefault(from);
181         }
182         return true;
183     }
184
185
186     private String JavaDoc m_FXID,m_name;
187 }
188
189 /* end-of-KillMethodSkeleton.java */
190
Popular Tags