KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > property > Property


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util.property;
23
24 import java.security.AccessController JavaDoc;
25 import java.security.PrivilegedAction JavaDoc;
26
27 /**
28  * Provides shorter method names for working with the {@link PropertyManager}.
29  *
30  * @version <tt>$Revision: 1958 $</tt>
31  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
32  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
33  */

34 public final class Property
35 {
36    /** Platform dependent line separator. */
37    public static String JavaDoc LINE_SEPARATOR;
38
39    /** Platform dependant file separator. */
40    public static String JavaDoc FILE_SEPARATOR;
41
42    /** Platform dependant path separator. */
43    public static String JavaDoc PATH_SEPARATOR;
44    
45    static
46    {
47       PrivilegedAction JavaDoc action = new PrivilegedAction JavaDoc()
48       {
49          public Object JavaDoc run()
50          {
51             LINE_SEPARATOR = Property.get("line.separator");
52             FILE_SEPARATOR = Property.get("file.separator");
53             PATH_SEPARATOR = Property.get("path.separator");
54             return null;
55          }
56       };
57       AccessController.doPrivileged(action);
58    }
59    
60    /**
61     * Add a property listener
62     *
63     * @param listener Property listener to add
64     */

65    public static void addListener(PropertyListener listener)
66    {
67       PropertyManager.addPropertyListener(listener);
68    }
69
70    /**
71     * Add an array of property listeners
72     *
73     * @param listeners Array of property listeners to add
74     */

75    public static void addListeners(PropertyListener[] listeners)
76    {
77       PropertyManager.addPropertyListeners(listeners);
78    }
79
80    /**
81     * Remove a property listener
82     *
83     * @param listener Property listener to remove
84     * @return True if listener was removed
85     */

86    public static boolean removeListener(PropertyListener listener)
87    {
88       return PropertyManager.removePropertyListener(listener);
89    }
90
91    /**
92     * Set a property
93     *
94     * @param name Property name
95     * @param value Property value
96     * @return Previous property value or null
97     */

98    public static String JavaDoc set(String JavaDoc name, String JavaDoc value)
99    {
100       return PropertyManager.setProperty(name, value);
101    }
102
103    /**
104     * Remove a property
105     *
106     * @param name Property name
107     * @return Removed property value or null
108     */

109    public static String JavaDoc remove(String JavaDoc name)
110    {
111       return PropertyManager.getProperty(name);
112    }
113
114    /**
115     * Get a property
116     *
117     * @param name Property name
118     * @param defaultValue Default property value
119     * @return Property value or default
120     */

121    public static String JavaDoc get(String JavaDoc name, String JavaDoc defaultValue)
122    {
123       return PropertyManager.getProperty(name, defaultValue);
124    }
125
126    /**
127     * Get a property
128     *
129     * @param name Property name
130     * @return Property value or null
131     */

132    public static String JavaDoc get(String JavaDoc name)
133    {
134       return PropertyManager.getProperty(name);
135    }
136
137    /**
138     * Get an array style property
139     *
140     * @param base Base property name
141     * @param defaultValues Default property values
142     * @return Array of property values or default
143     */

144    public static String JavaDoc[] getArray(String JavaDoc base, String JavaDoc[] defaultValues)
145    {
146       return PropertyManager.getArrayProperty(base, defaultValues);
147    }
148
149    /**
150     * Get an array style property
151     *
152     * @param name Property name
153     * @return Array of property values or empty array
154     */

155    public static String JavaDoc[] getArray(String JavaDoc name)
156    {
157       return PropertyManager.getArrayProperty(name);
158    }
159
160    /**
161     * Check if a property of the given name exists.
162     *
163     * @param name Property name
164     * @return True if property exists
165     */

166    public static boolean exists(String JavaDoc name)
167    {
168       return PropertyManager.containsProperty(name);
169    }
170
171    /**
172     * Get a property group for the given property base
173     *
174     * @param basename Base property name
175     * @return Property group
176     */

177    public static PropertyGroup getGroup(String JavaDoc basename)
178    {
179       return PropertyManager.getPropertyGroup(basename);
180    }
181
182    /**
183     * Get a property group for the given property base at the given index
184     *
185     * @param basename Base property name
186     * @param index Array property index
187     * @return Property group
188     */

189    public static PropertyGroup getGroup(String JavaDoc basename, int index)
190    {
191       return PropertyManager.getPropertyGroup(basename, index);
192    }
193 }
194
Popular Tags