Class SchemaModel
- All Implemented Interfaces:
DiffGenerating<SchemaModel>,Cloneable
Database schema version.-
Field Summary
FieldsFields inherited from class io.permazen.util.AbstractXMLStreaming
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Deep-clone this instance.differencesFrom(SchemaModel that) Detect the differences of this instance when compared to the given instance.booleanstatic SchemaModelfromXML(InputStream input) Deserialize an instance from the given XML input.final ItemTypeGet theItemTypecorresponding to this instance.final SchemaIdGenerate a uniqueSchemaIdcorresponding to the type and encoding structure of this schema item.Get the object types defined in this schema.inthashCode()booleanisEmpty()Determine if this schema is empty, i.e., defines zero object types.final booleanisLockedDown(boolean includingStorageIds) Determine whether this instance is locked down.voidlockDown(boolean includingStorageIds) Lock down thisSchemaModeland everySchemaItemit contains so that no further changes can be made.voidreadXML(XMLStreamReader reader, boolean openTag) Reset this instance and (re)populate it from the given XML input.voidReset 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.voidtoXML(OutputStream output, boolean includeStorageIds, boolean prettyPrint) Serialize this instance to the given XML output.final voidvalidate()Validate this instance.voidvalidateWithEncodings(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.voidvisitSchemaItems(Consumer<? super SchemaItem> visitor) Visit allSchemaItemdescendents of this instance with the given visitor.voidwriteXML(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
TheItemTypethat 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 allSchemaItemdescendents 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 thisSchemaModeland everySchemaItemit 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
outputis 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- ifoutputis 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 decodedSchemaModelis invalidIllegalArgumentException- ifinputis null
-
validate
public final void validate()Validate this instance.This performs basic structural validation. Full validation is not possible without a
Databaseinstance; 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 byencodingRegistryIllegalStateException- if this instance is not locked downIllegalArgumentException- ifencodingRegistryis 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 theItemTypecorresponding to this instance.- Returns:
- schema item type
-
differencesFrom
Description copied from interface:DiffGeneratingDetect the differences of this instance when compared to the given instance.- Specified by:
differencesFromin 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- ifreaderis 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 includeSchemaIdcomments- Throws:
XMLStreamException- if an XML error occursIllegalArgumentException- ifwriteris 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 includeSchemaIdcomments
-
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 uniqueSchemaIdcorresponding to the type and encoding structure of this schema item.The
SchemaIddoes 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:
-