org.rubato.xml
Class XMLReader

java.lang.Object
  extended by org.rubato.xml.XMLReader
All Implemented Interfaces:
RubatoDictionary

public final class XMLReader
extends java.lang.Object
implements RubatoDictionary

A reader for the XML-based Rubato file format.

Author:
Gérard Milmeister

Constructor Summary
XMLReader(java.io.File file)
          Creates an XMLReader from the given file.
XMLReader(java.io.Reader reader)
          Creates an XMLReader using the global repository.
XMLReader(java.io.Reader reader, Repository repository)
          Creates an XMLReader using the specified repository.
 
Method Summary
 void addDenoToBeResolved(Denotator d)
          Adds the given denotator to the list of denotators that have to be resolved later.
 void addFormToBeResolved(Form f)
          Adds the given form to the list of forms that have to be resolved later.
static boolean getBooleanAttribute(org.w3c.dom.Element element, java.lang.String attr)
          Returns the boolean value of the given attribute in the specified element.
static org.w3c.dom.Element getChild(org.w3c.dom.Element element, java.lang.String name)
          Returns the first child of the specified element that has the given name.
 Denotator getDenotator(java.lang.String name)
          Returns the denotator with the given name.
 java.util.List<Denotator> getDenotators()
          Returns a list of all denotators parsed from XML.
static double[] getDoubleArrayAttribute(org.w3c.dom.Element element, java.lang.String attr)
           
static java.util.List<java.lang.Double> getDoubleListAttribute(org.w3c.dom.Element element, java.lang.String attr)
           
 java.util.List<java.lang.String> getErrors()
          Returns the list of errors occurred during parsing.
 Form getForm(java.lang.String name)
          Returns the form with the given name.
 java.util.List<Form> getForms()
          Returns a list of all forms parsed from XML.
static int[] getIntArrayAttribute(org.w3c.dom.Element element, java.lang.String attr)
           
static int getIntAttribute(org.w3c.dom.Element element, java.lang.String attr, int def)
          Returns the integer value of the given attribute in the specified element.
static int getIntAttribute(org.w3c.dom.Element element, java.lang.String attr, int min, int max, int def)
          Returns the integer value of the given attribute in the specified element.
static java.util.List<java.lang.Integer> getIntListAttribute(org.w3c.dom.Element element, java.lang.String attr)
           
 Module getModule(java.lang.String name)
          Returns the module for the given name.
 ModuleElement getModuleElement(java.lang.String name)
          Returns the module element for the given name.
 java.util.Set<java.lang.String> getModuleElementNames()
          Returns the names of all parsed module elements.
 java.util.Map<java.lang.String,ModuleElement> getModuleElements()
          Returns the parsed module elements as a map from names to elements.
 ModuleMorphism getModuleMorphism(java.lang.String name)
          Returns the module morphism for the given name.
 java.util.Set<java.lang.String> getModuleMorphismNames()
          Returns the names of all parsed module morphisms.
 java.util.Map<java.lang.String,ModuleMorphism> getModuleMorphisms()
          Returns the parsed module morphisms as a map from names to morphisms.
 java.util.Set<java.lang.String> getModuleNames()
          Returns the names of all parsed modules.
 java.util.Map<java.lang.String,Module> getModules()
          Returns the parsed modules as a map from names to modules.
 java.util.List<NetworkModel> getNetworks()
          Returns the parsed networks as a list.
static org.w3c.dom.Element getNextSibling(org.w3c.dom.Element element, java.lang.String name)
          Returns the next (sibling) element after the specified element that has the given name.
static double getRealAttribute(org.w3c.dom.Element element, java.lang.String attr, double def)
          Returns the double value of the given attribute in the specified element.
 java.util.List<Rubette> getRubettes()
          Returns the parsed rubettes as a list.
 java.lang.String getSchemeCode()
          Returns the Scheme code.
static java.lang.String getStringAttribute(org.w3c.dom.Element element, java.lang.String attr)
          Returns the string value of the given attribute in the specified element.
