de.enough.polish
Class Environment

java.lang.Object
  extended by de.enough.polish.Environment

public class Environment
extends Object

Contains all variables, settings, etc not only for the preprocessing, but also for the various other build phases.

Copyright Enough Software 2005

  history
         22-Apr-2005 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected static Pattern FUNCTION_PATTERN
           
protected static Pattern PROPERTY_PATTERN
           
 
Constructor Summary
Environment()
          Creates a new empty environment.
Environment(ExtensionManager extensionsManager, Map<String,String> properties, File baseDir)
          Creates a new empty environment.
Environment(File polishHome)
          Creates a new empty environment.
 
Method Summary
 void addSymbol(String name)
           
 void addSymbols(Map<String,Boolean> additionalSymbols)
           
 void addTemporarySymbol(String name)
           
 void addTemporaryVariable(String name, String value)
           
 void addToVariable(String name, String value)
          Adds the given value to the specified variable.
 void addVariable(String name, String value)
           
 void addVariables(Map<String,String> vars)
           
 void clearTemporarySettings()
           
 Object get(String key)
          Retrieves any object to this environment.
 File getBaseDir()
           
 BooleanEvaluator getBooleanEvaluator()
           
 BuildSetting getBuildSetting()
           
 Device getDevice()
           
static Environment getInstance()
          Retrieves the instance of the environment
 LibraryManager getLibraryManager()
           
 Locale getLocale()
           
 File getProjectHome()
          Retrieves the project's home dir.
 String getProperty(String property, boolean needsToBeDefined)
          Retrieves the given property.
 Map<String,Boolean> getSymbols()
          Retrieves all symbols.
 String getVariable(String name)
           
 Map<String,String> getVariables()
          Retrieves all defined variables (capabilities) for the current device and this project.
 boolean hasSymbol(String name)
           
 boolean hasVariable(String name)
          Determines whether a variable is defined.
 void initialize(Device newDevice, Locale newLocale)
           
 boolean isConditionFulfilled(String condition)
          Checks whether a condition is met.
 void putAll(Map<String,String> properties)
          Puts all properties of the given map into the internal map without conversion.
 boolean removeSymbol(String name)
           
 boolean removeTemporarySymbol(String name)
           
 String removeTemporaryVariable(String name)
           
 String removeVariable(String name)
           
 File resolveFile(String url)
          Resolves the path to a file.
 String resolveVariable(String name)
          Retrieves the variables and writes any properties into it's value.
 void set(String key, Object value)
          Sets any object to this environment.
 void setBaseDir(File baseDir)
          Sets the project's main directory.
 void setBaseProperties(Map<String,String> properties)
          Sets the basic properties which are available the whole time.
 void setBuildSetting(BuildSetting setting)
           
 void setExtensionManager(ExtensionManager manager)
          Sets the extension manager.
 void setLibraryManager(LibraryManager manager)
           
 void setLocale(Locale locale)
           
 void setSymbols(Map<String,Boolean> features)
           
 void setVariable(String name, String value)
           
 void setVariables(Map<String,String> capabilities)
           
 String writeProperties(String input)
          Inserts the property-values in a string with property-definitions.
 String writeProperties(String input, boolean needsToBeDefined)
          Inserts the property-values in a string with property-definitions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_PATTERN

protected static final Pattern PROPERTY_PATTERN

FUNCTION_PATTERN

protected static final Pattern FUNCTION_PATTERN
Constructor Detail

Environment

public Environment()
Creates a new empty environment.


Environment

public Environment(File polishHome)
Creates a new empty environment.

Parameters:
polishHome - the path to the J2ME Polish installation directory

Environment

public Environment(ExtensionManager extensionsManager,
                   Map<String,String> properties,
                   File baseDir)
Creates a new empty environment.

Parameters:
extensionsManager - the manager for extensions
properties - basic environment settings
baseDir - the base directory like the project's home directory
Method Detail

getInstance

public static Environment getInstance()
Retrieves the instance of the environment

Returns:
the last instantiated instance of the environment

initialize

public void initialize(Device newDevice,
                       Locale newLocale)

setSymbols

public void setSymbols(Map<String,Boolean> features)
Parameters:
features -

setVariables

public void setVariables(Map<String,String> capabilities)
Parameters:
capabilities -

clearTemporarySettings

public void clearTemporarySettings()

addVariable

public void addVariable(String name,
                        String value)
Parameters:
name -
value -

removeVariable

public String removeVariable(String name)

setVariable

public void setVariable(String name,
                        String value)
Parameters:
name -
value -

removeTemporaryVariable

public String removeTemporaryVariable(String name)

getVariable

public String getVariable(String name)

addTemporaryVariable

