KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > util > variable > SystemPropertyExpanderStrategy


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.util.variable;
8
9
10 import com.inversoft.util.StringTools;
11
12
13 /**
14  * This class is the System property implementation of
15  * the ExpanderStrategy interface. This expands the
16  * variable name into the value of a System property with
17  * the same name.
18  *
19  * @author Brian Pontarelli
20  * @since 1.0
21  * @version 1.0
22  */

23 public class SystemPropertyExpanderStrategy implements ExpanderStrategy {
24
25     /**
26      * Constructs a new <code>SystemPropertyExpanderStrategy</code>.
27      */

28     public SystemPropertyExpanderStrategy() {
29     }
30
31
32     /**
33      * Expands the given variable into the value of the System property with
34      * the same, name. If there is no system property with the given name, then
35      * an ExpanderException is thrown
36      *
37      * @param variableName The name of the System Property whose value to
38      * return
39      * @return The value of the System property with the name given
40      * @throws ExpanderException If there is no System property with the given
41      * name
42      * @since 1.0
43      */

44     public String JavaDoc expand(String JavaDoc variableName) throws ExpanderException {
45
46         assert (!StringTools.isEmpty(variableName)) : "variableName is empty";
47
48         String JavaDoc value = System.getProperty(variableName);
49         if (value == null) {
50             throw new ExpanderException("No System property with the name: " +
51                 variableName);
52         }
53
54         return value;
55     }
56 }
57
58
Popular Tags