KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > slide > impl > SlideConfigurationAdapter


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.slide.impl;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.slide.util.conf.Configuration;
23 import org.apache.slide.util.conf.ConfigurationException;
24
25 /**
26  * The class represent an adapter for the configuration class from jakarta slide
27  *
28  * @version CVS $Id: SlideConfigurationAdapter.java 36347 2004-08-13 13:44:19Z unico $
29  */

30 public class SlideConfigurationAdapter implements Configuration {
31
32     private org.apache.avalon.framework.configuration.Configuration configuration;
33
34     /**
35      * Create a new adapter to map a Avalon configuration
36      * to a Slide configuration
37      *
38      * @param configuration Avalon configuration
39      */

40     public SlideConfigurationAdapter(org.apache.avalon.framework.configuration.Configuration configuration) {
41         this.configuration = configuration;
42     }
43
44     /**
45      * Return the name of the node.
46      *
47      * @return name of the <code>Configuration</code> node.
48      */

49     public String JavaDoc getName() {
50         return this.configuration.getName();
51     }
52
53     /**
54      * Return a new <code>Configuration</code> instance encapsulating the
55      * specified child node.
56      *
57      * @param child The name of the child node.
58      *
59      * @return Configuration
60      *
61      * @throws ConfigurationException If no child with that name exists.
62      */

63     public Configuration getConfiguration(String JavaDoc child)
64       throws ConfigurationException {
65         if (this.configuration.getChild(child, false) == null)
66             throw new ConfigurationException("No configuration element " + child
67                     + " at " + this.configuration.getLocation(), this);
68         return new SlideConfigurationAdapter(this.configuration.getChild(child));
69     }
70
71     /**
72      * Return an <code>Enumeration</code> of <code>Configuration<code>
73      * elements containing all node children with the specified name.
74      *
75      * @param name The name of the children to get.
76      *
77      * @return Enumeration. The <code>Enumeration</code> will be
78      * empty if there are no nodes by the specified name.
79      */

80     public Enumeration JavaDoc getConfigurations(String JavaDoc name) {
81
82         Vector JavaDoc configurations = new Vector JavaDoc();
83         org.apache.avalon.framework.configuration.Configuration[] childs = this.configuration.getChildren(name);
84
85         for (int i = 0; i<childs.length; i++) {
86             configurations.addElement(new SlideConfigurationAdapter(childs[i]));
87         }
88         return configurations.elements();
89     }
90
91     /**
92      * Return the value of specified attribute.
93      *
94      * @param paramName The name of the parameter you ask the value of.
95      *
96      * @return String value of attribute.
97      *
98      * @throws ConfigurationException If no attribute with that name exists.
99      */

100     public String JavaDoc getAttribute(String JavaDoc paramName)
101       throws ConfigurationException {
102
103         try {
104             return this.configuration.getAttribute(paramName);
105         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
106             throw new ConfigurationException(ce.getMessage(), this);
107         }
108     }
109
110     /**
111      * Return the <code>int</code> value of the specified attribute contained
112      * in this node.
113      *
114      * @param paramName The name of the parameter you ask the value of.
115      *
116      * @return int value of attribute
117      *
118      * @throws ConfigurationException If no parameter with that name exists.
119      * or if conversion to <code>int</code> fails.
120      */

121     public int getAttributeAsInt(String JavaDoc paramName)
122       throws ConfigurationException {
123
124         try {
125             return this.configuration.getAttributeAsInteger(paramName);
126         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
127             throw new ConfigurationException(ce.getMessage(), this);
128         }
129     }
130
131     /**
132      * Returns the value of the attribute specified by its name as a
133      * <code>long</code>.
134      *
135      *
136      * @param name
137      *
138      * @return long value of attribute
139      *
140      * @throws ConfigurationException If no parameter with that name exists.
141      * or if conversion to <code>long</code> fails.
142      */

143     public long getAttributeAsLong(String JavaDoc name)
144       throws ConfigurationException {
145
146         try {
147             return this.configuration.getAttributeAsLong(name);
148         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
149             throw new ConfigurationException(ce.getMessage(), this);
150         }
151     }
152
153     /**
154      * Return the <code>float</code> value of the specified parameter contained
155      * in this node.
156      *
157      * @param paramName The name of the parameter you ask the value of.
158      *
159      * @return float value of attribute
160      *
161      * @throws ConfigurationException If no parameter with that name exists.
162      * or if conversion to <code>float</code> fails.
163      */

164     public float getAttributeAsFloat(String JavaDoc paramName)
165       throws ConfigurationException {
166
167         try {
168             return this.configuration.getAttributeAsFloat(paramName);
169         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
170             throw new ConfigurationException(ce.getMessage(), this);
171         }
172     }
173
174     /**
175      * Return the <code>boolean</code> value of the specified parameter contained
176      * in this node.<br>
177      *
178      * @param paramName The name of the parameter you ask the value of.
179      *
180      * @return boolean value of attribute
181      *
182      * @throws ConfigurationException If no parameter with that name exists.
183      * or if conversion to <code>boolean</code> fails.
184      */

185     public boolean getAttributeAsBoolean(String JavaDoc paramName)
186       throws ConfigurationException {
187
188         try {
189             return this.configuration.getAttributeAsBoolean(paramName);
190         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
191             throw new ConfigurationException(ce.getMessage(), this);
192         }
193     }
194
195     /**
196      * Return the <code>String</code> value of the node.
197      *
198      * @return the value of the node.
199      */

200     public String JavaDoc getValue() {
201
202         try {
203             return this.configuration.getValue();
204         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
205             return "";
206         }
207     }
208
209     /**
210      * Return the <code>int</code> value of the node.
211      *
212      * @return the value of the node.
213      *
214      * @throws ConfigurationException If conversion to <code>int</code> fails.
215      */

216     public int getValueAsInt() throws ConfigurationException {
217
218         try {
219             return this.configuration.getValueAsInteger();
220         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
221             throw new ConfigurationException(ce.getMessage(), this);
222         }
223     }
224
225     /**
226      * Return the <code>float</code> value of the node.
227      *
228      * @return the value of the node.
229      *
230      * @throws ConfigurationException If conversion to <code>float</code> fails.
231      */

232     public float getValueAsFloat() throws ConfigurationException {
233
234         try {
235             return this.configuration.getValueAsFloat();
236         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
237             throw new ConfigurationException(ce.getMessage(), this);
238         }
239     }
240
241     /**
242      * Return the <code>boolean</code> value of the node.
243      *
244      * @return the value of the node.
245      *
246      * @throws ConfigurationException If conversion to <code>boolean</code> fails.
247      */

248     public boolean getValueAsBoolean() throws ConfigurationException {
249
250         try {
251             return this.configuration.getValueAsBoolean();
252         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
253             throw new ConfigurationException(ce.getMessage(), this);
254         }
255     }
256
257     /**
258      * Return the <code>long</code> value of the node.<br>
259      *
260      * @return the value of the node.
261      *
262      * @throws ConfigurationException If conversion to <code>long</code> fails.
263      */

264     public long getValueAsLong() throws ConfigurationException {
265
266         try {
267             return this.configuration.getValueAsLong();
268         } catch (org.apache.avalon.framework.configuration.ConfigurationException ce) {
269             throw new ConfigurationException(ce.getMessage(), this);
270         }
271     }
272
273     /**
274      * Returns the value of the configuration element as a <code>String</code>.
275      * If the configuration value is not set, the default value will be
276      * used.
277      *
278      * @param defaultValue The default value desired.
279      *
280      * @return String value of the <code>Configuration</code>, or default
281      * if none specified.
282      */

283     public String JavaDoc getValue(String JavaDoc defaultValue) {
284
285         return this.configuration.getValue(defaultValue);
286     }
287
288     /**
289      * Returns the value of the configuration element as an <code>int</code>.
290      * If the configuration value is not set, the default value will be
291      * used.
292      *
293      * @param defaultValue The default value desired.
294      *
295      * @return int value of the <code>Configuration</code>, or default
296      * if none specified.
297      */

298     public int getValueAsInt(int defaultValue) {
299
300         return this.configuration.getValueAsInteger(defaultValue);
301     }
302
303     /**
304      * Returns the value of the configuration element as a <code>long</code>.
305      * If the configuration value is not set, the default value will be
306      * used.
307      *
308      * @param defaultValue The default value desired.
309      *
310      * @return long value of the <code>Configuration</code>, or default
311      * if none specified.
312      */

313     public long getValueAsLong(long defaultValue) {
314
315         return this.configuration.getValueAsLong(defaultValue);
316     }
317
318     /**
319      * Returns the value of the configuration element as a <code>float</code>.
320      * If the configuration value is not set, the default value will be
321      * used.
322      *
323      * @param defaultValue The default value desired.
324      *
325      * @return float value of the <code>Configuration</code>, or default
326      * if none specified.
327      */

328     public float getValueAsFloat(float defaultValue) {
329
330         return this.configuration.getValueAsFloat(defaultValue);
331     }
332
333     /**
334      * Returns the value of the configuration element as a <code>boolean</code>.
335      * If the configuration value is not set, the default value will be
336      * used.
337      *
338      * @param defaultValue The default value desired.
339      *
340      * @return boolean value of the <code>Configuration</code>, or default
341      * if none specified.
342      */

343     public boolean getValueAsBoolean(boolean defaultValue) {
344
345         return this.configuration.getValueAsBoolean(defaultValue);
346     }
347
348     /**
349      * Returns the value of the attribute specified by its name as a
350      * <code>String</code>, or the default value if no attribute by
351      * that name exists or is empty.
352      *
353      * @param name The name of the attribute you ask the value of.
354      * @param defaultValue The default value desired.
355      *
356      * @return String value of attribute. It will return the default
357      * value if the named attribute does not exist, or if
358      * the value is not set.
359      */

360     public String JavaDoc getAttribute(String JavaDoc name, String JavaDoc defaultValue) {
361
362         return this.configuration.getAttribute(name, defaultValue);
363     }
364
365     /**
366      * Returns the value of the attribute specified by its name as a
367      * <code>int</code>, or the default value if no attribute by
368      * that name exists or is empty.
369      *
370      * @param name The name of the attribute you ask the value of.
371      * @param defaultValue The default value desired.
372      *
373      * @return int value of attribute. It will return the default
374      * value if the named attribute does not exist, or if
375      * the value is not set.
376      */

377     public int getAttributeAsInt(String JavaDoc name, int defaultValue) {
378
379         return this.configuration.getAttributeAsInteger(name, defaultValue);
380     }
381
382     /**
383      * Returns the value of the attribute specified by its name as a
384      * <code>long</code>, or the default value if no attribute by
385      * that name exists or is empty.
386      *
387      * @param name The name of the attribute you ask the value of.
388      * @param defaultValue The default value desired.
389      *
390      * @return long value of attribute. It will return the default
391      * value if the named attribute does not exist, or if
392      * the value is not set.
393      */

394     public long getAttributeAsLong(String JavaDoc name, long defaultValue) {
395
396         return this.configuration.getAttributeAsLong(name, defaultValue);
397     }
398
399     /**
400      * Returns the value of the attribute specified by its name as a
401      * <code>float</code>, or the default value if no attribute by
402      * that name exists or is empty.
403      *
404      * @param name The name of the attribute you ask the value of.
405      * @param defaultValue The default value desired.
406      *
407      * @return float value of attribute. It will return the default
408      * value if the named attribute does not exist, or if
409      * the value is not set.
410      */

411     public float getAttributeAsFloat(String JavaDoc name, float defaultValue) {
412
413         return this.configuration.getAttributeAsFloat(name, defaultValue);
414     }
415
416     /**
417      * Returns the value of the attribute specified by its name as a
418      * <code>boolean</code>, or the default value if no attribute by
419      * that name exists or is empty.
420      *
421      * @param name The name of the attribute you ask the value of.
422      * @param defaultValue The default value desired.
423      *
424      * @return boolean value of attribute. It will return the default
425      * value if the named attribute does not exist, or if
426      * the value is not set.
427      */

428     public boolean getAttributeAsBoolean(String JavaDoc name, boolean defaultValue) {
429
430         return this.configuration.getAttributeAsBoolean(name, defaultValue);
431     }
432
433     /**
434      * Return a <code>String</code> indicating the position of this
435      * configuration element in a source file or URI.
436      *
437      * @return String if a source file or URI is specified. Otherwise
438      * it returns <code>null</code>
439      */

440     public String JavaDoc getLocation() {
441
442         return this.configuration.getLocation();
443     }
444 }
445
Popular Tags