Class SchemaModel
- All Implemented Interfaces:
DiffGenerating<SchemaModel>
,Cloneable
Database
schema version.-
Field Summary
Fields inherited from class io.permazen.util.AbstractXMLStreaming
log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Deep-clone this instance.differencesFrom
(SchemaModel that) Detect the differences of this instance when compared to the given instance.boolean
static SchemaModel
fromXML
(InputStream input) Deserialize an instance from the given XML input.final ItemType
Get theItemType
corresponding to this instance.final SchemaId
Generate a uniqueSchemaId
corresponding to the type and encoding structure of this schema item.Get the object types defined in this schema.int
hashCode()
boolean
isEmpty()
Determine if this schema is empty, i.e., defines zero object types.final boolean
isLockedDown
(boolean includingStorageIds) Determine whether this instance is locked down.void
lockDown
(boolean includingStorageIds) Lock down thisSchemaModel
and everySchemaItem
it contains so that no further changes can be made.void
readXML
(XMLStreamReader reader, boolean openTag) Reset this instance and (re)populate it from the given XML input.void
Reset all non-zero storage ID's in this instance back to zero.toString()
Returns this schema model in XML form.toString
(boolean includeStorageIds, boolean prettyPrint) Returns this schema model in XML form.void
toXML
(OutputStream output, boolean includeStorageIds, boolean prettyPrint) Serialize this instance to the given XML output.final void
validate()
Validate this instance.void
validateWithEncodings
(EncodingRegistry encodingRegistry) Validate this instance itself and also verify that all of its field encodings can be found in the givenEncodingRegistry
.final <T extends SchemaItem>
voidvisitSchemaItems
(Class<T> nodeType, Consumer<? super T> visitor) Visit this schema item and all of its descendents matching the given type with the given visitor.void
visitSchemaItems
(Consumer<? super SchemaItem> visitor) Visit allSchemaItem
descendents of this instance with the given visitor.void
writeXML
(XMLStreamWriter writer, boolean includeStorageIds, boolean prettyPrint) Write this instance to the given XML output.Methods inherited from class io.permazen.util.AbstractXMLStreaming
expect, expectClose, getAttr, getAttr, getBooleanAttr, getBooleanAttr, getIntAttr, getIntAttr, getLongAttr, newInvalidAttributeException, newInvalidInputException, newInvalidInputException, next, skip, writeAttr, writeCData, writeCharacters, writeElement, writeEmptyElement, writeStartElement
-
Field Details
-
ITEM_TYPE
TheItemType
that this class represents.
-
-
Constructor Details
-
SchemaModel
public SchemaModel()
-
-
Method Details
-
getSchemaObjectTypes
Get the object types defined in this schema.- Returns:
- object types keyed by name
-
isEmpty
public boolean isEmpty()Determine if this schema is empty, i.e., defines zero object types.- Returns:
- true if this is an empty schema
-
visitSchemaItems
Visit allSchemaItem
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.
- Parameters:
visitor
- visitor for schema items
-
lockDown
public void lockDown(boolean includingStorageIds) Lock down thisSchemaModel
and everySchemaItem
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
.- Parameters:
includingStorageIds
- false to exclude storage ID's, true to lock down everything
-
toXML
public void toXML(OutputStream output, boolean includeStorageIds, boolean prettyPrint) throws IOException Serialize this instance to the given XML output.The
output
is not closed by this method.- Parameters:
output
- XML outputincludeStorageIds
- true to include storage ID'sprettyPrint
- true to indent the XML and add schema ID comments- Throws:
IOException
- if an I/O error occursIllegalArgumentException
- ifoutput
is null
-
fromXML
Deserialize an instance from the given XML input.- Parameters:
input
- XML input- Returns:
- deserialized schema model
- Throws:
IOException
- if an I/O error occursInvalidSchemaException
- if the XML input or decodedSchemaModel
is invalidIllegalArgumentException
- ifinput
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 fieldEncodingId
's must be resolved in the associatedEncodingRegistry
.Once this instance is locked down, repeated invocations of this method will be very fast, just returning the cached previous result.
- Throws:
InvalidSchemaException
- if this instance is invalidIllegalStateException
- if this instance is not locked down
-
validateWithEncodings
Validate this instance itself and also verify that all of its field encodings can be found in the givenEncodingRegistry
.- Parameters:
encodingRegistry
- registry of encodings- Throws:
InvalidSchemaException
- if this instance is itself invalidInvalidSchemaException
- if any simple field's encoding ID can't be resovled byencodingRegistry
IllegalStateException
- if this instance is not locked downIllegalArgumentException
- ifencodingRegistry
is null
-
resetStorageIds
public void resetStorageIds()Reset all non-zero storage ID's in this instance back to zero.- Throws:
UnsupportedOperationException
- if this instance is fully locked down
-
getItemType
Get theItemType
corresponding to this instance.- Returns:
- schema item type
-
differencesFrom
Description copied from interface:DiffGenerating
Detect the differences of this instance when compared to the given instance.- Specified by:
differencesFrom
in interfaceDiffGenerating<SchemaModel>
- Parameters:
that
- other instance- Returns:
- differences; will be empty if there are none detected
-
readXML
Reset this instance and (re)populate it from the given XML input.- Parameters:
reader
- XML inputopenTag
- true if the opening XML<SchemaModel>
tag has already been read frominput
, false to expect to read the tag as the next XML element- Throws:
XMLStreamException
- if the XML input is invalidIllegalArgumentException
- ifreader
is null
-
writeXML
public void writeXML(XMLStreamWriter writer, boolean includeStorageIds, boolean prettyPrint) throws XMLStreamException Write this instance to the given XML output.- Parameters:
writer
- XML outputincludeStorageIds
- true to include storage ID'sprettyPrint
- true to indent and includeSchemaId
comments- Throws:
XMLStreamException
- if an XML error occursIllegalArgumentException
- ifwriter
is null
-
toString
Returns this schema model in XML form. -
toString
Returns this schema model in XML form.- Parameters:
includeStorageIds
- true to include storage ID'sprettyPrint
- true to indent and includeSchemaId
comments
-
equals
-
hashCode
public int hashCode() -
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.
- Parameters:
nodeType
- node type to includevisitor
- visitor for schema items- Throws:
IllegalArgumentException
- if either parameter is null
-
isLockedDown
public final boolean isLockedDown(boolean includingStorageIds) Determine whether this instance is locked down.- Parameters:
includingStorageIds
- false to test all but storage ID's, true to require storage ID's to be locked down as well- Returns:
- true if instance is locked down, otherwise false
-
getSchemaId
Generate a uniqueSchemaId
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.
- Returns:
- schema ID
- Throws:
IllegalStateException
- if this instance is not locked down- See Also:
-