Package com.zeroc.Ice

Class Properties

java.lang.Object
com.zeroc.Ice.Properties

public final class Properties extends Object
Represents a set of properties used to configure Ice and Ice-based applications. A property is a key/value pair, where both the key and the value are strings. By convention, property keys should have the form application-name[.category[.sub-category]].name. This class is thread-safe: multiple threads can safely read and write the properties.
  • Constructor Details

    • Properties

      public Properties()
      Constructs an empty property set.
    • Properties

      public Properties(String[] args)
      Constructs a property set, loads the configuration files specified by the Ice.Config property or the ICE_CONFIG environment variable, and then parses Ice properties from args.

      This constructor loads properties from files specified by the ICE_CONFIG environment variable when there is no --Ice.Config command-line argument.

      Parameters:
      args - the command-line arguments. This constructor parses arguments starting with -- and one of the reserved prefixes (Ice, IceSSL, etc.) as properties. If there is an argument starting with --Ice.Config, this constructor loads the specified configuration file. When the same property is set in a configuration file and through a command-line argument, the command-line setting takes precedence.
    • Properties

      public Properties(String[] args, List<String> remainingArgs)
      Constructs a property set, loads the configuration files specified by the Ice.Config property or the ICE_CONFIG environment variable, and then parses Ice properties from args.

      This constructor loads properties from files specified by the ICE_CONFIG environment variable when there is no --Ice.Config command-line argument.

      Parameters:
      args - the command-line arguments. This constructor parses arguments starting with -- and one of the reserved prefixes (Ice, IceSSL, etc.) as properties. If there is an argument starting with --Ice.Config, this constructor loads the specified configuration file. When the same property is set in a configuration file and through a command-line argument, the command-line setting takes precedence.
      remainingArgs - if non-null, this list will be cleared and filled with any command-line arguments that were not used to set properties.
    • Properties

      public Properties(String[] args, Properties defaults)
      Constructs a property set, loads the configuration files specified by the Ice.Config property or the ICE_CONFIG environment variable, and then parses Ice properties from args.

      This constructor loads properties from files specified by the ICE_CONFIG environment variable when there is no --Ice.Config command-line argument.

      Parameters:
      args - the command-line arguments. This constructor parses arguments starting with -- and one of the reserved prefixes (Ice, IceSSL, etc.) as properties. If there is an argument starting with --Ice.Config, this constructor loads the specified configuration file. When the same property is set in a configuration file and through a command-line argument, the command-line setting takes precedence.
      defaults - default values for the new Properties object. Settings in configuration files and args override these defaults.
    • Properties

      public Properties(String[] args, Properties defaults, List<String> remainingArgs)
      Constructs a property set, loads the configuration files specified by the Ice.Config property or the ICE_CONFIG environment variable, and then parses Ice properties from args.

      This constructor loads properties from files specified by the ICE_CONFIG environment variable when there is no --Ice.Config command-line argument.

      Parameters:
      args - the command-line arguments. This constructor parses arguments starting with -- and one of the reserved prefixes (Ice, IceSSL, etc.) as properties. If there is an argument starting with --Ice.Config, this constructor loads the specified configuration file. When the same property is set in a configuration file and through a command-line argument, the command-line setting takes precedence.
      defaults - default values for the new Properties object. Settings in configuration files and args override these defaults.
      remainingArgs - if non-null, this list will be cleared and filled with any command-line arguments that were not used to set properties.
  • Method Details

    • getProperty

      public String getProperty(String key)
      Gets a property by key.
      Parameters:
      key - the property key
      Returns:
      the property value, or the empty string if the property is not set
      See Also:
    • getIceProperty

      public String getIceProperty(String key)
      Gets an Ice property by key.
      Parameters:
      key - the property key
      Returns:
      the property value, or the default value for this property if the property is not set
      Throws:
      PropertyException - if the property is not a known Ice property
      See Also:
    • getPropertyWithDefault

      public String getPropertyWithDefault(String key, String value)
      Gets a property by key.
      Parameters:
      key - the property key
      value - the default value to return if the property is not set
      Returns:
      the property value or the default value if the property is not set
      See Also:
    • getPropertyAsInt

      public int getPropertyAsInt(String key)
      Gets a property as an integer.
      Parameters:
      key - the property key
      Returns:
      the property value interpreted as an integer, or 0 if the property is not set
      Throws:
      PropertyException - if the property value is not a valid integer
      See Also:
    • getIcePropertyAsInt

      public int getIcePropertyAsInt(String key)
      Gets an Ice property as an integer.
      Parameters:
      key - the property key
      Returns:
      the property value interpreted as an integer, or the default value if the property is not set
      Throws:
      PropertyException - if the property is not a known Ice property or its value is not a valid integer
      See Also:
    • getPropertyAsIntWithDefault

      public int getPropertyAsIntWithDefault(String key, int value)
      Gets a property as an integer.
      Parameters:
      key - the property key
      value - the default value to return if the property does not exist
      Returns:
      the property value interpreted as an integer, or the default value if the property is not set
      Throws:
      PropertyException - if the property value is not a valid integer
      See Also:
    • getPropertyAsList

      public String[] getPropertyAsList(String key)
      Gets a property as a list of strings. The strings must be separated by whitespace or comma. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, an empty list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as O'Reilly, "O'Reilly" or 'O\'Reilly'.
      Parameters:
      key - the property key
      Returns:
      the property value interpreted as a list of strings, or an empty list if the property is not set
      See Also:
    • getIcePropertyAsList

      public String[] getIcePropertyAsList(String key)
      Gets an Ice property as a list of strings. The strings must be separated by whitespace or comma. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, the default list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as O'Reilly, "O'Reilly" or 'O\'Reilly'.
      Parameters:
      key - the property key
      Returns:
      the property value interpreted as a list of strings, or the default value if the property is not set
      Throws:
      PropertyException - if the property is not a known Ice property
      See Also:
    • getPropertyAsListWithDefault

      public String[] getPropertyAsListWithDefault(String key, String[] value)
      Gets a property as a list of strings. The strings must be separated by whitespace or comma. The strings in the list can contain whitespace and commas if they are enclosed in single or double quotes. If quotes are mismatched, the default list is returned. Within single quotes or double quotes, you can escape the quote in question with a backslash, e.g. O'Reilly can be written as O'Reilly, "O'Reilly" or 'O\'Reilly'.
      Parameters:
      key - the property key
      value - the default value to return if the property is not set
      Returns:
      the property value interpreted as a list of strings, or the default value if the property is not set
      See Also:
    • getPropertiesForPrefix

      public Map<String,String> getPropertiesForPrefix(String prefix)
      Gets all properties whose keys begin with prefix. If prefix is the empty string, then all properties are returned.
      Parameters:
      prefix - the prefix to search for
      Returns:
      the matching property set
    • setProperty

      public void setProperty(String key, String value)
      Sets a property. To unset a property, set it to the empty string.
      Parameters:
      key - the property key
      value - the property value
      See Also:
    • getCommandLineOptions

      public String[] getCommandLineOptions()
      Gets a sequence of command-line options that is equivalent to this property set. Each element of the returned sequence is a command-line option of the form --key=value.
      Returns:
      the command line options for this property set
    • parseCommandLineOptions

      public String[] parseCommandLineOptions(String prefix, String[] options)
      Converts a sequence of command-line options into properties. All options that start with --prefix. are converted into properties. If the prefix is empty, all options that begin with -- are converted to properties.
      Parameters:
      prefix - the property prefix, or the empty string to convert all options starting with --
      options - the command-line options
      Returns:
      the command-line options that do not start with the specified prefix, in their original order
    • parseIceCommandLineOptions

      public String[] parseIceCommandLineOptions(String[] options)
      Converts a sequence of command-line options into properties. All options that start with one of the reserved Ice prefixes (--Ice, --IceSSL, etc.) are converted into properties.
      Parameters:
      options - the command-line options
      Returns:
      the command-line options that do not start with one of the reserved prefixes, in their original order
    • load

      public void load(String file)
      Loads properties from a file.
      Parameters:
      file - the property file
    • _clone

      public Properties _clone()
      Creates a copy of this property set.
      Returns:
      a copy of this property set
    • getUnusedProperties

      public List<String> getUnusedProperties()
      Gets the properties that were never read.
      Returns:
      a list of unused properties