Class OptionDescriptorParser

java.lang.Object
org.jppf.ui.options.xml.OptionDescriptorParser

public class OptionDescriptorParser extends Object
Instances of this class are used to parse an XML document, describing an options page, into a tree of option descriptors.
Author:
Laurent Cohen
  • Constructor Details

    • OptionDescriptorParser

      public OptionDescriptorParser() throws Exception
      Initialize this parser.
      Throws:
      Exception - if the DOM parser could not be initialized.
  • Method Details

    • parse

      public OptionDescriptor parse(String docPath) throws Exception
      Parse an XML document in a file into a tree of option descriptors.
      Parameters:
      docPath - the path to XML document to parse.
      Returns:
      an OptionDescriptor instance, root of the generated tree, or null if the document could not be parsed.
      Throws:
      Exception - if an error occurs while parsing the document.
    • parse

      public OptionDescriptor parse(Reader reader) throws Exception
      Parse an XML document in a reader into a tree of option descriptors.
      Parameters:
      reader - the reader providing the XML document.
      Returns:
      an OptionDescriptor instance, root of the generated tree, or null if the document could not be parsed.
      Throws:
      Exception - if an error occurs while parsing the document.
    • findFirstElement

      public Node findFirstElement(Document doc)
      Find the first node in a document that is an element node.
      Parameters:
      doc - the document whose children are looked up.
      Returns:
      a Node instance if one was found, or null otherwise.
    • generateTree

      public OptionDescriptor generateTree(Node node)
      Generate an OptionDescriptor tree from a DOM subtree.
      Parameters:
      node - the document to generate the tree from.
      Returns:
      an OptionDescriptor instance, root of the generated tree, or null if the document could not be parsed.
    • createItemDescriptor

      public OptionDescriptor.ItemDescriptor createItemDescriptor(Node node)
      Create an item descriptor from a DOM node.
      Parameters:
      node - the node to generate the listener from.
      Returns:
      a ItemDescriptor instance.
    • createListenerDescriptor

      public OptionDescriptor.ListenerDescriptor createListenerDescriptor(Node node)
      Create a listener descriptor from a DOM node.
      Parameters:
      node - the node to generate the listener from.
      Returns:
      a ListenerDescriptor instance.
    • setListenerAttributes

      public void setListenerAttributes(Node node, OptionDescriptor.ListenerDescriptor desc)
      Set the attributes of a listener descriptor.
      Parameters:
      node - the parent listener node.
      desc - the listener descriptor whose attributes have to be set.
    • getTextNodeValue

      public String getTextNodeValue(Node node)
      Get the value of a node's text subelement.
      Parameters:
      node - the node to generate whose child is a text node.
      Returns:
      the text as a string.
    • createScriptDescriptor

      public OptionDescriptor.ScriptDescriptor createScriptDescriptor(Node node)
      Create a script descriptor from a DOM node.
      Parameters:
      node - the node to generate the listener from.
      Returns:
      a ScriptDescriptor instance.
    • addProperty

      public void addProperty(OptionDescriptor desc, Node node)
      Add a property to an option descriptor from a DOM node.
      Parameters:
      desc - the option descriptor to add the property to.
      node - the node to get the property name and value from.
    • loadImport

      public OptionDescriptor loadImport(Node node)
      Import an external XML descriptor.
      Parameters:
      node - the node to get the import description from.
      Returns:
      a OptionDescriptor instance.