stella.parameter
Class TargetList

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.TargetList
All Implemented Interfaces:
Cloneable, Parameter, TargetProviding<ParsedTarget>, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, Reloadable, ResourceSupplying
Direct Known Subclasses:
SubTargets

public class TargetList
extends AbstractParameter
implements TargetProviding<ParsedTarget>, Reloadable

A parameter that is capable of resolving a list of parsed targets in its get() method. Default action is to check if the #KEY_FILE property is set. If so, the file is located via the inherited ResourceSupplying.KEY_URLRESOURCES and the targets are loaded as ParsedTargets into an internal list during initialization.

This target is exit cleaning, meaning that the total list of targets hosted by this parameter is dumped when the KEY_DUMP key is present. In the current version, KEY_DUMP should point to a directory, where all targets are dumped.

The parameter is reloadable in a sense that its properties might be changed, then restore target is called.

See Also:
TargetList.TargetDump

Nested Class Summary
static class TargetList.Check
          Checks the file given on the command line.
static class TargetList.Invoke
          Mainly used for parsing input-xml files and writing them as serialized targets.
static class TargetList.TargetDump
          A class that is a thread and dumps all of the targets registered at VM-exit to the scheduler to the dump directory.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Collection<ParsedTarget> alltargets
          A list containing all targets, even those not wanted.
private static boolean DEFIGNORESERIAL
          Default ignore of serialized targtes.
static String DEFNAME
          The default name of the target list.
private static String DEFURLRESOURCES
          The default path for resource loccation.
static String KEY_CHAINFILE
          The file holding targets relevant only for chained targets.
static String KEY_DUMP
          The file holding target-xml file names.
static String KEY_HISTORYDB
          If present, the properties of the history database.
static String KEY_IGNORESERIAL
          If pointing to true, serialized versions are always ignored.
static String KEY_REMOVE
          The key to the comma-list of unwanted targets.
static String KEY_STELLA
          The telescope we work on.
static String KEY_TARGETDB
          If present, the properties of the target database.
static String KEY_TARGETFILE
          The file holding target-xml file names.
private  Collection<ParsedTarget> targets
          A list of parsed targets used.
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.TargetProviding
SERIAL, XML
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
TargetList(Map<String,String> sprop)
          Constructs a new target list parameter.
 
Method Summary
 boolean add(Object dom)
          Adds a new target to this scheduler.
 boolean addTarget(ParsedTarget dom)
          Add a target to all targets.
 void clear()
          Empties the targets hash map.
 void exit()
          Exits this parameter.
 Object get()
          Returns the Collection of targets currently handled by the target list.
 Collection<ParsedTarget> getActiveTargets()
          Returns all active targets.
 List<String> getAllNames()
          Returns a set of all target names.
 Collection<ParsedTarget> getAllTargets()
          Returns all targets known to this provider.
 Collection<ParsedTarget> getCompletedTargets()
          Parsed Targets provide a complete flag.
 ParsedTarget getFromActive(String name)
          Gets from all targets.
 ParsedTarget getFromAll(String name)
          Gets from all targets.
private  ParsedTarget getTargetFromResource(String xmlname)
          Returns a parsed document from a resource.
 void init()
          The init section.
private  ParsedTarget parseTargetResource(URL xml, URL serial)
          Returns the newer of two versions.
 double reload()
          Calls the super method and then restores my targets.
 boolean remove(TargetDefinition dom)
          Removes the target-defining DOM from the scheduler, classified by its name.
 boolean removeTarget(ParsedTarget dom)
          Removes the target-defining DOM from the scheduler, classified by its name.
 double rescanned(String key, String old, String newval)
          Makes this method public, no further changes.
private  Collection<ParsedTarget> resolveFileTargets(List<String> files)
          Reads the file indicated by the argument.
 boolean restore()
          Restores all targets.
 boolean restoreTargets()
          Restores all targets.
 Object set(Object list)
          Loads a list of target definitions to this scheduler.
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, setName, toString
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, removeProperty, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_TARGETFILE

public static final String KEY_TARGETFILE
The file holding target-xml file names.

See Also:
Constant Field Values

KEY_CHAINFILE

public static final String KEY_CHAINFILE
The file holding targets relevant only for chained targets.

See Also:
Constant Field Values

KEY_REMOVE

public static final String KEY_REMOVE
The key to the comma-list of unwanted targets.

See Also:
Constant Field Values

KEY_IGNORESERIAL

public static final String KEY_IGNORESERIAL
If pointing to true, serialized versions are always ignored.

See Also:
Constant Field Values

KEY_DUMP

public static final String KEY_DUMP
The file holding target-xml file names.

See Also:
Constant Field Values

KEY_HISTORYDB

public static final String KEY_HISTORYDB
If present, the properties of the history database.

See Also:
Constant Field Values

KEY_TARGETDB

public static final String KEY_TARGETDB
If present, the properties of the target database.

See Also:
Constant Field Values

KEY_STELLA

public static final String KEY_STELLA
The telescope we work on.

See Also:
Constant Field Values

DEFNAME

public static final String DEFNAME
The default name of the target list.

See Also:
Constant Field Values

DEFURLRESOURCES

private static final String DEFURLRESOURCES
The default path for resource loccation.

See Also:
Constant Field Values

DEFIGNORESERIAL

private static final boolean DEFIGNORESERIAL
Default ignore of serialized targtes.

