|
GemFire 6.6 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer
public class ReflectionBasedAutoSerializer
This class uses Java reflection in conjunction with
PdxSerialzer
to perform
automatic serialization of domain objects. The implication is that the domain
classes do not need to implement the PdxSerializable
interface.
This implementation will serialize all relevant fields
For example:
List<String> domainClasses = new ArrayList<String>(); domainClasses.add("com.foo.DomainObject"); Cache c = new CacheFactory().set("cache-xml-file", cacheXmlFileName) .setPdxSerializer(new ReflectionBasedAutoSerializer(domainClasses)) .create();
In this example DomainObject
would not need to implement
PdxSerializable
to be serialized.
The equivalent cache.xml
entries might be as follows:
<pdx> <pdx-serializer> <class-name> com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer </class-name> <parameter name="classes"> <string> com.company.domain.DomainObject </string> </parameter> </pdx-serializer> </pdx>See
setSerializableClasses
for additional details on the format of the parameter string.
Constructor Summary | |
---|---|
ReflectionBasedAutoSerializer()
Default constructor primarily used during declarative configuration via the cache.xml file. |
|
ReflectionBasedAutoSerializer(List<String> classes)
Constructor which takes a list of class name patterns which are to be auto-serialized. |
Method Summary | |
---|---|
Object |
fromData(Class clazz,
PdxReader reader)
Method implemented from PdxSerializer which performs object
de-serialization. |
Properties |
getConfig()
Return a Properties object with a representation of the
current config. |
void |
init(Properties props)
Used for declarative class initialization from cache.xml. |
void |
setSerializableClasses(List<String> patterns)
Method to configure classes to consider for serialization, to set any identity fields and to define any fields to exclude from serialization. |
boolean |
toData(Object obj,
PdxWriter writer)
Method implemented from PdxSerializer which performs object
serialization. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ReflectionBasedAutoSerializer()
public ReflectionBasedAutoSerializer(List<String> classes)
classes
- a list of patterns which are matched against domain class
names to determine whether they should be serializedMethod Detail |
---|
public final void setSerializableClasses(List<String> patterns)
Each string in the list represents a definition in the following form:
<class pattern>#identity=<identity field pattern>#exclude=<exclude field pattern>The hash (#) characters are separators and are not part of the parameter name. An example would be:
com.company.DomainObject.*#identity=id.*#exclude=creationDateThis would select all classes with a class name beginning with
com.company.DomainObject
and would select as PDX identity fields any fields beginning with id
and would not serialize the field called creationDate
.
There is no association between the the identity and exclude options, so the above example could also be expressed as:
com.company.DomainObject.*#identity=id.* com.company.DomainObject.*#exclude=creationDateNote that all defined patterns are used when determining whether a field should be considered as an identity field or should be excluded. Thus the order of the patterns is not relevant.
patterns
- the list of definitions to applypublic boolean toData(Object obj, PdxWriter writer)
PdxSerializer
which performs object
serialization.
toData
in interface PdxSerializer
obj
- the object to serializewriter
- the PdxWriter
to use when serializing this object
true
if the object was serialized, false
otherwisepublic Object fromData(Class clazz, PdxReader reader)
PdxSerializer
which performs object
de-serialization.
fromData
in interface PdxSerializer
clazz
- the class of the object to re-createreader
- the PdxReader
to use when creating this object
public void init(Properties props)
setSerializableClasses
for specifics.
init
in interface Declarable
props
- properties used to configure the auto serializerpublic Properties getConfig()
Properties
object with a representation of the
current config. Depending on how this ReflectionBasedAutoSerializer
was configured, the returned property value will have the correct semantics
but may differ from the the original configuration string.
Properties
object
|
GemFire 6.6 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |