org.springframework.extensions.surf.persister
Class ReadOnlyStoreObjectPersister

java.lang.Object
  extended by org.springframework.extensions.surf.persister.AbstractObjectPersister
      extended by org.springframework.extensions.surf.persister.AbstractCachedObjectPersister
          extended by org.springframework.extensions.surf.persister.ReadOnlyStoreObjectPersister
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, ModelObjectPersister
Direct Known Subclasses:
StoreObjectPersister

public class ReadOnlyStoreObjectPersister
extends AbstractCachedObjectPersister

A persister that provides read-only inter-operability with Web Script Framework stores. This persister follows the pattern of store usage in the web script framework by treating the cache as a "master copy" of the persistence state. The cache is populated by the init() method and is then considered to be the master copy. If contents change inside of the underlying store, they will not be detected until the reset() method is employed. This persister implementation therefore lets the web framework accommodate a pattern of store usage that is analogous to the web script framework.

Author:
muzquiano, kevinr
See Also:
ClassPathStore, RemoteStore, WebApplicationStore

Field Summary
protected  String pathPrefix
           
protected  Store store
           
 
Fields inherited from class org.springframework.extensions.surf.persister.AbstractCachedObjectPersister
cacheDelay, caches, GLOBAL_STORE_ID, useCache
 
Fields inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
MODELOBJECT_CLASSES
 
Constructor Summary
ReadOnlyStoreObjectPersister()
          Instantiates a new store model object persister.
 
Method Summary
protected  BasicCache<ModelObject> createCache()
          Creates the cache.
protected  ModelObject createObject(org.dom4j.Document document, String objectTypeId, String objectId, String path)
           
protected  String generatePath(String objectTypeId, String objectId)
          Generates a persistence path for a given object id and object type id.
 Map<String,ModelObject> getAllObjects(ModelPersistenceContext context, String objectTypeId)
          Returns a map of all of the objects referenced by this persister.
 Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context, String objectTypeId, String objectIdPattern)
          Returns a map of all of the objects referenced by this persister filtered by the given ID filter.
 ModelObject getObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Gets an object from persisted storage by id
protected  ModelObject getObjectByPath(ModelPersistenceContext context, String path)
          Retrieves an object from the underlying store by path This performs an interrogation of the underlying document to determine its object type and object id.
protected  String getObjectId(org.dom4j.Document doc, String path)
          Determines the object id of a serialized model object contained in a document.
protected  String getObjectTypeId(org.dom4j.Document doc, String path)
          Determines the object type id of a serialized model object contained in a document.
 String getPathPrefix()
          Gets the path prefix.
 long getTimestamp(ModelPersistenceContext context, String objectTypeId, String objectId)
          Returns the timestamp of the given object in the underlying store
 boolean hasObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Checks whether an object with the given path is persisted
 void init(ModelPersistenceContext context)
          Initializes the persister by preloading the object cache
protected  boolean isModelObject(org.dom4j.Document doc, String path)
          Determines whether the xml contained in the given document describes a valid model object type
protected  Map<String,ModelObject> loadObjectsAndDependents(ModelPersistenceContext context, org.dom4j.Document document, String objectTypeId, String objectId, String path)
           
 ModelObject newObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Creates a new object
 boolean removeObject(ModelPersistenceContext context, String objectTypeId, String objectId)
          Removes an object from persisted storage
 void reset()
          Resets the persister, clearing cache and starting anew.
 boolean saveObject(ModelPersistenceContext context, ModelObject modelObject)
          Saves an object to persisted storage
 void setCache(boolean useCache)
           
 void setCacheCheckDelay(int cacheCheckDelay)
           
 void setPathPrefix(String pathPrefix)
          Sets a path prefix to be applied to generated paths
 void setStore(Store store)
          Sets the store.
 
Methods inherited from class org.springframework.extensions.surf.persister.AbstractCachedObjectPersister
cacheGet, cachePut, cacheRemove, getCache, invalidateCache
 
Methods inherited from class org.springframework.extensions.surf.persister.AbstractObjectPersister
disable, getId, getServiceRegistry, getWebFrameworkConfiguration, getWebFrameworkManager, hasObject, isEnabled, removeObject, setBeanName, setServiceRegistry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

protected Store store

pathPrefix

protected String pathPrefix
Constructor Detail

ReadOnlyStoreObjectPersister

public ReadOnlyStoreObjectPersister()
Instantiates a new store model object persister.

Method Detail

setStore

public void setStore(Store store)
Sets the store.

Parameters:
store - the new store

setPathPrefix

public void setPathPrefix(String pathPrefix)
Sets a path prefix to be applied to generated paths

Parameters:
pathPrefix - the path prefix

getPathPrefix

public String getPathPrefix()
Gets the path prefix.

Returns:
the path prefix or null if not provided

generatePath

protected String generatePath(String objectTypeId,
                              String objectId)
Generates a persistence path for a given object id and object type id. Default way to convert an object id into a storage path is to add the .xml extension to the object id.

This method should never return a null value.

