Class StoreConfiguration

  • All Implemented Interfaces:
    java.io.Serializable, javax.swing.table.TableModel

    public class StoreConfiguration
    extends javax.swing.table.AbstractTableModel
    This class interacts with a permanent set of configuration states stored in an XML-format disk file. Each state is identified by a description and date stamp, which are added when a state is stored. The content of the state isn't actually understood at this level that is left to more specific classes.

    An instance of this class presents itself as two services. One is as a JTable model, this provides a model of two columns, the first being the state description the second the date stamp. The second set of services are provided to get at states and to store new ones. These latter options are provided by passing back references to suitable Elements of a Document, which then act as roots for the state.

    The format of the XML file is just determined by the practices adopted in this file and by the StoreSource implementation, rather than by a DTD or Schema. The root element is <configs> each child of this element is called whatever StoreSource.getTagName() returns, with the attributes "description" and "date-stamp", what goes after this is determined by the writer of the configurations, but the general idea is for each object in the configuration to write its state to a new Element.

    Author:
    Peter W. Draper
    See Also:
    Element, StoreControlFrame, StoreSource, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String applicationName
      Name of the application (used for name of config directory).
      protected org.w3c.dom.Document document
      The Document.
      protected org.w3c.dom.Element rootElement
      Document root Element.
      protected java.lang.String storeName
      Name of the file used for storage.
      • Fields inherited from class javax.swing.table.AbstractTableModel

        listenerList
    • Constructor Summary

      Constructors 
      Constructor Description
      StoreConfiguration​(java.io.InputStream inputStream)
      Create an instance.
      StoreConfiguration​(java.lang.String applicationName, java.lang.String storeName)
      Create an instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void createEmptyDoc()
      Create an empty document
      static java.util.List<org.w3c.dom.Element> getChildElements​(org.w3c.dom.Element element)
      Return all the Elements that are children of another Element.
      int getColumnCount()
      Get the number of columns.
      java.lang.String getColumnName​(int column)
      Get the name of a column.
      int getCount()
      Get the number of states that are stored.
      java.lang.String getDateStamp​(int index)
      Get the date stamp of a state by index.
      java.lang.String getDescription​(int index)
      Get the description of a state by index.
      int getRowCount()
      Return the numbers of states that we're currently storing.
      org.w3c.dom.Element getState​(int index)
      Get a state from the store.
      java.lang.Object getValueAt​(int row, int column)
      Return either the description or date stamp of a state.
      void initFromBackingStore()
      Initialise the local DOM from the backing store file.
      void initFromBackingStore​(java.io.InputStream inputStream)
      Initialise the local DOM from an InputStream.
      boolean isCellEditable​(int row, int column)
      Let the JTable know that the descriptions are edittable.
      org.w3c.dom.Element newState​(java.lang.String elementName, java.lang.String description)
      Create a new Element ready for attaching a configuration state to (i.e.
      org.w3c.dom.Element reGetState​(int index)
      Re-get a state from the store.
      void removeState​(int index)
      Permanently remove a state from store.
      void setDateStamp​(int index)
      Set the date stamp of a state by index.
      void setDescription​(int index, java.lang.String value)
      Set the description of a state by index.
      void setValueAt​(java.lang.Object value, int row, int column)
      Change a description in response to a user edit.
      void stateCompleted​(org.w3c.dom.Element newState)
      Add a new state root in a given Element.
      void writeToBackingStore()
      Save the Document to backing store.
      • Methods inherited from class javax.swing.table.AbstractTableModel

        addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
      • Methods inherited from class java.lang.Object

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

      • document

        protected org.w3c.dom.Document document
        The Document.
      • rootElement

        protected org.w3c.dom.Element rootElement
        Document root Element.
      • applicationName

        protected java.lang.String applicationName
        Name of the application (used for name of config directory).
      • storeName

        protected java.lang.String storeName
        Name of the file used for storage.
    • Constructor Detail

      • StoreConfiguration

        public StoreConfiguration​(java.lang.String applicationName,
                                  java.lang.String storeName)
        Create an instance. This synchronises the current total state with that of the backing store.
        Parameters:
        applicationName - name of the application controlling this store. Used to create a top-element, also defines the configuration directory. XXX use Properties for this?
        storeName - name of the file that contains the configuration
      • StoreConfiguration

        public StoreConfiguration​(java.io.InputStream inputStream)
        Create an instance. This synchronises the current total state with that read from a given InputStream (useful when want to get a default configuration using a getResource()). If you use this method it is not possible to save to backing store.
        Parameters:
        inputStream - InputStream that contains an XML description of a series of configurations (i.e. a wrapped backing store file).
    • Method Detail

      • initFromBackingStore

        public void initFromBackingStore​(java.io.InputStream inputStream)
        Initialise the local DOM from an InputStream.
      • initFromBackingStore

        public void initFromBackingStore()
        Initialise the local DOM from the backing store file. If this doesn't exist then just create an empty Document with a basic root Element.
      • createEmptyDoc

        protected void createEmptyDoc()
        Create an empty document
      • getChildElements

        public static java.util.List<org.w3c.dom.Element> getChildElements​(org.w3c.dom.Element element)
        Return all the Elements that are children of another Element.
      • getCount

        public int getCount()
        Get the number of states that are stored.
      • getState

        public org.w3c.dom.Element getState​(int index)
        Get a state from the store. These are indexed simply by the order in the current document.
      • reGetState

        public org.w3c.dom.Element reGetState​(int index)
        Re-get a state from the store. Re-getting implies that this will be overwritten so all children are removed.
      • getDescription

        public java.lang.String getDescription​(int index)
        Get the description of a state by index.
      • setDescription

        public void setDescription​(int index,
                                   java.lang.String value)
        Set the description of a state by index.
      • getDateStamp

        public java.lang.String getDateStamp​(int index)
        Get the date stamp of a state by index.
      • setDateStamp

        public void setDateStamp​(int index)
        Set the date stamp of a state by index. Updates to representation of the current time.
      • stateCompleted

        public void stateCompleted​(org.w3c.dom.Element newState)
        Add a new state root in a given Element. The Element should be created by the newState method.
      • newState

        public org.w3c.dom.Element newState​(java.lang.String elementName,
                                            java.lang.String description)
        Create a new Element ready for attaching a configuration state to (i.e. get this Element then write the configuration data attached to it). When the new configuration is completed invoke the stateCompleted method, the configuration will not be part of the structure until then.
      • removeState

        public void removeState​(int index)
        Permanently remove a state from store.
      • writeToBackingStore

        public void writeToBackingStore()
        Save the Document to backing store.
      • getRowCount

        public int getRowCount()
        Return the numbers of states that we're currently storing.
      • getColumnCount

        public int getColumnCount()
        Get the number of columns. Always 2.
      • getValueAt

        public java.lang.Object getValueAt​(int row,
                                           int column)
        Return either the description or date stamp of a state.
      • getColumnName

        public java.lang.String getColumnName​(int column)
        Get the name of a column.
        Specified by:
        getColumnName in interface javax.swing.table.TableModel
        Overrides:
        getColumnName in class javax.swing.table.AbstractTableModel
      • setValueAt

        public void setValueAt​(java.lang.Object value,
                               int row,
                               int column)
        Change a description in response to a user edit.
        Specified by:
        setValueAt in interface javax.swing.table.TableModel
        Overrides:
        setValueAt in class javax.swing.table.AbstractTableModel
      • isCellEditable

        public boolean isCellEditable​(int row,
                                      int column)
        Let the JTable know that the descriptions are edittable.
        Specified by:
        isCellEditable in interface javax.swing.table.TableModel
        Overrides:
        isCellEditable in class javax.swing.table.AbstractTableModel