ecologylab.appframework
Class ApplicationEnvironment

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.appframework.ApplicationEnvironment
All Implemented Interfaces:
Environment, XMLTranslationExceptionTypes
Direct Known Subclasses:
LogPlayer, PrefsEditorAp, ProjectionVisualizer

public class ApplicationEnvironment
extends Debug
implements Environment, XMLTranslationExceptionTypes

An instance of Environment, which is an application, rather than an applet, or a servlet. The Environment mechanism is used to enable the provision of contextual runtime configuration parameter services in a way that is independent of the deployment structure.

Author:
Andruid

Nested Class Summary
protected static class ApplicationEnvironment.LaunchType
           
 
Nested classes/interfaces inherited from interface ecologylab.appframework.Environment
Environment.The
 
Field Summary
protected static java.lang.String ECLIPSE_PREFS_DIR
          Subdirectory for eclipse launches.
protected  ParsedURL prefsPURL
          Place where Prefs are loaded from and stored to.
 
Fields inherited from interface ecologylab.appframework.Environment
APPLICATION, IE, NS, PLUGIN, the
 
Fields inherited from interface ecologylab.xml.XMLTranslationExceptionTypes
FILE_NOT_FOUND, IO_EXCEPTION, NULL_PURL, UNKNOWN
 
Constructor Summary
ApplicationEnvironment(java.lang.Class baseClass, java.lang.String applicationName, java.lang.String[] args)
          Create an ApplicationEnvironment.
ApplicationEnvironment(java.lang.Class baseClass, java.lang.String applicationName, TranslationSpace translationSpace, java.lang.String[] args, float prefsAssetVersion)
          Create an ApplicationEnvironment.
ApplicationEnvironment(java.lang.String applicationName)
          Create an ApplicationEnvironment.
ApplicationEnvironment(java.lang.String applicationName, java.lang.String[] args)
          Create an ApplicationEnvironment.
ApplicationEnvironment(java.lang.String applicationName, TranslationSpace translationSpace, java.lang.String[] args, float prefsAssetVersion)
          Create an ApplicationEnvironment.
 
Method Summary
 DownloadProcessor assetsDownloadProcessor()
           
 int browser()
          Find out which browser we're running in.
 ParsedURL codeBase()
          Change type from URL to ParsedURL.
 PrefEditorWidgets createPrefsEditor()
          Create and show an editor for preferences, iff the MetaPrefSet and PrefSet are non-null.
 PrefEditorWidgets createPrefsEditor(boolean createJFrame, boolean isStandalone)
          Create and show an editor for preferences, iff the MetaPrefSet and PrefSet are non-null.
 ParsedURL docBase()
          Change type from URL to ParsedURL.
 void exit(int code)
          Called at the end of an invocation.
protected  ApplicationEnvironment.LaunchType launchType()
           
static ElementState lookupElementStatePreference(java.lang.String name)
          Find a complex object set in preferences.
 java.lang.String lookupStringPreference(java.lang.String name)
          Get a parameter or property, based on a key.
protected  MetaPrefSet metaPrefSet()
           
 void navigate(ParsedURL purl, java.lang.String frame)
          Navigate to the purl using the best browser we can find.
 ParsedURL preferencesDir()
           
static java.lang.String preferencesFileRelativeFromArg0(java.lang.String[] args)
          Form the parameter file path.
static Scope preferencesRegistry()
           
protected  PrefSet prefSet()
           
 int runtimeEnv()
          Find out which java runtime we're operating in.
 void setCodeBase(ParsedURL codeBase)
          Set the codebase for the application.
 void showStatus(java.lang.String s)
           
 void status(java.lang.String msg)
          Show msg in the browser's status bar.
 TranslationSpace translationSpace()
          Translation space used to parse Preferences for this Application.
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ECLIPSE_PREFS_DIR

protected static final java.lang.String ECLIPSE_PREFS_DIR
Subdirectory for eclipse launches.

See Also:
Constant Field Values

prefsPURL

protected ParsedURL prefsPURL
Place where Prefs are loaded from and stored to.

Constructor Detail

ApplicationEnvironment

public ApplicationEnvironment(java.lang.String applicationName)
                       throws XMLTranslationException
Create an ApplicationEnvironment. Create an empty properties object for application parameters.

