Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

NSProperties


Inherits from:
Object
Package:
com.webobjects.foundation


Class Description


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.


Accessing the Properties

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 File

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.


Command Line Properties

The setPropertiesFromArgv method parses the command line arguments are recognizes the property formats listed in the table below.


Format Example
-Dkey=value -DWOPort=4321
-key value -WOAutoOpenInBrowser NO

Properties specified in these formats will be available as system properties after you invoke setPropertiesFromArgv.




Static Methods



arrayForKey

public static NSArray arrayForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



booleanForKey

public static boolean booleanForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



dataForKey

public static NSData dataForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



dictionaryForKey

public static NSDictionary dictionaryForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



doubleForKey

public static double doubleForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



floatForKey

public static float floatForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



integerForKey

public static int integerForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



longForKey

public static long longForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using 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.



setPropertiesFromArgv

public static void setPropertiesFromArgv(String[] argv)

Loads all of the application's properties and merges them with the Java System properties. This method obtains the properties (by invoking NSProperties's properties method) for every bundle in the application including the application and all of the frameworks it includes. It also merges any properties specified by the string array into the system properties.

stringForKey

public static String stringForKey(String key)

Deprecated in the Java Foundation framework. Don't use this method. Instead, get the system property using System.getProperty(key).

Equivalent to System.getProperty(key).



valuesFromArgv

public static NSDictionary valuesFromArgv(String[])

Description forthcoming.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents