org.geotools.data
Class ReTypeFeatureReader

Object
  extended by ReTypeFeatureReader
All Implemented Interfaces:
Closeable, DelegatingFeatureReader<SimpleFeatureType,SimpleFeature>, FeatureReader<SimpleFeatureType,SimpleFeature>

public class ReTypeFeatureReader
extends Object
implements DelegatingFeatureReader<SimpleFeatureType,SimpleFeature>

Supports on the fly retyping of FeatureReader contents.

This may be used to have a DataStore work with your own representation of Feature information.

Example Use:


  FeatureReader reader = dataStore.getFeatureReader( query, Transaction.AUTO_COMMIT );
 reader = new ReTypeFeatureReader( reader, myFeatureType );
 try {
   while( reader.hasNext() ){
     Feature f = reader.next();
     System.out.println( f );
   }
 }
 finally {
   reader.close(); // will close both
 } 
 

This Reader makes a simple one to one between the original schema and the target schema based on descriptor name.

Author:
Jody Garnett (Refractions Research)

Constructor Summary
ReTypeFeatureReader(FeatureReader<SimpleFeatureType,SimpleFeature> reader, SimpleFeatureType featureType)
          Constructs a FetureReader that will ReType streaming content.
ReTypeFeatureReader(FeatureReader<SimpleFeatureType,SimpleFeature> reader, SimpleFeatureType featureType, boolean clone)
          Constructs a FetureReader that will ReType streaming content.
 
Method Summary
 void close()
          Release the underlying resources associated with this stream.
 FeatureReader getDelegate()
           
 SimpleFeatureType getFeatureType()
          Return the FeatureType this reader has been configured to create.
 boolean hasNext()
          Query whether this FeatureReader has another Feature.
 SimpleFeature next()
          Reads the next Feature in the FeatureReader.
protected  AttributeDescriptor[] typeAttributes(SimpleFeatureType target, SimpleFeatureType origional)
          Supplies mapping from original to target FeatureType.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReTypeFeatureReader

public ReTypeFeatureReader(FeatureReader<SimpleFeatureType,SimpleFeature> reader,
                           SimpleFeatureType featureType)
Constructs a FetureReader that will ReType streaming content.

Parameters:
reader - Origional FeatureReader
featureType - Target FeatureType

ReTypeFeatureReader

public ReTypeFeatureReader(FeatureReader<SimpleFeatureType,SimpleFeature> reader,
                           SimpleFeatureType featureType,
                           boolean clone)
Constructs a FetureReader that will ReType streaming content.

Parameters:
reader - Original FeatureReader
featureType - Target FeatureType
clone - true to clone the content
Since:
2.3
Method Detail

getDelegate

public FeatureReader getDelegate()
Specified by:
getDelegate in interface DelegatingFeatureReader<SimpleFeatureType,SimpleFeature>
Returns:
The delegate feature reader.

typeAttributes

protected AttributeDescriptor[] typeAttributes(SimpleFeatureType target,
                                               SimpleFeatureType origional)
Supplies mapping from original to target FeatureType.

Will also ensure that mapping results in a valid selection of values from the original. Only the xpath expression and binding are checked.

Parameters:
target - Desired FeatureType
origional - Original FeatureType
Returns:
Mapping from originoal to target FeatureType
Throws:
IllegalArgumentException - if unable to provide a mapping

getFeatureType

public SimpleFeatureType getFeatureType()
Description copied from interface: FeatureReader
Return the FeatureType this reader has been configured to create.

Specified by:
getFeatureType in interface FeatureReader<SimpleFeatureType,SimpleFeature>
Returns:
the FeatureType of the Features this FeatureReader will create.
See Also:
FeatureReader.getFeatureType()

next

public SimpleFeature next()
                   throws IOException,
                          IllegalAttributeException,
                          NoSuchElementException
Description copied from interface: FeatureReader
Reads the next Feature in the FeatureReader.

Specified by:
next in interface FeatureReader<SimpleFeatureType,SimpleFeature>
Returns:
The next feature in the reader.
Throws:
IOException - If an error occurs reading the Feature.
IllegalAttributeException - If the attributes read do not comply with the FeatureType.
NoSuchElementException - If there are no more Features in the Reader.
See Also:
FeatureReader.next()

hasNext

public boolean hasNext()
                throws IOException
Description copied from interface: FeatureReader
Query whether this FeatureReader has another Feature.

Specified by:
hasNext in interface FeatureReader<SimpleFeatureType,SimpleFeature>
Returns:
True if there are more Features to be read. In other words, true if calls to next would return a feature rather than throwing an exception.
Throws:
IOException - If an error occurs determining if there are more Features.
See Also:
FeatureReader.hasNext()

close

public void close()
           throws IOException
Description copied from interface: FeatureReader
Release the underlying resources associated with this stream.

Specified by:
close in interface Closeable
Specified by:
close in interface FeatureReader<SimpleFeatureType,SimpleFeature>
Throws:
IOException - if an I/O error occurs
See Also:
FeatureReader.close()


Copyright © 1996-2014 Geotools. All Rights Reserved.