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 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:
  • 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 IdentifierAccessor
    • getAlias

      public String getAlias()
      Specified by:
      getAlias in interface AliasAccessor
    • getKey

      public String getKey()
      Specified by:
      getKey in interface KeyAccessor<String>
    • getType

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

      public Object getValue()
      Specified by:
      getValue in interface ValueAccessor<Object>
    • getHash

      public int getHash()

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

      Specified by:
      getHash in interface HashAccessor
    • getStereotype

      public String getStereotype()
      Specified by:
      getStereotype in interface StereotypeAccessor<String>
    • getException

      public Throwable getException()
      Specified by:
      getException in interface ExceptionAccessor<Throwable>
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface DescriptionAccessor
    • getChildren

      public Schema[] getChildren()
      Specified by:
      getChildren in interface 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