org.geotools.feature.type
Class ChoiceAttributeType

java.lang.Object
  extended byorg.geotools.feature.type.ChoiceAttributeType
All Implemented Interfaces:
AttributeType
Direct Known Subclasses:
ChoiceAttributeType.Geometric

public class ChoiceAttributeType
extends java.lang.Object
implements AttributeType

This represents a Choice of AttributeTypes. That means, an Attribute of this type may be one of any of this AttributeType's children. This attribute is not valid for Simple Features, and maps to the Choice construct in GML.

Another way to think about the ChoiceAttributeType is as a Union construction from C - it can store a number of different types of value, but it only stores the one value. The parse and validate methods try out each of the choices to see if one of them might work, since all are valid. The order that the child attributeTypes (the choices you can use) are specified is important, because some objects can parse and validate against several types. The first choice that returns true is the one that will

Author:
dzwiers, Chris Holmes, TOPP

Nested Class Summary
static class ChoiceAttributeType.Geometric
          A special class that is made so a Choice can serve as the Default Geometry in a FeatureType, by implementing GeometryAttributeType.
 
Field Summary
 
Fields inherited from interface org.geotools.feature.AttributeType
UNBOUNDED
 
Constructor Summary
ChoiceAttributeType(ChoiceAttributeType copy)
          DOCUMENT ME!
ChoiceAttributeType(java.lang.String name, AttributeType[] children)
           
ChoiceAttributeType(java.lang.String name, int min, int max, AttributeType[] children, Filter restriction)
           
 
Method Summary
 boolean calculateNillable(AttributeType[] children)
           
protected  AttributeType[] copyChildren(AttributeType[] attributes)
           
 java.lang.Object createDefaultValue()
          Returns the default value for the first child which does not throw an exception, null otherwise.
 java.lang.Object duplicate(java.lang.Object src)
          Goes through the children, and searches for a duplicator that works.
 boolean equals(java.lang.Object other)
           
 int find(AttributeType type)
          Find the position of a given AttributeType.
 int find(java.lang.String attName)
          Find the position of an AttributeType which matches the given String.
 int getAttributeCount()
          Returns the number of attributes at the first 'level' of the schema.
 AttributeType getAttributeType(int position)
          Gets the attributeType at the specified index.
 AttributeType getAttributeType(java.lang.String xPath)
          Gets the attributeType at this xPath, if the specified attributeType does not exist then null is returned.
 AttributeType[] getAttributeTypes()
           
 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 class of the object.
 boolean hasAttributeType(java.lang.String xPath)
          This is only used twice in the whole geotools code base, and one of those is for a test, so we're removing it from the interface.
 int hashCode()
          Override of hashCode.
 boolean isGeometry()
           
 boolean isNillable()
          Returns whether nulls are allowed for this attribute.
 java.lang.Object parse(java.lang.Object value)
          Goes through the children, and searches for a parser that works.
 java.lang.String toString()
          Gets a representation of this object as a string.
 void validate(java.lang.Object obj)
          Goes through the children, and searches for a validator that works.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChoiceAttributeType

public ChoiceAttributeType(ChoiceAttributeType copy)
DOCUMENT ME!

Parameters:
copy -

ChoiceAttributeType

public ChoiceAttributeType(java.lang.String name,
                           int min,
                           int max,
                           AttributeType[] children,
                           Filter restriction)

ChoiceAttributeType

public ChoiceAttributeType(java.lang.String name,
                           AttributeType[] children)
Method Detail

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.

copyChildren

protected AttributeType[] copyChildren(AttributeType[] attributes)

getName

public java.lang.String getName()
Description copied from interface: AttributeType
Gets the name of this attribute.

Specified by:
getName in interface AttributeType
Returns:
Name.

getType

public java.lang.Class getType()
Gets the class of the object. For a choice this is fairly useless, as it just returns Object, since we can not tell more than that.

Specified by:
getType in interface AttributeType
Returns:
currently always returns Object.class, since we can't tell more.
See Also:
AttributeType.getType()
Task:
REVISIT: Perhaps we should add a getTypes() method that returns an array of classes, that would represent the classes that you can choose from., REVISIT: Would also be good if this could dynamically figure out the broadest class - like Number if the choices were Double and Integer.

