Class SchemaModel

All Implemented Interfaces:
DiffGenerating<SchemaModel>, Cloneable

public class SchemaModel extends AbstractXMLStreaming implements DiffGenerating<SchemaModel>
Models one Permazen Database schema version.
  • Field Details


      public static final ItemType ITEM_TYPE
      The ItemType that this class represents.
  • Constructor Details

    • SchemaModel

      public SchemaModel()
  • Method Details

    • getSchemaObjectTypes

      public NavigableMap<String,SchemaObjectType> getSchemaObjectTypes()
      Get the object types defined in this schema.
      object types keyed by name
    • isEmpty

      public boolean isEmpty()
      Determine if this schema is empty, i.e., defines zero object types.
      true if this is an empty schema
    • visitSchemaItems

      public void visitSchemaItems(Consumer<? super SchemaItem> visitor)
      Visit all SchemaItem descendents of this instance with the given visitor.

      If this instance is also a SchemaItem, then also visit this instance.

      The traversal is depth first, pre-order.

      visitor - visitor for schema items
    • lockDown

      public void lockDown(boolean includingStorageIds)
      Lock down this SchemaModel and every SchemaItem it contains so that no further changes can be made.

      There are two levels of lock down: the first level locks everything, except storage ID's that are zero may be changed to a non-zero value. The second level locks down everything. Levels increase monotonically.

      Attempts to modify a locked down schema item generate an UnsupportedOperationException.

      includingStorageIds - false to exclude storage ID's, true to lock down everything
    • toXML

      public void toXML(OutputStream output, boolean prettyPrint) throws IOException
      Serialize this instance to the given XML output.

      The output is not closed by this method.

      output - XML output
      prettyPrint - true to indent the XML and add schema ID comments
      IOException - if an I/O error occurs
    • fromXML

      public static SchemaModel fromXML(InputStream input) throws IOException
      Deserialize an instance from the given XML input.
      input - XML input
      deserialized schema model
      IOException - if an I/O error occurs
      InvalidSchemaException - if the XML input or decoded SchemaModel is invalid
      IllegalArgumentException - if input is null
    • validate

      public final void validate()
      Validate this instance.

      This performs basic structural validation. Full validation is not possible without a Database instance; for example, simple field EncodingId's must be resolved in the associated EncodingRegistry.

      Once this instance is locked down, repeated invocations of this method will be very fast, just returning the cached previous result.

      InvalidSchemaException - if this instance is invalid
      IllegalStateException - if this instance is not locked down
    • validateWithEncodings

      public void validateWithEncodings(EncodingRegistry encodingRegistry)
      Validate this instance itself and also verify that all of its field encodings can be found in the given EncodingRegistry.
      encodingRegistry - registry of encodings
      InvalidSchemaException - if this instance is itself invalid
      InvalidSchemaException - if any simple field's encoding ID can't be resovled by encodingRegistry
      IllegalStateException - if this instance is not locked down
      IllegalArgumentException - if encodingRegistry is null
    • resetStorageIds

      public void resetStorageIds()
      Reset all non-zero storage ID's in this instance back to zero.
      UnsupportedOperationException - if this instance is fully locked down
    • getItemType

      public final ItemType getItemType()
      Get the ItemType corresponding to this instance.
      schema item type
    • differencesFrom

      public Diffs differencesFrom(SchemaModel that)
      Description copied from interface: DiffGenerating
      Detect the differences of this instance when compared to the given instance.
      Specified by:
      differencesFrom in interface DiffGenerating<SchemaModel>
      that - other instance
      differences; will be empty if there are none detected
    • readXML

      public void readXML(XMLStreamReader reader, boolean openTag) throws XMLStreamException
      Reset this instance and (re)populate it from the given XML input.
      reader - XML input
      openTag - true if the opening XML <SchemaModel> tag has already been read from input, false to expect to read the tag as the next XML element
      XMLStreamException - if the XML input is invalid
      IllegalArgumentException - if reader is null
    • writeXML

      public void writeXML(XMLStreamWriter writer, boolean prettyPrint) throws XMLStreamException
      Write this instance to the given XML output.
      writer - XML output
      prettyPrint - true to indent and include SchemaId comments
      XMLStreamException - if an XML error occurs
      IllegalArgumentException - if writer is null
    • toString

      public String toString()
      toString in class Object
    • equals

      public boolean equals(Object obj)
      equals in class Object
    • hashCode

      public int hashCode()
      hashCode in class Object
    • clone

      public SchemaModel clone()
      Deep-clone this instance.
    • visitSchemaItems

      public final <T extends SchemaItem> void visitSchemaItems(Class<T> nodeType, Consumer<? super T> visitor)
      Visit this schema item and all of its descendents matching the given type with the given visitor.

      The traversal is depth first, post-order.

      nodeType - node type to include
      visitor - visitor for schema items
      IllegalArgumentException - if either parameter is null
    • isLockedDown

      public final boolean isLockedDown(boolean includingStorageIds)
      Determine whether this instance is locked down.
      includingStorageIds - false to test all but storage ID's, true to require storage ID's to be locked down as well
      true if instance is locked down, otherwise false
    • getSchemaId

      public final SchemaId getSchemaId()
      Generate a unique SchemaId corresponding to the type and encoding structure of this schema item.

      The SchemaId does not depend on the storage ID.

      This instance must be locked down except for storage ID's. Repeated invocations of this method will be very fast, just returning the cached previous result.

      schema ID
      IllegalStateException - if this instance is not locked down
      See Also: