KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: IsResource.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 resource="&#46;&#46;&#46;"/&gt; to be inlined in
43  * boolean rules as &lt;require isresource="&#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 IsResource extends AssertableProjectComponent
55     implements Condition, URIable
56 {
57     /**
58      * Creates new IsResource condition.
59      **/

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

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

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

93     public void setName(String JavaDoc resource)
94     {
95         require_(resource!=null,"setval- nonzro rsrc name");
96         m_impl.setResource(resource);
97     }
98
99
100     /**
101      * Set the classpath to be used when searching for the resource.
102      * @param classpath an search path (non-null)
103      */

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

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

127     public void setSystemClasses(boolean include)
128     {
129         m_impl.setIgnoresystemclasses(!include);
130     }
131
132
133     /**
134      * Sets property name updated by <i>true</i> evaluation.
135      * @param property the property's name (non-null)
136      * @since JWare/AntX 0.3
137      **/

138     public void setTrueProperty(String JavaDoc property)
139     {
140         require_(property!=null,"setTrueProp- nonzro name");
141         m_updateProperty = property;//NB:don't use available's property
142
}
143
144
145     /**
146      * Returns property name updated by evaluation method. Returns
147      * <i>null</i> if never set or value is an exported property.
148      * @since JWare/AntX 0.3
149      **/

150     public final String JavaDoc getTrueProperty()
151     {
152         return m_updateProperty;
153     }
154
155
156
157     /**
158      * Sets this condition's name as part of a value URI.
159      * @param fragment the value uri bits (non-null)
160      * @since JWare/AntX 0.5
161      */

162     public void xsetFromURI(String JavaDoc fragment)
163     {
164         setName(fragment);
165     }
166
167
168     /**
169      * Checks whether given resource exists (and is loadable) or not.
170      * @throws BuildException if incomplete set or unable to check condition
171      **/

172     public boolean eval() throws BuildException
173     {
174         verifyInProject_("eval");
175
176         boolean istrue = m_impl.eval();
177
178         if (istrue && m_updateProperty!=null) {
179             log("IsResource was true; setting true-property '"+m_updateProperty+
180                 "' property", Project.MSG_DEBUG);
181             getProject().setNewProperty(m_updateProperty,Strings.TRUE);
182         }
183
184         return istrue;
185     }
186
187
188     private Available m_impl;
189     private String JavaDoc m_updateProperty;
190 }
191
192 /* end-of-IsResource.java */
193
Popular Tags