PATH |
- Inherits from:
- Object
- Package:
- com.webobjects.foundation
The NSProperties class enhances Java's properties mechanism to merge application properties with the standard system properties available using the java.lang.System.getProperties() method. The application properties can come from three sources: the command line, the application's Properties
file, and the Properties
files of any frameworks your application includes.
This class has only static methods and cannot be instantiated.
To access the application properties you first need to merge the application and command line properties with the system properties. A WebObjects application automatically performs this step for you. You can then access the property as a string, and convert the string to the property's actual data type.
To obtain the application properties and merge them with the system properties you invoke setPropertiesFromArgv. Application properties can come from the application's Properties
file, the Properties
files for the frameworks the application includes, and the command line. For more information about Properties
files, see "The Properties File" (page 238). For more information about specifying properties on the command line, see "Command Line Properties" (page 238).
Every property is a key-value pair. For example, on Unix machines, the property value for the key "file.separator" is "/". To access a property corresponding to a particular key, use the java.lang.System.getProperty method. This method returns the property as a string.
If the property string represents a boolean value, NSArray, or NSDictionary you need to convert it to the appropriate data type using the NSPropertyListSerialization booleanForString, arrayForString, or dictionaryForString method, respectively. NSPropertyListSerialization also provides an intForString method to simplify converting a property string to an integer.
The properties must be stored in a file named Properties
in the application or framework's Resources
directory. You can add a Properties
file to your application or framework by adding it to the Resources suitcase in Project Builder.
The Properties file must be in the format specified by java.io.Properties. See Sun's documentation for the load method in that class for the format specification.
Boolean values, NSArrays, and NSDictionaries must be specified using the property list representation. See the NSPropertyListSerialization class description for more information on property lists.
The setPropertiesFromArgv method parses the command line arguments are recognizes the property formats listed in the table below.
Format | Example |
-D key= value |
-DWOPort=4321 |
- key value |
-WOAutoOpenInBrowser NO |
Properties specified in these formats will be available as system properties after you invoke setPropertiesFromArgv.
public static NSArray arrayForKey(String key)
System.getProperty(key)
and convert it to an NSArray using NSPropertyListSerialization's arrayForString method.
Returns the system property with the specified name as an NSArray or null
if no system property with that name exists. Throws a NullPointerException if key is null
.
public static boolean booleanForKey(String key)
System.getProperty(key)
and convert it to a boolean
using NSPropertyListSerialization's booleanForString method.
Returns the system property with the specified name as a boolean
. Returns false
if no system property with that name exists. Throws a NullPointerException if key is null
.
public static NSData dataForKey(String key)
System.getProperty(key)
, convert it to a property list using NSPropertyListSerialization's propertyListFromString method, and convert the property list to an NSData object using NSPropertyListSerialization's dataFromPropertyList method.
Interprets the system property with the specified name as a string representation of a property list, converts it to bytes using the current encoding, and stores the result in an NSData object. Returns null
if no system property with that name exists. Throws a NullPointerException if key is null
.
public static NSDictionary dictionaryForKey(String key)
System.getProperty(key)
and convert it to an NSDictionary using NSPropertyListSerialization's dictionaryForString method.
Returns the system property with the specified name as an NSDictionary. Returns null
if no system property with that name exists. Throws a NullPointerException if key is null
.
public static double doubleForKey(String key)
System.getProperty(key)
and convert it to a double
.
Returns the system property with the specified name as a double
. Returns 0 if no system property with that name exists. Throws a NullPointerException if key is null
.
public static float floatForKey(String key)
System.getProperty(key)
and convert it to a float
.
Returns the system property with the specified name as a float
. Returns 0 if no system property with that name exists. Throws a NullPointerException if key is null
.
public static int integerForKey(String key)
System.getProperty(key)
and convert it to an int
using NSPropertyListSerialization's intForString method.
Returns the system property with the specified name as an int
. Returns 0 if no system property with that name exists. Throws a NullPointerException if key is null
.
public static long longForKey(String key)
System.getProperty(key)
and convert it to a long
.
Returns the system property with the specified name as a long
. Returns 0 if no system property with that name exists. Throws a NullPointerException if key is null
.
public static void setPropertiesFromArgv(String[] argv)
public static String stringForKey(String key)
System.getProperty(key)
.
Equivalent to System.getProperty(key)
.
public static NSDictionary valuesFromArgv(String[])
© 2001 Apple Computer, Inc. (Last Published April 17, 2001)