Class Schema
- All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, ExceptionAccessor<Throwable>, AliasAccessor, ChildrenAccessor<Schema[]>, Clearable, DescriptionAccessor, EmptyAccessor, HashAccessor, IdentifierAccessor, KeyAccessor<String>, StereotypeAccessor<String>, TypeAccessor, ValueAccessor<Object>, org.refcodes.ontology.Ontology, Containable, ImmutableTable<String, Object>, ImmutableTable.MutableTable<String, Object>, Keys<String, Object>, Keys.MutableKeys<String, Object>, Keys.MutableValues<String, Object>
A Schema is a lightweight, recursive description of an object graph.
A Schema is not the data structure itself. Instead, it captures
diagnostic and documentation relevant metadata about an instance and its
nested children. This enables rendering the structure as a notation such as
JSON, XML or PlantUML by applying a SchemaVisitor.
A Schema consists of:
- A property map (this class extends
Map) holding descriptive attributes such as identifier, alias, type, hash, value, description, stereotype, or exceptions. - An optional ordered set of child
Schemainstances representing a nested structure.
Rendering is done via visit(SchemaVisitor) or via convenience
methods such as toNotation(SchemaNotation). The default
toString() returns a JSON like representation using
SchemaNotation.JSON.
This type is intended for diagnostics, debugging, verification, and optional
documentation generation. Implementations typically populate it through
builder().
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> Nested classes/interfaces inherited from interface AliasAccessor
AliasAccessor.AliasBuilder<B>, AliasAccessor.AliasMutator, AliasAccessor.AliasPropertyNested classes/interfaces inherited from interface ChildrenAccessor
ChildrenAccessor.ChildrenBuilder<T,B>, ChildrenAccessor.ChildrenMutator<T>, ChildrenAccessor.ChildrenProperty<T> Nested classes/interfaces inherited from interface DescriptionAccessor
DescriptionAccessor.DescriptionBuilder<B>, DescriptionAccessor.DescriptionMutator, DescriptionAccessor.DescriptionPropertyNested classes/interfaces inherited from interface EmptyAccessor
EmptyAccessor.EmptyBuilder<B>, EmptyAccessor.EmptyMutator, EmptyAccessor.EmptyPropertyNested classes/interfaces inherited from interface ExceptionAccessor
ExceptionAccessor.ExceptionBuilder<EXC,B>, ExceptionAccessor.ExceptionMutator<EXC>, ExceptionAccessor.ExceptionProperty<EXC> Nested classes/interfaces inherited from interface HashAccessor
HashAccessor.HashBuilder<B>, HashAccessor.HashMutator, HashAccessor.HashPropertyNested classes/interfaces inherited from interface IdentifierAccessor
IdentifierAccessor.IdentifierBuilder<B>, IdentifierAccessor.IdentifierMutator, IdentifierAccessor.IdentifierPropertyNested classes/interfaces inherited from interface ImmutableTable
ImmutableTable.MutableTable<K,V> Nested classes/interfaces inherited from interface KeyAccessor
KeyAccessor.KeyBuilder<K,B>, KeyAccessor.KeyMutator<K>, KeyAccessor.KeyProperty<K> Nested classes/interfaces inherited from interface Keys
Keys.MutableKeys<K,V>, Keys.MutableValues<K, V> Nested classes/interfaces inherited from interface StereotypeAccessor
StereotypeAccessor.StereotypeBuilder<T,B>, StereotypeAccessor.StereotypeMutator<T>, StereotypeAccessor.StereotypeProperty<T> Nested classes/interfaces inherited from interface TypeAccessor
TypeAccessor.TypeBuilder<T,B>, TypeAccessor.TypeMutator<T>, TypeAccessor.TypeProperty<T> Nested classes/interfaces inherited from interface ValueAccessor
ValueAccessor.ValueBuilder<V,B>, ValueAccessor.ValueMutator<V>, ValueAccessor.ValueProperty<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Schema[]Optional child schemas representing the nested structure (aggregation).static final charThis separator is used to separate the hash code form on object's name. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSchema()Instantiates a new schema.protectedSchema(Schema.Builder aBuilder) Instantiates a newSchemainstance from the providedSchema.Builderinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic Schema.Builderbuilder()Creates a newSchema.Builderfor constructingSchemainstances.<T> TGets the value for the .getAlias()Schema[]intgetHash()getKey()<T> TGets the or.Class<?> getType()getValue()protected voidInitializes theSchemawith the given parameters, in case of beingnull, the according values are derived by internal logic.static StringtoInstanceId(Object aObj) Derives a simple instance identifierStringfrom the simple class's name of the provided instance.toLabel()Determines a stable label for this schema.toNotation(SchemaNotation aNotation) static StringtoSimpleInstanceId(Object aObj) Derives a simple instance identifierStringfrom the simple class's name of the provided instance.toString()<T> Tvisit(SchemaVisitor<T> aVisitor) Applies the givenSchemaVisitorto thisSchema.Methods inherited from class HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class AbstractMap
equals, hashCodeMethods inherited from interface Containable
sizeMethods inherited from interface EmptyAccessor
isEmptyMethods inherited from interface ImmutableTable.MutableTable
delete, putMethods inherited from interface Keys
containsKey, containsValue, get, getOr, keySet, valuesMethods inherited from interface Keys.MutableValues
putMethods inherited from interface Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface org.refcodes.ontology.Ontology
get, get, get, getOr, getOr, getOr, putMethods inherited from interface ValueAccessor
getValueOr, hasValue
-
Field Details
-
HASH_SEPARATOR
public static final char HASH_SEPARATORThis separator is used to separate the hash code form on object's name.- See Also:
-
_children
Optional child schemas representing the nested structure (aggregation). May benullto indicate that no children are present.
-
-
Constructor Details
-
Schema
protected Schema()Instantiates a new schema. -
Schema
Instantiates a new
Schemainstance from the providedSchema.Builderinstance.The builder's options are applied, then derived defaults for identifier, alias, and type are initialized if not explicitly provided.
- Parameters:
aBuilder- The builder instance from which to populateSchemainstance.
-
-
Method Details
-
init
Initializes theSchemawith the given parameters, in case of beingnull, the according values are derived by internal logic. -
getIdentifier
- Specified by:
getIdentifierin interfaceIdentifierAccessor
-
getAlias
- Specified by:
getAliasin interfaceAliasAccessor
-
getKey
- Specified by:
getKeyin interfaceKeyAccessor<String>
-
getType
- Specified by:
getTypein interfaceTypeAccessor
-
getValue
- Specified by:
getValuein interfaceValueAccessor<Object>
-
getHash
public int getHash()If the hash is not explicitly set,
-1is returned.- Specified by:
getHashin interfaceHashAccessor
-
getStereotype
- Specified by:
getStereotypein interfaceStereotypeAccessor<String>
-
getException
- Specified by:
getExceptionin interfaceExceptionAccessor<Throwable>
-
getDescription
- Specified by:
getDescriptionin interfaceDescriptionAccessor
-
getChildren
- Specified by:
getChildrenin interfaceChildrenAccessor<Schema[]>
-
get
-
getOr
-
toLabel
Determines a stable label for this schema.
The label is derived in this order: identifier (without the trailing
'@hash'part), type simple name, alias, key, and finally the computed identifier.- Returns:
- the derived label
-
visit
Applies the given
SchemaVisitorto thisSchema.The
SchemaVisitordecides how to traverse theSchemaand its children and returns a consolidated result of the traversal.- Type Parameters:
T- The produced result type- Parameters:
aVisitor- TheSchemaVisitorto apply- Returns:
- The result produced by the visitor
-
toNotation
- Parameters:
aNotation- A @link SchemaNotation}'sSchemaVisitorproducing a textual representation- Returns:
- The rendered notation
-
toString
- Overrides:
toStringin classAbstractMap<String,Object>
-
toInstanceId
-
toSimpleInstanceId
-
builder
Creates a newSchema.Builderfor constructingSchemainstances.- Returns:
- A new builder instance
-