gov.nih.nci.cagrid.introduce.servicetools
Class XmlPersistenceHelper

java.lang.Object
  extended by gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper
      extended by gov.nih.nci.cagrid.introduce.servicetools.XmlPersistenceHelper
All Implemented Interfaces:
PersistenceHelper

public class XmlPersistenceHelper
extends FilePersistenceHelper
implements PersistenceHelper

This helper is used to persist a ReflectionResource by serializing the resource implementation JavaBean used in constructing the ReflectionResource. The result of storing the resource is an XML file that corresponds exactly to the XML Schema Resource document defined for this resource. Future versions will offer alternative modes of persistence.

Usage:

Use this helper on the model of PersistentReflectionResource

See Also:
ReflectionResource, PersistentReflectionResource, ResourceHomeImpl, PersistentResource, RemoveCallback

Field Summary
 
Fields inherited from class gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper
beanClass, fileSuffix, storageDir
 
Constructor Summary
XmlPersistenceHelper(java.lang.Class beanClass, ServiceConfiguration configuration)
           
 
Method Summary
static void copyFile(java.io.File in, java.io.File out)
           
 java.lang.Object load(java.lang.Class clazz, java.lang.Object key)
          Loads and returns the object of the given key from the persistent storage.
 void load(java.lang.Object key, ReflectionResource resource)
          Loads and initialize the resource.
 void remove(ReflectionResource resource)
          Removes the resource from persistent storage.
 void store(java.lang.Object key, java.lang.Object object, javax.xml.namespace.QName topElementQName)
          Stores the object of the given key to persistent storage.
 void store(ReflectionResource resource)
          Store the resource into an XML document (current implementation).
 
Methods inherited from class gov.nih.nci.cagrid.introduce.servicetools.FilePersistenceHelper
createStorageDirectory, getBeanClass, getDefaultStorageDirectory, getFileSuffix, getKeyAsFile, getStorageDirectory, list, remove, removeAll, setStorageDirectory, setStorageDirectory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nih.nci.cagrid.introduce.servicetools.PersistenceHelper
list, removeAll
 

Constructor Detail

XmlPersistenceHelper

public XmlPersistenceHelper(java.lang.Class beanClass,
                            ServiceConfiguration configuration)
                     throws java.io.IOException
Throws:
java.io.IOException
Method Detail

load

public void load(java.lang.Object key,
                 ReflectionResource resource)
          throws org.globus.wsrf.ResourceException
Description copied from interface: PersistenceHelper
Loads and initialize the resource.

Specified by:
load in interface PersistenceHelper
Parameters:
key - the key of the potentially new resource
resource - the new resource to load. Its key and implementation bean are null. They will be set by a call from this method to resource.initialize().
Throws:
org.globus.wsrf.ResourceException
See Also:
PersistentResource

store

public void store(ReflectionResource resource)
           throws org.globus.wsrf.ResourceException
Description copied from interface: PersistenceHelper
Store the resource into an XML document (current implementation). The name of the file is governed by getKeyAsFile(). This stores the state of the implementation JavaBean. If some resource properties have been implemented with something else (for instance getters and setters from another object) they will not be persisted with the current state. This is not a problem if their state is immutable after initial creation, as their values will be set by initialize, ReflectionResource.initialize()} which is called by this method. (TODO: persist based on each RP?)

Specified by:
store in interface PersistenceHelper
Parameters:
resource - the resource to store the state of.
Throws:
org.globus.wsrf.ResourceException - if the resource could not be stored
See Also:
getKeyAsFile(), PersistentResource

remove

public void remove(ReflectionResource resource)
            throws org.globus.wsrf.ResourceException
Description copied from interface: PersistenceHelper
Removes the resource from persistent storage.

Specified by:
remove in interface PersistenceHelper
Parameters:
resource - the resource to remove from storage.
Throws:
org.globus.wsrf.ResourceException - if the resource could not be removed.
See Also:
RemoveCallback

load

public java.lang.Object load(java.lang.Class clazz,
                             java.lang.Object key)
                      throws org.globus.wsrf.ResourceException
Loads and returns the object of the given key from the persistent storage.

Specified by:
load in interface PersistenceHelper
Parameters:
key - key of object to load.
Returns:
loaded Object instance.
Throws:
org.globus.wsrf.ResourceException - If the object cannot be loaded from file.

store

public void store(java.lang.Object key,
                  java.lang.Object object,
                  javax.xml.namespace.QName topElementQName)
           throws org.globus.wsrf.ResourceException
Stores the object of the given key to persistent storage.
Note: Calls to this function must be synchronized on per key basis.

Parameters:
key - key of object.
object - object to persist.
topElementQName - the top element name of the XML object.
Throws:
org.globus.wsrf.ResourceException - If the object cannot be saved to a file.

copyFile

public static void copyFile(java.io.File in,
                            java.io.File out)
                     throws java.io.IOException
Throws:
java.io.IOException