public abstract class AbstractPersistenceManager extends java.lang.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() |
protected |
AbstractPersistenceManager(PersistenceManager.Factories factories) |
Modifier and Type | Method and Description |
---|---|
void |
addAlias(java.lang.String name,
java.lang.Class aClass)
Associates an alias with a class.
|
protected DynStruct |
addDefinition(java.lang.Class theClass,
DynClass definition,
java.lang.String domainName,
java.lang.String domainUrl) |
void |
addDefinition(java.lang.Class theClass,
java.lang.String name,
java.io.InputStream resource) |
DynStruct |
addDefinition(java.lang.Class theClass,
java.lang.String name,
java.io.InputStream definitions,
java.lang.ClassLoader loader,
java.lang.String domainName,
java.lang.String domainUrl)
Add a new definition to the class in the persistent manager.
|
DynStruct |
addDefinition(java.lang.Class theClass,
java.lang.String name,
java.util.Map definitions,
java.lang.String domainName,
java.lang.String domainUrl)
Add a new definition to the class in the persistent manager.
|
void |
addDefinition(java.lang.Class theClass,
java.lang.String name,
java.lang.String resourceName) |
DynStruct |
addDefinition(java.lang.Class theClass,
java.lang.String name,
java.lang.String description,
java.lang.String domainName,
java.lang.String domainUrl)
Add a new definition to the class in the persistent manager.
|
DynStruct |
addDefinition(DynStruct definition,
java.lang.String domainName,
java.lang.String domainUrl)
Add a new definition to the class in the persistent manager.
|
java.lang.Object |
create(PersistentState state)
Instantiates an object from a persistent state.
|
PersistentStateServices |
createPersistentState(PersistentContextServices context) |
PersistentStateServices |
createState(java.lang.Object object,
PersistentContextServices context) |
int |
getAutoValidation()
Gets the validation which will be applied in
PersistenceManager.getState(Object) ,
PersistenceManager.create(PersistentState) methods. |
DynStruct |
getDefinition(java.lang.Class persistentClass)
If the provided persistent class has registered an attribute definition
in this manager, then this method returns that definition.
|
DynStruct |
getDefinition(java.lang.String className)
Return the associated definition to the java class name passed as parameter.
|
java.util.List |
getDomainDefinitions(java.lang.String domainName) |
java.util.Map |
getDomains() |
DynStruct |
getDynObjectDefinition(java.lang.String className)
Return the associated definition to the dynClass name passed as parameter.
|
PersistenceManager.Factories |
getFactories() |
PersistentContextServices |
getNewContext() |
PersistentContextServices |
getNewContext(MutableInt referenceCounter) |
java.lang.Object |
getObject(java.io.InputStream is)
De-serializes an state from the data read from the provided
is . |
PersistentState |
getState(java.lang.Object obj)
Creates a persistent state from an Persistent object.
|
PersistentState |
getState(java.lang.Object obj,
boolean collectAllErrors)
Creates a persistent state from an Persistent object.
|
PersistentState |
getState(java.lang.Object obj,
boolean collectAllErrors,
MutableInt referenceCounter) |
java.util.List |
getWrappedList(java.util.List list,
PersistentContextServices context) |
java.util.Map |
getWrappedMap(java.util.Map map,
PersistentContextServices context) |
java.util.Set |
getWrappedSet(java.util.Set set,
PersistentContextServices context) |
PersistentState |
loadState(java.io.InputStream in) |
void |
putObject(java.io.OutputStream os,
java.lang.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(java.lang.Class theClass)
Unregister a registered class from the manager.
|
void |
unregisterClass(java.lang.String name)
Unregister a registered java class from the manager.
|
void |
unregisterFactory(PersistenceFactory factory) |
DynStruct |
updateDefinition(java.lang.Class theClass,
java.lang.String name,
java.io.InputStream definitions,
java.lang.ClassLoader loader,
java.lang.String domainName,
java.lang.String domainUrl) |
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, saveState
protected AbstractPersistenceManager()
protected AbstractPersistenceManager(PersistenceManager.Factories factories)
public void addAlias(java.lang.String name, java.lang.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 PersistenceManager
getNewContext
in interface PersistenceManagerServices
public PersistentContextServices getNewContext(MutableInt referenceCounter)
getNewContext
in interface PersistenceManager
getNewContext
in interface PersistenceManagerServices
public java.lang.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 java.lang.Object getObject(java.io.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(java.io.OutputStream os, java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.Object obj, boolean collectAllErrors) throws PersistenceException
PersistenceManager
getState
in interface PersistenceManager
PersistenceException
public PersistentState getState(java.lang.Object obj, boolean collectAllErrors, MutableInt referenceCounter) throws PersistenceException
getState
in interface PersistenceManager
PersistenceException
public PersistentStateServices createState(java.lang.Object object, PersistentContextServices context) throws PersistenceException
createState
in interface PersistenceManagerServices
PersistenceException
public java.util.List getWrappedList(java.util.List list, PersistentContextServices context)
getWrappedList
in interface PersistenceManagerServices
public java.util.Map getWrappedMap(java.util.Map map, PersistentContextServices context)
getWrappedMap
in interface PersistenceManagerServices
public java.util.Set getWrappedSet(java.util.Set set, PersistentContextServices context)
getWrappedSet
in interface PersistenceManagerServices
public java.util.Map getDomains()
getDomains
in interface PersistenceManagerServices
public java.util.List getDomainDefinitions(java.lang.String domainName)
getDomainDefinitions
in interface PersistenceManagerServices
public DynStruct addDefinition(java.lang.Class theClass, java.lang.String name, java.lang.String description, java.lang.String domainName, java.lang.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(java.lang.Class theClass, java.lang.String name, java.io.InputStream definitions, java.lang.ClassLoader loader, java.lang.String domainName, java.lang.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 updateDefinition(java.lang.Class theClass, java.lang.String name, java.io.InputStream definitions, java.lang.ClassLoader loader, java.lang.String domainName, java.lang.String domainUrl)
updateDefinition
in interface PersistenceManager
public DynStruct addDefinition(java.lang.Class theClass, java.lang.String name, java.util.Map definitions, java.lang.String domainName, java.lang.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(java.lang.Class theClass, DynClass definition, java.lang.String domainName, java.lang.String domainUrl)
public DynStruct addDefinition(DynStruct definition, java.lang.String domainName, java.lang.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(java.lang.Class theClass)
PersistenceManager
Unregister a registered class from the manager.
unregisterClass
in interface PersistenceManager
#registerClass(Class, DynStruct, String)
public void unregisterClass(java.lang.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
public PersistentState loadState(java.io.InputStream in) throws PersistenceException
loadState
in interface PersistenceManager
PersistenceException
public void addDefinition(java.lang.Class theClass, java.lang.String name, java.lang.String resourceName)
addDefinition
in interface PersistenceManager
public void addDefinition(java.lang.Class theClass, java.lang.String name, java.io.InputStream resource)
addDefinition
in interface PersistenceManager