Class Schema

All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.ChildrenAccessor<Schema[]>, org.refcodes.mixin.DescriptionAccessor, org.refcodes.mixin.TypeAccessor

public class Schema extends HashMap<String,Object> implements org.refcodes.mixin.ChildrenAccessor<Schema[]>, org.refcodes.mixin.TypeAccessor, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.DescriptionAccessor
A Schema describes a nested data structure (having 0..n Schema children) whilst not being the data structure itself. A documentation in JSON or XML notation can be produced from a Schema instance for debugging or diagnostic purposes (see JsonVisitor as well as XmlVisitor) by invoking the visit(SchemaVisitor) method (also custom SchemaVisitor classes my be programmed).For description purposes, any descriptive attribute can be added as a key with the according value, as a Schema extends the Map interface. The Schema is a useful base class when implementing a package's Schema type. By default it's toString() method produces a JSON alike String representation of this Schema instances alongside its children by uses the JsonVisitor type applied to the visit(SchemaVisitor) method.
See Also:
  • Field Details

    • ALIAS

      public static String ALIAS
    • COMMENT

      public static String COMMENT
    • DESCRIPTION

      public static String DESCRIPTION
    • EXCEPTION

      public static String EXCEPTION
    • KEY

      public static String KEY
    • TYPE

      public static String TYPE
    • VALUE

      public static String VALUE
    • VERBOSE

      public static String VERBOSE
  • Constructor Details

    • Schema

      public Schema(Class<?> aType, String aDescription)
      Constructs a Schema with the provided arguments.
      Parameters:
      aType - The type providing the this Schema instance.
      aDescription - The description of the schema described by the Schema providing type.
    • Schema

      public Schema(String aAlias, Class<?> aType)
      Constructs a Schema with the provided arguments.
      Parameters:
      aAlias - The alias (name) of the schema described by the Schema providing type.
      aType - The type providing the this Schema instance.
    • Schema

      public Schema(String aAlias, Class<?> aType, String aDescription)
      Constructs a Schema with the provided arguments.
      Parameters:
      aAlias - The alias (name) of the schema described by the Schema providing type.
      aType - The type providing the this Schema instance.
      aDescription - The description of the schema described by the Schema providing type.
    • Schema

      public Schema(Class<?> aType, String aDescription, Schema... aChildren)
      Constructs a Schema with the provided arguments.
      Parameters:
      aType - The type providing the this Schema instance.
      aDescription - The description of the schema described by the Schema providing type.
      aChildren - The children's Schema descriptions representing part of the Schema providing type.
    • Schema

      public Schema(String aAlias, Class<?> aType, String aDescription, Schema... aChildren)
      Constructs a Schema with the provided arguments.
      Parameters:
      aAlias - The alias (name) of the schema described by the Schema providing type.
      aType - The type providing the this Schema instance.
      aDescription - The description of the schema described by the Schema providing type.
      aChildren - The children's Schema descriptions representing part of the Schema providing type.
    • Schema

      public Schema(Schema aSchema)
      Constructs a Schema with the properties of the provided Schema ("copy constructor"),.
      Parameters:
      aSchema - The Schema from which to copy the attributes.
    • Schema

      public Schema(Class<?> aType, Schema aSchema)
      Constructs a Schema with the provided arguments.
      Parameters:
      aType - The type providing the this Schema instance.
      aSchema - The Schema from which to copy the attributes.
    • Schema

      public Schema(Schema aSchema, Schema... aChildren)
      Constructs a Schema with the properties of the provided Schema ("copy constructor"),.
      Parameters:
      aSchema - The Schema from which to copy the attributes.
      aChildren - The children's Schema descriptions representing part of the Schema providing type.
  • Method Details

    • getAlias

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

      public Class<?> getType()
      Specified by:
      getType in interface org.refcodes.mixin.TypeAccessor
    • 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[]>
    • visit

      public <T> T visit(SchemaVisitor<T> aVisitor)
      Visits this Schema instance, the provided SchemaVisitor visitor is invoked with the result's of the Schema instance's children (as of visit(SchemaVisitor) and this Schema instance to produce a result. Therefore this method visits (invokes the SchemaVisitor.visit(Schema, java.util.Collection) method for) the leaves first, traversing down till the root Schema instance (the one where the visit(SchemaVisitor) method was initially called).
      Type Parameters:
      T - The type of the value which the visitor produces.
      Parameters:
      aVisitor - The SchemaVisitor visitor to traverse this Schema instance.
      Returns:
      The according result produced by the SchemaVisitor instance.
    • toString

      public String toString()
      Uses the JsonVisitor type applied to the visit(SchemaVisitor) method to produce a JSON alike String representation of this Schema instances alongside its children.
      Overrides:
      toString in class AbstractMap<String,Object>