org.sape.carbon.services.config.jndi
Class JNDIConfigurationDocument

java.lang.Object
  |
  +--org.sape.carbon.core.config.node.AbstractNode
        |
        +--org.sape.carbon.core.config.node.AbstractConfigurationDocument
              |
              +--org.sape.carbon.services.config.jndi.JNDIConfigurationDocument
All Implemented Interfaces:
ConfigurationDocument, EventListener, NamespaceChangeListener, NamingListener, Node, ObjectChangeListener

public class JNDIConfigurationDocument
extends AbstractConfigurationDocument
implements NamespaceChangeListener, ObjectChangeListener

A node that represents a JNDI context that contains content. Content is read and writen using a ConfigurationFormatService. This implementation implements NamespaceChangeListener and ObjectChangeListener from the javax.naming.event package in order to listen for changes in the backing datastore. Copyright 2003 Sapient

Since:
carbon 2.0
Version:
$Revision: 1.11 $($Author: dvoet $ / $Date: 2003/05/05 21:21:10 $)
Author:
Douglas Voet, March 2003

Field Summary
private  JNDILinkNodeConfiguration config
           
private  String documentType
           
private  DirContext initialContext
           
private  org.apache.commons.logging.Log log
           
private  Name nodeContextName
           
 
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
JNDIConfigurationDocument(Node parent, String name, ConfigurationFormatService formatter, DirContext initialContext, Name nodeContextName, JNDILinkNodeConfiguration config, String documentType)
          Constructs the JNDIConfigurationDocument and registers itself as a JNDI naming listener
 
Method Summary
protected  boolean backingDataExists()
          Checks the backing directory to see if this nodes context exists and if it does, has the right attributes.
protected  void closeOutputStream(OutputStream out)
          Gets the data from the output stream and writes it to the jndi directory
protected  void destroyBackingData()
          Calls destroySubcontext with this context's name
 void namingExceptionThrown(NamingExceptionEvent evt)
          Logs the fact that a NamingExceptionEvent occured
 void objectAdded(NamingEvent evt)
          This implementation does not do anything if an object is added.
 void objectChanged(NamingEvent evt)
          Causes a refresh of this node
 void objectRemoved(NamingEvent evt)
          Causes a refresh of this node
 void objectRenamed(NamingEvent evt)
          Causes a refresh of this node
protected  InputStream openInputStream()
          Gets the content from the JNDI directory and converts it to a stream
protected  OutputStream openOutputStream()
          Returns a new ByteArrayOutputStream that is read when it is closed
protected  void registerNamingListener()
          Registers this node as a NamingListener with the backing context
 
Methods inherited from class org.sape.carbon.core.config.node.AbstractConfigurationDocument
addNestedConfigurationDocument, closeInputStream, 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

initialContext

private DirContext initialContext

nodeContextName

private Name nodeContextName

config

private JNDILinkNodeConfiguration config

documentType

private String documentType
Constructor Detail

JNDIConfigurationDocument

public JNDIConfigurationDocument(Node parent,
                                 String name,
                                 ConfigurationFormatService formatter,
                                 DirContext initialContext,
                                 Name nodeContextName,
                                 JNDILinkNodeConfiguration config,
                                 String documentType)
Constructs the JNDIConfigurationDocument and registers itself as a JNDI naming listener

Parameters:
parent - the parent node of this node
name - the name of this node
formatter - the format service this node should use
initialContext - the jndi initial context
nodeContextName - the name of this node's context
config - configuration used to get the names of the attributes that hold node name, node and document type, and document content as well as valid attribute values for node and document type.
Method Detail

destroyBackingData

protected void destroyBackingData()
                           throws NodeRemovalException
Calls destroySubcontext with this context's name

Specified by:
destroyBackingData in class AbstractNode
Throws:
NodeRemovalException - if a NamingException is encountered

openInputStream

protected InputStream openInputStream()
                               throws NamingException
Gets the content from the JNDI directory and converts it to a stream

Specified by:
openInputStream in class AbstractConfigurationDocument
Returns:
InputStream the InputStream from which to read the Configuration object within this ConfigurationDocument
Throws:
NamingException - if content cannot be read from the jndi directory
InvalidConfigurationException - if there is no content in this nodes context

openOutputStream

protected OutputStream openOutputStream()
Returns a new ByteArrayOutputStream that is read when it is closed

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

closeOutputStream

protected void closeOutputStream(OutputStream out)
                          throws Exception
Gets the data from the output stream and writes it to the jndi directory

Overrides:
closeOutputStream in class AbstractConfigurationDocument
Parameters:
out - the stream to close
Throws:
NamingException - if there is a problem writing to the directory
Exception - indicates an error closing the stream

backingDataExists

protected boolean backingDataExists()
Checks the backing directory to see if this nodes context exists and if it does, has the right attributes.

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

objectAdded

public void objectAdded(NamingEvent evt)
This implementation does not do anything if an object is added.

Specified by:
objectAdded in interface NamespaceChangeListener

objectRemoved

public void objectRemoved(NamingEvent evt)
Causes a refresh of this node

Specified by:
objectRemoved in interface NamespaceChangeListener

objectRenamed

public void objectRenamed(NamingEvent evt)
Causes a refresh of this node

Specified by:
objectRenamed in interface NamespaceChangeListener

objectChanged

public void objectChanged(NamingEvent evt)
Causes a refresh of this node

Specified by:
objectChanged in interface ObjectChangeListener

namingExceptionThrown

public void namingExceptionThrown(NamingExceptionEvent evt)
Logs the fact that a NamingExceptionEvent occured

Specified by:
namingExceptionThrown in interface NamingListener

registerNamingListener

protected void registerNamingListener()
Registers this node as a NamingListener with the backing context



Copyright 1999-2003 Sapient Corporation. All Rights Reserved.