org.sape.carbon.services.config.classloader
Class ClassloaderConfigurationDocument

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

public class ClassloaderConfigurationDocument
extends AbstractConfigurationDocument

Implementation of ConfigurationDocument using streams found from a classloader.

Copyright 2003 Sapient

Since:
carbon 2.0
Version:
$Revision: 1.7 $($Author: dvoet $ / $Date: 2003/12/11 18:43:31 $)
Author:
Greg Hinkle, April 2003

Field Summary
private  ConfigurationSource configSource
          The source for configuration data.
private  boolean isInMemoryOnly
          Keeps track of whether or not this node was created in memory only or it is actually on the backing data store.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
private  String resourcePath
          The path of the resource that contains this configuration.
 
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
ClassloaderConfigurationDocument(Node parent, String name, ConfigurationFormatService formatter, String resourcePath, ConfigurationSource configSource)
          Constructor for ClassloaderConfigurationDocument.
 
Method Summary
protected  boolean backingDataExists()
          If this node exists, then it was either loaded from a classloader resource or it is in-memory-only.
protected  void closeOutputStream(OutputStream out)
          This implementation cannot write configurations to a backing data store.
protected  void destroyBackingData()
          This is only called in the case of in-memory-only configurations.
protected  InputStream openInputStream()
          This implementation opens an input stream of the resource itentified by this.resourcePath by calling classloader.getResourceAsStream(this.resourcePath)
protected  OutputStream openOutputStream()
          This implementation cannot write configurations to a backing data store.
 void refresh()
          This implementation only refreshes the node if it is not in memory only
 int remove()
          Only configurations that exist in-memory-only can be removed.
 void writeConfiguration(Configuration config)
          This implementation does not write through to the backing datastore as Classloader resources are read-only.
 
Methods inherited from class org.sape.carbon.core.config.node.AbstractConfigurationDocument
addNestedConfigurationDocument, closeInputStream, getAllChildNames, getFormatService, getNestedNodeFactory, issueNodeModifiedEvent, loadChild, notifyNestedDocuments, readConfiguration, writeChildReferences
 
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


resourcePath

private final String resourcePath
The path of the resource that contains this configuration. final as this should never change during the life of the instance, if it does, more synchronization may be required.


configSource

private final ConfigurationSource configSource
The source for configuration data. final as this should never change during the life of the instance, if it does, more synchronization may be required.


isInMemoryOnly

private final boolean isInMemoryOnly
Keeps track of whether or not this node was created in memory only or it is actually on the backing data store. final as this should never change during the life of the instance, if it does, more synchronization may be required.

Constructor Detail

ClassloaderConfigurationDocument

public ClassloaderConfigurationDocument(Node parent,
                                        String name,
                                        ConfigurationFormatService formatter,
                                        String resourcePath,
                                        ConfigurationSource configSource)
Constructor for ClassloaderConfigurationDocument.

Parameters:
parent -
name -
formatter -
resourcePath -
Method Detail

writeConfiguration

public void writeConfiguration(Configuration config)
This implementation does not write through to the backing datastore as Classloader resources are read-only. The in-memory copy of the configuration is replaced with a clone of the config parameter

This method is synchronized internally to prevent multiple writes from saving Configurations concurrently and to make sure that no one is writing a new Configuration while someone else is reading.

Specified by:
writeConfiguration in interface ConfigurationDocument
Overrides:
writeConfiguration in class AbstractConfigurationDocument
Parameters:
config - the new Configuration

openInputStream

protected InputStream openInputStream()
                               throws IOException
This implementation opens an input stream of the resource itentified by this.resourcePath by calling classloader.getResourceAsStream(this.resourcePath)

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

openOutputStream

protected OutputStream openOutputStream()
                                 throws IOException
This implementation cannot write configurations to a backing data store. writeConfiguration has been overridden in this class so as not to call this method.

Specified by:
openOutputStream in class AbstractConfigurationDocument
Returns:
OutputStream the OutputStream to which to write the Configuration object within this ConfigurationDocument
Throws:
UnsupportedOperationException
IOException

closeOutputStream

protected void closeOutputStream(OutputStream out)
                          throws IOException
This implementation cannot write configurations to a backing data store. writeConfiguration has been overridden in this class so as not to call this method.

Overrides:
closeOutputStream in class AbstractConfigurationDocument
Parameters:
out - the stream to close
Throws:
UnsupportedOperationException
IOException

destroyBackingData

protected void destroyBackingData()
                           throws NodeRemovalException
This is only called in the case of in-memory-only configurations. If this node is backed by a classloader resource, the remove method should throw an exception.

Specified by:
destroyBackingData in class AbstractNode
Throws:
NodeRemovalException - indicates an error removing the node

backingDataExists

protected boolean backingDataExists()
If this node exists, then it was either loaded from a classloader resource or it is in-memory-only. In either case the backing data exists so this method always returns true.

Specified by:
backingDataExists in class AbstractNode
Returns:
boolean true if the backing date exists, false otherwise

remove

public int remove()
           throws NodeRemovalException
Only configurations that exist in-memory-only can be removed.

Specified by:
remove in interface Node
Overrides:
remove in class AbstractConfigurationDocument
Throws:
NodeRemovalException - if this configuration was created from a classloader resource.
See Also:
synchronized to ensure no one is fetching or adding children while this method is removing them

refresh

public void refresh()
This implementation only refreshes the node if it is not in memory only

Specified by:
refresh in interface Node
Overrides:
refresh in class AbstractConfigurationDocument
See Also:
Node.refresh()


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.