No command line argument is processed. Only default preferences are loaded, and processed with the default TranslationSpace.

Parameters:
args - The args array, which is treated as a stack with optional entries. They are: *) JNLP -- if that is the launch method *) preferences file if you are running in eclipse. Relative to CODEBASE/config/preferences/ *) graphics_device (screen number) *) screen_size (used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full)
Throws:
XMLTranslationException

ApplicationEnvironment

public ApplicationEnvironment(java.lang.String applicationName,
                              TranslationSpace translationSpace,
                              java.lang.String[] args,
                              float prefsAssetVersion)
                       throws XMLTranslationException
Create an ApplicationEnvironment. Load preferences from XML file founds in the config/preferences directory. Default preferences will be loaded from preferences.xml. If there is a 0th command line argument, that is the name of an additional preferences file.

Parameters:
applicationName -
translationSpace - TranslationSpace used for translating preferences XML. If this is null, ecologylab.services.message.DefaultServicesTranslations will be used.
args - The args array, which is treated as a stack with optional entries. They are: *) JNLP -- if that is the launch method *) preferences file if you are running in eclipse. Relative to CODEBASE/config/preferences/ *) graphics_device (screen number) *) screen_size (used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full)
prefsAssetVersion - TODO
Throws:
XMLTranslationException

ApplicationEnvironment

public ApplicationEnvironment(java.lang.String applicationName,
                              java.lang.String[] args)
                       throws XMLTranslationException
Create an ApplicationEnvironment. Load preferences from XML files found in the config/preferences directory. Default preferences will be loaded from preferences.xml. If there is a 0th command line argument, that is the name of an additional preferences file.

The default TranslationSpace, from ecologylab.services.message.DefaultServicesTranslations will be used.

Parameters:
applicationName - ecologylab.services.message.DefaultServicesTranslations will be used.
args - The args array, which is treated as a stack with optional entries. They are: *) JNLP -- if that is the launch method *) preferences file if you are running in eclipse. Relative to CODEBASE/config/preferences/ *) graphics_device (screen number) *) screen_size (used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full)
Throws:
XMLTranslationException

ApplicationEnvironment

public ApplicationEnvironment(java.lang.Class baseClass,
                              java.lang.String applicationName,
                              java.lang.String[] args)
                       throws XMLTranslationException
Create an ApplicationEnvironment. Get the base for finding the path to the "codeBase" by using the package path of the baseClass passed in.

Load preferences from XML file founds in the codeBase/config/preferences directory. Default preferences will be loaded from preferences.xml. If there is a 0th command line argument, that is the name of an additional preferences file.

Also, sets the Assets cacheRoot to the applicationDir().

The default TranslationSpace, from ecologylab.services.message.DefaultServicesTranslations will be used.

Parameters:
baseClass - Used for computing codeBase property.
applicationName -
args - The args array, which is treated as a stack with optional entries. They are: *) JNLP -- if that is the launch method *) preferences file if you are running in eclipse. Relative to CODEBASE/config/preferences/ *) graphics_device (screen number) *) screen_size (used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full
Throws:
XMLTranslationException

ApplicationEnvironment

public ApplicationEnvironment(java.lang.Class baseClass,
                              java.lang.String applicationName,
                              TranslationSpace translationSpace,
                              java.lang.String[] args,
                              float prefsAssetVersion)
                       throws XMLTranslationException
Create an ApplicationEnvironment.

Treats the args array like a stack. If any args are missing (based on their format), they are skipped.

The first arg we seek is codeBase. This is a path that ends in slash. It may be a local relative path, or a URL-based absolute path.

The next possible arg is a preferences file. This ends with .xml.

The next 2 possible args are integers, for graphicsDev and screenSize. graphics_device (screen number) to display window. count from 0. screenSize used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full

Get the base for finding the path to the "codeBase" by using the package path of the baseClass passed in.

Load preferences from XML file founds in the codeBase/config/preferences directory. Default preferences will be loaded from preferences.xml. If there is a 0th command line argument, that is the name of an additional preferences file.

Also, sets the Assets cacheRoot to the applicationDir().

The default TranslationSpace, from ecologylab.services.message.DefaultServicesTranslations will be used.

Parameters:
baseClass - Used for computing codeBase property.
applicationName - Name of the application.
translationSpace - TranslationSpace used for translating preferences XML. If this is null, ecologylab.services.message.DefaultServicesTranslations will be used.
args - The args array, which is treated as a stack with optional entries. They are: *) JNLP -- if that is the launch method *) preferences file if you are running in eclipse. Relative to CODEBASE/config/preferences/ *) graphics_device (screen number) *) screen_size (used in TopLevel -- 1 - quarter; 2 - almost half; 3; near full; 4 full)
prefsAssetVersion - TODO
Throws:
XMLTranslationException
Method Detail

