KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > ownhelpers > InnerProperties


1 /**
2  * $Id: InnerProperties.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 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 (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.ownhelpers;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33
34 import com.idaremedia.antx.AntX;
35 import com.idaremedia.antx.AssertableProjectComponent;
36 import com.idaremedia.antx.helpers.Tk;
37 import com.idaremedia.antx.parameters.IgnoreCaseEnabled;
38 import com.idaremedia.antx.parameters.PropertySource;
39
40 /**
41  * Custom &lt;propertyset&gt; that simplifies syntax for succinct inclusion in
42  * assertions and other AntX rules. Also supports the AntX nomenclature for a
43  * property's {@linkplain PropertySource source domain}.
44  * <p>
45  * Note that an <span class="src">InnerProperties</span>'s default domain is
46  * "<span class="src">script--</span>" <em>not</em> "<span class="src">all</span>".
47  * <p>
48  * For Example:<pre>
49  * &lt;allset malformed="reject"&gt;
50  * &lt;properties prefix="jware.antx." domain="all--"/&gt;
51  * &lt;properties like="^build\..*$"/&gt;
52  * &lt;properties prefix="build." ignorecase="yes"/&gt;
53  * &lt;/allset&gt;
54  * </pre>
55  *
56  * @since JWare/AntX 0.4
57  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
58  * @version 0.5
59  * @.safety single
60  * @.group api,helper
61  * @see PropertiesIterator
62  **/

63
64 public class InnerProperties extends AssertableProjectComponent
65     implements IgnoreCaseEnabled, Cloneable JavaDoc
66 {
67     private static final String JavaDoc PATTERN="like";
68     private static final String JavaDoc PREFIX="prefix";
69     private static final String JavaDoc NOTLIKE="notlike";
70
71
72     /**
73      * Initializes a new properties declaration.
74      **/

75     public InnerProperties()
76     {
77         super(AntX.nopackage);
78     }
79
80
81     /**
82      * Initializes a new utility properties
83      * declaration.
84      **/

85     public InnerProperties(String JavaDoc iam)
86     {
87         super(iam);
88     }
89
90
91
92     /**
93      * Returns a clone of this properties declaration.
94      * @since JWare/AntX 0.5
95      */

96     public Object JavaDoc clone()
97     {
98         try {
99             return super.clone();
100         } catch(CloneNotSupportedException JavaDoc clnX) {
101             throw new CloneBrokenError();
102         }
103     }
104
105
106
107     /**
108      * Defines a regular expression filter for properties.
109      **/

110     public void setLike(String JavaDoc pattern)
111     {
112         require_(!Tk.isWhitespace(pattern),"setLik- nonzro pattern");
113         setNewFilter(PATTERN,pattern);
114     }
115
116
117     /**
118      * Returns this declaration's regular expression filter.
119      * Returns <i>null</i> if never set.
120      **/

121     public String JavaDoc getLikeFilterPattern()
122     {
123         return getFilterParameter(PATTERN);
124     }
125
126
127     /**
128      * Defines a prefix filter for properties.
129      **/

130     public void setPrefix(String JavaDoc prefix)
131     {
132         require_(prefix!=null,"setPrefx- nonzro prefix");
133         setNewFilter(PREFIX,prefix);
134     }
135
136
137     /**
138      * Returns this declaration's prefix filter.
139      * Returns <i>null</i> if never set.
140      **/

141     public String JavaDoc getPrefixFilterPattern()
142     {
143         return getFilterParameter(PREFIX);
144     }
145
146
147     /**
148      * Defines a regular expression filter for excluded properties.
149      **/

150     public void setNotLike(String JavaDoc pattern)
151     {
152         require_(!Tk.isWhitespace(pattern),"setNotLik- nonzro pattern");
153         setNewFilter(NOTLIKE,pattern);
154     }
155
156
157     /**
158      * Returns this declaration's exclusion regular expression filter.
159      * Returns <i>null</i> if never set.
160      **/

161     public String JavaDoc getNotLikeFilterPattern()
162     {
163         return getFilterParameter(NOTLIKE);
164     }
165
166
167     /**
168      * Sets the source of this declaration's properties. This setter
169      * allows all the synonyms for the AntX property sources that
170      * are compatible with Ant's own &lt;propertyset&gt;'s
171      * <span class="src">builtin</span> parameter.
172      * @param domainname symbolic name of domain (synonyms allowed)
173      **/

174     public void setDomain(String JavaDoc domainname)
175     {
176         PropertySource domain = PropertySource.from(domainname);
177         require_(domain!=null,"setDomain- nonzro domain");
178         m_domain = domain;
179     }
180
181
182     /**
183      * Returns the source of this declaration's properties.
184      * Returns {@linkplain PropertySource#SCRIPTlite} if
185      * never set explicitly.
186      **/

187     public PropertySource getDomain()
188     {
189         return m_domain;
190     }
191
192
193     /**
194      * Tells this declaration to ignore case (or not)
195      * in filters.
196      * @param ignore <i>true</i> to ignore
197      **/

198     public void setIgnoreCase(boolean ignore)
199     {
200         m_ignoreCase = ignore;
201     }
202
203
204     /**
205      * Returns <i>true</i> if this declaration wants
206      * case-insensitive filtering. Is <i>false</i> by default.
207      **/

208     public boolean isIgnoreCase()
209     {
210         return m_ignoreCase;
211     }
212
213
214     /**
215      * Called whenever a filter is defined; ensures at most one
216      * filter is defined.
217      **/

218     private void setNewFilter(String JavaDoc choice, String JavaDoc param)
219     {
220         if (m_filterType!=null) {
221             String JavaDoc error = uistrs().get
222                 ("task.one.or.other.attr","like","prefix");
223             log(error, Project.MSG_ERR);
224             throw new BuildException(error);
225         }
226         m_filterType = choice;
227         m_filterParameter = param;
228     }
229
230
231     /**
232      * Returns the filter parameter string if if the caller's
233      * type matches what was set. Otherwise, returns <i>null</i>.
234      **/

235     private String JavaDoc getFilterParameter(String JavaDoc choice)
236     {
237         return (m_filterType==choice) ? m_filterParameter : null;
238     }
239
240
241     private String JavaDoc m_filterType;
242     private String JavaDoc m_filterParameter;
243     private PropertySource m_domain = PropertySource.SCRIPTlite;
244     private boolean m_ignoreCase;
245 }
246
247 /* end-of-InnerProperties.java */
248
Popular Tags