public void addTemporaryVariable(String name,
                                 String value)

addSymbol

public void addSymbol(String name)
Parameters:
name -

removeSymbol

public boolean removeSymbol(String name)

hasSymbol

public boolean hasSymbol(String name)

addTemporarySymbol

public void addTemporarySymbol(String name)

removeTemporarySymbol

public boolean removeTemporarySymbol(String name)

getLocale

public Locale getLocale()

writeProperties

public String writeProperties(String input)
Inserts the property-values in a string with property-definitions.

Parameters:
input - the string in which property definition might be included, e.g. "file=${source}/MyFile.java"
Returns:
the input with all properties replaced by their values. When a property is not defined the full property-name is inserted instead (e.g. "${ property-name }").

writeProperties

public String writeProperties(String input,
                              boolean needsToBeDefined)
Inserts the property-values in a string with property-definitions.

Parameters:
input - the string in which property definition might be included, e.g. "file=${source}/MyFile.java"
needsToBeDefined - true when an IllegalArgumentException should be thrown when no value for a property was found.
Returns:
the input with all properties replaced by their values. When a property is not defined (and needsToBeDefined is false), the full property-name is inserted instead (e.g. "${ property-name }").
Throws:
IllegalArgumentException - when a property-value was not found and needsToBeDefined is true.

getProperty

public String getProperty(String property,
                          boolean needsToBeDefined)
Retrieves the given property.

Parameters:
property - the name of the property
needsToBeDefined - true when an exception should be thrown when the property is not defined
Returns:
the found property or null when it is not found

setLocale

public void setLocale(Locale locale)
Parameters:
locale - the locale

getBooleanEvaluator

public BooleanEvaluator getBooleanEvaluator()

getVariables

public Map<String,String> getVariables()
Retrieves all defined variables (capabilities) for the current device and this project.

Returns:
all defined variables

addSymbols

public void addSymbols(Map<String,Boolean> additionalSymbols)
Parameters:
additionalSymbols -

getDevice

public Device getDevice()

addVariables

public void addVariables(Map<String,String> vars)
Parameters:
vars -

resolveFile

public File resolveFile(String url)
Resolves the path to a file.

Parameters:
url - the filepath that can contain properties such as ${polish.home}.
Returns:
the appropriate file. Please note that the file doesn't need to exist, call file.exists() for determining that.

getBaseDir

public File getBaseDir()

setBuildSetting

public void setBuildSetting(BuildSetting setting)
Parameters:
setting -

getBuildSetting

public BuildSetting getBuildSetting()

setLibraryManager

public void setLibraryManager(LibraryManager manager)

getLibraryManager

public LibraryManager getLibraryManager()

getSymbols

public Map<String,Boolean> getSymbols()
Retrieves all symbols.

Returns:
a map containing the names of all defined symbols. The value for the symbols is always Boolean.TRUE

set

public void set(String key,
                Object value)
Sets any object to this environment. This eases communication between different components.

Parameters:
key - the key under which the value is stored
value - the value
See Also:
get( String )

get

public Object get(String key)
Retrieves any object to this environment. This eases communication between different components.

Parameters:
key - the key under which the value is stored
Returns:
the object that has been stored previously, or null when none has been set
See Also:
set( String, Object )

isConditionFulfilled

public boolean isConditionFulfilled(String condition)
Checks whether a condition is met.

Parameters:
condition - the condition
Returns:
true when the given condition is met by this environment

resolveVariable

public String resolveVariable(String name)
Retrieves the variables and writes any properties into it's value.

Parameters:
name - the name of the variable
Returns:
the value of the variable that doesn't include any properties

hasVariable

public boolean hasVariable(String name)
Determines whether a variable is defined.

Parameters:
name - the name of the variable
Returns:
true when the variable is defined

putAll

public void putAll(Map<String,String> properties)
Puts all properties of the given map into the internal map without conversion.

Parameters:
properties - a map of properties

getProjectHome

public File getProjectHome()
Retrieves the project's home dir.

Returns:
the current project's base directory, the working dir when there is no Ant project attached.

setBaseDir

public void setBaseDir(File baseDir)
Sets the project's main directory.

Parameters:
baseDir - the project's home directory

setExtensionManager

public void setExtensionManager(ExtensionManager manager)
Sets the extension manager.

Parameters:
manager - the manager

setBaseProperties

public void setBaseProperties(Map<String,String> properties)
Sets the basic properties which are available the whole time.

Parameters:
properties - the properties

addToVariable

public void addToVariable(String name,
                          String value)
Adds the given value to the specified variable. If the variable is already present the value will be added with a comma as a separator

Parameters:
name - name of the variable
value - value of the variable