Class Schema
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,Object> org.refcodes.exception.ExceptionAccessor<Throwable>,org.refcodes.mixin.AliasAccessor,org.refcodes.mixin.ChildrenAccessor<Schema[]>,org.refcodes.mixin.DescriptionAccessor,org.refcodes.mixin.HashAccessor,org.refcodes.mixin.IdentifierAccessor,org.refcodes.mixin.KeyAccessor<String>,org.refcodes.mixin.StereotypeAccessor<String>,org.refcodes.mixin.TypeAccessor,org.refcodes.mixin.ValueAccessor<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 java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.ChildrenAccessor
org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T,B extends org.refcodes.mixin.ChildrenAccessor.ChildrenBuilder<T, B>>, org.refcodes.mixin.ChildrenAccessor.ChildrenMutator<T>, org.refcodes.mixin.ChildrenAccessor.ChildrenProperty<T> Nested classes/interfaces inherited from interface org.refcodes.mixin.DescriptionAccessor
org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B extends org.refcodes.mixin.DescriptionAccessor.DescriptionBuilder<B>>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionPropertyNested classes/interfaces inherited from interface org.refcodes.exception.ExceptionAccessor
org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<EXC extends Throwable,B extends org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<EXC, B>>, org.refcodes.exception.ExceptionAccessor.ExceptionMutator<EXC extends Throwable>, org.refcodes.exception.ExceptionAccessor.ExceptionProperty<EXC extends Throwable> Nested classes/interfaces inherited from interface org.refcodes.mixin.HashAccessor
org.refcodes.mixin.HashAccessor.HashBuilder<B extends org.refcodes.mixin.HashAccessor.HashBuilder<B>>, org.refcodes.mixin.HashAccessor.HashMutator, org.refcodes.mixin.HashAccessor.HashPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.IdentifierAccessor
org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<B extends org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<B>>, org.refcodes.mixin.IdentifierAccessor.IdentifierMutator, org.refcodes.mixin.IdentifierAccessor.IdentifierPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.KeyAccessor
org.refcodes.mixin.KeyAccessor.KeyBuilder<K,B extends org.refcodes.mixin.KeyAccessor.KeyBuilder<K, B>>, org.refcodes.mixin.KeyAccessor.KeyMutator<K>, org.refcodes.mixin.KeyAccessor.KeyProperty<K> Nested classes/interfaces inherited from interface org.refcodes.mixin.StereotypeAccessor
org.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<T,B extends org.refcodes.mixin.StereotypeAccessor.StereotypeBuilder<T, B>>, org.refcodes.mixin.StereotypeAccessor.StereotypeMutator<T>, org.refcodes.mixin.StereotypeAccessor.StereotypeProperty<T> Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor
org.refcodes.mixin.TypeAccessor.TypeBuilder<T,B extends org.refcodes.mixin.TypeAccessor.TypeBuilder<T, B>>, org.refcodes.mixin.TypeAccessor.TypeMutator<T>, org.refcodes.mixin.TypeAccessor.TypeProperty<T> Nested classes/interfaces inherited from interface org.refcodes.mixin.ValueAccessor
org.refcodes.mixin.ValueAccessor.ValueBuilder<V,B extends org.refcodes.mixin.ValueAccessor.ValueBuilder<V, B>>, org.refcodes.mixin.ValueAccessor.ValueMutator<V>, org.refcodes.mixin.ValueAccessor.ValueProperty<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Schema[]Optional child schemas representing the nested structure (aggregation).static final StringThis key labels the short name of aSchema.static final StringThis key labels a child's parent's association in terms of UML.static final StringThis key labels the description aSchema.static final StringThis key labels an exception related to aSchema.static final StringThis key labels the hash of an object described by aSchema.static final charThis separator is used to separate the hash code form on object's name.static final StringThis key labels the unique identifier of aSchema.static final StringThis key labels a child's parent key of aSchema.static final StringThis key labels a stereotype (category) in terms of UML.static final StringThis key labels the type described by aSchema.static final StringThis key labels the value described by aSchema. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSchema()Schema(String aIdentifier, String aAlias, String aKey, Class<?> aType, Integer aHash, String aStereotype, Object aValue, Throwable aException, String aDescription, Schema aSchema, Schema[] aChildren) Constructs aSchemawith explicit metadata, optional base schema, and optional children.protectedSchema(Schema.Builder aBuilder) Instantiates a newSchemainstance from the providedSchema.Builderinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic Schema.Builderbuilder()Creates a newSchema.Builderfor constructingSchemainstances.<T> TgetAlias()Schema[]intgetHash()getKey()<T> TClass<?> getType()getValue()protected voidtoLabel()Determines a stable label for this schema.toNotation(SchemaNotation aNotation) protected static StringtoObjectId(Object aObj) protected static StringtoSimpleObjectId(Object aObj) toString()Returns a default textual representation of thisSchema.<T> Tvisit(SchemaVisitor<T> aVisitor) Applies the givenSchemaVisitorto thisSchema.Methods inherited from class java.util.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 java.util.AbstractMap
equals, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.refcodes.mixin.ValueAccessor
getValueOr
-
Field Details
-
ASSOCIATION
This key labels a child's parent's association in terms of UML.- See Also:
-
IDENTIFIER
-
ALIAS
-
KEY
-
TYPE
-
HASH
-
VALUE
-
DESCRIPTION
-
EXCEPTION
-
STEREOTYPE
This key labels a stereotype (category) in terms of UML.- See Also:
-
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() -
Schema
Instantiates a new
Schemainstance from the providedSchema.Builderinstance.The builder's properties 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.
-
Schema
public Schema(String aIdentifier, String aAlias, String aKey, Class<?> aType, Integer aHash, String aStereotype, Object aValue, Throwable aException, String aDescription, Schema aSchema, Schema[] aChildren) Constructs a
Schemawith explicit metadata, optional base schema, and optional children.At least one of
aAlias,aKey,aType, oraIdentifiermust be non-null so that a stable label/identifier can be derived.- Parameters:
aIdentifier- unique identifier for this schema; ifnulla default identifier is derivedaAlias- human-readable short name; ifnulla default alias is derived from the identifieraKey- optional key when this schema represents a keyed valueaType- described type; ifnullit may be derived fromaValueaHash- identity or content hash of the described instance (optional)aStereotype- optional UML-like categoryaValue- optional described valueaException- optional related exceptionaDescription- optional human-readable descriptionaSchema- optional base schema from which properties are copied if not explicitly setaChildren- optional child schemas forming the nested structure- Throws:
IllegalArgumentException- if all ofaAlias,aKey,aType, andaIdentifierarenull
-
-
Method Details
-
init
-
getIdentifier
- Specified by:
getIdentifierin interfaceorg.refcodes.mixin.IdentifierAccessor
-
getAlias
- Specified by:
getAliasin interfaceorg.refcodes.mixin.AliasAccessor
-
getKey
-
getType
- Specified by:
getTypein interfaceorg.refcodes.mixin.TypeAccessor
-
getValue
-
getHash
public int getHash()If the hash is not explicitly set,
-1is returned.- Specified by:
getHashin interfaceorg.refcodes.mixin.HashAccessor
-
getStereotype
-
getException
-
getDescription
- Specified by:
getDescriptionin interfaceorg.refcodes.mixin.DescriptionAccessor
-
getChildren
-
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
Returns a default textual representation of this
Schema.By default, this method renders the
SchemausingSchemaNotation.JSON.- Overrides:
toStringin classAbstractMap<String,Object> - Returns:
- A JSON like string representation
-
builder
Creates a newSchema.Builderfor constructingSchemainstances.- Returns:
- a new builder instance
-
toObjectId
-
toSimpleObjectId
-