org.geotools.feature
Class DefaultAttributeType

java.lang.Object
  extended byorg.geotools.feature.DefaultAttributeType
All Implemented Interfaces:
AttributeType
Direct Known Subclasses:
GeometricAttributeType, MultiAttributeType, NumericAttributeType, TemporalAttributeType, TextualAttributeType

public class DefaultAttributeType
extends java.lang.Object
implements AttributeType

Simple, immutable class to store attributes. This class should be sufficient for all simple (ie. non-schema) attribute implementations of this interface.

Version:
$Id: DefaultAttributeType.java 17701 2006-01-23 00:00:51Z desruisseaux $
Author:
Rob Hranac, VFNY, Chris Holmes, TOPP, Ian Schneider

Field Summary
protected  java.lang.Object defaultValue
           
protected  int max
           
protected  int min
           
protected  java.lang.String name
          Name of this attribute.
protected  boolean nillable
          Indicates if nulls are allowed for this attribute
protected  java.lang.Class type
          Class type of this attribute.
 
Fields inherited from interface org.geotools.feature.AttributeType
UNBOUNDED
 
Constructor Summary
protected DefaultAttributeType(AttributeType copy)
           
protected DefaultAttributeType(java.lang.String name, java.lang.Class type, boolean nillable, int min, int max, java.lang.Object defaultValue)
           
protected DefaultAttributeType(java.lang.String name, java.lang.Class type, boolean nillable, int min, int max, java.lang.Object defaultValue, Filter f)
          Constructor with name and type.
protected DefaultAttributeType(java.lang.String name, java.lang.Class type, boolean nillable, java.lang.Object defaultValue)
           
 
Method Summary
 java.lang.Object createDefaultValue()
          Create a default value for this AttributeType.
 java.lang.Object duplicate(java.lang.Object src)
          Return a safe Object copy.
 boolean equals(java.lang.Object other)
          Override of equals.
 int getMaxOccurs()
          Defaults are flat, always return 1.
 int getMinOccurs()
          Defaults are flat, always return 1.
 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.
 int hashCode()
          Override of hashCode.
 boolean isGeometry()
          Returns whether the attribute is a geometry.
 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.
 java.lang.String toString()
          Gets a representation of this object as a string.
 void validate(java.lang.Object attribute)
          Whether the tested object passes the validity constraints of this AttributeType.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected final java.lang.String name
Name of this attribute.


type

protected final java.lang.Class type
Class type of this attribute.


nillable

protected final boolean nillable
Indicates if nulls are allowed for this attribute


min

protected final int min

max

protected final int max

defaultValue

protected java.lang.Object defaultValue
Constructor Detail

DefaultAttributeType

protected DefaultAttributeType(java.lang.String name,
                               java.lang.Class type,
                               boolean nillable,
                               int min,
                               int max,
                               java.lang.Object defaultValue,
                               Filter f)
Constructor with name and type.

Parameters:
name - Name of this attribute.
type - Class type of this attribute.
nillable - If nulls are allowed for the attribute of this type.
defaultValue - default value when none is suppled
Task:
REVISIT: make this protected? I think it's only used by facotries at this time.

DefaultAttributeType

protected DefaultAttributeType(java.lang.String name,
                               java.lang.Class type,
                               boolean nillable,
                               int min,
                               int max,
                               java.lang.Object defaultValue)

DefaultAttributeType

protected DefaultAttributeType(java.lang.String name,
                               java.lang.Class type,
                               boolean nillable,
                               java.lang.Object defaultValue)

DefaultAttributeType

protected DefaultAttributeType(AttributeType copy)
Method Detail

getMinOccurs

public int getMinOccurs()
Defaults are flat, always return 1.

Specified by:
getMinOccurs in interface AttributeType
Returns:
Task:
REVISIT: return 0? That's our current assumption in some code, but

getMaxOccurs

public int getMaxOccurs()
Defaults are flat, always return 1.

Specified by:
getMaxOccurs in interface AttributeType
Returns:

getName

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

Specified by:
getName in interface AttributeType
Returns:
The name of this attribute.

getType

public java.lang.Class getType()
Gets the type of this attribute. All attributes that are assigned to this AttributeType must be an instance of this class. Subclasses are allowed as well.

Specified by:
getType in interface AttributeType
Returns:
The class that the attribute must match to be valid for this AttributeType.

isNillable

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

Specified by:
isNillable in interface AttributeType
Returns:
true if nulls are permitted, false otherwise.

duplicate

public java.lang.Object duplicate(java.lang.Object src)
                           throws IllegalAttributeException
Return a safe Object copy.

Obtain a duplicate Object if the object is mutable, or the same Object reference if it is immutable.

Specified by:
duplicate in interface AttributeType
Parameters:
src - The Object to duplicate.
Returns:
A duplicated Object if the type is mutable or the same Object if it is immutable or null if the passed Object is null.
Throws:
IllegalAttributeException - if the Object cannot be duplicated.

hashCode

public int hashCode()
Override of hashCode.

Returns:
hashCode for this object.

equals

public boolean equals(java.lang.Object other)
Override of equals.

Parameters:
other - the object to be tested for equality.
Returns:
whether other is equal to this attribute Type.

isGeometry

public boolean isGeometry()
Returns whether the attribute is a geometry.

Returns:
true if the attribute's type is a geometry.

toString

public java.lang.String toString()
Gets a representation of this object as a string.

Returns:
A representation of this object as a string

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.

Specified by:
parse in interface AttributeType
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 attribute)
              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.

Specified by:
validate in interface AttributeType
Parameters:
attribute - The object to be tested for validity.
Throws:
java.lang.IllegalArgumentException - if the object does not validate.

createDefaultValue

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

Specified by:
createDefaultValue in interface AttributeType
Returns:
Default value, note may be null if isNillable is true

getRestriction

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

Specified by:
getRestriction in interface AttributeType
Returns:
Filter, or Filter.NONE if no restriction is needed.


Copyright © GeoTools. All Rights Reserved.