Package cbsw

Class InventoryBasic


  • public class InventoryBasic
    extends java.lang.Object

    An API for an inventory stored as an XML document.

    • Constructor Summary

      Constructors 
      Constructor Description
      InventoryBasic​(java.lang.String fileName, java.lang.String elementName)
      Loads the inventory (.xml) document and locates the named table.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void doIndex​(java.lang.String indexAttributeName)
      Indexes the table.
      org.w3c.dom.Document getDocument()  
      java.lang.String getFieldValue​(java.lang.String name)
      Get the value for the named field for the current row.
      java.lang.String getFieldValue​(org.w3c.dom.Element el, java.lang.String name)
      Get the value for the named field in the Element.
      org.w3c.dom.Element identify​(java.lang.String id, java.lang.String match, java.lang.String reference, java.lang.String idAttributeName)
      Prompts for an identify and updates the current element.
      boolean isCurrentElementNull()  
      void setText​(org.w3c.dom.Element element, java.lang.String text)  
      void updateField​(java.lang.String name, java.lang.String value)
      Update the value for the named field.
      void write​(java.lang.String fileName)
      Writes the modfied inventory.
      void writeBackup​(java.lang.String fileNamePrefix)
      Writes the current inventory document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • inventoryDocument

        protected org.w3c.dom.Document inventoryDocument
      • inventoryElement

        protected org.w3c.dom.Element inventoryElement
      • currentElement

        protected org.w3c.dom.Element currentElement
      • elementName

        protected java.lang.String elementName
    • Constructor Detail

      • InventoryBasic

        public InventoryBasic​(java.lang.String fileName,
                              java.lang.String elementName)

        Loads the inventory (.xml) document and locates the named table.

        Parameters:
        fileName - Directory path of XML file.
        elementName - Name of the element.
    • Method Detail

      • getDocument

        public org.w3c.dom.Document getDocument()
      • doIndex

        public void doIndex​(java.lang.String indexAttributeName)

        Indexes the table.

        An indexing attribute is added to each table row to allow simple searching using the getElementById method.

        Parameters:
        indexAttributeName - The name of the indexing attribute.
      • identify

        public org.w3c.dom.Element identify​(java.lang.String id,
                                            java.lang.String match,
                                            java.lang.String reference,
                                            java.lang.String idAttributeName)

        Prompts for an identify and updates the current element.

        Parameters:
        id - The candidate identifier.
        match - The identifier must match this regular expression.
        reference - Identifier of existing element to clone.
        idAttributeName - The name of the id attribute.
        Returns:
        The element.
      • write

        public void write​(java.lang.String fileName)

        Writes the modfied inventory.

        Parameters:
        fileName - Path of database XML file.
      • writeBackup

        public void writeBackup​(java.lang.String fileNamePrefix)

        Writes the current inventory document.

        A timestamp is appended to the created file name after the provided prefix.

        Parameters:
        fileNamePrefix - The file name prefix.
      • updateField

        public void updateField​(java.lang.String name,
                                java.lang.String value)

        Update the value for the named field.

        Parameters:
        name - Name of the field to update.
        value - The new value.
      • getFieldValue

        public java.lang.String getFieldValue​(java.lang.String name)

        Get the value for the named field for the current row.

        Parameters:
        name - Name of the field.
        Returns:
        The value.
      • getFieldValue

        public java.lang.String getFieldValue​(org.w3c.dom.Element el,
                                              java.lang.String name)

        Get the value for the named field in the Element.

        Parameters:
        el - The Element.
        name - Name of the field.
        Returns:
        The value.
      • isCurrentElementNull

        public boolean isCurrentElementNull()
      • setText

        public void setText​(org.w3c.dom.Element element,
                            java.lang.String text)