KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > IsClass


1 /**
2  * $Id: IsClass.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2003 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.condition;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.taskdefs.Available;
34 import org.apache.tools.ant.taskdefs.condition.Condition;
35 import org.apache.tools.ant.types.Path;
36 import org.apache.tools.ant.types.Reference;
37
38 import com.idaremedia.antx.AssertableProjectComponent;
39 import com.idaremedia.antx.helpers.Strings;
40
41 /**
42  * Adapter that allows &lt;available class="&#46;&#46;&#46;"/&gt; to be inlined in
43  * boolean rules as &lt;require isclass="&#46;&#46;&#46;"/&gt;. Delegates to a private
44  * Available condition.
45  *
46  * @since JWare/AntX 0.1
47  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
48  * @version 0.5
49  * @.safety single (see Available)
50  * @.group impl,helper
51  * @.pattern GoF.Adapter
52  **/

53
54 public final class IsClass extends AssertableProjectComponent
55     implements Condition, URIable
56 {
57     /**
58      * Creates new IsClass condition.
59      **/

60     public IsClass()
61     {
62         m_impl = new Available();
63     }
64
65
66
67     /**
68      * Creates a new pre-initialized IsClass condition.
69      * @param value resource name/path to be located.
70      * @see #setName
71      **/

72     public IsClass(String JavaDoc value)
73     {
74         this();
75         setName(value);
76     }
77
78
79
80     /**
81      * Sets this condition's project; updates underlying available
82      * condition too.
83      **/

84     public void setProject(Project p)
85     {
86         super.setProject(p);
87         m_impl.setProject(p);
88     }
89
90
91
92     /**
93      * Sets the name of the class to be located.
94      * @param classname class name (non-null)
95      **/

96     public void setName(String JavaDoc classname)
97     {
98         require_(classname!=null,"setval- nonzro clazname");
99         m_impl.setClassname(classname);
100     }
101
102
103
104     /**
105      * Set the classpath to be used when searching for the class.
106      * @param classpath an search path (non-null)
107      */

108     public void setClasspath(Path classpath)
109     {
110         require_(classpath!=null,"setCP- nonzro cp");
111         m_impl.setClasspath(classpath);
112     }
113
114
115
116     /**
117      * Like {@linkplain #setClasspath setClasspath} but by reference.
118      * @param r a Reference to a Path instance to be used as classpath (non-null)
119      */

120     public void setClasspathRef(Reference r)
121     {
122         require_(r!=null,"setCPref- nonzro cp refid");
123         m_impl.setClasspathRef(r);
124     }
125
126
127
128     /**
129      * Sets whether Ant's runtime classes will be included in search
130      * classpath. "<i>true</i>" by default.
131      * @param include <i>false</i> if Ant's classes excluded
132      */

133     public void setSystemClasses(boolean include)
134     {
135         m_impl.setIgnoresystemclasses(!include);
136     }
137
138
139
140     /**
141      * Sets property name updated by <i>true</i> evaluation.
142      * @param property the property's name (non-null)
143      * @since JWare/AntX 0.3
144      **/

145     public void setTrueProperty(String JavaDoc property)
146     {
147         require_(property!=null,"setTrueProp- nonzro name");
148         m_updateProperty = property;//NB:don't use available's property
149
}
150
151
152
153     /**
154      * Returns property name updated by evaluation method. Returns
155      * <i>null</i> if never set or value is an exported property.
156      * @since JWare/AntX 0.3
157      **/

158     public final String JavaDoc getTrueProperty()
159     {
160         return m_updateProperty;
161     }
162
163
164
165     /**
166      * Sets this condition's target class name as part of a
167      * value URI.
168      * @param fragment the value uri bits (non-null)
169      * @since JWare/AntX 0.5
170      */

171     public void xsetFromURI(String JavaDoc fragment)
172     {
173         setName(fragment);
174     }
175
176
177
178     /**
179      * Checks whether given class exists (and is loadable) or not.
180      * @throws BuildException if incomplete set or unable to check condition
181      **/

182     public boolean eval() throws BuildException
183     {
184         verifyInProject_("eval");
185
186         boolean istrue = m_impl.eval();
187
188         if (istrue && m_updateProperty!=null) {
189             log("IsClass was true; setting true-property '"+m_updateProperty+
190                 "' property", Project.MSG_DEBUG);
191             getProject().setNewProperty(m_updateProperty,Strings.TRUE);
192         }
193
194         return istrue;
195     }
196
197
198     private Available m_impl;
199     private String JavaDoc m_updateProperty;
200 }
201
202 /* end-of-IsClass.java */
203
Popular Tags