Parameters:
objectTypeId - the object type id
objectId - the object id
Returns:
the storage path for this id

saveObject

public boolean saveObject(ModelPersistenceContext context,
                          ModelObject modelObject)
                   throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Saves an object to persisted storage

Returns:
whether the object was saved
Throws:
ModelObjectPersisterException

newObject

public ModelObject newObject(ModelPersistenceContext context,
                             String objectTypeId,
                             String objectId)
                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Creates a new object

Returns:
the object
Throws:
ModelObjectPersisterException

removeObject

public boolean removeObject(ModelPersistenceContext context,
                            String objectTypeId,
                            String objectId)
                     throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Removes an object from persisted storage

Returns:
whether the object was removed
Throws:
ModelObjectPersisterException

getObject

public ModelObject getObject(ModelPersistenceContext context,
                             String objectTypeId,
                             String objectId)
                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Gets an object from persisted storage by id

Returns:
object instance
Throws:
ModelObjectPersisterException

hasObject

public boolean hasObject(ModelPersistenceContext context,
                         String objectTypeId,
                         String objectId)
                  throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Checks whether an object with the given path is persisted

Returns:
whether the object is persisted
Throws:
ModelObjectPersisterException

getTimestamp

public long getTimestamp(ModelPersistenceContext context,
                         String objectTypeId,
                         String objectId)
                  throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns the timestamp of the given object in the underlying store

Returns:
Throws:
ModelObjectPersisterException

getAllObjects

public Map<String,ModelObject> getAllObjects(ModelPersistenceContext context,
                                             String objectTypeId)
                                      throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns a map of all of the objects referenced by this persister.

In general, this is a very expensive call and should be avoided. Each object descriptor referenced by the persister is loaded into the model object cache.

Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

getAllObjectsByFilter

public Map<String,ModelObject> getAllObjectsByFilter(ModelPersistenceContext context,
                                                     String objectTypeId,
                                                     String objectIdPattern)
                                              throws ModelObjectPersisterException
Description copied from interface: ModelObjectPersister
Returns a map of all of the objects referenced by this persister filtered by the given ID filter.

In general, this is an expensive call but less expensive than getAllObjects(). Each object descriptor referenced by the persister found using the filter is loaded into the model object cache.

Returns:
Map of object IDs to ModelObject instances
Throws:
ModelObjectPersisterException

init

public void init(ModelPersistenceContext context)
Description copied from interface: ModelObjectPersister
Initializes the persister by preloading the object cache

Specified by:
init in interface ModelObjectPersister
Overrides:
init in class AbstractObjectPersister
Parameters:
context - the persistence context

reset

public void reset()
Description copied from interface: ModelObjectPersister
Resets the persister, clearing cache and starting anew.

Specified by:
reset in interface ModelObjectPersister
Overrides:
reset in class AbstractObjectPersister

createCache

protected BasicCache<ModelObject> createCache()
Description copied from class: AbstractCachedObjectPersister
Creates the cache.

Overrides:
createCache in class AbstractCachedObjectPersister
Returns:
the basic cache< model object>

getObjectByPath

protected ModelObject getObjectByPath(ModelPersistenceContext context,
                                      String path)
                               throws ModelObjectPersisterException
Retrieves an object from the underlying store by path This performs an interrogation of the underlying document to determine its object type and object id.

Parameters:
context -
path -
Returns:
Throws:
ModelObjectPersisterException

loadObjectsAndDependents

protected Map<String,ModelObject> loadObjectsAndDependents(ModelPersistenceContext context,
                                                           org.dom4j.Document document,
                                                           String objectTypeId,
                                                           String objectId,
                                                           String path)
                                                    throws ModelObjectPersisterException
Throws:
ModelObjectPersisterException

createObject

protected ModelObject createObject(org.dom4j.Document document,
                                   String objectTypeId,
                                   String objectId,
                                   String path)

getObjectTypeId

protected String getObjectTypeId(org.dom4j.Document doc,
                                 String path)
Determines the object type id of a serialized model object contained in a document. This will assert that the discovered object type is a valid, registered object type. If the object type is invalid, null will be returned.

Parameters:
doc - document
path - the path
Returns:
object type id (or null if it is not a model object)

getObjectId

protected String getObjectId(org.dom4j.Document doc,
                             String path)
Determines the object id of a serialized model object contained in a document. If the property is available in the serialized document, it will be used. Otherwise, the id will be assumed to be the file name.

Parameters:
doc - document
path - the path
Returns:
object id (or null if it is not a model object)

isModelObject

protected boolean isModelObject(org.dom4j.Document doc,
                                String path)
Determines whether the xml contained in the given document describes a valid model object type

Parameters:
doc - document
path - the path
Returns:
whether this describes a valid model object type

setCache

public void setCache(boolean useCache)
Overrides:
setCache in class AbstractCachedObjectPersister

setCacheCheckDelay

public void setCacheCheckDelay(int cacheCheckDelay)
Overrides:
setCacheCheckDelay in class AbstractCachedObjectPersister


Copyright © 2009 SpringSource, Inc. All Rights Reserved.