edu.iu.iv.common.persistence
Class BasicPersistenceRegistry

java.lang.Object
  |
  +--edu.iu.iv.common.persistence.BasicPersistenceRegistry
All Implemented Interfaces:
PersistenceRegistry

public class BasicPersistenceRegistry
extends java.lang.Object
implements PersistenceRegistry

Version:
0.1
Author:
Shashikant

Constructor Summary
BasicPersistenceRegistry()
           
 
Method Summary
 Persister findPersister(java.lang.Object model, ResourceDescriptor resource)
          Finds a persister that can persist a specified data model to a specified data resource or one that can restore from a particular resource.
 java.util.List getPersisters()
          Gets the list of all persisters currently registered with the registry.
 java.util.List getSupportingPersisters(java.lang.Object model)
          Returns the list of persisters that can persist the specified data model.
 java.util.List getSupportingPersisters(ResourceDescriptor resource)
          Returns the list of persisters that can restore from the specified data resource.
 java.lang.Object load(ResourceDescriptor source)
          Attempts to load the specified data model with data from the specified source.
 void register(Persister persister)
          Registers the persister with the registry.
 void save(java.lang.Object model, ResourceDescriptor destination)
          Attempts to save the specified data model's data to the specified resource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicPersistenceRegistry

public BasicPersistenceRegistry()
Method Detail

register

public void register(Persister persister)
Description copied from interface: PersistenceRegistry
Registers the persister with the registry. A persister needs to be registered with the registry only once during the runtime of the IVC.

Specified by:
register in interface PersistenceRegistry
Parameters:
persister - The persister to add to the registry.
See Also:
PersistenceRegistry.register(edu.iu.iv.core.persistence.Persister)

getSupportingPersisters

public java.util.List getSupportingPersisters(java.lang.Object model)
Description copied from interface: PersistenceRegistry
Returns the list of persisters that can persist the specified data model. It is expected that several persisters would be able to save out a data model to a resource. Hence, UI based systems should take advantage of this and provide the user with several choices about what persister to use. If no persisters are found, then an empty list is returned. Note that this behaviour is different from the behaviour of the save() method of the PersistenceFacade, which throws a PersisterNotFoundException if no persisters are found capable of satisfying the save request.

Specified by:
getSupportingPersisters in interface PersistenceRegistry
Parameters:
model - The data model for which persistence is desired.
Returns:
The list of Persisters that can persist this model or empty list if not persisters are found.
See Also:
PersistenceRegistry.getSupportingPersisters(java.lang.Object)

getSupportingPersisters

public java.util.List getSupportingPersisters(ResourceDescriptor resource)
Description copied from interface: PersistenceRegistry
Returns the list of persisters that can restore from the specified data resource. It is expected that several persisters would be able to load data from a resource. Hence, UI based systems should take advantage of this and provide the user with several choices about what persister to use. If no persisters are found, then an empty list is returned. Note that this behaviour is different from the behaviour of the load() method of the PersistenceFacade, which throws a PersisterNotFoundException if no persisters are found capable of satisfying the load request.

Specified by:
getSupportingPersisters in interface PersistenceRegistry
Parameters:
resource - The data source from which the data model needs to be restored.
Returns:
The list of Persisters or an empty list if no persisters are found.
See Also:
PersistenceRegistry.getSupportingPersisters(edu.iu.iv.core.persistence.ResourceDescriptor)

getPersisters

public java.util.List getPersisters()
Description copied from interface: PersistenceRegistry
Gets the list of all persisters currently registered with the registry. If nothing is registered then an empty list is returned. Applications that wish to select a suitable persister in their own way instead of using the default implementation should make use of this method. For example, an application might want to keep track of the frequency of usage of a certain persister in order to optimize the ones most used in addition to the average size of the data that is persisted with a certain persister. All such information about a persister can easily be maintained in a lookup table indexed by the persisters available in the system.

Specified by:
getPersisters in interface PersistenceRegistry
Returns:
The list of all registered persisters or an empty list if no persisters are registered.
See Also:
PersistenceRegistry.getPersisters()

findPersister

public Persister findPersister(java.lang.Object model,
                               ResourceDescriptor resource)
Description copied from interface: PersistenceRegistry
Finds a persister that can persist a specified data model to a specified data resource or one that can restore from a particular resource. Currently we assume that there is only one persister that maps a particular data model to a particular data resource. In future this method will likely be changed to return a list of persisters that can successfully satisfy this request, hence applications are discouraged from using it directly.

Specified by:
findPersister in interface PersistenceRegistry
Parameters:
model - The data model that needs to be persisted or restored.
resource - The resource to which this data needs to be persisted to or restored from.
Returns:
The persister than can satisfy this request or null if none found.

save

public void save(java.lang.Object model,
                 ResourceDescriptor destination)
          throws java.io.IOException,
                 PersistenceException
Attempts to save the specified data model's data to the specified resource. This method scans the available persisters to find a suitable one to satisfy this request, failing which it throws an exception to signify the fact that no suitable persister was found.

Specified by:
save in interface PersistenceRegistry
Parameters:
model - The model to be saved.
destination - The object describing the properties of the data resource where this model should be saved.
java.io.IOException
PersistenceException
See Also:
PersistenceRegistry.save(Object, ResourceDescriptor)

load

public java.lang.Object load(ResourceDescriptor source)
                      throws java.io.IOException,
                             java.lang.OutOfMemoryError,
                             PersistenceException
Attempts to load the specified data model with data from the specified source. This method scans the available persisters to find a suitable persister, failing which it throws an exception to signify the fact that no suitable persister was found. Once it gets a list of persisters the method uses one of the available persisters to load the model in memory.

Specified by:
load in interface PersistenceRegistry
Parameters:
source - The resource from where the data model is to be loaded.
Returns:
The data model populated with the data from the resource or null if it fails.
java.io.IOException
java.lang.OutOfMemoryError
PersistenceException
See Also:
PersistenceRegistry.load(ResourceDescriptor)