org.gvsig.tools.persistence.impl
Class AbstractPersistenceManager

java.lang.Object
  extended by org.gvsig.tools.persistence.impl.AbstractPersistenceManager
All Implemented Interfaces:
PersistenceManager, PersistenceManagerServices
Direct Known Subclasses:
XMLPersistenceManager

public abstract class AbstractPersistenceManager
extends Object
implements PersistenceManagerServices


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.gvsig.tools.persistence.PersistenceManager
PersistenceManager.Factories
 
Field Summary
 
Fields inherited from interface org.gvsig.tools.persistence.PersistenceManager
DEFAULT_DOMAIN_NAME, DEFAULT_DOMAIN_URL, DISABLED, MANDATORY, MANDATORY_IF_DECLARED, PERSISTENCE_DYNOBJECT_NAMESPACE, PERSISTENCE_NAMESPACE
 
Constructor Summary
protected AbstractPersistenceManager()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gvsig.tools.persistence.spi.PersistenceManagerServices
createPersistentState
 
Methods inherited from interface org.gvsig.tools.persistence.PersistenceManager
loadState, saveState
 

Constructor Detail

AbstractPersistenceManager

protected AbstractPersistenceManager()
Method Detail

addAlias

public void addAlias(String name,
                     Class aClass)
              throws PersistenceClassNotRegistered
Description copied from interface: 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.

Specified by:
addAlias in interface PersistenceManager
Parameters:
name - The alias to reference a class
Throws:
PersistenceClassNotRegistered - if aClass is not registered

getFactories

public PersistenceManager.Factories getFactories()
Specified by:
getFactories in interface PersistenceManager

getNewContext

public PersistentContextServices getNewContext()
Specified by:
getNewContext in interface PersistenceManagerServices

create

public Object create(PersistentState state)
              throws PersistenceException
Description copied from interface: 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.

Specified by:
create in interface PersistenceManager
Parameters:
state - The state of the object to be instantiated
Returns:
A new object whose state is the same as the provided state object.
Throws:
PersistenceException

getObject

public Object getObject(InputStream is)
Description copied from interface: 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.

Specified by:
getObject in interface PersistenceManager
Returns:

putObject

public void putObject(OutputStream os,
                      Object obj)
Description copied from interface: 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.

Specified by:
putObject in interface PersistenceManager

getDefinition

public DynStruct getDefinition(Class persistentClass)
Description copied from interface: PersistenceManager

If the provided persistent class has registered an attribute definition in this manager, then this method returns that definition. Otherwise, it returns null.

Specified by:
getDefinition in interface PersistenceManager
Parameters:
persistentClass - The class whose corresponding attribute definition is to be retrieved.
Returns:
The attribute definition corresponding to the provided persistent class, or null otherwise.

getDefinition

public DynStruct getDefinition(String className)
Description copied from interface: PersistenceManager

Return the associated definition to the java class name passed as parameter.

Specified by:
getDefinition in interface PersistenceManager
Parameters:
className - of the java class to retrieve definition
Returns:
The attribute definition corresponding to the provided java class, or null otherwise.

getDynObjectDefinition

public DynStruct getDynObjectDefinition(String className)
Description copied from interface: PersistenceManager

Return the associated definition to the dynClass name passed as parameter.

Specified by:
getDynObjectDefinition in interface PersistenceManager
Returns:
The attribute definition corresponding to the provided dynClass, or null otherwise.

validate

public void validate(PersistentState state,
                     int mode)
              throws PersistenceValidateExceptions
Description copied from interface: 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.

Specified by:
validate in interface PersistenceManager
Throws:
PersistenceValidateExceptions

validateAll

public void validateAll(PersistentState state,
                        int mode)
                 throws PersistenceValidateExceptions
Description copied from interface: 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.

Specified by:
validateAll in interface PersistenceManager
Throws:
PersistenceValidateExceptions
See Also:
#setAutoValidation(int)}

getAutoValidation

public int getAutoValidation()
Description copied from interface: PersistenceManager

Gets the validation which will be applied in PersistenceManager.getState(Object), PersistenceManager.create(PersistentState) methods.

Specified by:
getAutoValidation in interface PersistenceManager
Returns:
The current mode for automatic validation: PersistenceManager.DISABLED, PersistenceManager.MANDATORY or PersistenceManager.MANDATORY_IF_DECLARED
See Also:
#validateAll(PersistentState), #registerClass(Class, DynStruct)

setAutoValidation

public void setAutoValidation(int validationMode)
                       throws PersistenceException
Description copied from interface: 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.

Specified by:
setAutoValidation in interface PersistenceManager
Parameters:
validationMode - On of the following values: PersistenceManager.DISABLED, PersistenceManager.MANDATORY or PersistenceManager.MANDATORY_IF_DECLARED
Throws:
PersistenceException - If the mode is not supported by this manager
See Also:
#validateAll(PersistentState), #registerClass(Class, DynStruct)

getState

public PersistentState getState(Object obj)
                         throws PersistenceException,
                                PersistenceValidateExceptions,
                                PersistenceTypeNotSupportedException
