nl.knowledgeplaza.util
Class EnvironmentVariables

java.lang.Object
  extended by nl.knowledgeplaza.util.EnvironmentVariables

public class EnvironmentVariables
extends 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.


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
 Set envNames()
          Return the set of environment variables names
 Set envPropertyNames()
          Return the set of property names derived by the environment variables, as obtained by getEnvProperty()
 Properties getAsProperties()
          Return a Properties object with the environment properties, whose names are names derived by the environment variables, as obtained by getEnvProperty()
 String getEnv(String name)
          Return the value of the environemnt variable of the given name
protected  String getEnv(String name, EnvironmentVariables.NameTransformer t)
          Return the name of the given variable, after applying the given name transformation
 String getEnvProperty(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
static void main(String[] args)
          Test
 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 String getEnv(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 String getEnv(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 String getEnvProperty(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 Set envNames()
Return the set of environment variables names

Returns:
the set of environment variables names

envPropertyNames

public 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 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

main

public static void main(String[] args)
Test



Copyright © 2012 KnowledgePlaza. All Rights Reserved.