See Also:
Constant Field Values

targets

private Collection<ParsedTarget> targets
A list of parsed targets used.


alltargets

private Collection<ParsedTarget> alltargets
A list containing all targets, even those not wanted.

Constructor Detail

TargetList

public TargetList(Map<String,String> sprop)
Constructs a new target list parameter. The resources are defaulted. Target loading and parsing is deferred to the init() section.

Method Detail

init

public void init()
The init section. If the KEY_TARGETFILE is set, the target list is searched, read and passed to the resolveFileTargets(java.util.List) method.

Specified by:
init in interface Initializable
Overrides:
init in class AbstractParameter

rescanned

public double rescanned(String key,
                        String old,
                        String newval)
Makes this method public, no further changes.

Specified by:
rescanned in interface Reloadable
Overrides:
rescanned in class AbstractParameter

reload

public double reload()
Calls the super method and then restores my targets.

Specified by:
reload in interface Reloadable
Overrides:
reload in class PropertyContainer

getCompletedTargets

public Collection<ParsedTarget> getCompletedTargets()
Parsed Targets provide a complete flag.

Specified by:
getCompletedTargets in interface TargetProviding<ParsedTarget>
See Also:
HistoryAware, Appointable

getAllTargets

public Collection<ParsedTarget> getAllTargets()
Description copied from interface: TargetProviding
Returns all targets known to this provider.

Specified by:
getAllTargets in interface TargetProviding<ParsedTarget>

getActiveTargets

public Collection<ParsedTarget> getActiveTargets()
Description copied from interface: TargetProviding
Returns all active targets. These are the targets that take part in a scheduling process. br> This collection must be contained in the TargetProviding.getAllTargets().

Specified by:
getActiveTargets in interface TargetProviding<ParsedTarget>

restore

public boolean restore()
Restores all targets. From the interface definition.

Specified by:
restore in interface TargetProviding<ParsedTarget>

restoreTargets

public boolean restoreTargets()
Restores all targets.


exit

public void exit()
Exits this parameter. If the KEY_DUMP key points to a directory, all targets hosted by this parameter are dumped as xml-files into the specified directory.

Specified by:
exit in interface ExitCleaning
Overrides:
exit in class AbstractParameter

set

public Object set(Object list)
Loads a list of target definitions to this scheduler. Any old targets are removed. The list handed over is checked for ParsedTargets. Only these enter the final set.

Specified by:
set in interface Parameter
Returns:
The previous value of this parameter.

get

public Object get()
Returns the Collection of targets currently handled by the target list.

Specified by:
get in interface Parameter
Returns:
A Collection of TargetDefinitions, or null.

getFromAll

public ParsedTarget getFromAll(String name)
Gets from all targets.

Specified by:
getFromAll in interface TargetProviding<ParsedTarget>

getFromActive

public ParsedTarget getFromActive(String name)
Gets from all targets.

Specified by:
getFromActive in interface TargetProviding<ParsedTarget>

add

public boolean add(Object dom)
Adds a new target to this scheduler. The targets name is querried and matched in a look-up table against the argumental ParsedTarget. It's priority is also retrieved and, if valid, added to the look-up table matching priorities to target names. If the argument is null false is returned.

Parameters:
target - An object that must be an instance of ParsedTarget.
Returns:
True if the target was successful added.
Throws:
IllegalArgumentException - If the argument is not an instance of ParsedTarget.

addTarget

public boolean addTarget(ParsedTarget dom)
Description copied from interface: TargetProviding
Add a target to all targets. The target state will define, if it also appears in the active/finished list.

Specified by:
addTarget in interface TargetProviding<ParsedTarget>
Returns:
True, if adding was successful.

removeTarget

public boolean removeTarget(ParsedTarget dom)
Removes the target-defining DOM from the scheduler, classified by its name. The target is physically removed and must be re-parsed from the target-definition file if re-added.

Specified by:
removeTarget in interface TargetProviding<ParsedTarget>
Returns:
True, if target was present in at least one list.

remove

public boolean remove(TargetDefinition dom)
Removes the target-defining DOM from the scheduler, classified by its name. The target is physically removed and must be re-parsed from the target-definition file if re-added.


clear

public void clear()
Empties the targets hash map. All parsed information is lost. Additionally, adding targets after a call to this method may require re-hashing.

Specified by:
clear in interface TargetProviding<ParsedTarget>

getAllNames

public List<String> getAllNames()
Returns a set of all target names. If no targets are stored within this scheduler null is returned, instead of an empty set. Note that the returned set is backed by the targets' hash map.


resolveFileTargets

private Collection<ParsedTarget> resolveFileTargets(List<String> files)
Reads the file indicated by the argument. To work properly, please remember that All entries are validated using the DOMTarget.parseTarget(java.lang.String, org.w3c.dom.Document, java.util.Map) method. The parsed documents are then returned in a target set.
To check for multiple instances of the same target, e.g. as a daugther and a top-level target, all targets, including their daughters, are scanned after they have been initialized. Only a single instance of each target is kept.

Parameters:
file - An object of the file type
Returns:
null, if file doesn't exist or contains no entries.

getTargetFromResource

private ParsedTarget getTargetFromResource(String xmlname)
Returns a parsed document from a resource.


parseTargetResource

private ParsedTarget parseTargetResource(URL xml,
                                         URL serial)
Returns the newer of two versions.