Class DefaultRecordSchema

java.lang.Object
org.apache.sis.util.iso.DefaultRecordSchema
All Implemented Interfaces:
org.opengis.util.RecordSchema
Direct Known Subclasses:
RecordSchemaSIS

public class DefaultRecordSchema extends Object implements org.opengis.util.RecordSchema
A collection of record types in a given namespace. This class works also as a factory for creating RecordType and Record instances. The factory methods are: Subclasses can modify the characteristics of the records to be created by overriding the following methods:

Thread safety

The same DefaultRecordSchema instance can be safely used by many threads without synchronization on the part of the caller if the NameFactory given to the constructor is also thread-safe. Subclasses should make sure that any overridden methods remain safe to call from multiple threads.

Limitations

This class is currently not serializable because RecordSchema contain an arbitrary number of record types in its description map. Since each RecordType has a reference to its schema, serializing a single RecordType could imply serializing all of them. In order to reduce the risk of unexpected behavior, serialization is currently left to subclasses. For example, a subclass may define a Object readResolve() method (as documented in the Serializable interface) returning a system-wide static constant for their schema.
Since:
0.5
Version:
1.3
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ConcurrentMap<Class<?>,org.opengis.util.Type>
    The pool of attribute types created so far.
    private final Map<org.opengis.util.TypeName,org.opengis.util.RecordType>
    The record types in the namespace of this schema.
    protected final DefaultNameFactory
    The factory to use for creating names.
    private final org.opengis.util.NameSpace
    The namespace of RecordType to be created by this class.
    private final ObjectConverter<Class<?>,org.opengis.util.Type>
    The converter to use for converting Java Class to ISO 19103 Type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultRecordSchema(DefaultNameFactory nameFactory, org.opengis.util.NameSpace parent, CharSequence schemaName)
    Creates a new schema of the given name.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.opengis.util.RecordType
    Creates a new record type of the given name, which will contain the given fields.
    org.opengis.util.TypeName
    Creates the name of a record.
    Map<org.opengis.util.TypeName,org.opengis.util.RecordType>
    Returns the dictionary of all (name, record type) pairs in this schema.
    org.opengis.util.LocalName
    Returns the schema name.
    org.opengis.util.RecordType
    locate(org.opengis.util.TypeName name)
    Returns the record type for the given name.
    (package private) final org.opengis.util.Type
    toAttributeType(Class<?> valueClass)
    Suggests an attribute type for the given value class.
    Returns a string representation of this schema for debugging purpose only.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • nameFactory

      protected final DefaultNameFactory nameFactory
      The factory to use for creating names. This is the factory given at construction time.
      Upcoming API change — generalization
      This field type will be changed to the NameFactory interface when that interface will provide a createMemberName(…) method (tentatively in GeoAPI 3.1).
    • namespace

      private final org.opengis.util.NameSpace namespace
      The namespace of RecordType to be created by this class. This is also (indirectly) the schema name.
    • description

      private final Map<org.opengis.util.TypeName,org.opengis.util.RecordType> description
      The record types in the namespace of this schema.
    • attributeTypes

      private final ConcurrentMap<Class<?>,org.opengis.util.Type> attributeTypes
      The pool of attribute types created so far.
    • toTypes

      private final ObjectConverter<Class<?>,org.opengis.util.Type> toTypes
      The converter to use for converting Java Class to ISO 19103 Type. This converter delegates its work to the toAttributeType(Class) method.
  • Constructor Details

    • DefaultRecordSchema

      public DefaultRecordSchema(DefaultNameFactory nameFactory, org.opengis.util.NameSpace parent, CharSequence schemaName)
      Creates a new schema of the given name.
      Upcoming API change — generalization
      This type of the first argument will be changed to the NameFactory interface when that interface will provide a createMemberName(…) method (tentatively in GeoAPI 3.1).
      Parameters:
      nameFactory - the factory to use for creating names, or null for the default factory.
      parent - the parent namespace, or null if none.
      schemaName - the name of the new schema.
  • Method Details

    • getSchemaName

      public org.opengis.util.LocalName getSchemaName()
      Returns the schema name.
      Specified by:
      getSchemaName in interface org.opengis.util.RecordSchema
      Returns:
      the schema name.
    • createRecordTypeName

      public org.opengis.util.TypeName createRecordTypeName(CharSequence typeName)
      Creates the name of a record.
      Parameters:
      typeName - name of the record type to create.
      Returns:
      name of a record type.
      Since:
      1.3
    • createRecordType

      public org.opengis.util.RecordType createRecordType(CharSequence typeName, Map<CharSequence,Class<?>> fields) throws IllegalArgumentException
      Creates a new record type of the given name, which will contain the given fields. Fields are declared in iteration order.
      Parameters:
      typeName - name of the record type to create.
      fields - the name of each record field, together with the expected value types.
      Returns:
      a record type of the given name and fields.
      Throws:
      IllegalArgumentException - if a record already exists for the given name but with different fields.
    • toAttributeType

      final org.opengis.util.Type toAttributeType(Class<?> valueClass)
      Suggests an attribute type for the given value class. The TypeName will use the UML identifier of OGC/ISO specification when possible, e.g. "GCO:CharacterString" for java.lang.String. See Mapping Java classes to type names in DefaultTypeName javadoc for more information.
      Parameters:
      valueClass - the value class to represent as an attribute type.
      Returns:
      attribute type for the given value class.
    • getDescription

      public Map<org.opengis.util.TypeName,org.opengis.util.RecordType> getDescription()
      Returns the dictionary of all (name, record type) pairs in this schema.
      Specified by:
      getDescription in interface org.opengis.util.RecordSchema
      Returns:
      all (name, record type) pairs in this schema.
    • locate

      public org.opengis.util.RecordType locate(org.opengis.util.TypeName name)
      Returns the record type for the given name. If the type name is not defined within this schema, then this method returns null.
      Specified by:
      locate in interface org.opengis.util.RecordSchema
      Parameters:
      name - the name of the type to lookup.
      Returns:
      the type for the given name, or null if none.
    • toString

      public String toString()
      Returns a string representation of this schema for debugging purpose only.
      Overrides:
      toString in class Object