KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > match > ChoiceTask


1 /**
2  * $Id: ChoiceTask.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2004 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 as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * 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 (GNU Lesser General Public License) 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 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.flowcontrol.match;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.Task;
34 import org.apache.tools.ant.types.Reference;
35
36 import com.idaremedia.antx.helpers.TaskHandle;
37 import com.idaremedia.antx.parameters.FlexValueSupport;
38 import com.idaremedia.antx.starters.Quiet;
39 import com.idaremedia.antx.starters.StrictInnerTaskSet;
40
41 /**
42  * Required superclass for any nested choice selector task. This class defines
43  * the required evaluation and filtering methods for all choice task sets.
44  *
45  * @since JWare/AntX 0.1
46  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
47  * @version 0.5
48  * @.safety single
49  * @.group impl,infra
50  * @see SwitchTask
51  **/

52
53 public abstract class ChoiceTask extends StrictInnerTaskSet
54     implements Quiet, FlexValueSupport
55 {
56     /**
57      * Initializes new choice task.
58      **/

59     protected ChoiceTask(String JavaDoc iam)
60     {
61         super(iam);
62     }
63
64
65
66     /**
67      * Initializes new choice task with custom delay configuration.
68      * @param iam CV-label
69      * @param delayConfiguration <i>true</i> if delay nested task configuration
70      **/

71     protected ChoiceTask(String JavaDoc iam, boolean delayConfiguration)
72     {
73         super(iam,delayConfiguration);
74     }
75
76
77
78     /**
79      * Returns this choice's underlying match value (as-is).
80      * @since JWare/AntX 0.2
81      **/

82     public abstract String JavaDoc getFlexValue();
83
84
85
86     /**
87      * Returns <i>true</i> if this choice has not been defined properly.
88      **/

89     public abstract boolean isUndefined();
90
91
92
93     /**
94      * Returns the actual value used in this choice's comparision. Returns
95      * <i>null</i> if value never defined or determined value doesn't
96      * exist; for example, if the named reference doesn't exist in project.
97      **/

98     public abstract String JavaDoc getVUT();
99
100
101
102     /**
103      * Returns <i>true</i> if task is not another choice task
104      * definition. Cannot nest choices directly into one another.
105      **/

106     protected boolean includeTask(TaskHandle taskH)
107     {
108         Task task = candidateTask(taskH,COI_);
109         return (task!=null) && !(task instanceof ChoiceTask);
110     }
111
112
113
114     /**
115      * Evaluates this choice's condition for a hit. Returns
116      * <i>true</i> if this choice's criteria are met by the incoming
117      * value under consideration.
118      * @param vut value under test (vut-vut)
119      * @param context [optional] evaluation context
120      * @throws BuildException if this task isn't nested properly
121      **/

122     public abstract boolean eval(String JavaDoc vut, Reference context)
123         throws BuildException;
124
125
126
127     /**
128      * Ensure this choice has had its match value assigned and exists
129      * within a valid block task.
130      **/

131     protected void verifyCanExecute_(String JavaDoc calr)
132     {
133         super.verifyCanExecute_(calr);
134
135         if (isUndefined()) {
136             String JavaDoc ermsg = uistrs().get("flow.switch.needs.value",getTaskName());
137             log(ermsg, Project.MSG_ERR);
138             throw new BuildException(ermsg,getLocation());
139         }
140     }
141
142
143
144     /**
145      * Controls the amount of peek-under for UnknownElement placeholders
146      * nested inside task containers.
147      * @since JWare/AntX 0.4
148      **/

149     private static final Class JavaDoc[] COI_= {
150         ChoiceTask.class
151     };
152 }
153
154 /* end-of-ChoiceTask.java */
155
Popular Tags