org.geotools.caching.util
Class SimpleFeatureMarshaller

java.lang.Object
  extended by org.geotools.caching.util.SimpleFeatureMarshaller

public class SimpleFeatureMarshaller
extends java.lang.Object

Simple marshaller that can write features to an ObjectOutputStream. Feature is not Serializable, but this is based on the idea that most attributes object are Serializable (JTS geometries are Serializable), and that attributes which are not simple, are either a collection we can iterate through, or another Feature. Serialization is then achieved recursively. Unmarshalling implies to know the FeatureType of the marshalled feature. Storage format : Header, Attributes Header := int : FeatureType hashCode, String : FeatureType name, String : Feature ID, int : number of attributes Attributes := [Attribute] Attribute := int : multiplicity, or O if simple, or -1 if FeatureAttribute, Object|Feature|[Attribute] : attribute value This implementation does not have the ambition of being robust.

Author:
Christophe Rousson, SoC 2007, CRG-ULAVAL

Field Summary
static int FEATURE
          marker to indicate an attribute is a feature in the serialized form
static int SIMPLEATTRIBUTE
           
 
Constructor Summary
SimpleFeatureMarshaller()
          Default constructor.
 
Method Summary
 void marshall(org.opengis.feature.simple.SimpleFeature f, java.io.ObjectOutput s)
          Marshall a feature into a stream.
protected  void marshallSimpleAttribute(java.lang.Object o, java.io.ObjectOutput s)
          Marshall an attribute into a stream.
 void registerType(org.opengis.feature.simple.SimpleFeatureType type)
          Registers a type with the feature marshaller
 org.opengis.feature.simple.SimpleFeature unmarshall(java.io.ObjectInput s)
          Inverse operation of marshall : read a feature from a stream.
protected  org.opengis.feature.simple.SimpleFeature unmarshall(java.io.ObjectInput s, org.opengis.feature.simple.SimpleFeatureType type)
          Inverse operation of marshall : read a feature from a stream.
protected  java.lang.Object unmarshallSimpleAttribute(java.io.ObjectInput s)
          Read attribute values from a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FEATURE

public static final int FEATURE
marker to indicate an attribute is a feature in the serialized form

See Also:
Constant Field Values

SIMPLEATTRIBUTE

public static final int SIMPLEATTRIBUTE
See Also:
Constant Field Values
Constructor Detail

SimpleFeatureMarshaller

public SimpleFeatureMarshaller()
Default constructor.

Method Detail

registerType

public void registerType(org.opengis.feature.simple.SimpleFeatureType type)
Registers a type with the feature marshaller

Parameters:
type -

marshall

public void marshall(org.opengis.feature.simple.SimpleFeature f,
                     java.io.ObjectOutput s)
              throws java.io.IOException
Marshall a feature into a stream. The type of that feature is not marshalled, type name is marshalled.

Parameters:
f - the Feature to marshall
s - the stream to write to
Throws:
java.io.IOException

marshallSimpleAttribute

protected void marshallSimpleAttribute(java.lang.Object o,
                                       java.io.ObjectOutput s)
                                throws java.io.IOException
Marshall an attribute into a stream.

Parameters:
o - an attribute value which is Serializable, or a feature, or a collection
s - the stream to write to
Throws:
java.io.IOException

unmarshall

public org.opengis.feature.simple.SimpleFeature unmarshall(java.io.ObjectInput s)
                                                    throws java.io.IOException,
                                                           java.lang.ClassNotFoundException,
                                                           org.opengis.feature.IllegalAttributeException
Inverse operation of marshall : read a feature from a stream.

Parameters:
s - the stream to read from
Returns:
the unmarshalled feature
Throws:
java.io.IOException
java.lang.ClassNotFoundException
org.opengis.feature.IllegalAttributeException

unmarshall

protected org.opengis.feature.simple.SimpleFeature unmarshall(java.io.ObjectInput s,
                                                              org.opengis.feature.simple.SimpleFeatureType type)
                                                       throws java.io.IOException,
                                                              java.lang.ClassNotFoundException,
                                                              org.opengis.feature.IllegalAttributeException
Inverse operation of marshall : read a feature from a stream.

Parameters:
s - the stream to read from
the - type of the feature to unmarshall
Returns:
the unmarshalled feature
Throws:
java.io.IOException
java.lang.ClassNotFoundException
org.opengis.feature.IllegalAttributeException

unmarshallSimpleAttribute

protected java.lang.Object unmarshallSimpleAttribute(java.io.ObjectInput s)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException,
                                                     org.opengis.feature.IllegalAttributeException
Read attribute values from a stream.

Parameters:
s - the stream to read from
Returns:
a list of attribute values, possibly a singleton, if attribute's multiplicity is 1
Throws:
java.io.IOException
java.lang.ClassNotFoundException
org.opengis.feature.IllegalAttributeException


Copyright © 1996-2010 Geotools. All Rights Reserved.