KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

61     public IsDirectory()
62     {
63         m_impl = new Available();
64     }
65
66
67     /**
68      * Creates a new pre-initialized IsDirectory condition.
69      * @param location location to be checked.
70      * @see #setLocation
71      **/

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

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

94     public void setLocation(String JavaDoc location)
95     {
96         require_(location!=null,"setname- nonzro location");
97         m_impl.setFile(new File JavaDoc(location));
98     }
99
100
101     /**
102      * Set the filepath to be used when searching for the directory.
103      * @param filepath a search path (non-null)
104      */

105     public void setFilepath(Path filepath)
106     {
107         require_(filepath!=null,"setFilepath- nonzro path");
108         m_impl.setFilepath(filepath);
109     }
110
111
112     /**
113      * Sets property name updated by <i>true</i> evaluation.
114      * @param property the property's name (non-null)
115      **/

116     public void setTrueProperty(String JavaDoc property)
117     {
118         require_(property!=null,"setTrueProp- nonzro name");
119         m_updateProperty = property;//NB:don't use available's property
120
}
121
122
123     /**
124      * Returns property name updated by evaluation method. Returns
125      * <i>null</i> if never set or value is an exported property.
126      **/

127     public final String JavaDoc getTrueProperty()
128     {
129         return m_updateProperty;
130     }
131
132
133
134     /**
135      * Sets this condition's location as part of a value URI.
136      * @param fragment the value uri bits (non-null)
137      */

138     public void xsetFromURI(String JavaDoc fragment)
139     {
140         setLocation(fragment);
141     }
142
143
144
145     /**
146      * Checks whether given location is a readable directory or not.
147      * @throws BuildException if incomplete set or unable to check condition
148      **/

149     public boolean eval() throws BuildException
150     {
151         verifyInProject_("eval");
152
153         boolean istrue = m_impl.eval();
154
155         if (istrue && m_updateProperty!=null) {
156             log("IsDirectory was true; setting true-property '"+m_updateProperty+
157                 "' property", Project.MSG_DEBUG);
158             getProject().setNewProperty(m_updateProperty,Strings.TRUE);
159         }
160
161         return istrue;
162     }
163
164
165     private Available m_impl;
166     private String JavaDoc m_updateProperty;
167 }
168
169 /* end-of-IsDirectory.java */
170
Popular Tags