runtimeEnv

public int runtimeEnv()
Description copied from interface: Environment
Find out which java runtime we're operating in.

Specified by:
runtimeEnv in interface Environment
See Also:
Environment.runtimeEnv()

showStatus

public void showStatus(java.lang.String s)
See Also:
Environment.status(String)

status

public void status(java.lang.String msg)
Description copied from interface: Environment
Show msg in the browser's status bar. Short form, with for (@link java.cm.applet.Applet#showStatus). Also more robust: avoids breaking when msg is null.

Specified by:
status in interface Environment
See Also:
Environment.status(String)

lookupStringPreference

public java.lang.String lookupStringPreference(java.lang.String name)
Description copied from interface: Environment
Get a parameter or property, based on a key. Implements a name/value pair.

Specified by:
lookupStringPreference in interface Environment
Parameters:
name - The name of the key.
See Also:
Environment.lookupStringPreference(String)

codeBase

public ParsedURL codeBase()
Description copied from interface: Environment
Change type from URL to ParsedURL.

Specified by:
codeBase in interface Environment
See Also:
return the path to root of the

docBase

public ParsedURL docBase()
Description copied from interface: Environment
Change type from URL to ParsedURL.

Specified by:
docBase in interface Environment
See Also:
return the current working directory of the application which is "c:\web\code\java\cm"

preferencesDir

public ParsedURL preferencesDir()

navigate

public void navigate(ParsedURL purl,
                     java.lang.String frame)
Navigate to the purl using the best browser we can find.

Specified by:
navigate in interface Environment
Parameters:
purl -
frame -

browser

public int browser()
Description copied from interface: Environment
Find out which browser we're running in.

Specified by:
browser in interface Environment

exit

public void exit(int code)
Called at the end of an invocation. Calls System.exit(code).

Specified by:
exit in interface Environment
Parameters:
code - -- 0 for normal. other values are application specific.

preferencesFileRelativeFromArg0

public static java.lang.String preferencesFileRelativeFromArg0(java.lang.String[] args)
Form the parameter file path. Use the 0th argument if there is one, to find a file in config. If not, use config/interface/params.txt.

Parameters:
args -
Returns:
preferences file path

setCodeBase

public void setCodeBase(ParsedURL codeBase)
Set the codebase for the application. Should only be done at startup.


preferencesRegistry

public static Scope preferencesRegistry()
Returns:
Returns the preferencesRegistry.

lookupElementStatePreference

public static ElementState lookupElementStatePreference(java.lang.String name)
Find a complex object set in preferences.

Parameters:
name -
Returns:
ElementState preference object.

translationSpace

public TranslationSpace translationSpace()
Translation space used to parse Preferences for this Application.

Returns:
TranslationSpace in use for parsing Preferences

assetsDownloadProcessor

public DownloadProcessor assetsDownloadProcessor()

createPrefsEditor

public PrefEditorWidgets createPrefsEditor()
Create and show an editor for preferences, iff the MetaPrefSet and PrefSet are non-null. If the PrefSet is null, a new empty one will be created for the editor to use.

Returns:

createPrefsEditor

public PrefEditorWidgets createPrefsEditor(boolean createJFrame,
                                           boolean isStandalone)
Create and show an editor for preferences, iff the MetaPrefSet and PrefSet are non-null. If the PrefSet is null, a new empty one will be created for the editor to use.

Returns:

launchType

protected ApplicationEnvironment.LaunchType launchType()

metaPrefSet

protected MetaPrefSet metaPrefSet()
Returns:
MetaPrefSet for this application, loaded from standard locations.

prefSet

protected PrefSet prefSet()
Returns:
The set of Prefs associated with this application.