public interface PersistenceManager
This interface contains the necessary methods to get a persistent representation of an object, suitable for storage or transmission, and to create a an object from its persistent representation.
Modifier and Type | Interface and Description |
---|---|
static interface |
PersistenceManager.Factories |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DOMAIN_NAME |
static String |
DEFAULT_DOMAIN_URL |
static int |
DISABLED
Validation Mode - DISABLED: No validation is performed at all.
|
static int |
MANDATORY
Validation Mode -- MANDATORY: Validation is active, so
create(org.gvsig.tools.persistence.PersistentState)
and getState(Object) will throw validation
exceptions if validation errors are found. |
static int |
MANDATORY_IF_DECLARED
Validation Mode -- MANDATORY_IF_DECLARED: Validation is active, but it
will be only applied to Persistent objects which have been registered.
|
static String |
PERSISTENCE_DYNOBJECT_NAMESPACE |
static String |
PERSISTENCE_NAMESPACE
The namespace used on the definition of DynClasses used by the
persistence manager.
|
Modifier and Type | Method and Description |
---|---|
void |
addAlias(String alias,
Class theClass)
Associates an alias with a class.
|
DynStruct |
addDefinition(Class theClass,
String name,
InputStream definitions,
ClassLoader loader,
String domainName,
String domainUrl)
Add a new definition to the class in the persistent manager.
|
DynStruct |
addDefinition(Class theClass,
String name,
Map definitions,
String domainName,
String domainUrl)
Add a new definition to the class in the persistent manager.
|
DynStruct |
addDefinition(Class persistentClass,
String name,
String description,
String domainName,
String domainURL)
Add a new definition to the class in the persistent manager.
|
DynStruct |
addDefinition(DynStruct definition,
String domainName,
String domainUrl)
Add a new definition to the class in the persistent manager.
|
Object |
create(PersistentState state)
Instantiates an object from a persistent state.
|
int |
getAutoValidation()
Gets the validation which will be applied in
getState(Object) ,
create(PersistentState) methods. |
DynStruct |
getDefinition(Class persistentClass)
If the provided persistent class has registered an attribute definition
in this manager, then this method returns that definition.
|
DynStruct |
getDefinition(String name)
Return the associated definition to the java class name passed as parameter.
|
DynStruct |
getDynObjectDefinition(String className)
Return the associated definition to the dynClass name passed as parameter.
|
PersistenceManager.Factories |
getFactories() |
Object |
getObject(InputStream is)
De-serializes an state from the data read from the provided
is . |
PersistentState |
getState(Object obj)
Creates a persistent state from an Persistent object.
|
PersistentState |
getState(Object obj,
boolean collectAllErrors)
Creates a persistent state from an Persistent object.
|
PersistentState |
loadState(InputStream in)
De-serializes an state from the data read from the provided
reader . |
void |
putObject(OutputStream os,
Object obj)
Serializes the object "obj" and writes the serialized data in
the provided
OutputStream . |
void |
registerFactory(PersistenceFactory factory)
Register an instance of
PersistenceFactory that can manage some
objects that requires an especial construction or persistence. |
void |
saveState(PersistentState state,
OutputStream out)
Serializes the
PersistentState and writes the serialized data in
the provided OutputStream . |
void |
setAutoValidation(int validationMode)
Sets the validation which will be applied in
getState(Object) ,
create(PersistentState) methods. |
void |
unregisterClass(Class theClass)
Unregister a registered class from the manager.
|
void |
unregisterClass(String className)
Unregister a registered java class from the manager.
|
void |
unregisterFactory(PersistenceFactory factory) |
void |
validate(PersistentState state,
int mode)
Validates persistent state by using the corresponding registered
attribute definition.
|
void |
validateAll(PersistentState state,
int mode)
Validates all persistent state related to the
state by using
the corresponding registered attribute definition. |
static final String PERSISTENCE_NAMESPACE
static final String PERSISTENCE_DYNOBJECT_NAMESPACE
static final String DEFAULT_DOMAIN_URL
static final String DEFAULT_DOMAIN_NAME
static final int MANDATORY
Validation Mode -- MANDATORY: Validation is active, so
create(org.gvsig.tools.persistence.PersistentState)
and getState(Object)
will throw validation
exceptions if validation errors are found.
If an undeclared attribute or class is found, this will be considered a validation error.
static final int MANDATORY_IF_DECLARED
Validation Mode -- MANDATORY_IF_DECLARED: Validation is active, but it
will be only applied to Persistent objects which have been registered.
create(org.gvsig.tools.persistence.PersistentState)
and getState(Object)
methods will throw
validation exceptions if validation errors are found.
static final int DISABLED
Validation Mode - DISABLED: No validation is performed at all. In this
mode, PersistenceManager#ge
PersistentState getState(Object obj) throws PersistenceException
Creates a persistent state from an Persistent object.
obj
- The Persistent object to be persistedPersistenceException
PersistentState getState(Object obj, boolean collectAllErrors) throws PersistenceException
obj
- collectAllErrors
- PersistenceException
Object create(PersistentState state) throws PersistenceException, PersistenceCreateException
Instantiates an object from a persistent state. The PersistentState object knows the class of the persisted object, and instantiates it by using introspection. The object must implement the Persistent interface so that it can understand the PersistentState.
state
- The state of the object to be instantiatedstate
object.PersistenceException
PersistenceCreateException
void addAlias(String alias, Class theClass) throws PersistenceClassNotRegistered
Associates an alias with a class. This is similar to a symbolic link, which allows to access the class by means of its alias.
When an alias is defined, it replaces any class whose qualified name is equal to the alias. Therefore, this class will never be instantiated, and instead the class pointed by the the alias will be instantiated.
For example, if the following alias is defined:
Class aClass = org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol.class; manager.addAlias( "org.gvsig.fmap.mapcontext.rendering.symbols.ArrowMarkerSymbol", aClass);
then, SimpleMarkerSymbol will be instantiated instead of ArrowMarkerSymbol from any PersistentState which references ArrowMarkerSymbol.
Aliases are useful to provided backward-compatibility paths (as old no existing classes may be aliased to substitution classes), but are also useful to avoid limitations on ClassLoaders. As a Class object is provided, it will be possible to instantiate it even if the current ClassLoader has no direct visibility of the class to instantiate.
alias
- The alias to reference a classaClass
- The class to be referenced by the aliasPersistenceClassNotRegistered
- if aClass
is not registeredDynStruct addDefinition(Class persistentClass, String name, String description, String domainName, String domainURL) throws AddDefinitionException
domainName
can by in only one
domainURL
. If you try to register the same
domainName
with two URL an exception will be raised. persistentClass
- name
- of the new definitiondescription
- of the new definition, can be null.domainName
- , can be null.domainURL
- , can be null.AddDefinitionException
DynStruct addDefinition(Class theClass, String name, InputStream definitions, ClassLoader loader, String domainName, String domainUrl) throws AddDefinitionException
theClass
- to be persistentname
- of the class definition to associate to theClassdefinitions
- input stream from load the definitions of classesloader
- , loader to resolve references to classesdomainName
- (can be null)domainUrl
- (can be null)AddDefinitionException
addDefinition(Class, String, String, String, String)
DynStruct addDefinition(Class theClass, String name, Map definitions, String domainName, String domainUrl) throws AddDefinitionException
theClass
- to be persistentname
- of the class definition to associate to theClassdefinitions
- , map from get the definition of the classdomainName
- (can be null)domainUrl
- (can be null)AddDefinitionException
addDefinition(Class, String, String, String, String)
DynStruct addDefinition(DynStruct definition, String domainName, String domainUrl) throws AddDefinitionException
definition
- , TODOdomainName
- (can be null)domainUrl
- (can be null)AddDefinitionException
addDefinition(Class, String, String, String, String)
void registerFactory(PersistenceFactory factory)
Register an instance of PersistenceFactory
that can manage some
objects that requires an especial construction or persistence. This
factory will use the default domain name and URL.
factory
- void unregisterFactory(PersistenceFactory factory)
void unregisterClass(Class theClass) throws PersistenceClassNotRegistered
Unregister a registered class from the manager.
persistentClass
- PersistenceClassNotRegistered
- if persistentClass
is not registered#registerClass(Class, DynStruct, String)
void unregisterClass(String className) throws PersistenceClassNotRegistered
Unregister a registered java class from the manager.
className
- the java class name to unregisterPersistenceClassNotRegistered
- if className
is not registered#registerClass(Class)
void validate(PersistentState state, int mode) throws PersistenceValidateExceptions
Validates persistent state by using the corresponding registered
attribute definition. mode
specifies what to do when a
definition of a state class is not registered.
state
- mode
- PersistenceValidateExceptions
void validateAll(PersistentState state, int mode) throws PersistenceValidateExceptions
Validates all persistent state related to the state
by using
the corresponding registered attribute definition. mode
specifies what to do when a definition of a state class is not
registered.
state
- mode
- PersistenceValidateExceptions
#setAutoValidation(int)}
DynStruct getDefinition(Class persistentClass)
If the provided persistent class has registered an attribute definition in this manager, then this method returns that definition. Otherwise, it returns null.
persistentClass
- The class whose corresponding attribute definition is to be
retrieved.DynStruct getDefinition(String name)
Return the associated definition to the java class name passed as parameter.
name
- of the java class to retrieve definitionDynStruct getDynObjectDefinition(String className)
Return the associated definition to the dynClass name passed as parameter.
name
- of the dynClass to retrieve definitionPersistentState loadState(InputStream in) throws PersistenceException
De-serializes an state from the data read from the provided
reader
. Depending on the implementation the serialized data
may have different formats, such as XML or binary data.
Note that a particular implementation will only be able to de-serialize data which has been serialized by the same implementation.
reader
- PersistenceException
void saveState(PersistentState state, OutputStream out) throws PersistenceException, PersistenceValidateExceptions
Serializes the PersistentState
and writes the serialized data in
the provided OutputStream
. Depending on the implementation the
serialized data may have different formats, such as XML or binary data.
Note that a particular implementation will only be able to de-serialize data which has been serialized by the same implementation.
out
- PersistenceValidateExceptions
PersistenceException
Object getObject(InputStream is)
De-serializes an state from the data read from the provided
is
. Depending on the implementation the serialized data
may have different formats, such as XML or binary data.
Note that a particular implementation will only be able to de-serialize data which has been serialized by the same implementation.
reader
- is
- void putObject(OutputStream os, Object obj)
Serializes the object "obj" and writes the serialized data in
the provided OutputStream
. Depending on the implementation the
serialized data may have different formats, such as XML or binary data.
Note that a particular implementation will only be able to de-serialize data which has been serialized by the same implementation.
os
- obj
- void setAutoValidation(int validationMode) throws PersistenceException
Sets the validation which will be applied in getState(Object)
,
create(PersistentState)
methods. Validation ensures that
persisted or de-persisted objects match the declared definition (which
must have been previously registered by using
#registerClass(Class, DynStruct)
).
When automatic validation is enabled (MANDATORY or
MANDATORY_IF_DECLARED), a ValidationException will be thrown by
getState(Object)
, create(PersistentState)
if a
validation error is found.
validationMode
- On of the following values: DISABLED
,
MANDATORY
or MANDATORY_IF_DECLARED
PersistenceException
- If the mode is not supported by this manager#validateAll(PersistentState)
,
#registerClass(Class, DynStruct)
int getAutoValidation()
Gets the validation which will be applied in getState(Object)
,
create(PersistentState)
methods.
DISABLED
,
MANDATORY
or MANDATORY_IF_DECLARED
#validateAll(PersistentState)
,
#registerClass(Class, DynStruct)
PersistenceManager.Factories getFactories()