org.geotools.data.view
Class DefaultView

Object
  extended by DefaultView
All Implemented Interfaces:
FeatureSource<SimpleFeatureType,SimpleFeature>

public class DefaultView
extends Object
implements FeatureSource<SimpleFeatureType,SimpleFeature>

Wrapper for FeatureSource constrained by a Query.

Support FeatureSource decorator that takes care of mapping a Query & FeatureSource with the schema and definition query configured for it.

Because GeoServer requires that attributes always be returned in the same order we need a way to smoothly inforce this. Could we use this class to do so?

WARNING: this class is a placeholder for ideas right now - it may not always impement FeatureSource.

Author:
Gabriel Rold�n
Module:

Field Summary
protected  FeatureSource<SimpleFeatureType,SimpleFeature> source
          FeatureSource being served up
 
Constructor Summary
DefaultView(FeatureSource<SimpleFeatureType,SimpleFeature> source, Query query)
          Creates a new GeoServerFeatureSource object.
 
Method Summary
 void addFeatureListener(FeatureListener listener)
          Implement addFeatureListener.
static FeatureSource<SimpleFeatureType,SimpleFeature> create(FeatureSource<SimpleFeatureType,SimpleFeature> source, Query query)
          Factory that make the correct decorator for the provided featureSource.
 ReferencedEnvelope getBounds()
          Retrieves the total extent of this FeatureSource.
 ReferencedEnvelope getBounds(Query query)
          Retrive the extent of the Query.
 int getCount(Query query)
          Adjust query and forward to source.
 DataStore getDataStore()
          Implement getDataStore.
 FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures()
          Implement getFeatures.
 FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures(Filter filter)
          Implement getFeatures.
 FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures(Query query)
          Implement getFeatures.
 ResourceInfo getInfo()
          Information describing the contents of this resoruce.
 Name getName()
          Returns the qualified name for the Features this FeatureSource serves.
 QueryCapabilities getQueryCapabilities()
          Returns and indication of what query capabilities this FeatureSource supports natively.
 SimpleFeatureType getSchema()
          Implement getSchema.
 Set getSupportedHints()
          Returns the set of hints this FeatureSource is able to support.
protected  Filter makeDefinitionFilter(Filter filter)
          If a definition query has been configured for the FeatureTypeInfo, makes and return a new Filter that contains both the query's filter and the layer's definition one, by logic AND'ing them.
protected  DefaultQuery makeDefinitionQuery(Query query)
          Takes a query and adapts it to match re definitionQuery filter configured for a feature type.
 void removeFeatureListener(FeatureListener listener)
          Implement removeFeatureListener.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected FeatureSource<SimpleFeatureType,SimpleFeature> source
FeatureSource being served up

Constructor Detail

DefaultView

public DefaultView(FeatureSource<SimpleFeatureType,SimpleFeature> source,
                   Query query)
            throws SchemaException
Creates a new GeoServerFeatureSource object.

Grabs the following from query:

Schema is generated based on this information.

Parameters:
source - a FeatureSource
query - Filter used to limit results
Throws:
SchemaException
Method Detail

getName

public Name getName()
Description copied from interface: FeatureSource
Returns the qualified name for the Features this FeatureSource serves.

Note this is different from getSchema().getType().getName() (that is, the feature type name), this name specifies the AttributeDescriptor name for the Features served by this source. So, FeatureSoruce.getName() == FeatureSource.getFeatures().next().getAttributeDescriptor().getName().

Though it's a common practice when dealing with SimpleFeatureType and SimpleFeature to assume they're equal. There's no conflict (as per the dynamic typing system the org.opengis.feature package defines) in a Feature and its type sharing the same name, as well as in a GML schema an element declaration and a type definition may be named the same. Yet, the distinction becomes important as we get rid of that assumption and thus allow to reuse a type definition for different FeatureSoruces, decoupling the descriptor (homologous to the Feature element declaration in a GML schema) from its type definition.

So, even if implementors are allowed to delegate to getSchema().getName() if they want to call the fatures and their type the same, client code asking a DataAccess.getFeatureSource(Name) shall use this name to request for a FeatureSource, rather than the type name, as used in pre 2.5 versions of GeoTools. For example, if we have a FeatureSource named Roads and its type is named Roads_Type, the DataAccess shall be queried through Roads, not Roads_Type.

Specified by:
getName in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
the name of the AttributeDescriptor for the Features served by this FeatureSource
Since:
2.5
See Also:
FeatureSource.getName()

create

public static FeatureSource<SimpleFeatureType,SimpleFeature> create(FeatureSource<SimpleFeatureType,SimpleFeature> source,
                                                                    Query query)
                                                             throws SchemaException
Factory that make the correct decorator for the provided featureSource.

This factory method is public and will be used to create all required subclasses. By comparison the constructors for this class have package visibiliy.

TODO: revisit this - I am not sure I want write access to views (especially if they do reprojection).

Parameters:
source -
query -
Returns:
@throws SchemaException
Throws:
SchemaException

makeDefinitionQuery

protected DefaultQuery makeDefinitionQuery(Query query)
                                    throws IOException
Takes a query and adapts it to match re definitionQuery filter configured for a feature type. It won't handle coordinate system changes

Grabs the following from query:

Parameters:
query - Query against this DataStore
Returns:
Query restricted to the limits of definitionQuery
Throws:
IOException - See DataSourceException
DataSourceException - If query could not meet the restrictions of definitionQuery

makeDefinitionFilter

protected Filter makeDefinitionFilter(Filter filter)
                               throws DataSourceException
If a definition query has been configured for the FeatureTypeInfo, makes and return a new Filter that contains both the query's filter and the layer's definition one, by logic AND'ing them.

Parameters:
filter - Origional user supplied Filter
Returns:
Filter adjusted to the limitations of definitionQuery
Throws:
DataSourceException - If the filter could not meet the limitations of definitionQuery

getDataStore

public DataStore getDataStore()
Implement getDataStore.

Description ...

Specified by:
getDataStore in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
@see org.geotools.data.FeatureSource#getDataStore()

addFeatureListener

public void addFeatureListener(FeatureListener listener)
Implement addFeatureListener.

Description ...

Specified by:
addFeatureListener in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
listener -
See Also:
FeatureSource.addFeatureListener(org.geotools.data.FeatureListener)

removeFeatureListener

public void removeFeatureListener(FeatureListener listener)
Implement removeFeatureListener.

Description ...

Specified by:
removeFeatureListener in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
listener -
See Also:
FeatureSource.removeFeatureListener(org.geotools.data.FeatureListener)

getFeatures

public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures(Query query)
                                                               throws IOException
Implement getFeatures.

Description ...

Specified by:
getFeatures in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
query -
Returns:
@throws IOException
Throws:
IOException - For all data source errors.
See Also:
FeatureSource.getFeatures(org.geotools.data.Query)

getFeatures

public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures(Filter filter)
                                                               throws IOException
Implement getFeatures.

Description ...

Specified by:
getFeatures in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
filter -
Returns:
@throws IOException
Throws:
IOException - For all data source errors.

getFeatures

public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatures()
                                                               throws IOException
Implement getFeatures.

Description ...

Specified by:
getFeatures in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
@throws IOException
Throws:
IOException - For all data source errors.
See Also:
FeatureSource.getFeatures()

getSchema

public SimpleFeatureType getSchema()
Implement getSchema.

Description ...

Specified by:
getSchema in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
@see org.geotools.data.FeatureSource#getSchema()

getInfo

public ResourceInfo getInfo()
Description copied from interface: FeatureSource
Information describing the contents of this resoruce.

Please note that for FeatureContent:


getBounds

public ReferencedEnvelope getBounds()
                             throws IOException
Retrieves the total extent of this FeatureSource.

Please note this extent will reflect the provided definitionQuery.

Specified by:
getBounds in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
Extent of this FeatureSource, or null if no optimizations exist.
Throws:
IOException - If bounds of definitionQuery

getBounds

public ReferencedEnvelope getBounds(Query query)
                             throws IOException
Retrive the extent of the Query.

This method provides access to an optimized getBounds opperation. If no optimized opperation is available null will be returned.

You may still make use of getFeatures( Query ).getCount() which will return the correct answer (even if it has to itterate through all the results to do so.

Specified by:
getBounds in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
query - User's query
Returns:
Extend of Query or null if no optimization is available
Throws:
IOException - If a problem is encountered with source

getCount

public int getCount(Query query)
Adjust query and forward to source.

This method provides access to an optimized getCount opperation. If no optimized opperation is available -1 will be returned.

You may still make use of getFeatures( Query ).getCount() which will return the correct answer (even if it has to itterate through all the results to do so).

Specified by:
getCount in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Parameters:
query - User's query.
Returns:
Number of Features for Query, or -1 if no optimization is available.

getSupportedHints

public Set getSupportedHints()
Description copied from interface: FeatureSource
Returns the set of hints this FeatureSource is able to support.

Hints are to be specified in the Query, for each data access where they may be required.
Depending on the actual value provide by the user, the FeatureSource may decide not to honor the hint.

Specified by:
getSupportedHints in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
a set of RenderingHints#Key objects (eventually empty, never null).

getQueryCapabilities

public QueryCapabilities getQueryCapabilities()
Description copied from interface: FeatureSource
Returns and indication of what query capabilities this FeatureSource supports natively.

Specified by:
getQueryCapabilities in interface FeatureSource<SimpleFeatureType,SimpleFeature>
Returns:
a QueryCapabilities object containing the native query capabilities.


Copyright © 1996-2009 Geotools. All Rights Reserved.