org.geotools.feature
Class DefaultAttributeType

Object
  extended by PropertyDescriptorImpl
      extended by AttributeDescriptorImpl
          extended by DefaultAttributeType
All Implemented Interfaces:
AttributeType, AttributeDescriptor, PropertyDescriptor
Direct Known Subclasses:
GeometricAttributeType, MultiAttributeType, NumericAttributeType, TemporalAttributeType, TextualAttributeType

public class DefaultAttributeType
extends AttributeDescriptorImpl
implements AttributeType

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

Author:
Rob Hranac, VFNY, Chris Holmes, TOPP, Ian Schneider
Module:

Field Summary
 
Fields inherited from class AttributeDescriptorImpl
defaultValue
 
Fields inherited from class PropertyDescriptorImpl
isNillable, maxOccurs, minOccurs, name, type
 
Fields inherited from interface AttributeType
UNBOUNDED
 
Constructor Summary
protected DefaultAttributeType(AttributeType copy)
           
  DefaultAttributeType(AttributeType type, Name name, int min, int max, boolean isNillable, Object defaultValue)
           
protected DefaultAttributeType(AttributeType type, String name, boolean nillable, int min, int max, Object defaultValue)
           
protected DefaultAttributeType(String name, Class type, boolean nillable, int min, int max, Object defaultValue)
           
protected DefaultAttributeType(String name, Class type, boolean nillable, int min, int max, Object defaultValue, Filter f)
          Constructor with name and type.
protected DefaultAttributeType(String name, Class type, boolean nillable, Object defaultValue)
           
 
Method Summary
static AttributeType createAttributeType(String name, Class binding, Filter restriction)
          Method for geotools AttributeType implementations to create a geoapi attribute type.
 Object createDefaultValue()
          Create a default value for this AttributeType.
 Object duplicate(Object src)
          Return a safe Object copy.
 boolean equals(Object other)
          Override of equals.
 Class getBinding()
          Gets the type of this attribute.
static Class getBinding(AttributeType type)
           
 String getLocalName()
          Gets the name of this attribute.
static String getLocalName(AttributeType type)
           
 Filter getRestriction()
          This represents a Facet in XML schema ... for example can be used to represent the max length of 20 for a string.
static Filter getRestriction(AttributeType type)
           
 int hashCode()
          Override of hashCode.
 boolean isGeometry()
          Returns whether the attribute is a geometry.
 Object parse(Object value)
          Allows this AttributeType to convert an argument to its prefered storage type.
 String toString()
          Gets a representation of this object as a string.
 void validate(Object attribute)
          Whether the tested object passes the validity constraints of this AttributeType.
 
Methods inherited from class AttributeDescriptorImpl
getDefaultValue, getType
 
Methods inherited from class PropertyDescriptorImpl
getMaxOccurs, getMinOccurs, getName, getUserData, isNillable
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface AttributeType
getMaxOccurs, getMinOccurs, isNillable
 
Methods inherited from interface AttributeDescriptor
getDefaultValue, getType
 
Methods inherited from interface PropertyDescriptor
getName, getUserData
 

Constructor Detail

DefaultAttributeType

protected DefaultAttributeType(String name,
                               Class type,
                               boolean nillable,
                               int min,
                               int max,
                               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.
min -
max -
defaultValue - default value when none is suppled
f -
TODO:
REVISIT: make this protected? I think it's only used by facotries at this time.

DefaultAttributeType

protected DefaultAttributeType(AttributeType type,
                               String name,
                               boolean nillable,
                               int min,
                               int max,
                               Object defaultValue)

DefaultAttributeType

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

DefaultAttributeType

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

DefaultAttributeType

protected DefaultAttributeType(AttributeType copy)

DefaultAttributeType

public DefaultAttributeType(AttributeType type,
                            Name name,
                            int min,
                            int max,
                            boolean isNillable,
                            Object defaultValue)
Method Detail

getLocalName

public String getLocalName()
Gets the name of this attribute.

Specified by:
getLocalName in interface AttributeType
Specified by:
getLocalName in interface AttributeDescriptor
Overrides:
getLocalName in class AttributeDescriptorImpl
Returns:
The name of this attribute.
See Also:
PropertyDescriptor.getName()

getBinding

public Class getBinding()
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:
getBinding in interface AttributeType
Returns:
The class that the attribute must match to be valid for this AttributeType.
See Also:
AttributeDescriptor.getType()

duplicate

public Object duplicate(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.

Overrides:
hashCode in class AttributeDescriptorImpl
Returns:
hashCode for this object.

equals

public boolean equals(Object other)
Override of equals.

Overrides:
equals in class AttributeDescriptorImpl
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 String toString()
Gets a representation of this object as a string.

Overrides:
toString in class AttributeDescriptorImpl
Returns:
A representation of this object as a string

parse

public final Object parse(Object value)
                   throws 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:
IllegalArgumentException - if parsing is attempted and is unsuccessful.

validate

public void validate(Object attribute)
              throws IllegalArgumentException
Whether the tested object passes the validity constraints of this AttributeType. At a minimum it should be of the correct class specified by getBinding(), 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:
IllegalArgumentException - if the object does not validate.

createDefaultValue

public 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.INCLUDE if no restriction is needed.

createAttributeType

public static AttributeType createAttributeType(String name,
                                                Class binding,
                                                Filter restriction)
Method for geotools AttributeType implementations to create a geoapi attribute type.

This method is usually called from the constructors of the old AttributeType implememtnations.

Parameters:
name - THe attribute type name.
binding - The attribute type binding.
restriction - Restriction on the attribute type.
Returns:
A geoapi attribute type.
Since:
2.5

getLocalName

public static String getLocalName(AttributeType type)

getBinding

public static Class getBinding(AttributeType type)

getRestriction

public static Filter getRestriction(AttributeType type)


Copyright © 1996-2009 Geotools. All Rights Reserved.