Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.muse.core
Class AbstractFilePersistence

    java.lang.Object
      org.apache.muse.core.AbstractFilePersistence

All Implemented Interfaces:
  InitializationParameters, Persistence

Direct Known Subclasses:
  NotificationProducerFilePersistence, RouterFilePersistence, ServiceGroupFilePersistence

public abstract class AbstractFilePersistence
extends java.lang.Object
implements Persistence

AbstractFilePersistence is an abstract component that provides generic resource-state-to-file utilities without specifying the format of the XML that goes into the files. It can be used by resources or capabilities that wish to save state to disk and reload that state the next time the application is initialized.

Author:
  Dan Jemiolo (danj)

Constructor Summary
`AbstractFilePersistence()`

Method Summary
`protected void` | `createResourceFile(EndpointReference epr, Resource resource)` Creates the proper file name for the given resource instance and then delegates creation of the file's contents to the abstract method of the same name.
`protected abstract void` | `createResourceFile(EndpointReference epr, Resource resource, java.io.File resourceFile)` This method should be overridden by concrete file-based persistence classes to create the given file and fill it with the appropriate XML content.
`protected void` | `destroyResourceFile(EndpointReference epr)` Finds the file associated with the given resource EPR and removes it from the file system.
`protected java.lang.String` | `getContextPath(EndpointReference epr)`
`protected java.lang.Integer` | `getFileNumber(java.lang.String fileName)`
`protected java.util.Map` | `getFileNumberTables()`
`protected abstract java.lang.String` | `getFilePrefix()`
`java.lang.String` | `getInitializationParameter(java.lang.String name)`
`java.util.Map` | `getInitializationParameters()`
`protected java.lang.String` | `getNextFileName(int fileNumber)`
`protected int` | `getNextFileNumber(java.lang.String contextPath)`
`protected java.io.File` | `getPersistenceDirectory()`
`java.lang.String` | `getPersistenceLocation()`
`ResourceManager` | `getResourceManager()`
`protected java.io.File` | `getResourceTypeDirectory(java.lang.String contextPath)`
`void` | `reload()` This implementation re-loads all saved instances of the resource types found in the ResourceManager.
`protected abstract Resource` | `reloadResource(java.lang.String contextPath, org.w3c.dom.Element resourceXML)` This method should be overridden by concrete file-based persistence classes to update a resource instance with the saved data from the XML fragment.
`protected void` | `reloadResources(java.lang.String contextPath, java.io.File resourceTypeDir)` This method finds all of the files in the resource type's persistence directory and reloads them one at a time.
`void` | `setInitializationParameters(java.util.Map parameters)` Allows the resource's creator to provide it with arbitrary name-value pairs that may be used during initialization.
`void` | `setPersistenceLocation(java.lang.String location)`
`void` | `setResourceManager(ResourceManager manager)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AbstractFilePersistence

    public AbstractFilePersistence()

Method Detail

### createResourceFile

    protected void createResourceFile(EndpointReference epr,
                                      Resource resource)
                               throws SoapFault

  Creates the proper file name for the given resource instance and then delegates creation of the file's contents to the abstract method of the same name.

  Parameters:
    `epr` -
    `resource` -
  Throws:
    `SoapFault`
  See Also:
    `getNextFileNumber(String)`, `createResourceFile(EndpointReference, Resource, File)`

### createResourceFile

    protected abstract void createResourceFile(EndpointReference epr,
                                               Resource resource,
                                               java.io.File resourceFile)
                                        throws SoapFault

  This method should be overridden by concrete file-based persistence classes to create the given file and fill it with the appropriate XML content. Classes that are only interested in the serialization of a certain capability's data can use the Resource object to get access to said capability.

  Parameters:
    `epr` - The EPR that maps to the given Resource in the ResourceManager.
    `resource` - The resource instance whose state is being persisted.
    `resourceFile` - The File object that represents the yet-to-be-created XML file that will contain the content generated by this method. The implementation of this method must be sure to create the File on disk somehow.
  Throws:
    `SoapFault` -
    - If there is an error generating the proper content for the persistence file.
    - If there is an I/O error while reading or writing to the file system.

### destroyResourceFile

    protected void destroyResourceFile(EndpointReference epr)
                                throws SoapFault

  Finds the file associated with the given resource EPR and removes it from the file system. This method should be called when a resource is destroyed (gone forever), but not when it is merely shutdown (because of server reboot, etc.).

  Parameters:
    `epr` - The EPR of the resource that has been permanently destroyed.
  Throws:
    `SoapFault`

### getContextPath

    protected java.lang.String getContextPath(EndpointReference epr)

  Parameters:
    `epr` -
  Returns:
    The last token after the last slash in the EPR's address. That is, for an EPR with address http://example.com/my-resource, the method returns 'my-resource'.

### getFileNumber

    protected java.lang.Integer getFileNumber(java.lang.String fileName)

  Parameters:
    `fileName` -
  Returns:
    The number at the end of the file name, before the suffix. That is, for a file named 'my-file-14.xml', the method returns 14.

### getFileNumberTables

    protected java.util.Map getFileNumberTables()

### getFilePrefix

    protected abstract java.lang.String getFilePrefix()

  Returns:
    The common string that will start all files created by the persistence implementation. This string will have the next file number appended to it in order to create unique file names.
  See Also:
    `getNextFileNumber(String)`

### getInitializationParameter

    public java.lang.String getInitializationParameter(java.lang.String name)

  Specified by:
    `getInitializationParameter` in interface `InitializationParameters`
  Parameters:
    `name` -
  Returns:
    The value of the initialization parameter, or null if it does not exist.

### getInitializationParameters

    public java.util.Map getInitializationParameters()

  Specified by:
    `getInitializationParameters` in interface `InitializationParameters`
  Returns:
    The set of name-value pairs provided at initialization time. The Map may be empty.

### getNextFileName

    protected java.lang.String getNextFileName(int fileNumber)

  Parameters:
    `fileNumber` -
  Returns:
    A string of the following format: {file-prefix}{file-number}.xml

### getNextFileNumber

    protected int getNextFileNumber(java.lang.String contextPath)

  Returns:
    The next number that is available for creation of unique file names; this number is determined by taking the largest number currently used and incrementing it by one. The method does not attempt to reuse numbers in 'gaps' caused by deletions (that is, if numbers 1, 2, 5, and 6 are used, the method returns 7, not 3).

### getPersistenceDirectory

    protected java.io.File getPersistenceDirectory()

  Returns:
    The File directory that was specified as the persistence location in muse.xml. The directory may not exist, so use File.exists() and/or File.mkdirs() to prevent I/O errors.

### getPersistenceLocation

    public java.lang.String getPersistenceLocation()

  Specified by:
    `getPersistenceLocation` in interface `Persistence`
  Returns:
    The value specified in muse.xml under the persistence element. The semantics of this value are dependent on the type of storage used by the implementation class. As an example, a simple file-based persistence class might interpret the location to be the directory where files are stored; a database-oriented class might interpret it as the JNDI URI for the database.

### getResourceManager

    public ResourceManager getResourceManager()

  Specified by:
    `getResourceManager` in interface `Persistence`
  Returns:
    The ResourceManager that stores all of the resource type definitions and all current resource instances.

### getResourceTypeDirectory

    protected java.io.File getResourceTypeDirectory(java.lang.String contextPath)

  Parameters:
    `contextPath` -
  Returns:
    Returns a directory for a given resource type, under the specified persistence location. The name of the directory is the context path provided. If the directory does not exist, this method will create it before returning the File object.
  See Also:
    `getPersistenceDirectory()`, `File.mkdirs()`

### reload

    public void reload()
                throws SoapFault

  This implementation re-loads all saved instances of the resource types found in the ResourceManager. It delegates the actual reloading work to reloadResources(String, File).

  Specified by:
    `reload` in interface `Persistence`
  Throws:
    `SoapFault`
  See Also:
    `reloadResources(String, File)`

### reloadResource

    protected abstract Resource reloadResource(java.lang.String contextPath,
                                               org.w3c.dom.Element resourceXML)
                                        throws SoapFault

  This method should be overridden by concrete file-based persistence classes to update a resource instance with the saved data from the XML fragment. The resource instance may be created by this method, or it may exist prior to invocation.

  Parameters:
    `contextPath` - The context path of the instance's resource type.
    `resourceXML` - The persisted data that must be reloaded.
  Returns:
    The Resource instance whose state (or part of it) has been reloaded from XML. The Resource may have already existed prior to the method being called, and simply had one of its capabilities updated with saved data; it may also have been created by the method and initialized right before return.
  Throws:
    `SoapFault`

### reloadResources

    protected void reloadResources(java.lang.String contextPath,
                                   java.io.File resourceTypeDir)
                            throws SoapFault

  This method finds all of the files in the resource type's persistence directory and reloads them one at a time. It delegates the reloading of individual resource instances to reloadResource(String, Element).

  Parameters:
    `contextPath` -
    `resourceTypeDir` -
  Throws:
    `SoapFault`
  See Also:
    `reloadResource(String, Element)`

### setInitializationParameters

    public void setInitializationParameters(java.util.Map parameters)

  Description copied from interface: `InitializationParameters`
  Allows the resource's creator to provide it with arbitrary name-value pairs that may be used during initialization. The way that these values are used and/or stored is an implementation detail, and there is no requirement that this feature be used - it is a generic way to specify deployment/initialization parameters. This method should be called before the resource is initialized.

  Specified by:
    `setInitializationParameters` in interface `InitializationParameters`
  Parameters:
    `parameters` - A simple set of name-value pairs - Map[String, String] - that contains initialization parameters for the resource.

### setPersistenceLocation

    public void setPersistenceLocation(java.lang.String location)

  Specified by:
    `setPersistenceLocation` in interface `Persistence`

### setResourceManager

    public void setResourceManager(ResourceManager manager)

  Specified by:
    `setResourceManager` in interface `Persistence`

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD