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

java.lang.Object
  |
  +--org.sape.carbon.core.config.node.AbstractNode
        |
        +--org.sape.carbon.core.config.node.AbstractFolder
              |
              +--org.sape.carbon.services.config.jar.JarFolder
All Implemented Interfaces:
Folder, Node

public class JarFolder
extends AbstractFolder

Implementation of folder node for folders residing in Jars Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.4 $($Author: dvoet $ / $Date: 2003/10/16 20:57:28 $)
Author:
Douglas Voet, April 2002

Field Summary
private  EnhancedJarFile currentOpenJar
          reference to the currently openned jar
private static String CVS_DIR
          A CVS directory.
private static Collection EXCLUDE_NODE_NAMES
          Collection of node names that will not be loaded.
private  FileNodeFilter fileFilter
          The filter used to obtain valid child entries that may be represented by JarNodes from the jarFile.
static String JAR_DELIMETER
          string that delimits entry names in the jar
private  String jarEntryName
          name of the entry of this folder
private  File jarFile
          reference to file containing the jar
private  boolean jarOpenForRead
          flag to keep track of how the jar was openned: true for read, false for write
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
private static String META_INF_DIR
          The java meta-inf directory.
private  ReadWriteLock readWriteLock
          reference to the jar's monitor
 
Fields inherited from class org.sape.carbon.core.config.node.AbstractFolder
 
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
JarFolder(Node parent, String name, NodeFactory subFolderFactory, NodeFactory configurationDocumentFactory, NodeFactory linkNodeFactory, ReadWriteLock readWriteLock, File jarFile, String jarEntryName)
          Constructor for JarFolder.
 
Method Summary
protected  boolean backingDataExists()
          Method called from the refresh method to see if the backing data still exists.
private  void closeJar()
          Closes the jar file if it is open, releasing the lock based upon how it was opened
protected  void destroyBackingData()
          This implementation does nothing as jars have no concept of folders, so there is nothing to remove
protected  Set getAllChildNames()
          This is sychronized because it is called from AbstractFolder.fetchAllChildren which is not synchronized, but the design of the class requires that openJar is not called multiple times without intervening calls to close jar
(package private)  String getInternalJarEntryName()
          Returns the entry name of this node.
(package private)  File getInternalJarFile()
          Returns the file object pointing to the jar file.
(package private)  ReadWriteLock getReadWriteLock()
          Returns the monitor for this jar.
protected  Node loadChild(String nodeName)
          This is not synchronized because it is called from AbstractFolder.fetchChild which is synchronized
private  Node loadChildLinkNode(String nodeName)
          Helper method used to create sub links
private  Node loadConfigurationDocument(String nodeName)
          Helper method used to create sub config docs
private  Node loadSubFolder(String nodeName)
          Helper method used to create sub folders
private  EnhancedJarFile openJar(boolean forRead)
          Opens the jar file.
 
Methods inherited from class org.sape.carbon.core.config.node.AbstractFolder
addConfigurationDocument, addLink, addSubFolder, createNewConfigurationDocument, createNewFolder, getConfigurationDocumentFactory, getLinkNodeFactory, getSubFolderFactory, issueChildAddedEvent
 
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, refresh, remove, 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, refresh, remove
 

Field Detail

log

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


jarFile

private File jarFile
reference to file containing the jar


jarEntryName

private String jarEntryName
name of the entry of this folder


currentOpenJar

private EnhancedJarFile currentOpenJar
reference to the currently openned jar


jarOpenForRead

private boolean jarOpenForRead
flag to keep track of how the jar was openned: true for read, false for write


readWriteLock

private final ReadWriteLock readWriteLock
reference to the jar's monitor


fileFilter

private FileNodeFilter fileFilter
The filter used to obtain valid child entries that may be represented by JarNodes from the jarFile.


JAR_DELIMETER

public static final String JAR_DELIMETER
string that delimits entry names in the jar

See Also:
Constant Field Values

EXCLUDE_NODE_NAMES

private static final Collection EXCLUDE_NODE_NAMES
Collection of node names that will not be loaded.


META_INF_DIR

private static final String META_INF_DIR
The java meta-inf directory.

See Also:
Constant Field Values

CVS_DIR

private static final String CVS_DIR
A CVS directory.

See Also:
Constant Field Values
Constructor Detail

JarFolder

public JarFolder(Node parent,
                 String name,
                 NodeFactory subFolderFactory,
                 NodeFactory configurationDocumentFactory,
                 NodeFactory linkNodeFactory,
                 ReadWriteLock readWriteLock,
                 File jarFile,
                 String jarEntryName)
Constructor for JarFolder.

Parameters:
parent - the parent of this folder
name - the name of this folder
subFolderFactory - the factory for creating sub folders
configurationDocumentFactory - the factory for creating documents
linkNodeFactory - the factory for creating sub links
readWriteLock - the monitor used to coordinate reads and writes to the jar
jarFile - the file that is the jar
jarEntryName - the entry name within the jar that this node represents
Method Detail

loadChild

protected Node loadChild(String nodeName)
                  throws NodeNotFoundException
This is not synchronized because it is called from AbstractFolder.fetchChild which is synchronized

Specified by:
loadChild in class AbstractNode
Parameters:
nodeName - the name of the node to load
Returns:
Node the loaded node
Throws:
NodeNotFoundException - if the backing data for the specifed node could not be found in the data store.
See Also:
AbstractNode.loadChild(String)

getAllChildNames

protected Set getAllChildNames()
This is sychronized because it is called from AbstractFolder.fetchAllChildren which is not synchronized, but the design of the class requires that openJar is not called multiple times without intervening calls to close jar

Specified by:
getAllChildNames in class AbstractNode
Returns:
Set of Strings, the names of all the children
See Also:
AbstractNode.getAllChildNames()

destroyBackingData

protected void destroyBackingData()
                           throws NodeRemovalException
This implementation does nothing as jars have no concept of folders, so there is nothing to remove

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()

getInternalJarFile

File getInternalJarFile()
Returns the file object pointing to the jar file. Called by factories to propagate the file object to child nodes

Returns:
File

getInternalJarEntryName

String getInternalJarEntryName()
Returns the entry name of this node. Called by factories to preprend to entry names of child nodes

Returns:
String

getReadWriteLock

ReadWriteLock getReadWriteLock()
Returns the monitor for this jar. Called by factories to propagate the monitor to child nodes so that all nodes within this structure use the same monitory

Returns:
a read write lock used to synchronize access to the jar containing this folder.

loadSubFolder

private Node loadSubFolder(String nodeName)
                    throws NodeCreationException
Helper method used to create sub folders

Parameters:
nodeName - the name of the sub-node
Returns:
Node the sub-node
Throws:
NodeCreationException - indicates an error loading a subfolder

loadConfigurationDocument

private Node loadConfigurationDocument(String nodeName)
                                throws NodeCreationException
Helper method used to create sub config docs

Parameters:
nodeName - name of the sub-config to load
Returns:
Node the loaded configuration document
Throws:
NodeCreationException - indicates an error loading the child node

loadChildLinkNode

private Node loadChildLinkNode(String nodeName)
                        throws NodeCreationException
Helper method used to create sub links

Parameters:
nodeName - name of the child link node
Returns:
Node the child link node specified by the given name
Throws:
NodeCreationException - indicates an error loading the child link node

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 manipulating the jar file

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 manipulating the jar file


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.