KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > solo > RuleMacroDef


1 /**
2  * $Id: RuleMacroDef.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.condition.solo;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Task;
33 import org.apache.tools.ant.taskdefs.MacroDef;
34
35 import com.idaremedia.antx.AntX;
36 import com.idaremedia.antx.NoiseLevel;
37 import com.idaremedia.antx.starters.MacroMaker;
38
39 /**
40  * Macro maker that enforces a macro's definition to constraints of an AntX build rule.
41  * However, unlike an AntX build rule, you can include batch checks in a rule macrodef.
42  *
43  * @since JWare/AntX 0.4
44  * @author ssmc, &copy;2004-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
45  * @version 0.5
46  * @.safety single
47  * @.group api,infra
48  * @.pattern GoF.Proxy
49  * @see BuildRule
50  **/

51
52 public final class RuleMacroDef extends MacroMaker
53 {
54     private static final String JavaDoc IAM_= AntX.conditions+"rulemacro";
55
56     /**
57      * Initializes a new rule macro instance.
58      **/

59     public RuleMacroDef()
60     {
61         super(IAM_);
62     }
63
64
65     /**
66      * Initializes a new enclosed macro instance.
67      * @param iam CV-label (non-null)
68      **/

69     public RuleMacroDef(String JavaDoc iam)
70     {
71         super(iam);
72     }
73
74
75     /**
76      * Adds a new attribute definition to this rule macro.
77      * @param attr the attribute definition (non-null)
78      **/

79     public final void addConfiguredAttribute(MacroDef.Attribute attr)
80     {
81         addMacroParameter(attr);
82     }
83
84
85     /**
86      * Returns the supposed effect if this macro evaluates
87      * <i>false</i>. Should be called after this rule is fully
88      * configured.
89      **/

90     public NoiseLevel getFailureEffect()
91     {
92         return m_failureEffect;
93     }
94
95
96     /**
97      * Allows only sub-rules (of single effect) to this rule macro. If
98      * the new item is the first sub-rule defined, it determines the kind
99      * of subsequent sub-rules allowed. If the item is a rule, it must
100      * be of the expected (dominant) type. Note that fixture checks are
101      * always allowed.
102      * @param taskClass class of task to be instantiated in macro instance
103      * @param taskProxy task proxy (UnknownElement), non-null
104      * @throws BuildException if task of wrong kind
105      **/

106     protected boolean includeTask(Class JavaDoc taskClass, Task taskProxy)
107         throws BuildException
108     {
109         if (VerifyFixture.class.isAssignableFrom(taskClass)) {//always
110
return true;
111         }
112
113         boolean isRequire = isRequireType(taskClass);
114         boolean isPrefer = !isRequire && PreferTask.class.isAssignableFrom(taskClass);
115
116         if (!isRequire && !isPrefer) {
117             return false;
118         }
119
120         if (m_failureEffect!=null) {
121             BuildRule.checkAcceptable(this,isRequire,m_failureEffect);
122         } else if (isRequire) {
123             m_failureEffect = NoiseLevel.ERROR;
124         } else {
125             m_failureEffect = NoiseLevel.WARNING;
126         }
127
128         return true;
129     }
130
131
132
133     private boolean isRequireType(Class JavaDoc taskClass)
134     {
135         return AssertTask.class.isAssignableFrom(taskClass) ||
136                BatchChecksTaskSet.class.isAssignableFrom(taskClass);
137     }
138
139
140     private NoiseLevel m_failureEffect=null;//NB: unknown->defined by 1st subrule
141
}
142
143 /* end-of-RuleMacroDef.java */
144
Popular Tags