org.geotools.feature.type
Class Types

Object
  extended by Types

public class Types
extends Object

This is a set of utility methods used when implementing types.

This set of classes captures the all important how does it work questions, particularly with respect to super types.

FIXME: These methods need a Q&A check to confirm correct use of Super TODO: Cannot tell the difference in intent from FeatureTypes

Author:
Jody Garnett, LISAsoft, Justin Deoliveira, The Open Planning Project
Module:
modules/library/main (gt-main.jar)

Constructor Summary
Types()
           
 
Method Summary
static void assertNameAssignable(FeatureType expected, FeatureType actual)
          FeatureType comparison indicating if the description provided by two FeatureTypes is similar to the point data can be exchanged.
static void assertOrderAssignable(SimpleFeatureType expected, SimpleFeatureType actual)
          SimpleFeatureType comparison indicating that data from one FeatureType can be exchanged with another - specifically ensuring that the order / value is a reasonable match with the expected number of attributes on each side and the values correctly assignable.
static boolean isValid(Attribute attribute)
          Ensures an attribute value is withing the restrictions of the AttributeDescriptor and AttributeType.
static Object parse(AttributeDescriptor descriptor, Object value)
          Do our best to make the provided value line up with the needs of descriptor.
static void validate(AttributeDescriptor descriptor, Object value)
          Ensure that attributeContent is a good value for descriptor.
static void validate(Attribute attribute, Object attributeContent)
          Validates content against an attribute.
static void validate(AttributeType type, Attribute attribute, Object attributeContent)
           
protected static void validate(AttributeType type, Attribute attribute, Object attributeContent, boolean isSuper)
           
protected static void validate(AttributeType type, Object value, boolean isSuper)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Types

public Types()
Method Detail

isValid

public static boolean isValid(Attribute attribute)
Ensures an attribute value is withing the restrictions of the AttributeDescriptor and AttributeType.

Parameters:
attribute -
Returns:
true if the attribute value is valid

validate

public static void validate(Attribute attribute,
                            Object attributeContent)
                     throws IllegalAttributeException
Validates content against an attribute.

Parameters:
attribute - The attribute.
attributeContent - Content of attribute (often attribute.getValue()
Throws:
IllegalAttributeException - In the event that content violates any restrictions specified by the attribute.

validate

public static void validate(AttributeType type,
                            Attribute attribute,
                            Object attributeContent)
                     throws IllegalAttributeException
Parameters:
type - AttributeType (often attribute.getType() )
attribute - Attribute being tested
attributeContent - Content of the attribute (often attribute.getValue() )
Throws:
IllegalAttributeException

validate

protected static void validate(AttributeType type,
                               Attribute attribute,
                               Object attributeContent,
                               boolean isSuper)
                        throws IllegalAttributeException
Parameters:
type - AttributeType (often attribute.getType() )
attribute - Attribute being tested
attributeContent - Content of the attribute (often attribute.getValue() )
isSuper - True if super type is being checked
Throws:
IllegalAttributeException

validate

public static void validate(AttributeDescriptor descriptor,
                            Object value)
                     throws IllegalAttributeException
Ensure that attributeContent is a good value for descriptor.

Throws:
IllegalAttributeException

parse

public static Object parse(AttributeDescriptor descriptor,
                           Object value)
                    throws IllegalArgumentException
Do our best to make the provided value line up with the needs of descriptor.

This helper method uses the Coverters api to convert the provided value into the required class. If the value is null (and the attribute is not nillable) a default value will be returned.

Parameters:
descriptor - Attribute descriptor we need to supply a value for.
value - The provided value
Returns:
Our best attempt to make a valid value
Throws:
IllegalArgumentException - if we really could not do it.

validate

protected static void validate(AttributeType type,
                               Object value,
                               boolean isSuper)
                        throws IllegalAttributeException
Throws:
IllegalAttributeException

assertNameAssignable

public static void assertNameAssignable(FeatureType expected,
                                        FeatureType actual)
FeatureType comparison indicating if the description provided by two FeatureTypes is similar to the point data can be exchanged. This comparison is really very focused on the name / value contract and is willing to overlook details like length restrictions.

When creating compatible FeatureTypes you will find some systems have different abilities which is reflected in how well they support a given FeatureType.

As an example databases traditionally support variable length strings with a limit of 32 k; while a shapefile is limited to 256 characters. When working with data from both these data sources you will need to make adjustments based on these abilities.

If true is returned data conforming to the expected FeatureType can be used with the actual FeatureType.

After assertOrderCovered returns without error the following code will work:


 for( Property property : feature.getProperties() ){
     Object value = property.getValue();
     
     Property target = newFeature.getProperty( property.getName().getLocalPart() );
     target.setValue( value );
 }
 
Specifically this says that between the two feature types data is assignable on a name by name basis.

Parameters:
expected - Expected FeatureType being used to compare against
actual - Actual FeatureType

assertOrderAssignable

public static void assertOrderAssignable(SimpleFeatureType expected,
                                         SimpleFeatureType actual)
SimpleFeatureType comparison indicating that data from one FeatureType can be exchanged with another - specifically ensuring that the order / value is a reasonable match with the expected number of attributes on each side and the values correctly assignable.

After assertOrderCovered returns without error the following code will work:


 List values = feature.getAttributes();
 newFeature.setAttributes( values );
 

Parameters:
expected -
actual -


Copyright © 1996-2010 Geotools. All Rights Reserved.