org.hippoecm.hst.mock.content.beans.manager
Class MockObjectBeanPersistenceManager

java.lang.Object
  extended by org.hippoecm.hst.mock.content.beans.manager.MockObjectBeanPersistenceManager
All Implemented Interfaces:
ObjectBeanManager, ObjectBeanPersistenceManager

public class MockObjectBeanPersistenceManager
extends Object
implements ObjectBeanPersistenceManager

Simple in-memory implementation for MockObjectBeanPersistenceManager interface.

This implementation assumes that a content object has 'path' bean property to indicate from which absolute path the content object is originated. So, it will use getPath() method to read the original absolute path to update or remove the object.

The absolute content paths and objects mapped to the paths are stored in maps. To store an object to maps, it uses Java Serialization. Therefore, the object used with this implementation should implement java.io.Serializable, public boolean equals(Object object); and public int hashCode(); properly.

By the way, this mock implementation does not have any knowledge on how to create a new content based on its node type.

Version:
$Id: MockObjectBeanPersistenceManager.java 20882 2009-11-26 10:21:54Z aschrijvers $

Constructor Summary
MockObjectBeanPersistenceManager()
           
 
Method Summary
protected  Object bytesToObject(byte[] bytes)
           
 void create(String absPath, String nodeTypeName, String name)
          Creates content node(s) with the specified node type at the specified absolute path.
 void create(String absPath, String nodeTypeName, String name, boolean autoCreateFolders)
          Creates content node(s) with the specified node type at the specified absolute path.
 String createAndReturn(String absPath, String nodeTypeName, String name, boolean autoCreateFolders)
          Creates content node(s) with the specified node type at the specified absolute path.
 Object getObject(String absPath)
          Get an object from the JCR repository.
 Object getObjectByUuid(String uuid)
          Get an object from the JCR repository
protected  String getPathProperty(Object object)
           
protected  Object getSerializedCopy(Object object)
           
 javax.jcr.Session getSession()
          This method returns the JCR session.
protected  String getUuidProperty(Object object)
           
protected  byte[] objectToBytes(Object object)
           
 void refresh()
          Invokes Session.refresh(boolean) with false parameter.
 void refresh(boolean keepChanges)
          Invokes Session.refresh(boolean).
 void remove(Object content)
          Removes the content node which is mapped to the object.
 void save()
          Saves all pending changes.
 void setObject(String absPath, Object object)
           
 void update(Object content)
          Updates the content node which is mapped to the object.
 void update(Object content, ContentNodeBinder customBinder)
          Updates the content node which is mapped to the object by the customContentNodeBinder provided by client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockObjectBeanPersistenceManager

public MockObjectBeanPersistenceManager()
Method Detail

getObject

public Object getObject(String absPath)
                 throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanManager
Get an object from the JCR repository. path is the absolute object path and must start with a "/"

Specified by:
getObject in interface ObjectBeanManager
Parameters:
absPath - the absolute object path.
Returns:
the object found or null
Throws:
ObjectBeanPersistenceException

getObjectByUuid

public Object getObjectByUuid(String uuid)
                       throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanManager
Get an object from the JCR repository

Specified by:
getObjectByUuid in interface ObjectBeanManager
Returns:
the object found or null
Throws:
ObjectBeanPersistenceException

setObject

public void setObject(String absPath,
                      Object object)
               throws ObjectBeanPersistenceException
Throws:
ObjectBeanPersistenceException

create

public void create(String absPath,
                   String nodeTypeName,
                   String name)
            throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Creates content node(s) with the specified node type at the specified absolute path.

The absolute path could be regarded differently according to physical implementations. For example, an implementation can regard the path as a simple one to create a simple JCR node. On the other hand, a sophisticated implementation can regard the path as an input for a workflow-enabled document/folder path.

Specified by:
create in interface ObjectBeanPersistenceManager
Parameters:
absPath - the absolute node path
nodeTypeName - the node type name of the content object
name - the content node name
Throws:
ObjectBeanPersistenceException

