standup.profiling
Class OptionsPackage

java.lang.Object
  extended by standup.profiling.OptionsPackage
All Implemented Interfaces:
XMLizable, XMLsaveable

public class OptionsPackage
extends Object
implements XMLsaveable

An OptionsPackage contains a collection of Options, and defines a complete configuration of a STANDUP system.

The current implementation of OptionsPackage is rather hard-coded to include one each of OptionsCloudFrontend, OptionsJokeGeneration, and OptionsLexicon. Given more time, it would have been nice to allow arbitrary collections of Options implementations...

Author:
Ruli Manurung

Field Summary
static String[] optionClassNames
           
private  Hashtable<String,Options> optionsHashtable
          Contains a cache of instantiated options.
 
Constructor Summary
OptionsPackage()
          Constructor for a new "default" options package.
OptionsPackage(Element element)
          Constructor for an options package from the given XML Element.
OptionsPackage(File optionsFile)
          Constructor for an options package that contains settings and values obtained from the given File.
OptionsPackage(Set<Options> optionsSet)
          Constructor for an options package from an existing set of Options.
OptionsPackage(URL optionsURL)
          Constructor for an options package that contains settings and values obtained from the given URL.
 
Method Summary
 Collection<Options> getAllOptions()
          Returns all Options in this OptionsPackage.
 Options getOptions(String xmlTag)
           
static void main(String[] args)
           
private static Options reflectionDefaultInstance(String optionsClassName)
           
private static Options reflectionElementInstance(String optionsClassName, Element element)
           
 void save(File file)
          This method saves the necessary information contained within an instance to an XML file.
 void setOptions(Options options)
          Adds the given Options to this OptionsPackage.
 void writeXML(Writer out, String indent)
          This method writes the necessary information contained within an instance to an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

optionsHashtable

private final transient Hashtable<String,Options> optionsHashtable
Contains a cache of instantiated options. Whenever getOptions(Profile) is called, it stores the appropriate instance and saves it under the Profile's class. The main information is the loaded XML Element.


optionClassNames

public static final String[] optionClassNames
Constructor Detail

OptionsPackage

public OptionsPackage()
               throws ProfileException
Constructor for a new "default" options package. This obtains values from ProfileManager.getDefaultOptionsPackage().

Throws:
ProfileException

OptionsPackage

public OptionsPackage(Element element)
Constructor for an options package from the given XML Element.

NOTE: this method may possibly instantiate an incomplete OptionsPackage, i.e. if the given Element contains a definition for an Options that is not known, it will not load it. For example, if the Options contains an tag, it won't load it from the joke generation / lexicon API.


OptionsPackage

public OptionsPackage(URL optionsURL)
Constructor for an options package that contains settings and values obtained from the given URL.

Parameters:
optionsURL -

OptionsPackage

public OptionsPackage(File optionsFile)
Constructor for an options package that contains settings and values obtained from the given File.

Parameters:
optionsFile -

OptionsPackage

public OptionsPackage(Set<Options> optionsSet)
Constructor for an options package from an existing set of Options.

Parameters:
optionsCloudFrontend -
optionsJokeGeneration -
optionsLexicon -
Method Detail

getOptions

public Options getOptions(String xmlTag)

getAllOptions

public Collection<Options> getAllOptions()
Returns all Options in this OptionsPackage.

Returns:

setOptions

public void setOptions(Options options)
Adds the given Options to this OptionsPackage. If an Options of the same type already currently exists, it will be replaced.

Parameters:
options -

reflectionDefaultInstance

private static Options reflectionDefaultInstance(String optionsClassName)

reflectionElementInstance

private static Options reflectionElementInstance(String optionsClassName,
                                                 Element element)

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

save

public void save(File file)
          throws XMLException
Description copied from interface: XMLsaveable
This method saves the necessary information contained within an instance to an XML file. It should:

Specified by:
save in interface XMLsaveable
Parameters:
file - The file to be saved.
Throws:
XMLException

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Description copied from interface: XMLizable
This method writes the necessary information contained within an instance to an XML file.

Specified by:
writeXML in interface XMLizable
Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException