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>

public class Schema extends HashMap<String,Object> implements 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 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.AliasProperty

    Nested 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.DescriptionProperty

    Nested 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.HashProperty

    Nested 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.IdentifierProperty

    Nested 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 java.util.Map

    Map.Entry<K,V>

    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

    Fields
    Modifier and Type
    Field
    Description
    protected Schema[]
    Optional child schemas representing the nested structure (aggregation).
    static final String
    This key labels the short name of a Schema.
    static final String
    This key labels a child's parent's association in terms of UML.
    static final String
    This key labels the description a Schema.
    static final String
    This key labels an exception related to a Schema.
    static final String
    This key labels the hash of an object described by a Schema.
    static final char
    This separator is used to separate the hash code form on object's name.
    static final String
    This key labels the unique identifier of a Schema.
    static final String
    This key labels a child's parent key of a Schema.
    static final String
    This key labels a stereotype (category) in terms of UML.
    static final String
    This key labels the type described by a Schema.
    static final String
    This key labels the value described by a Schema.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
     
    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 Schema with explicit metadata, optional base schema, and optional children.
    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)
     
    int
    <T> T
    getOr(String aKey, Class<T> aType, T aValue)
     
    protected void
    init(String aAlias, String aIdentifier, Class<?> aType)
     
    Determines a stable label for this schema.
    Renders this Schema using the given SchemaNotation's SchemaVisitor.
    protected static String
     
    protected static String
     
    Returns a default textual representation of this Schema.
    <T> T
    visit(SchemaVisitor<T> aVisitor)
    Applies the given SchemaVisitor to this Schema.

    Methods inherited from class java.util.AbstractMap

    equals, hashCode

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.util.Map

    equals, hashCode

    Methods inherited from interface org.refcodes.mixin.ValueAccessor

    getValueOr
  • Field Details

  • Constructor Details

    • Schema

      protected Schema()
    • Schema

      protected Schema(Schema.Builder aBuilder)

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

      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 populate Schema instance.
    • 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 Schema with explicit metadata, optional base schema, and optional children.

      At least one of aAlias, aKey, aType, or aIdentifier must be non-null so that a stable label/identifier can be derived.

      Parameters:
      aIdentifier - unique identifier for this schema; if null a default identifier is derived
      aAlias - human-readable short name; if null a default alias is derived from the identifier
      aKey - optional key when this schema represents a keyed value
      aType - described type; if null it may be derived from aValue
      aHash - identity or content hash of the described instance (optional)
      aStereotype - optional UML-like category
      aValue - optional described value
      aException - optional related exception
      aDescription - optional human-readable description
      aSchema - optional base schema from which properties are copied if not explicitly set
      aChildren - optional child schemas forming the nested structure
      Throws:
      IllegalArgumentException - if all of aAlias, aKey, aType, and aIdentifier are null
  • Method Details

    • init

      protected void init(String aAlias, String aIdentifier, Class<?> aType)
    • 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)
    • getOr

      public <T> T getOr(String aKey, Class<T> aType, T aValue)
    • 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()

      Returns a default textual representation of this Schema.

      By default, this method renders the Schema using SchemaNotation.JSON.

      Overrides:
      toString in class AbstractMap<String,Object>
      Returns:
      A JSON like string representation
    • builder

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

      protected static String toObjectId(Object aObj)
    • toSimpleObjectId

      protected static String toSimpleObjectId(Object aObj)