create

public void create(String absPath,
                   String nodeTypeName,
                   String name,
                   boolean autoCreateFolders)
            throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Creates content node(s) with the specified node type at the specified absolute path.

The absolute path could be regarded differently according to physical implementations. For example, an implementation can regard the path as a simple one to create a simple JCR node. On the other hand, a sophisticated implementation can regard the path as an input for a workflow-enabled document/folder path.

If autoCreateFolders is true, then folders will be automatically created.

Specified by:
create in interface ObjectBeanPersistenceManager
Parameters:
absPath - the absolute node path
nodeTypeName - the node type name of the content object
name - the content node name
autoCreateFolders - the flag to create folders
Throws:
ObjectBeanPersistenceException

createAndReturn

public String createAndReturn(String absPath,
                              String nodeTypeName,
                              String name,
                              boolean autoCreateFolders)
                       throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Creates content node(s) with the specified node type at the specified absolute path.

The absolute path could be regarded differently according to physical implementations. For example, an implementation can regard the path as a simple one to create a simple JCR node. On the other hand, a sophisticated implementation can regard the path as an input for a workflow-enabled document/folder path.

If autoCreateFolders is true, then folders will be automatically created.

Specified by:
createAndReturn in interface ObjectBeanPersistenceManager
Parameters:
absPath - the absolute node path
nodeTypeName - the node type name of the content object
name - the content node name
autoCreateFolders - the flag to create folders
Returns:
the absolute path of the created node
Throws:
ObjectBeanPersistenceException

update

public void update(Object content)
            throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Updates the content node which is mapped to the object.

An implementation can provide binding the content object to the physical JCR node(s) and updates. An implementation can provide automatic content binding, or another requires pre-registered ContentNodeBinder map to do real bindings. It probably depends on the functionalities of underlying repository.

Specified by:
update in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

update

public void update(Object content,
                   ContentNodeBinder customBinder)
            throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Updates the content node which is mapped to the object by the customContentNodeBinder provided by client.

Unlike ObjectBeanPersistenceManager.update(Object), the implementation should not try to do automatic or predefined bindings. Instead, it should invoke customContentNodeBinder to do bindings.

Therefore, if a developer wants to customize the bindings, the developer should provide a customContentNodeBinder.

Specified by:
update in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

remove

public void remove(Object content)
            throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Removes the content node which is mapped to the object.

Specified by:
remove in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

save

public void save()
          throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Saves all pending changes.

Specified by:
save in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

refresh

public void refresh()
             throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Invokes Session.refresh(boolean) with false parameter.

Specified by:
refresh in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

refresh

public void refresh(boolean keepChanges)
             throws ObjectBeanPersistenceException
Description copied from interface: ObjectBeanPersistenceManager
Invokes Session.refresh(boolean).

Specified by:
refresh in interface ObjectBeanPersistenceManager
Throws:
ObjectBeanPersistenceException

getPathProperty

protected String getPathProperty(Object object)

getUuidProperty

protected String getUuidProperty(Object object)

getSerializedCopy

protected Object getSerializedCopy(Object object)
                            throws ObjectBeanPersistenceException
Throws:
ObjectBeanPersistenceException

objectToBytes

protected byte[] objectToBytes(Object object)
                        throws ObjectBeanPersistenceException
Throws:
ObjectBeanPersistenceException

bytesToObject

protected Object bytesToObject(byte[] bytes)
                        throws ObjectBeanPersistenceException
Throws:
ObjectBeanPersistenceException

getSession

public javax.jcr.Session getSession()
Description copied from interface: ObjectBeanManager
This method returns the JCR session. The JCR session could be used to make some JCR specific calls.

Specified by:
getSession in interface ObjectBeanManager
Returns:
the associated JCR session


Copyright © 2008-2012 Hippo. All Rights Reserved.