org.sadun.util
Class EnvironmentVariables

java.lang.Object
  extended byorg.sadun.util.EnvironmentVariables

public class EnvironmentVariables
extends java.lang.Object

An helper class to handle environment variables when they're present on the underlying operating system. So far, the only supported operating system is Windows 2000 - but the underlying mechanism (based on running a 'set' command on the system shell) is easly usable for different o/s.

In order to add support for one OS, add the identification string and the associated shell command in the private getGenerator() method, and check that the parsing code in setBasedGenerator.getEnvironment() is correct for parsing the result.

A typical usage consists in just invoking

  EnvironmentVariables.getInstance(). toSystemProperties();
 

and then browse the system properties for env. entries.

Author:
cris

Nested Class Summary
static interface EnvironmentVariables.Generator
          A class implementing this interface is able to retrieve environment information in some way.
static interface EnvironmentVariables.NameTransformer
          Classes implementing this interface can transform environment names in a "canonical" form
 class EnvironmentVariables.SimpleNameTransformer
          A NameTransformerwhich produces names in the style of typical java property names.
 
Constructor Summary
EnvironmentVariables()
          Constructor for EnvironmentVariables.
 
Method Summary
 java.util.Set envNames()
          Return the set of environment variables names
 java.util.Set envPropertyNames()
          Return the set of property names derived by the environment variables, as obtained by getEnvProperty()
 java.util.Properties getAsProperties()
          Return a Properties object with the environment properties, whose names are names derived by the environment variables, as obtained by getEnvProperty()
 java.lang.String getEnv(java.lang.String name)
          Return the value of the environemnt variable of the given name
protected  java.lang.String getEnv(java.lang.String name, EnvironmentVariables.NameTransformer t)
          Return the name of the given variable, after applying the given name transformation
 java.lang.String getEnvProperty(java.lang.String name)
          Return the value of a property whose name is a transformation of an environment variable name according to a SimpleNameTransformer
static EnvironmentVariables getInstance()
          Return the single instance of this class
 void toSystemProperties()
          Add properties obtained by getEnvProperty() to the system properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvironmentVariables

public EnvironmentVariables()
Constructor for EnvironmentVariables.

Method Detail

getEnv

protected java.lang.String getEnv(java.lang.String name,
                                  EnvironmentVariables.NameTransformer t)
Return the name of the given variable, after applying the given name transformation

Parameters:
name - the name of the required environment entry
t - the transformation to apply
Returns:
the value of the variable with the transformed name, or null if such a name is undefined

getEnv

public java.lang.String getEnv(java.lang.String name)
Return the value of the environemnt variable of the given name

Parameters:
name - the environemnt variable name
Returns:
the environemnt variable value

getEnvProperty

public java.lang.String getEnvProperty(java.lang.String name)
Return the value of a property whose name is a transformation of an environment variable name according to a SimpleNameTransformer

Parameters:
name -
Returns:
String

envNames

public java.util.Set envNames()
Return the set of environment variables names

Returns:
the set of environment variables names

envPropertyNames

public java.util.Set envPropertyNames()
Return the set of property names derived by the environment variables, as obtained by getEnvProperty()

Returns:
the set of property names derived by the environment variables

getAsProperties

public java.util.Properties getAsProperties()
Return a Properties object with the environment properties, whose names are names derived by the environment variables, as obtained by getEnvProperty()

Returns:
Properties

toSystemProperties

public void toSystemProperties()
Add properties obtained by getEnvProperty() to the system properties.


getInstance

public static EnvironmentVariables getInstance()
Return the single instance of this class

Returns:
EnvironmentVariables