public abstract class AbstractPersistenceManager extends Object implements PersistenceManagerServices
PersistenceManager.Factories
DEFAULT_DOMAIN_NAME, DEFAULT_DOMAIN_URL, DISABLED, MANDATORY, MANDATORY_IF_DECLARED, PERSISTENCE_DYNOBJECT_NAMESPACE, PERSISTENCE_NAMESPACE
Modifier | Constructor and Description |
---|---|
protected |
AbstractPersistenceManager() |
Modifier and Type | Method and Description |
---|---|
void |
addAlias(String name,
Class aClass)
Associates an alias with a class.
|
protected DynStruct |
addDefinition(Class theClass,
DynClass definition,
String domainName,
String domainUrl) |
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 theClass,
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.
|
PersistentStateServices |
createPersistentState(PersistentContextServices context) |
PersistentStateServices |
createState(Object object,
PersistentContextServices context) |
int |
getAutoValidation()
Gets the validation which will be applied in
PersistenceManager.getState(Object) ,
PersistenceManager.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 className)
Return the associated definition to the java class name passed as parameter.
|
List |
getDomainDefinitions(String domainName) |
Map |
getDomains() |
DynStruct |
getDynObjectDefinition(String className)
Return the associated definition to the dynClass name passed as parameter.
|
PersistenceManager.Factories |
getFactories() |
PersistentContextServices |
getNewContext() |
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.
|
List |
getWrappedList(List list,
PersistentContextServices context) |
Map |
getWrappedMap(Map map,
PersistentContextServices context) |
Set |
getWrappedSet(Set set,
PersistentContextServices context) |
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 |
setAutoValidation(int validationMode)
Sets the validation which will be applied in
PersistenceManager.getState(Object) ,
PersistenceManager.create(PersistentState) methods. |
void |
unregisterClass(Class theClass)
Unregister a registered class from the manager.
|
void |
unregisterClass(String name)
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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createPersistentState
loadState, saveState
public void addAlias(String name, Class aClass) throws PersistenceClassNotRegistered
PersistenceManager
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.
addAlias
in interface PersistenceManager
name
- The alias to reference a classPersistenceClassNotRegistered
- if aClass
is not registeredpublic PersistenceManager.Factories getFactories()
getFactories
in interface PersistenceManager
public PersistentContextServices getNewContext()
getNewContext
in interface PersistenceManagerServices
public Object create(PersistentState state) throws PersistenceException
PersistenceManager
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.
create
in interface PersistenceManager
state
- The state of the object to be instantiatedstate
object.PersistenceException
public Object getObject(InputStream is)
PersistenceManager
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.
getObject
in interface PersistenceManager
public void putObject(OutputStream os, Object obj)
PersistenceManager
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.
putObject
in interface PersistenceManager
public DynStruct getDefinition(Class persistentClass)
PersistenceManager
If the provided persistent class has registered an attribute definition in this manager, then this method returns that definition. Otherwise, it returns null.
getDefinition
in interface PersistenceManager
persistentClass
- The class whose corresponding attribute definition is to be
retrieved.public DynStruct getDefinition(String className)
PersistenceManager
Return the associated definition to the java class name passed as parameter.
getDefinition
in interface PersistenceManager
className
- of the java class to retrieve definitionpublic DynStruct getDynObjectDefinition(String className)
PersistenceManager
Return the associated definition to the dynClass name passed as parameter.
getDynObjectDefinition
in interface PersistenceManager
public void validate(PersistentState state, int mode) throws PersistenceValidateExceptions
PersistenceManager
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.
validate
in interface PersistenceManager
PersistenceValidateExceptions
public void validateAll(PersistentState state, int mode) throws PersistenceValidateExceptions
PersistenceManager
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.
validateAll
in interface PersistenceManager
PersistenceValidateExceptions
#setAutoValidation(int)}
public int getAutoValidation()
PersistenceManager
Gets the validation which will be applied in PersistenceManager.getState(Object)
,
PersistenceManager.create(PersistentState)
methods.
getAutoValidation
in interface PersistenceManager
PersistenceManager.DISABLED
,
PersistenceManager.MANDATORY
or PersistenceManager.MANDATORY_IF_DECLARED
#validateAll(PersistentState)
,
#registerClass(Class, DynStruct)
public void setAutoValidation(int validationMode) throws PersistenceException
PersistenceManager
Sets the validation which will be applied in PersistenceManager.getState(Object)
,
PersistenceManager.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
PersistenceManager.getState(Object)
, PersistenceManager.create(PersistentState)
if a
validation error is found.
setAutoValidation
in interface PersistenceManager
validationMode
- On of the following values: PersistenceManager.DISABLED
,
PersistenceManager.MANDATORY
or PersistenceManager.MANDATORY_IF_DECLARED
PersistenceException
- If the mode is not supported by this manager#validateAll(PersistentState)
,
#registerClass(Class, DynStruct)
public PersistentState getState(Object obj) throws PersistenceException, PersistenceValidateExceptions, PersistenceTypeNotSupportedException
PersistenceManager
Creates a persistent state from an Persistent object.
getState
in interface PersistenceManager
obj
- The Persistent object to be persistedPersistenceException
PersistenceValidateExceptions
PersistenceTypeNotSupportedException
public PersistentState getState(Object obj, boolean collectAllErrors) throws PersistenceException
PersistenceManager
getState
in interface PersistenceManager
PersistenceException
public PersistentStateServices createState(Object object, PersistentContextServices context) throws PersistenceException
createState
in interface PersistenceManagerServices
PersistenceException
public List getWrappedList(List list, PersistentContextServices context)
getWrappedList
in interface PersistenceManagerServices
public Map getWrappedMap(Map map, PersistentContextServices context)
getWrappedMap
in interface PersistenceManagerServices
public Set getWrappedSet(Set set, PersistentContextServices context)
getWrappedSet
in interface PersistenceManagerServices
public Map getDomains()
getDomains
in interface PersistenceManagerServices
public List getDomainDefinitions(String domainName)
getDomainDefinitions
in interface PersistenceManagerServices
public DynStruct addDefinition(Class theClass, String name, String description, String domainName, String domainUrl)
PersistenceManager
domainName
can by in only one
domainURL
. If you try to register the same
domainName
with two URL an exception will be raised. addDefinition
in interface PersistenceManager
name
- of the new definitiondescription
- of the new definition, can be null.domainName
- , can be null.domainUrl
- , can be null.public DynStruct addDefinition(Class theClass, String name, InputStream definitions, ClassLoader loader, String domainName, String domainUrl)
PersistenceManager
addDefinition
in interface PersistenceManager
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)PersistenceManager.addDefinition(Class, String, String, String, String)
public DynStruct addDefinition(Class theClass, String name, Map definitions, String domainName, String domainUrl)
PersistenceManager
addDefinition
in interface PersistenceManager
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)PersistenceManager.addDefinition(Class, String, String, String, String)
protected DynStruct addDefinition(Class theClass, DynClass definition, String domainName, String domainUrl)
public DynStruct addDefinition(DynStruct definition, String domainName, String domainUrl) throws AddDefinitionException
PersistenceManager
addDefinition
in interface PersistenceManager
definition
- , TODOdomainName
- (can be null)domainUrl
- (can be null)AddDefinitionException
PersistenceManager.addDefinition(Class, String, String, String, String)
public void registerFactory(PersistenceFactory factory)
PersistenceManager
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.
registerFactory
in interface PersistenceManager
public void unregisterClass(Class theClass)
PersistenceManager
Unregister a registered class from the manager.
unregisterClass
in interface PersistenceManager
#registerClass(Class, DynStruct, String)
public void unregisterClass(String name)
PersistenceManager
Unregister a registered java class from the manager.
unregisterClass
in interface PersistenceManager
name
- the java class name to unregister#registerClass(Class)
public void unregisterFactory(PersistenceFactory factory)
unregisterFactory
in interface PersistenceManager
public PersistentStateServices createPersistentState(PersistentContextServices context)
createPersistentState
in interface PersistenceManagerServices