Class InventoryBasic

java.lang.Object
cbsw.InventoryBasic

public class InventoryBasic extends Object

An API for an inventory stored as an XML document.

  • Field Details

    • inventoryDocument

      protected Document inventoryDocument
    • inventoryElement

      protected Element inventoryElement
    • currentElement

      protected Element currentElement
    • elementName

      protected String elementName
  • Constructor Details

    • InventoryBasic

      public InventoryBasic(String fileName, 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 Details

    • getDocument

      public Document getDocument()
    • doIndex

      public void doIndex(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 Element identify(String id, String match, String reference, 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(String fileName)

      Writes the modfied inventory.

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

      public void writeBackup(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(String name, String value)

      Update the value for the named field.

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

      public String getFieldValue(String name)

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

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

      public String getFieldValue(Element el, 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(Element element, String text)