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.Clearable, org.refcodes.mixin.DescriptionAccessor, org.refcodes.mixin.EmptyAccessor, 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>, org.refcodes.ontology.Ontology, org.refcodes.struct.Containable, org.refcodes.struct.ImmutableTable<String,Object>, org.refcodes.struct.ImmutableTable.MutableTable<String,Object>, org.refcodes.struct.Keys<String,Object>, org.refcodes.struct.Keys.MutableKeys<String,Object>, org.refcodes.struct.Keys.MutableValues<String,Object>

public class Schema extends HashMap<String,Object> implements org.refcodes.ontology.Ontology, org.refcodes.mixin.ChildrenAccessor<Schema[]>, org.refcodes.mixin.IdentifierAccessor, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.TypeAccessor, org.refcodes.mixin.HashAccessor, org.refcodes.mixin.DescriptionAccessor, org.refcodes.mixin.KeyAccessor<String>, org.refcodes.mixin.StereotypeAccessor<String>, org.refcodes.exception.ExceptionAccessor<Throwable>, 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 Schema instances 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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for creating Schema instances.

    Nested classes/interfaces inherited from class 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>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty

    Nested classes/interfaces inherited from interface org.refcodes.mixin.ChildrenAccessor

    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>, org.refcodes.mixin.DescriptionAccessor.DescriptionMutator, org.refcodes.mixin.DescriptionAccessor.DescriptionProperty

    Nested classes/interfaces inherited from interface org.refcodes.mixin.EmptyAccessor

    org.refcodes.mixin.EmptyAccessor.EmptyBuilder<B>, org.refcodes.mixin.EmptyAccessor.EmptyMutator, org.refcodes.mixin.EmptyAccessor.EmptyProperty

    Nested classes/interfaces inherited from interface org.refcodes.exception.ExceptionAccessor

    org.refcodes.exception.ExceptionAccessor.ExceptionBuilder<EXC,B>, org.refcodes.exception.ExceptionAccessor.ExceptionMutator<EXC>, org.refcodes.exception.ExceptionAccessor.ExceptionProperty<EXC>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.HashAccessor

    org.refcodes.mixin.HashAccessor.HashBuilder<B>, org.refcodes.mixin.HashAccessor.HashMutator, org.refcodes.mixin.HashAccessor.HashProperty

    Nested classes/interfaces inherited from interface org.refcodes.mixin.IdentifierAccessor

    org.refcodes.mixin.IdentifierAccessor.IdentifierBuilder<B>, org.refcodes.mixin.IdentifierAccessor.IdentifierMutator, org.refcodes.mixin.IdentifierAccessor.IdentifierProperty

    Nested classes/interfaces inherited from interface org.refcodes.struct.ImmutableTable

    org.refcodes.struct.ImmutableTable.MutableTable<K,V>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.KeyAccessor

    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.struct.Keys

    org.refcodes.struct.Keys.MutableKeys<K,V>, org.refcodes.struct.Keys.MutableValues<K,V>

    Nested classes/interfaces inherited from interface Map

    Map.Entry<K,V>

    Nested classes/interfaces inherited from interface org.refcodes.mixin.StereotypeAccessor

    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>, 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>, org.refcodes.mixin.ValueAccessor.ValueMutator<V>, org.refcodes.mixin.ValueAccessor.ValueProperty<V>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Schema[]
    Optional child schemas representing the nested structure (aggregation).
    static final char
    This separator is used to separate the hash code form on object's name.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Instantiates a new schema.
    protected
    Instantiates a new Schema instance from the provided Schema.Builder instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new Schema.Builder for constructing Schema instances.
    <T> T
    get(String aKey, Class<T> aType)
    Gets the value for the .
    int
    <T> T
    getOr(String aKey, Class<T> aType, T aValue)
    Gets the or.
    protected void
    init(String aAlias, String aIdentifier, Class<?> aType)
    Initializes the Schema with the given parameters, in case of being null, the according values are derived by internal logic.
    static String
    Derives a simple instance identifier String from the simple class's name of the provided instance.
    Determines a stable label for this schema.
    Renders this Schema using the given SchemaNotation's SchemaVisitor.
    static String
    Derives a simple instance identifier String from the simple class's name of the provided instance.
    <T> T
    visit(SchemaVisitor<T> aVisitor)
    Applies the given SchemaVisitor to this Schema.

    Methods inherited from class AbstractMap

    equals, hashCode

    Methods inherited from class Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.refcodes.mixin.Clearable

    clear

    Methods inherited from interface org.refcodes.struct.Containable

    size

    Methods inherited from interface org.refcodes.mixin.EmptyAccessor

    isEmpty

    Methods inherited from interface org.refcodes.struct.ImmutableTable.MutableTable

    delete, put

    Methods inherited from interface org.refcodes.struct.Keys

    containsKey, containsValue, get, getOr, keySet, values

    Methods inherited from interface org.refcodes.struct.Keys.MutableValues

    put

    Methods inherited from interface org.refcodes.ontology.Ontology

    get, get, get, getOr, getOr, getOr, put

    Methods inherited from interface org.refcodes.mixin.ValueAccessor

    getValueOr, hasValue
  • Field Details

    • HASH_SEPARATOR

      public static final char HASH_SEPARATOR
      This separator is used to separate the hash code form on object's name.
      See Also:
    • _children

      protected Schema[] _children
      Optional child schemas representing the nested structure (aggregation). May be null to indicate that no children are present.
  • Constructor Details

    • Schema

      protected Schema()
      Instantiates a new schema.
    • Schema

      protected Schema(Schema.Builder aBuilder)

      Instantiates a new Schema instance from the provided Schema.Builder instance.

      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 populate Schema instance.
  • Method Details

    • init

      protected void init(String aAlias, String aIdentifier, Class<?> aType)
      Initializes the Schema with the given parameters, in case of being null, the according values are derived by internal logic.
      Parameters:
      aAlias - The alias for of the Schema, if null it is derived by internal logic.
      aIdentifier - The identifier for the Schema, if null it is derived by internal logic.
      aType - The type described by the Schema, if null it is derived by internal logic.
    • getIdentifier

      public String getIdentifier()
      Specified by:
      getIdentifier in interface org.refcodes.mixin.IdentifierAccessor
    • getAlias

      public String getAlias()
      Specified by:
      getAlias in interface org.refcodes.mixin.AliasAccessor
    • getKey

      public String getKey()
      Specified by:
      getKey in interface org.refcodes.mixin.KeyAccessor<String>
    • getType

      public Class<?> getType()
      Specified by:
      getType in interface org.refcodes.mixin.TypeAccessor
    • getValue

      public Object getValue()
      Specified by:
      getValue in interface org.refcodes.mixin.ValueAccessor<Object>
    • getHash

      public int getHash()

      If the hash is not explicitly set, -1 is returned.

      Specified by:
      getHash in interface org.refcodes.mixin.HashAccessor
    • getStereotype

      public String getStereotype()
      Specified by:
      getStereotype in interface org.refcodes.mixin.StereotypeAccessor<String>
    • getException

      public Throwable getException()
      Specified by:
      getException in interface org.refcodes.exception.ExceptionAccessor<Throwable>
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface org.refcodes.mixin.DescriptionAccessor
    • getChildren

      public Schema[] getChildren()
      Specified by:
      getChildren in interface org.refcodes.mixin.ChildrenAccessor<Schema[]>
    • get

      public <T> T get(String aKey, Class<T> aType)
      Gets the value for the .
      Type Parameters:
      T - the generic type
      Parameters:
      aKey - the key
      aType - the type
      Returns:
      the t
    • getOr

      public <T> T getOr(String aKey, Class<T> aType, T aValue)
      Gets the or.
      Type Parameters:
      T - the generic type
      Parameters:
      aKey - the key
      aType - the type
      aValue - the value
      Returns:
      the or
    • toLabel

      public String 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

      public <T> T visit(SchemaVisitor<T> aVisitor)

      Applies the given SchemaVisitor to this Schema.

      The SchemaVisitor decides how to traverse the Schema and its children and returns a consolidated result of the traversal.

      Type Parameters:
      T - The produced result type
      Parameters:
      aVisitor - The SchemaVisitor to apply
      Returns:
      The result produced by the visitor
    • toNotation

      public String toNotation(SchemaNotation aNotation)
      Renders this Schema using the given SchemaNotation's SchemaVisitor.
      Parameters:
      aNotation - A @link SchemaNotation}'s SchemaVisitor producing a textual representation
      Returns:
      The rendered notation
    • toString

      public String toString()
      Overrides:
      toString in class AbstractMap<String,Object>
    • toInstanceId

      public static String toInstanceId(Object aObj)
      Derives a simple instance identifier String from the simple class's name of the provided instance.
      Parameters:
      aObj - The instance from which to retrieve the simple instance ID String.
      Returns:
      The derived instance's ID.
    • toSimpleInstanceId

      public static String toSimpleInstanceId(Object aObj)
      Derives a simple instance identifier String from the simple class's name of the provided instance.
      Parameters:
      aObj - The instance from which to retrieve the simple instance ID String.
      Returns:
      The derived instance's ID.
    • builder

      public static Schema.Builder builder()
      Creates a new Schema.Builder for constructing Schema instances.
      Returns:
      A new builder instance.