Description copied from interface: PersistenceManager

Creates a persistent state from an Persistent object.

Specified by:
getState in interface PersistenceManager
Parameters:
obj - The Persistent object to be persisted
Returns:
A PersistentState object, which stores the state of the provided Persistent Object.
Throws:
PersistenceException
PersistenceValidateExceptions
PersistenceTypeNotSupportedException

getState

public PersistentState getState(Object obj,
                                boolean collectAllErrors)
                         throws PersistenceException
Description copied from interface: PersistenceManager
Creates a persistent state from an Persistent object. When collectAllErrors is true, try to continue when an error is detected, and raise all errors when finish the process.

Specified by:
getState in interface PersistenceManager
Returns:
Throws:
PersistenceException

createState

public PersistentStateServices createState(Object object,
                                           PersistentContextServices context)
                                    throws PersistenceException
Specified by:
createState in interface PersistenceManagerServices
Throws:
PersistenceException

getWrappedList

public List getWrappedList(List list,
                           PersistentContextServices context)
Specified by:
getWrappedList in interface PersistenceManagerServices

getWrappedMap

public Map getWrappedMap(Map map,
                         PersistentContextServices context)
Specified by:
getWrappedMap in interface PersistenceManagerServices

getWrappedSet

public Set getWrappedSet(Set set,
                         PersistentContextServices context)
Specified by:
getWrappedSet in interface PersistenceManagerServices

getDomains

public Map getDomains()
Specified by:
getDomains in interface PersistenceManagerServices

getDomainDefinitions

public List getDomainDefinitions(String domainName)
Specified by:
getDomainDefinitions in interface PersistenceManagerServices

addDefinition

public DynStruct addDefinition(Class theClass,
                               String name,
                               String description,
                               String domainName,
                               String domainUrl)
Description copied from interface: PersistenceManager
Add a new definition to the class in the persistent manager. The new definition is defined in the namespace by default for DynClasses used in persistence. if domainName or domainURL are null, values by default arent supplied by the manager. Note: A domainName can by in only one domainURL. If you try to register the same domainName with two URL an exception will be raised.

Specified by:
addDefinition in interface PersistenceManager
name - of the new definition
description - of the new definition, can be null.
domainName - , can be null.
domainUrl - , can be null.
Returns:
the new definition

addDefinition

public DynStruct addDefinition(Class theClass,
                               String name,
                               InputStream definitions,
                               ClassLoader loader,
                               String domainName,
                               String domainUrl)
Description copied from interface: PersistenceManager
Add a new definition to the class in the persistent manager.

Specified by:
addDefinition in interface PersistenceManager
Parameters:
theClass - to be persistent
name - of the class definition to associate to theClass
definitions - input stream from load the definitions of classes
loader - , loader to resolve references to classes
domainName - (can be null)
domainUrl - (can be null)
Returns:
See Also:
PersistenceManager.addDefinition(Class, String, String, String, String)

addDefinition

public DynStruct addDefinition(Class theClass,
                               String name,
                               Map definitions,
                               String domainName,
                               String domainUrl)
Description copied from interface: PersistenceManager
Add a new definition to the class in the persistent manager.

Specified by:
addDefinition in interface PersistenceManager
Parameters:
theClass - to be persistent
name - of the class definition to associate to theClass
definitions - , map from get the definition of the class
domainName - (can be null)
domainUrl - (can be null)
Returns:
See Also:
PersistenceManager.addDefinition(Class, String, String, String, String)

addDefinition

protected DynStruct addDefinition(Class theClass,
                                  DynClass definition,
                                  String domainName,
                                  String domainUrl)

addDefinition

public DynStruct addDefinition(DynStruct definition,
                               String domainName,
                               String domainUrl)
                        throws AddDefinitionException
Description copied from interface: PersistenceManager
Add a new definition to the class in the persistent manager.

Specified by:
addDefinition in interface PersistenceManager
Parameters:
definition - , TODO
domainName - (can be null)
domainUrl - (can be null)
Returns:
Throws:
AddDefinitionException
See Also:
PersistenceManager.addDefinition(Class, String, String, String, String)

registerFactory

public void registerFactory(PersistenceFactory factory)
Description copied from interface: 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.

Specified by:
registerFactory in interface PersistenceManager

unregisterClass

public void unregisterClass(Class theClass)
Description copied from interface: PersistenceManager

Unregister a registered class from the manager.

Specified by:
unregisterClass in interface PersistenceManager
See Also:
#registerClass(Class, DynStruct, String)

unregisterClass

public void unregisterClass(String name)
Description copied from interface: PersistenceManager

Unregister a registered java class from the manager.

Specified by:
unregisterClass in interface PersistenceManager
Parameters:
name - the java class name to unregister
See Also:
#registerClass(Class)

unregisterFactory

public void unregisterFactory(PersistenceFactory factory)
Specified by:
unregisterFactory in interface PersistenceManager

createPersistentState

public PersistentStateServices createPersistentState(PersistentContextServices context)
Specified by:
createPersistentState in interface PersistenceManagerServices


Copyright © 2004-2011 gvSIG. All Rights Reserved.