static java.lang.String getText(org.w3c.dom.Element element)
          Returns the text content of element.
 boolean hasError()
          Returns true if parsing produced any error.
 void parse()
          Parses an XML file.
 Form parseAndResolveForm(org.w3c.dom.Element formNode)
          Parses the form starting from the given XML element, then, if the form is a reference, resolve the reference.
 Denotator parseDenotator(org.w3c.dom.Element denotatorNode)
          Parses the denotator starting from the given XML element.
 void parseFile(java.lang.String fileName)
          Parses an XML file with the specified file name.
 Form parseForm(org.w3c.dom.Element formNode)
          Parses the form starting from the given XML element.
 Module parseModule(org.w3c.dom.Element moduleNode)
          Parses the module starting from the given XML element.
 ModuleElement parseModuleElement(org.w3c.dom.Element elementNode)
          Parses the module element starting from the given XML element.
 ModuleMorphism parseModuleMorphism(org.w3c.dom.Element morphismNode)
          Parses the module morphism starting from the given XML element.
 MorphismMap parseMorphismMap(org.w3c.dom.Element morphismMapNode)
          Parses the morphism map starting from the given XML element.
 void parseString(java.lang.String string)
          Parses an XML file contained in the specified string.
 void printDenotators()
          Displays the denotators that have been parsed.
 void printElements()
          Displays the module elements that have been parsed.
 void printForms()
          Displays the forms that have been parsed.
 void printModules()
          Displays the modules that have been parsed.
 void setError(java.lang.Exception e)
          Appends the error contained in the given exception to the list of errors.
 void setError(java.lang.String string)
          Appends the specified error string to the list of errors.
 void setError(java.lang.String string, java.lang.Object... objects)
          Appends the specified error string to the list of errors.
 java.lang.String toAbsolutePath(java.lang.String path)
          Returns an absolute path based on the specified (relative) path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLReader

public XMLReader(java.io.File file)
          throws java.io.IOException
Creates an XMLReader from the given file.

Throws:
java.io.IOException

XMLReader

public XMLReader(java.io.Reader reader)
Creates an XMLReader using the global repository.


XMLReader

public XMLReader(java.io.Reader reader,
                 Repository repository)
Creates an XMLReader using the specified repository.

Method Detail

parse

public void parse()
Parses an XML file.


parseFile

public void parseFile(java.lang.String fileName)
               throws java.io.FileNotFoundException
Parses an XML file with the specified file name.

Throws:
java.io.FileNotFoundException

parseString

public void parseString(java.lang.String string)
Parses an XML file contained in the specified string.


hasError

public boolean hasError()
Returns true if parsing produced any error.


getErrors

public java.util.List<java.lang.String> getErrors()
Returns the list of errors occurred during parsing.

Returns:
a list of error strings

setError

public void setError(java.lang.String string)
Appends the specified error string to the list of errors.


setError

public void setError(java.lang.String string,
                     java.lang.Object... objects)
Appends the specified error string to the list of errors.


setError

public void setError(java.lang.Exception e)
Appends the error contained in the given exception to the list of errors.


parseModule

public Module parseModule(org.w3c.dom.Element moduleNode)
Parses the module starting from the given XML element.

Returns:
the parsed module or null if parsing failed

parseModuleElement

public ModuleElement parseModuleElement(org.w3c.dom.Element elementNode)
Parses the module element starting from the given XML element.

Returns:
the parsed module element or null if parsing failed

parseModuleMorphism

public ModuleMorphism parseModuleMorphism(org.w3c.dom.Element morphismNode)
Parses the module morphism starting from the given XML element.

Returns:
the parsed module morphism or null if parsing failed

parseMorphismMap

public MorphismMap parseMorphismMap(org.w3c.dom.Element morphismMapNode)
Parses the morphism map starting from the given XML element.

Returns:
the parsed morphism map or null if parsing failed

parseDenotator

public Denotator parseDenotator(org.w3c.dom.Element denotatorNode)
Parses the denotator starting from the given XML element.

Returns:
the parsed denotator or null if parsing failed

parseForm

public Form parseForm(org.w3c.dom.Element formNode)
Parses the form starting from the given XML element. Forms are put into the forms hashtable immediately as they are parsed. In an XML file, only one form definition per name must occur.

Returns:
the parsed form or null if parsing failed

parseAndResolveForm

public Form parseAndResolveForm(org.w3c.dom.Element formNode)
Parses the form starting from the given XML element, then, if the form is a reference, resolve the reference.

Returns:
the parsed form or null if parsing failed

getChild

public static org.w3c.dom.Element getChild(org.w3c.dom.Element element,
                                           java.lang.String name)
Returns the first child of the specified element that has the given name.

Returns:
the first child with the given name or null if there is no such child.

getNextSibling

public static org.w3c.dom.Element getNextSibling(org.w3c.dom.Element element,
                                                 java.lang.String name)
Returns the next (sibling) element after the specified element that has the given name.

Returns:
the next element with the given name or null if there is no such element

getText

public static java.lang.String getText(org.w3c.dom.Element element)
Returns the text content of element.


getIntAttribute

public static int getIntAttribute(org.w3c.dom.Element element,
                                  java.lang.String attr,
                                  int def)
Returns the integer value of the given attribute in the specified element.

Parameters:
element - the element containing the attribute
attr - the attribute whose value is to be returned
def - the default value to return if the attribute has wrong format

getIntAttribute

public static int getIntAttribute(org.w3c.dom.Element element,
                                  java.lang.String attr,
                                  int min,
                                  int max,
                                  int def)
Returns the integer value of the given attribute in the specified element.

