org.geotools.feature
Interface AttributeType

All Known Subinterfaces:
FeatureAttributeType, GeometryAttributeType, PrimativeAttributeType
All Known Implementing Classes:
ChoiceAttributeType, ChoiceAttributeType.Geometric, DefaultAttributeType, FeatureAttributeType, GeometricAttributeType, ListAttributeType, NumericAttributeType, SetAttributeType, TemporalAttributeType, TextualAttributeType, VPFColumn

public interface AttributeType

Stores metadata about a single attribute object.

  1. Name: A string that is used to reference the attribute.
  2. Nillable: if nulls are allowed as this attribute.
  3. Type: The expected Java class of this attribute.

AttributeTypes must also provide the validate(Object obj) method, which determines whether a given object matches the constraints imposed by the AttributeType. In a default attribute this will simply be that it is of the correct class and non-null (or null if isNillable is true). More complex AttributeTypes can impose any restrictions that they like. Nested FeatureTypes are an example of this, as they need to check that the Feature object matches all its constraints, not that it is just of class Feature.

Additionally, implementors may use the parse method to convert an object to its preferred storage type. If an implementor does not choose to provide any functionality for this method they should simple return the object passed in. If parsing is attempted and not successful, then an exception should be thrown. This method is primarily used by FeatureType to try to convert objects to the correct storage type, such as a string of a double when the AttributeType requires a Double.

Version:
$Id: AttributeType.java 17702 2006-01-23 00:08:55Z desruisseaux $
Author:
Rob Hranac, VFNY, Chris Holmes, TOPP

Field Summary
static int UNBOUNDED
          Represents any number of elements.
 
Method Summary
 java.lang.Object createDefaultValue()
          Create a default value for this AttributeType.
 java.lang.Object duplicate(java.lang.Object src)
          Create a duplicate value of the passed Object.
 int getMaxOccurs()
          Returns the Max number of occurences ...
 int getMinOccurs()
          Returns the Min number of occurences ...
 java.lang.String getName()
          Gets the name of this attribute.
 Filter getRestriction()
          This represents a Facet in XML schema ... for example can be used to represent the max length of 20 for a string.
 java.lang.Class getType()
          Gets the type of this attribute.
 boolean isNillable()
          Returns whether nulls are allowed for this attribute.
 java.lang.Object parse(java.lang.Object value)
          Allows this AttributeType to convert an argument to its prefered storage type.
 void validate(java.lang.Object obj)
          Whether the tested object passes the validity constraints of this AttributeType.
 

Field Detail

UNBOUNDED

public static final int UNBOUNDED
Represents any number of elements. Same '' in a reg-ex

See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()
Gets the name of this attribute.

Returns:
Name.

getType

public java.lang.Class getType()
Gets the type of this attribute.

Returns:
Type.

getRestriction

public Filter getRestriction()
This represents a Facet in XML schema ... for example can be used to represent the max length of 20 for a string.

Returns:
Filter, or Filter.NONE if no restriction is needed.

isNillable

public boolean isNillable()
Returns whether nulls are allowed for this attribute.

Returns:
true if nulls are permitted, false otherwise.

getMinOccurs

public int getMinOccurs()
Returns the Min number of occurences ...

Returns:

getMaxOccurs

public int getMaxOccurs()
Returns the Max number of occurences ...

Returns:

parse

public java.lang.Object parse(java.lang.Object value)
                       throws java.lang.IllegalArgumentException
Allows this AttributeType to convert an argument to its prefered storage type. If no parsing is possible, returns the original value. If a parse is attempted, yet fails (i.e. a poor decimal format) throw the Exception. This is mostly for use internally in Features, but implementors should simply follow the rules to be safe.

Parameters:
value - the object to attempt parsing of.
Returns:
value converted to the preferred storage of this AttributeType. If no parsing was possible then the same object is returned.
Throws:
java.lang.IllegalArgumentException - if parsing is attempted and is unsuccessful.

validate

public void validate(java.lang.Object obj)
              throws java.lang.IllegalArgumentException
Whether the tested object passes the validity constraints of this AttributeType. At a minimum it should be of the correct class specified by getType(), non-null if isNillable is false, and a geometry if isGeometry is true. If The object does not validate then an IllegalArgumentException reporting the error in validation should be thrown.

Parameters:
obj - The object to be tested for validity.
Throws:
java.lang.IllegalArgumentException - if the object does not validate.

duplicate

public java.lang.Object duplicate(java.lang.Object src)
                           throws IllegalAttributeException
Create a duplicate value of the passed Object. For immutable Objects, it is not neccessary to create a new Object.

Parameters:
src - The Object to duplicate.
Returns:
Duplicate of provided object
Throws:
IllegalAttributeException - If the src Object is not the correct type.

createDefaultValue

public java.lang.Object createDefaultValue()
Create a default value for this AttributeType. If the type is nillable, the Object may or may not be null.

Returns:
Default value, note may be null if isNillable is true


Copyright © GeoTools. All Rights Reserved.