Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Znav
nextReading Properties
prevCommand-Line Parsing and Initialization

You can use the same configuration file and command-line mechanisms to set application-specific properties. For example, we could introduce a property to control the maximum file size for our file system application:

Wiki Markup
{zcode}
# Configuration file for file system application

Filesystem.MaxFileSize=1024    # Max file size in kB
{zcode}

The Ice run time stores the Filesystem.MaxFileSize property like any other property and makes it accessible via the Properties interface.

To access property values from within your program, you need to acquire the communicator's properties by calling getProperties:

Wiki Markup
{zcode:slice}
module Ice {

    local interface Properties; // Forward declaration

    local interface Communicator {

        Properties getProperties();

        // ...
    };
};
{zcode}

The Properties interface is shown below:

Wiki Markup
{zcode:slice}
module Ice {
    local dictionary<string, string> PropertyDict;

    local interface Properties {

        string getProperty(string key);
        string getPropertyWithDefault(string key, string value);
        int getPropertyAsInt(string key);
        int getPropertyAsIntWithDefault(string key, int value);
        PropertyDict getPropertiesForPrefix(string prefix);

        void setProperty(string key, string value);

        StringSeq getCommandLineOptions();
        StringSeq parseCommandLineOptions(string prefix, StringSeq options);
        StringSeq parseIceCommandLineOptions(StringSeq options);

        void load(string file);

        Properties clone();
    };
};
{zcode}

Most of the operations involve reading properties, setting properties, and parsing properties.

The Properties interface also provides two utility operations that are useful if you need to work with multiple communicators that use different property sets:

  • clone
    This operation makes a copy of an existing property set. The copy contains exactly the same properties and values as the original.
  • load
    This operation accepts a path name to a configuration file and initializes the property set from that file. If the specified file cannot be read (for example, because it does not exist or the caller does not have read permission), the operation throws a FileException. In Java, the given path name can refer to a class loader resource or a regular file.
    Ztop
See Also
Zret
Znav
nextReading Properties
prevCommand-Line Parsing and Initialization