edu.ucsb.adl.middleware
Class CachingMetadataDriver

java.lang.Object
  |
  +--edu.ucsb.adl.middleware.CachingMetadataDriver
All Implemented Interfaces:
MetadataDriver

public final class CachingMetadataDriver
extends java.lang.Object
implements MetadataDriver

Metadata driver that caches reports. This driver can sit, as a kind of filter, in front of any nominal metadata driver; it is automatically created by MetadataService for a collection if (and only if) the collection's metadata.cache property is "on".

This class reads the following properties from the collection-specific middleware configuration file drivers.conf for the collection in question:

metadata.driver.class
The fully-qualified name of the driver class of the wrapped (or nominal) metadata driver, e.g., "edu.ucsb.adl.bucket99.MetadataDriver".
metadata.cache.directory
The directory (i.e., Berkeley DB "environment") in which to cache reports. If the pathname is not absolute, it is interpreted relative to the directory containing the collection-specific configuration file. The directory must already exist. If the collection name is C, reports for metadata view V are cached in Berkeley DB database "C:V" within the environment. As a consequence, the cache directory may be shared by multiple collections without conflict.
metadata.cache.views
The metadata views to cache expressed as a list of zero or more view names separated by commas, e.g., "adl:bucket,adl:browse,adl:access".
In the above, property values may be indirectly specified using the notation @P where P is the name of another property (see ExtendedProperties for more information). Note that the main middleware configuration file serves as a properties default for the collection-specific configuration files.

Implementation note: this class validates reports, and valid reports are processed (e.g., by removing any XML encoding declaration) just as MetadataService would. All reports are returned, but only valid (and processed) reports are cached. Cached reports are prefixed with the string "VALID"; this prefix is detected and removed by MetadataService, and is interpreted by that class as meaning that no further validation or processing need be done.

Version:
$Header: /export/home/gjanee/middleware/edu/ucsb/adl/middleware/RCS/CachingMetadataDriver.java,v 1.1 2006/06/23 22:59:56 gjanee Exp $

$Log: CachingMetadataDriver.java,v $ Revision 1.1 2006/06/23 22:59:56 gjanee Initial revision

Author:
Greg Janée
Alexandria Digital Library

Method Summary
static edu.ucsb.adl.middleware.CachingMetadataDriver createDriver(edu.ucsb.adl.middleware.Global global, java.io.File directory, java.lang.String collection)
          Creates a CachingMetadataDriver for a collection.
static edu.ucsb.adl.middleware.CachingMetadataDriver createDriverInternal(edu.ucsb.adl.middleware.Global global, java.io.File directory, java.lang.String collection)
          Creates a CachingMetadataDriver for a collection.
 void destroy()
          Frees all resources held by the driver.
 java.lang.String performMetadataService(java.lang.String view, java.lang.String collection, java.lang.String holding)
          Returns a view of the metadata for a holding within the collection.
 java.lang.String[] performViewsService(java.lang.String collection, java.lang.String holding)
          Returns a list of the views supported by a holding within the collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createDriver

public static edu.ucsb.adl.middleware.CachingMetadataDriver createDriver(edu.ucsb.adl.middleware.Global global,
                                                                         java.io.File directory,
                                                                         java.lang.String collection)
                                                                  throws InternalErrorException
Creates a CachingMetadataDriver for a collection. The wrapped metadata driver is created as well.

Parameters:
global - The global object representing this instance of the middleware.
directory - The pathname of the directory containing the collection-specific middleware configuration file.
collection - The name of the collection, e.g., "adl_catalog".
Returns:
A CachingMetadataDriver.
Throws:
InternalErrorException - If any error is encountered.

createDriverInternal

public static edu.ucsb.adl.middleware.CachingMetadataDriver createDriverInternal(edu.ucsb.adl.middleware.Global global,
                                                                                 java.io.File directory,
                                                                                 java.lang.String collection)
                                                                          throws InternalErrorException
Creates a CachingMetadataDriver for a collection. The wrapped metadata driver is created as well.

Parameters:
global - The global object representing this instance of the middleware.
directory - The pathname of the directory containing the collection-specific middleware configuration file.
collection - The name of the collection, e.g., "adl_catalog".
Returns:
A CachingMetadataDriver.
Throws:
InternalErrorException - If any error is encountered.

performMetadataService

public java.lang.String performMetadataService(java.lang.String view,
                                               java.lang.String collection,
                                               java.lang.String holding)
                                        throws MiddlewareException
Returns a view of the metadata for a holding within the collection. This method is threadsafe.

Specified by:
performMetadataService in interface MetadataDriver
Parameters:
view - The metadata view, e.g., "adl:bucket".
collection - The collection name, e.g., "adl_catalog".
holding - The holding identifier.
Returns:
An XML document that is well-formed and valid according to the appropriate DTD.
Throws:
BadRequestException - If holding is not a valid holding identifier.
UnsupportedException - If the request is valid but not supported (e.g., the view is unsupported by the holding).
InternalErrorException - If the request is valid but cannot otherwise be completed.
MiddlewareException
See Also:
MetadataService

performViewsService

public java.lang.String[] performViewsService(java.lang.String collection,
                                              java.lang.String holding)
                                       throws MiddlewareException
Returns a list of the views supported by a holding within the collection. This method is threadsafe.

Specified by:
performViewsService in interface MetadataDriver
Parameters:
collection - The collection name, e.g., "adl_catalog".
holding - The holding identifier.
Returns:
The views supported by the holding.
Throws:
BadRequestException - If holding is not a valid holding identifier.
InternalErrorException - If the request is valid but cannot otherwise be completed.
MiddlewareException
See Also:
MetadataService

destroy

public void destroy()
Frees all resources held by the driver.

Specified by:
destroy in interface MetadataDriver