isNillable

public boolean isNillable()
Description copied from interface: AttributeType
Returns whether nulls are allowed for this attribute.

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

calculateNillable

public boolean calculateNillable(AttributeType[] children)

getMinOccurs

public int getMinOccurs()
Description copied from interface: AttributeType
Returns the Min number of occurences ...

Specified by:
getMinOccurs in interface AttributeType
Returns:

getMaxOccurs

public int getMaxOccurs()
Description copied from interface: AttributeType
Returns the Max number of occurences ...

Specified by:
getMaxOccurs in interface AttributeType
Returns:

isGeometry

public boolean isGeometry()

parse

public java.lang.Object parse(java.lang.Object value)
                       throws java.lang.IllegalArgumentException
Goes through the children, and searches for a parser that works. This method searches in the order in which the children are specified ... please keep this in mind when creating these objects if you care about precedence.

Specified by:
parse in interface AttributeType
Parameters:
value - The object to parse.
Returns:
The object parsed into the appropriate form for the Attribute.
Throws:
java.lang.IllegalArgumentException - If the object could not be parsed by any of the child attribute Types.

validate

public void validate(java.lang.Object obj)
              throws java.lang.IllegalArgumentException
Goes through the children, and searches for a validator that works. This method searches in the order in which the children are specified ... please keep this in mind when creating these objects if you care about precedence.

Specified by:
validate in interface AttributeType
Parameters:
obj - The object to validate.
Throws:
java.lang.IllegalArgumentException - If none of the children can validate.

duplicate

public java.lang.Object duplicate(java.lang.Object src)
                           throws IllegalAttributeException
Goes through the children, and searches for a duplicator that works. This method searches in the order in which the children are specified ... please keep this in mind when creating these objects if you care about precedence.

Specified by:
duplicate in interface AttributeType
Parameters:
src - The object to be duplicated.
Returns:
A deep copy of the original object.
Throws:
IllegalAttributeException - For any attribute errors.
java.lang.IllegalArgumentException - If the object could not be duplicated.

createDefaultValue

public java.lang.Object createDefaultValue()
Returns the default value for the first child which does not throw an exception, null otherwise.

Specified by:
createDefaultValue in interface AttributeType
Returns:
The default value of the first choice that does not throw an exception.

hasAttributeType

public boolean hasAttributeType(java.lang.String xPath)
This is only used twice in the whole geotools code base, and one of those is for a test, so we're removing it from the interface. If getAttributeType does not have the AttributeType it will just return null. Gets the number of occurrences of this attribute.

Parameters:
xPath - XPath pointer to attribute type.
Returns:
Number of occurrences.

getAttributeCount

public int getAttributeCount()
Returns the number of attributes at the first 'level' of the schema.

Returns:
equivalent value to getAttributeTypes().length

getAttributeType

public AttributeType getAttributeType(java.lang.String xPath)
Gets the attributeType at this xPath, if the specified attributeType does not exist then null is returned.

Parameters:
xPath - XPath pointer to attribute type.
Returns:
True if attribute exists.

find

public int find(AttributeType type)
Find the position of a given AttributeType.

Parameters:
type - The type to search for.
Returns:
-1 if not found, a zero-based index if found.

find

public int find(java.lang.String attName)
Find the position of an AttributeType which matches the given String.

Parameters:
attName - the name to look for
Returns:
-1 if not found, zero-based index otherwise

getAttributeType

public AttributeType getAttributeType(int position)
Gets the attributeType at the specified index.

Parameters:
position - the position of the attribute to check.
Returns:
The attribute type at the specified position.

getAttributeTypes

public AttributeType[] getAttributeTypes()

equals

public boolean equals(java.lang.Object other)

hashCode

public int hashCode()
Override of hashCode.

Returns:
hashCode for this object.

toString

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

Returns:
A representation of this object as a string


Copyright © GeoTools. All Rights Reserved.