org.sape.carbon.services.config.jar
Class JarConfigurationDocument

java.lang.Object
  |
  +--org.sape.carbon.core.config.node.AbstractNode
        |
        +--org.sape.carbon.core.config.node.AbstractConfigurationDocument
              |
              +--org.sape.carbon.services.config.jar.JarConfigurationDocument
All Implemented Interfaces:
ConfigurationDocument, Node

public class JarConfigurationDocument
extends AbstractConfigurationDocument

Implementation of ConfigurationDocument using entries within jar files as the backing datastore.

This implementation does not maintain an open jar file. It will open the jar file only when it needs to read or write and close it when it is done.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.2 $($Author: dvoet $ / $Date: 2003/05/05 21:21:09 $)
Author:
Douglas Voet, April 2002

Field Summary
private  EnhancedJarFile currentOpenJar
          Holds the enhanced jar being wrapped.
private  String jarEntryName
          Name of the jar entry.
private  File jarFile
          Holds the simple reference to the jar file.
private  boolean jarOpenForRead
          flags if the jar is open for read.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
private  ReadWriteLock readWriteLock
          Holds a read/write lock for this jar.
 
Fields inherited from class org.sape.carbon.core.config.node.AbstractConfigurationDocument
configuration
 
Fields inherited from class org.sape.carbon.core.config.node.AbstractNode
childNodes, nodeListeners
 
Fields inherited from interface org.sape.carbon.core.config.node.Node
DELIMITER
 
Constructor Summary
JarConfigurationDocument(Node parent, String name, ConfigurationFormatService formatter, ReadWriteLock readWriteLock, File jarFile, String jarEntryName)
          Constructor for JarConfigurationDocument.
 
Method Summary
protected  boolean backingDataExists()
          Method called from the refresh method to see if the backing data still exists.
protected  void closeInputStream(InputStream in)
          Closes the input stream.
private  void closeJar()
          Closes the jar file if it is open, releasing the lock based upon how it was opened.
protected  void closeOutputStream(OutputStream out)
          Closes the output stream.
protected  void destroyBackingData()
          This method is called by remove to destroy the data backing this node in the data source.
protected  InputStream openInputStream()
          This method should be overridden by classes implementing ConfigurationDocuments for specific data stores.
private  EnhancedJarFile openJar(boolean forRead)
          Opens the jar file.
protected  OutputStream openOutputStream()
          This method should be overridden by classes implementing ConfigurationDocuments for specific data stores.
 
Methods inherited from class org.sape.carbon.core.config.node.AbstractConfigurationDocument
addNestedConfigurationDocument, getAllChildNames, getFormatService, getNestedNodeFactory, issueNodeModifiedEvent, loadChild, notifyNestedDocuments, readConfiguration, refresh, remove, writeChildReferences, writeConfiguration
 
Methods inherited from class org.sape.carbon.core.config.node.AbstractNode
addNodeListener, addNodeListener, addNodeListener, containsChild, fetchChild, fetchChildren, getAbsoluteName, getAddOrLoadChildLock, getAllowsChildren, getName, getParent, getReadOrAlterNodeLock, isRemoved, issueChildLoadedEvent, issueNodeRemovedEvent, removeRemovedChildren, setRemoved, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.sape.carbon.core.config.node.Node
addNodeListener, addNodeListener, containsChild, fetchChild, fetchChildren, getAbsoluteName, getAllowsChildren, getName, getParent, isRemoved
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


jarFile

private File jarFile
Holds the simple reference to the jar file.


jarEntryName

private String jarEntryName
Name of the jar entry.


currentOpenJar

private EnhancedJarFile currentOpenJar
Holds the enhanced jar being wrapped.


jarOpenForRead

private boolean jarOpenForRead
flags if the jar is open for read.


readWriteLock

private final ReadWriteLock readWriteLock
Holds a read/write lock for this jar.

Constructor Detail

JarConfigurationDocument

public JarConfigurationDocument(Node parent,
                                String name,
                                ConfigurationFormatService formatter,
                                ReadWriteLock readWriteLock,
                                File jarFile,
                                String jarEntryName)
Constructor for JarConfigurationDocument.

Parameters:
parent - the parent node of the configuration document
name - name of the configuration document
formatter - formatter to use on the document
readWriteLock - lock for the document
jarFile - jarfile the document is wrapping
jarEntryName - entry inside the jarfile
Method Detail

openInputStream

protected InputStream openInputStream()
                               throws IOException
Description copied from class: AbstractConfigurationDocument
This method should be overridden by classes implementing ConfigurationDocuments for specific data stores. The returned InputStream should be a stream of data that can be read by the ConfigurationFormatService and converted to a Configuration object.

This method is called by readConfiguration.

Specified by:
openInputStream in class AbstractConfigurationDocument
Returns:
InputStream the InputStream from which to read the Configuration object within this ConfigurationDocument
IOException
See Also:
AbstractConfigurationDocument.openInputStream()

closeInputStream

protected void closeInputStream(InputStream in)
                         throws IOException
Description copied from class: AbstractConfigurationDocument
Closes the input stream.

Overrides:
closeInputStream in class AbstractConfigurationDocument
Parameters:
in - the stream to open
IOException
See Also:
AbstractConfigurationDocument.closeInputStream(InputStream)

openOutputStream

protected OutputStream openOutputStream()
                                 throws IOException
Description copied from class: AbstractConfigurationDocument
This method should be overridden by classes implementing ConfigurationDocuments for specific data stores. The returned OutputStream should be a stream of data that can be written to by the ConfigurationFormatService.

This method is called by writeConfiguration.

Specified by:
openOutputStream in class AbstractConfigurationDocument
Returns:
OutputStream the OutputStream to which to write the Configuration object within this ConfigurationDocument
IOException
See Also:
AbstractConfigurationDocument.openOutputStream()

closeOutputStream

protected void closeOutputStream(OutputStream out)
                          throws IOException
Description copied from class: AbstractConfigurationDocument
Closes the output stream.

Overrides:
closeOutputStream in class AbstractConfigurationDocument
Parameters:
out - the stream to close
IOException
See Also:
AbstractConfigurationDocument.closeOutputStream(OutputStream)

destroyBackingData

protected void destroyBackingData()
                           throws NodeRemovalException
Description copied from class: AbstractNode
This method is called by remove to destroy the data backing this node in the data source. Implementations of this method should remove all traces of the Node's existence

Specified by:
destroyBackingData in class AbstractNode
Throws:
NodeRemovalException - indicates an error removing the node
See Also:
AbstractNode.destroyBackingData()

backingDataExists

protected boolean backingDataExists()
Description copied from class: AbstractNode
Method called from the refresh method to see if the backing data still exists. If it exists, the isRemoved flag is set to false, if it does not, the isRemoved flag is set to true.

Specified by:
backingDataExists in class AbstractNode
Returns:
boolean true if the backing date exists, false otherwise
See Also:
AbstractNode.backingDataExists()

openJar

private EnhancedJarFile openJar(boolean forRead)
                         throws IOException
Opens the jar file. Based on the boolean value of forRead, a read or a write lock will be acquired.

Parameters:
forRead - if true a read lock will be acquired, if false, a write lock will be acquired
Returns:
the opened jar file
Throws:
IOException - indicates an error opening the jar

closeJar

private void closeJar()
               throws IOException
Closes the jar file if it is open, releasing the lock based upon how it was opened.

Throws:
IOException - indicates an error closing the jar


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.