ptolemy.backtrack.xmlparser
Class ConfigParser

java.lang.Object
  extended by ptolemy.backtrack.xmlparser.ConfigParser

public class ConfigParser
extends java.lang.Object

Ptolemy XML configuration parser. This parser builds an XML tree in memory as it parses a configuration. The tree is either a complete representation of the configuration file, or a partial representation that defines only the given Java classes. See ConfigXmlHandler for more information on the second usage.

Since:
Ptolemy II 5.1
Version:
$Id: ConfigParser.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Field Summary
private  java.util.Set<java.lang.String> _excludedFiles
          The set of excluded files.
private  ConfigXmlTree _xmlTree
          The XML tree.
static java.lang.String DEFAULT_SYSTEM_ID
          The default path of the default Ptolemy configuration file.
 
Constructor Summary
ConfigParser()
          Construct a configuration parser with no parent node.
ConfigParser(ConfigXmlTree xmlTree)
          Construct a configuration parser with a parent node.
 
Method Summary
 void addExcludedFile(java.lang.String canonicalPath)
          Add an excluded file to the XML handler.
 void addExcludedFiles(java.util.Collection<java.lang.String> canonicalPaths)
          Add a collection of excluded files to the XML handler.
private  void addPackagePrefix(ConfigXmlTree tree, java.lang.String packagePrefix, java.util.Set classes)
          The recursive function to traverse the XML tree and add a package prefix to each class name found in the given set.
 void addPackagePrefix(java.lang.String packagePrefix, java.util.Set classes)
          Add a package prefix to the classes in the XML tree.
 ConfigXmlTree getTree()
          Get the parsed XML tree.
static void main(java.lang.String[] args)
          The main function to test the functionality of this class.
 void parseConfigFile(java.lang.String fileName, java.util.Set<java.lang.String> includedClasses)
          Parse a configuration file and build the XML tree below the given parent node (or null if not given).
 void parseConfigFile(java.lang.String fileName, java.util.Set<java.lang.String> includedClasses, boolean backtrackingElement)
          Parse a configuration file and build the XML tree below the given parent node (or null if not given).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SYSTEM_ID

public static final java.lang.String DEFAULT_SYSTEM_ID
The default path of the default Ptolemy configuration file. It is usually located at ptolemy/configs/full/configuration.xml in the Ptolemy tree.


_excludedFiles

private java.util.Set<java.lang.String> _excludedFiles
The set of excluded files.


_xmlTree

private ConfigXmlTree _xmlTree
The XML tree.

Constructor Detail

ConfigParser

public ConfigParser()
Construct a configuration parser with no parent node. The parent node is default to null.


ConfigParser

public ConfigParser(ConfigXmlTree xmlTree)
Construct a configuration parser with a parent node.

Parameters:
xmlTree - The parent node of the XML tree.
Method Detail

addExcludedFile

public void addExcludedFile(java.lang.String canonicalPath)
Add an excluded file to the XML handler.

Parameters:
canonicalPath - The canonical path of the file to be excluded.
See Also:
ConfigXmlHandler.addExcludedFile(String)

addExcludedFiles

public void addExcludedFiles(java.util.Collection<java.lang.String> canonicalPaths)
Add a collection of excluded files to the XML handler.

Parameters:
canonicalPaths - The collection of canonical paths of the files to be excluded.
See Also:
ConfigXmlHandler.addExcludedFiles(Collection)

addPackagePrefix

public void addPackagePrefix(java.lang.String packagePrefix,
                             java.util.Set classes)
Add a package prefix to the classes in the XML tree.

Parameters:
packagePrefix - The package prefix to be added to the head of each class name.
classes - The names of affected classes.

getTree

public ConfigXmlTree getTree()
Get the parsed XML tree.

Returns:
The XML tree. It may be null if no configuration has been parsed.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
The main function to test the functionality of this class. It parses the Ptolemy configuration file and extracts the nodes (and their parents) pertaining to class ptolemy.actor.lib.Sequence, and outputs the result to the standard output.

Parameters:
args - The command-line arguments (not used).
Throws:
java.lang.Exception - If error occurs.

parseConfigFile

public void parseConfigFile(java.lang.String fileName,
                            java.util.Set<java.lang.String> includedClasses)
                     throws java.lang.Exception
Parse a configuration file and build the XML tree below the given parent node (or null if not given). Only the nodes corresponding to the classes in includedClasses and their parent nodes are created. Other nodes in the XML tree are ignored.

This method is the same as parseConfigFile(fileName, includedClasses, true).

Parameters:
fileName - The name of the configuration file.
includedClasses - The set of names of classes to be included.
Throws:
java.lang.Exception - If error occurs.
See Also:
parseConfigFile(String, Set, boolean)

parseConfigFile

public void parseConfigFile(java.lang.String fileName,
                            java.util.Set<java.lang.String> includedClasses,
                            boolean backtrackingElement)
                     throws java.lang.Exception
Parse a configuration file and build the XML tree below the given parent node (or null if not given). Only the nodes corresponding to the classes in includedClasses and their parent nodes are created. Other nodes in the XML tree are ignored.

Parameters:
fileName - The name of the configuration file.
includedClasses - The set of names of classes to be included.
backtrackingElement - Whether to set the parent node of the constructed XML tree to be the "backtrack" node.
Throws:
java.lang.Exception - If error occurs.

addPackagePrefix

private void addPackagePrefix(ConfigXmlTree tree,
                              java.lang.String packagePrefix,
                              java.util.Set classes)
The recursive function to traverse the XML tree and add a package prefix to each class name found in the given set.

Parameters:
tree - The XML tree to be traversed.
packagePrefix - The package prefix to be added.
classes - The set of names of affected classes.