Parameters:
element - the element containing the attribute
attr - the attribute whose value is to be returned
min - the minimum value allowed
max - the maximum value allowed
def - the default value to return if the attribute has wrong format

getBooleanAttribute

public static boolean getBooleanAttribute(org.w3c.dom.Element element,
                                          java.lang.String attr)
Returns the boolean value of the given attribute in the specified element.

Parameters:
element - the element containing the attribute
attr - the attribute whose value is to be returned

getStringAttribute

public static java.lang.String getStringAttribute(org.w3c.dom.Element element,
                                                  java.lang.String attr)
Returns the string value of the given attribute in the specified element. Some escaped characters are replaced by their real values.

Parameters:
element - the element containing the attribute
attr - the attribute whose value is to be returned

getRealAttribute

public static double getRealAttribute(org.w3c.dom.Element element,
                                      java.lang.String attr,
                                      double def)
Returns the double value of the given attribute in the specified element.

Parameters:
element - the element containing the attribute
attr - the attribute whose value is to be returned
def - the default value to return if the attribute has wrong format

getIntArrayAttribute

public static int[] getIntArrayAttribute(org.w3c.dom.Element element,
                                         java.lang.String attr)

getIntListAttribute

public static java.util.List<java.lang.Integer> getIntListAttribute(org.w3c.dom.Element element,
                                                                    java.lang.String attr)

getDoubleArrayAttribute

public static double[] getDoubleArrayAttribute(org.w3c.dom.Element element,
                                               java.lang.String attr)

getDoubleListAttribute

public static java.util.List<java.lang.Double> getDoubleListAttribute(org.w3c.dom.Element element,
                                                                      java.lang.String attr)

printModules

public void printModules()
Displays the modules that have been parsed.


printElements

public void printElements()
Displays the module elements that have been parsed.


printForms

public void printForms()
Displays the forms that have been parsed.


printDenotators

public void printDenotators()
Displays the denotators that have been parsed.


getModuleElements

public java.util.Map<java.lang.String,ModuleElement> getModuleElements()
Returns the parsed module elements as a map from names to elements.


getModuleElementNames

public java.util.Set<java.lang.String> getModuleElementNames()
Returns the names of all parsed module elements.


getModuleElement

public ModuleElement getModuleElement(java.lang.String name)
Returns the module element for the given name.

Specified by:
getModuleElement in interface RubatoDictionary
Returns:
null if no such element exists

getModules

public java.util.Map<java.lang.String,Module> getModules()
Returns the parsed modules as a map from names to modules.


getModuleNames

public java.util.Set<java.lang.String> getModuleNames()
Returns the names of all parsed modules.


getModule

public Module getModule(java.lang.String name)
Returns the module for the given name. First try to resolve using the parsed modules then using the global repository.

Specified by:
getModule in interface RubatoDictionary
Returns:
null if no such module exists

getModuleMorphisms

public java.util.Map<java.lang.String,ModuleMorphism> getModuleMorphisms()
Returns the parsed module morphisms as a map from names to morphisms.


getModuleMorphismNames

public java.util.Set<java.lang.String> getModuleMorphismNames()
Returns the names of all parsed module morphisms.


getModuleMorphism

public ModuleMorphism getModuleMorphism(java.lang.String name)
Returns the module morphism for the given name. First try to resolve using the parsed morphisms then using the global repository.

Specified by:
getModuleMorphism in interface RubatoDictionary
Returns:
null if no such morphism exists

getDenotators

public java.util.List<Denotator> getDenotators()
Returns a list of all denotators parsed from XML.

Specified by:
getDenotators in interface RubatoDictionary

getDenotator

public Denotator getDenotator(java.lang.String name)
Returns the denotator with the given name. First try to resolve using the parsed denotators then using the global repository.

Specified by:
getDenotator in interface RubatoDictionary
Returns:
null if no such denotator exists

getForms

public java.util.List<Form> getForms()
Returns a list of all forms parsed from XML.

Specified by:
getForms in interface RubatoDictionary

getForm

public Form getForm(java.lang.String name)
Returns the form with the given name. First try to resolve using the parsed forms then using the global repository.

Specified by:
getForm in interface RubatoDictionary
Returns:
null if no such form exists

getNetworks

public java.util.List<NetworkModel> getNetworks()
Returns the parsed networks as a list.


getRubettes

public java.util.List<Rubette> getRubettes()
Returns the parsed rubettes as a list.


getSchemeCode

public java.lang.String getSchemeCode()
Returns the Scheme code.


addFormToBeResolved

public void addFormToBeResolved(Form f)
Adds the given form to the list of forms that have to be resolved later.


addDenoToBeResolved

public void addDenoToBeResolved(Denotator d)
Adds the given denotator to the list of denotators that have to be resolved later.


toAbsolutePath

public java.lang.String toAbsolutePath(java.lang.String path)
Returns an absolute path based on the specified (relative) path.