com.xerox.bantam
Class Schema

java.lang.Object
  |
  +--com.xerox.bantam.Schema
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SchemaSchema

public class Schema
extends Object
implements Serializable

A Schema object is an immutable representation of a Bantam schema.

The Schema object allows the user to specify the enforcement of both the presence and type of document properties. To define a schema in code, create a subclass of Schema according to the following guidelines:

  • Define a method static public Schema getSchema() that returns an instance of the schema, preferably the same instance every time it is called. Repetitively generating new instances not only wastes memory but will prevent efficient validation, slowing down many operations.
  • Arrange to use the no-arguments constructor of Schema, preferably by creating the subclass with an empty no-argument constructor
  • Define a class variable for every schema field, with type exactly public static final com.xerox.bantam.FieldDescriptor and an initializer using one of the constructors of FieldDescriptor. With this form of definition, code can use the class variables to identify individual fields, and the single schema object to identify the schema with compile-time type checking. The no-argument public constructor of Schema will introspect to gather all required information. Alternatively, a subclass constructor can call a Schema constructor with an explicit list of FieldDescriptors.

    To enable efficient validation of Schema objects when they are passed in Bantam methods, Schema objects must be immmutable. This is the reason why subclasses are not permitted to override getFields() or to access internal field records.

    Version:
    $Revision: 1.12 $, $Date: 2000/08/11 07:16:21 $
    Author:
    Keith Edwards
    See Also:
    Serialized Form

    Inner Class Summary
    protected  class Schema.fieldCompare
              Comparator for partial ordering by field name This comparator is inconsistent with equals for FieldDescriptor
     
    Field Summary
    protected  String name
              Name of the schema.
    protected  long version
              Version of the schema.
     
    Constructor Summary
    protected Schema()
              Constructor for subclasses which define a schema in code.
      Schema(String schemaName, FieldDescriptor[] f)
              Construct from field descriptors.
     
    Method Summary
     boolean equals(Object obj)
              Equality test
     FieldDescriptor[] getFields()
              Return all field definitions in the schema
     String getName()
              Return schema name.
    static Schema getSchema(Class clazz)
              Retrieve the canonical instance of a schema by class
    static Schema getSchema(String name)
              Retrieve the canonical instance of a schema by name
    static List getSchemaFields(Class clazz)
              Get all the FieldDescriptors from clazz which are used to describe the schema they represent.
     long getVersion()
              Return a version stamp which is a signature value for this schema.
     Schema parse(String text)
              Create a Schema from a text definition
     int size()
              Return the number of entries in this schema.
     String toString()
               
     
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Field Detail

    name

    protected String name
    Name of the schema. Schemas are uniquely identified by name.

    version

    protected long version
    Version of the schema. Schema version number is used for quick validation that two Schema objects with the same name represent precisely the same schema.
    Constructor Detail

    Schema

    protected Schema()
    Constructor for subclasses which define a schema in code. Automatically gathers FieldDescriptor definitions from public static final slots.

    Schema

    public Schema(String schemaName,
                  FieldDescriptor[] f)
    Construct from field descriptors.
    Method Detail

    getSchemaFields

    public static List getSchemaFields(Class clazz)
    Get all the FieldDescriptors from clazz which are used to describe the schema they represent.

    getSchema

    public static Schema getSchema(Class clazz)
    Retrieve the canonical instance of a schema by class
    Parameters:
    name - the name of the schema to retrieve

    getSchema

    public static Schema getSchema(String name)
    Retrieve the canonical instance of a schema by name
    Parameters:
    name - the name of the schema to retrieve

    size

    public int size()
    Return the number of entries in this schema.
    Returns:
    int the number of SchemaEntries we hold

    getName

    public String getName()
    Return schema name. A schema is uniquely identified by name.

    getVersion

    public long getVersion()
    Return a version stamp which is a signature value for this schema. The signature is computed similarly to the computation of Java serialVersionUIDs.

    getFields

    public final FieldDescriptor[] getFields()
    Return all field definitions in the schema

    toString

    public final String toString()
    Overrides:
    toString in class Object

    parse

    public Schema parse(String text)
    Create a Schema from a text definition

    equals

    public boolean equals(Object obj)
    Equality test
    Overrides:
    equals in class Object

    Project Harland