org.ceryle.xnode
Class XNodeStoreImpl

java.lang.Object
  extended by org.ceryle.xnode.XNodeStoreImpl
All Implemented Interfaces:
XNodeStore

public class XNodeStoreImpl
extends Object
implements XNodeStore

Provides an implementation of the XNodeStore API as a database manager for XNode (XML Node) content. This class currently uses either a Berkeley DB JE or file system-based backend store (the former is the default).

The XNode Implementation (the package org.ceryle.xnode.*, both its source code and documentation), are released under the Apache 2.0 License. For more details, check the LICENSE file contained with the distribution, or see The Ceryle Project for more information. It is distributed with no warranty.

Individual XNodes are stored in XNodeCollections, which are in turn stored in a root XNodeCollection. The createCollection(String,boolean) method is used to create all but the root collection, which is lazily created using the getRootCollection() method (and may be called repeatedly, as it simply returns the existing root collection once created).

Notes

See notes at bottom of code for version details.

Since:
XNode 1.0
Version:
$Id: XNodeStoreImpl.java,v 3.30 2007-06-20 04:42:27 altheim Exp $
Author:
Murray Altheim

Field Summary
static String DATABASE_STORAGE
          The System property name for the XNode database storage path.
static String DEFAULT_XNODESTORE_PROVIDER
          The class name of the default implementation for the XNodeStoreProvider.
static String ENCODING
          The character encoding used by all Database content ("UTF-8").
protected static String m_rootURI
          A String containing the URL of the default root collection.
static String privateCollectionName
          The String constant used as the name of the private (Ceryle) Collection ("_private").
static String PROPERTY_XNODESTORE_PROVIDER
          The XNode property name for the XNodeStoreProvider implementation class name.
static String READ_ONLY
          The System property name for the XNode database read only flag.
static String SAFE_OVERWRITE_MODE
          The System property name for the XNode database safe overwrite mode.
static String USE_CACHE
          The System property name for the XNode database use cache flag.
static String USE_CHANGE_CACHE
          The System property name for the XNode database use change cache flag.
static String USE_REVISION_CONTROL
          The System property name for the XNode database use revision control flag.
static String XNODE_DEFAULT_STORAGE
          The default value for the Ceryle database storage path.
static String XNODE_HOME_DIRECTORY
          The System property name for the XNode application installation directory.
static String XNODESTORE_PROVIDER
          The System property name for the XNodeStoreProvider implementation class name.
 
Fields inherited from interface org.purl.xnode.XNodeStore
ALL_COLLECTIONS, DATABASE_ROOT, FEATURE_COPY_MOVE, XNODE_DEFAULT_ROOT, XNODE_PROTOCOL
 
Constructor Summary
XNodeStoreImpl(MessageHandler messagehandler, XMLProcessor xmlprocessor)
          Constructor provided with a MessageHandler and a well-formed XML Processor.
 
Method Summary
 XNode addXNode(String cid, String nid, Node node)
          Insert a new XNode with ID nid and DOM Node node content into the XNodeCollection with ID cid.
 XNode addXNode(String cid, String nid, String content)
          Insert a new XNode with ID nid whose content is the String content, into the XNodeCollection with ID cid.
 void addXNodeStoreListener(XNodeStoreListener listener)
          Adds listener as a listener for changes to the XNodeStore.
 boolean canOptimize()
          Returns true if the current provider is capable of optimization.
 boolean closeCollection(String cid)
          Close an existing XNodeCollection cid.
 void closeDatabase(XNodeCollection collection)
          Close the XNodeCollection's database.
 void connect(String root, String driver, int timeout)
          Make a database connection to the XNodeCollection root and establish service, using timeout as the maximum number of seconds to wait for the collection manager to open before abandoning.
 void copyXNode(String scid, String snid, String dcid, String dnid, boolean move, boolean overwrite)
          Copy the XNode with ID snid from Collection scid to XNode nid in the Collection ID cid.
 void copyXNode(XNodeID xids, XNodeID xidd, boolean move, boolean overwrite)
          Copy the XNode with XNodeID xids to XNodeID xidd.
 XNodeCollection createCollection(String cid, boolean overwrite)
          Create (or recreate, if it already exists) an XNodeCollection identified by cid.
 XNode createRevision(String cid, String nid)
          Creates a revision of the specified XNode, storing it internal to the XNode.
 XNode createRevision(XNode xnode)
          Creates a revision of the provided XNode, storing it internal to the XNode.
 XNode createRevision(XNodeID xid)
          Creates a revision of the specified XNode, storing it internal to the XNode.
 XNode createXNode(String nid, Node node)
          Returns an XNode provided a DOM Node node.
 void deleteCollection(String cid)
          Delete an existing XML database XNodeCollection cid.
protected  void deleteContent(String did, String rid)
          Essential access to org.purl.xnode.XNodeProvider#deleteContent(String,String).
 void deleteXNode(String cid, String nid)
          Delete the XNode identified by ID nid from the XNodeCollection cid.
 void deleteXNode(XNodeID xid)
          Delete the XNode identified by the XNodeID xid.
 void disconnect()
          Disconnect any connection to the root XNodeCollection and close down all services.
protected  void fireXNodeStoreEvent(XNodeState state, String cid, String nid)
          Notify all listeners having a registered interest in change events occurring in this XNodeStore.
 Clock getClock()
          Returns the Clock used to provide timestamps.
 XNodeCollection getCollection(String cid)
          Load and return an existing XML database XNodeCollection cid, returning null if a matching XNodeCollection does not exist.
 List getCollectionIndex()
          Returns a List view of the collection index, as provided by the root collection.
 String getCollectionMetadata(String cid, String name)
          Return the value of the XNodeCollection metadata property name for the XNodeCollection whose ID is cid, null if it has not been set.
protected  String getContent(String did, String rid)
          Essential access to org.purl.xnode.XNodeProvider#getContent(String,String).
 int getContentSize(String did, String rid)
          Essential access to org.purl.xnode.XNodeProvider#getContentSize(String,String).
 String getDatabaseURI(String cid, String nid)
          Returns a URI-like String representing the Collection ID cid and Node ID id using the currently available database (if DB services are unavailable, returns null).
 String getDatabaseURI(XNodeID xid)
          Returns a URI-like String representing the XNodeID xid using using the currently available database (if DB services are unavailable, returns null).
 List getIndex(String cid)
          Return a List containing the index of XNode IDs within the XNodeCollection cid.
 MessageHandler getMessageHandler()
          Returns the MessageHandler used by this XNodeStore.
 XNodeRevisionManager getRevisionManager()
          Returns the XNodeRevisionManager for this XNodeStore, null if revision control is not active or supported.
 XNodeCollection getRootCollection()
          Returns the lazily-created root XNodeCollection.
 String getRootURI()
          Return the URL of the root XNodeCollection as a String.
 XNodeState getState()
          Returns the state of this XNodeStore.
 float getStorageRatio()
          Non-essential access to BerkeleyDBProvider.getStorageRatio().
 Document getTextDocument()
          Returns a blank Document containing a <xnode:Text> Element wrapping an empty CDATA section.
 XMLProcessor getXMLProcessor()
          Returns the XMLProcessor used by this XNodeStore.
 XNode getXNode(String cid, String nid)
          Retrieves an XNode with ID nid from XNodeCollection with ID cid, or null if unable to retrieve.
 XNode getXNode(XNodeID xid)
          Retrieves an XNode specified via the XNodeID xid, or null if unable to retrieve.
 XNodeCollectionFactory getXNodeCollectionFactory()
          Returns a lazily-instantiated XNodeCollectionFactory.
 Node getXNodeContent(XNode xnode)
          Returns the DOM Node node envelope provided an XNode.
 Node getXNodeContent(XNodeID xid)
          Returns the DOM Node node envelope provided an XNodeID.
 XNodeFactory getXNodeFactory()
          Returns a lazily-instantiated XNodeFactory.
 XNodeStoreChangeCache getXNodeStoreChangeCache()
          Returns the XNodeStore's change cache if available.
 Set getXNodeStoreListeners()
          Return a Set containing the XNodeStoreListeners of the XNodeStore.
 boolean hasCollection(String cid)
          Returns true if there is a record of an XNodeCollection ID matching cid and the XNodeCollection object exists in the root cache.
 boolean hasCollectionID(String cid)
          Returns true if there is a record of an XNodeCollection ID matching cid in the metadata of the root collection.
 boolean hasXNode(String cid, String nid)
          Returns true if an XNode with ID nid from XNodeCollection with ID cid exists, false if not.
 boolean hasXNode(XNodeID xid)
          Returns true if an XNode matching the XNodeID xid exists, false if not.
 boolean isConnected()
          Returns true if the database is running and its service is available.
 boolean isReadOnly()
          Returns true if the database is in a read only state.
 boolean isRevisionControlActive()
          Returns true if the revision control features are active.
 XNode modifyXNode(String cid, String nid, Node node)
          Modify an XNode with ID nid in the XNodeCollection cid, replacing its content with the DOM Node node, returning the modified XNode.
 XNode modifyXNode(String cid, String nid, String content)
          Modify an XNode with ID nid in XNodeCollection cid, replacing its contents with the contents of the String content, returning the modified XNode.
 XNode modifyXNode(XNodeID xid, Node node)
          Modify an XNode with XNodeID xid, replacing its content with the DOM Node node, returning the modified XNode.
 void optimize(ActionListener listener)
          Non-essential access to BerkeleyDBProvider.optimize(ActionListener).
 XNode recreateXNode(Node node)
          Returns an XNode provided a DOM Node node, assuming the provided node's content is a serialization of an XNode (some minor validation will necessarily occur).
 void removeXNodeStoreListener(XNodeStoreListener listener)
          Removes listener from the XNodeStore.
 void setCachingEnabled(boolean enabled)
          Sets the document caching features on or off.
 void setCollectionMetadata(String cid, String name, String value)
          Set a metadata property of XNodeCollection metadata (a name-value pair) for the XNodeCollection whose ID is cid.
protected  void setProperties()
          Called upon instantiation of the class, this method establishes the XNodeStore properties.
 void setReadOnly(boolean readOnly)
          Sets the database to a read only state when the parameter is true.
 void setRevisionControlEnabled(boolean enabled)
          Sets the revision control features on or off.
 void setState(XNodeState state)
          Sets the state of this XNodeStore to the XNodeState state.
 void setXNodeMetadata(XNode xnode, Document doc, Map metadata)
          Sets various XNode metadata based upon application and Document information, including content type and the DOCTYPE declaration's name and identifiers.
 void setXNodeMetadata(XNode xnode, Document doc, String title, String systemId, String source, String mimetype)
          Sets a subset of the XNode metadata based upon application and Document information, including content type and the DOCTYPE declaration's name and identifiers.
 void setXNodeProperties(XNode xnode, Map properties)
          For an XNode with ID nid in XNodeCollection cid, set the named properties provided by the key-value pairs found in the Map properties.
 void setXNodeProperty(XNode xnode, String name, String value)
          For an XNode with ID nid in XNodeCollection cid, set the named property name whose value is the String value.
 void start()
          Start the database service.
 void stop()
          Shuts down the database service.
 boolean touch(String cid, XNode xnode)
          Touches (updates the modification date of) the XNode xnode in the XNodeCollection cid and if the XNode exists, sets the state to XNode.NODE_MODIFY.
 String toURI(XNodeID xid)
          Returns a URI representation of the XNodeID xid based on the root database URI, eg., ""xnode://db/cid/nid".
 XNode writeXNode(String cid, XNode xnode)
          Write the XNode xnode to the XNodeCollection cid.
protected  void writeXNodeToDatabase(XNode xnode, XNodeCollection collection, boolean overwrite)
          Essential access to org.purl.xnode.XNodeProvider#writeXNodeToDatabase(XNode,XNodeCollection,boolean).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XNODESTORE_PROVIDER

public static final String XNODESTORE_PROVIDER
The System property name for the XNodeStoreProvider implementation class name. The value is "xnode.database.provider".

See Also:
Constant Field Values

PROPERTY_XNODESTORE_PROVIDER

public static final String PROPERTY_XNODESTORE_PROVIDER
The XNode property name for the XNodeStoreProvider implementation class name. This is the property name for XNODESTORE_PROVIDER prefixed with Ceryle's property base URI Constants.CERYLE_PROP. The value is "http://purl.org/ceryle/prop/#xnode.database.provider".

See Also:
Constant Field Values

DEFAULT_XNODESTORE_PROVIDER

public static final String DEFAULT_XNODESTORE_PROVIDER
The class name of the default implementation for the XNodeStoreProvider. The value is "FileSystemProvider".

See Also:
Constant Field Values

XNODE_HOME_DIRECTORY

public static final String XNODE_HOME_DIRECTORY
The System property name for the XNode application installation directory. The value is "xnode.home.directory".

See Also:
Constant Field Values

DATABASE_STORAGE

public static final String DATABASE_STORAGE
The System property name for the XNode database storage path. The value is "xnode.database.storage".

See Also:
Constant Field Values

USE_CHANGE_CACHE

public static final String USE_CHANGE_CACHE
The System property name for the XNode database use change cache flag. The value is "xnode.database.use.change.cache".

See Also:
Constant Field Values

USE_CACHE

public static final String USE_CACHE
The System property name for the XNode database use cache flag. The value is "xnode.database.use.cache".

See Also:
Constant Field Values

READ_ONLY

public static final String READ_ONLY
The System property name for the XNode database read only flag. The value is "xnode.database.read.only".

See Also:
Constant Field Values

USE_REVISION_CONTROL

public static final String USE_REVISION_CONTROL
The System property name for the XNode database use revision control flag. The value is "xnode.database.use.revision.control".

See Also:
Constant Field Values

SAFE_OVERWRITE_MODE

public static final String SAFE_OVERWRITE_MODE
The System property name for the XNode database safe overwrite mode. This is a "true" or "false" property value that controls whether or not there should be an identity check on overwriting existing documents with writeXNode(). The default (when not set) is false. The value is "xnode-database-safe-overwrite-mode". Note that if set true this will disable the ability to perform overwrites without first deleting an existing XNode. The value is "xnode.database.safe.overwrite.mode".

See Also:
Constant Field Values

privateCollectionName

public static final String privateCollectionName
The String constant used as the name of the private (Ceryle) Collection ("_private").

See Also:
Constant Field Values

XNODE_DEFAULT_STORAGE

public static final String XNODE_DEFAULT_STORAGE
The default value for the Ceryle database storage path. The value is "resource/storage" (with an OS-dependent file separator).


ENCODING

public static final String ENCODING
The character encoding used by all Database content ("UTF-8").

See Also:
Constant Field Values

m_rootURI

protected static String m_rootURI
A String containing the URL of the default root collection.

Constructor Detail

XNodeStoreImpl

public XNodeStoreImpl(MessageHandler messagehandler,
                      XMLProcessor xmlprocessor)
               throws XNodeException
Constructor provided with a MessageHandler and a well-formed XML Processor.

Parameters:
messagehandler - provides message services.
xmlprocessor - provides XML parsing/processing services.
Throws:
XNodeException - if unable to instantiate the class.
Method Detail

setProperties

protected void setProperties()
                      throws XNodeException
Called upon instantiation of the class, this method establishes the XNodeStore properties.

Throws:
XNodeException - if the database directory doesn't exist or can't be read.

getXNodeStoreChangeCache

public XNodeStoreChangeCache getXNodeStoreChangeCache()
Returns the XNodeStore's change cache if available. If inactive, returns null.

This is not an XNode API method.


start

public void start()
           throws XNodeException
Start the database service. If already started, this has no effect.

Specified by:
start in interface XNodeStore
Throws:
XNodeException - if unable to open the database.

stop

public void stop()
          throws XNodeException
Shuts down the database service. If already stopped, this has no effect. This actually calls the provider, which closes the collections down prior to safely closing the backing storage.

Specified by:
stop in interface XNodeStore
Throws:
XNodeException - if an error occurs while stopping the database.

getCollectionIndex

public List getCollectionIndex()
                        throws XNodeException
Returns a List view of the collection index, as provided by the root collection. Like the method in the XNodeCollection API, this returns an empty list rather than null. This should probably return an Iterator, as modifying the List mucks up the database, so don't modify it. Just don't.

Specified by:
getCollectionIndex in interface XNodeStore
Returns:
a List containing all available XNodeCollection IDs.
Throws:
XNodeException - if unable to provide the List.

hasCollection

public boolean hasCollection(String cid)
Returns true if there is a record of an XNodeCollection ID matching cid and the XNodeCollection object exists in the root cache.

IMPORTANT: This is an indication of the existence of the XNodeCollection in the root collection cache, not simply its ID occurring in the index (which is the answer returned from getCollectionIndex().

Specified by:
hasCollection in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
Returns:
true if the XNodeCollection matching ID 'cid' exists.
Since:
XNode 1.2

hasCollectionID

public boolean hasCollectionID(String cid)
Returns true if there is a record of an XNodeCollection ID matching cid in the metadata of the root collection. This does not mean that the XNodeCollection or its corresponding Database have been creating/loaded.

This is not an XNode API method.

Parameters:
cid - the XNodeCollection ID String.
Returns:
true if the XNodeCollection ID matching 'cid' exists.
Since:
XNode 1.2

setCachingEnabled

public void setCachingEnabled(boolean enabled)
Sets the document caching features on or off.


setRevisionControlEnabled

public void setRevisionControlEnabled(boolean enabled)
Sets the revision control features on or off.


isRevisionControlActive

public boolean isRevisionControlActive()
Returns true if the revision control features are active.

(This is an XNode API method)

Specified by:
isRevisionControlActive in interface XNodeStore

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the database to a read only state when the parameter is true.


isReadOnly

public boolean isReadOnly()
Returns true if the database is in a read only state.


getXNodeFactory

public XNodeFactory getXNodeFactory()
Returns a lazily-instantiated XNodeFactory.

Specified by:
getXNodeFactory in interface XNodeStore

getXNodeCollectionFactory

public XNodeCollectionFactory getXNodeCollectionFactory()
Returns a lazily-instantiated XNodeCollectionFactory.

Specified by:
getXNodeCollectionFactory in interface XNodeStore

isConnected

public boolean isConnected()
Returns true if the database is running and its service is available.

(This is an XNode API method)

Specified by:
isConnected in interface XNodeStore
Returns:
true if the database is running.

getRootCollection

public XNodeCollection getRootCollection()
                                  throws XNodeException
Returns the lazily-created root XNodeCollection.

(This is an XNode API method)

Specified by:
getRootCollection in interface XNodeStore
Returns:
the root database XNodeCollection.
Throws:
XNodeException
Since:
XNode 1.0

createCollection

public XNodeCollection createCollection(String cid,
                                        boolean overwrite)
                                 throws XNodeException
Create (or recreate, if it already exists) an XNodeCollection identified by cid.

(This is an XNode API method)

Specified by:
createCollection in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
overwrite - when true allows overwriting of an existing XNodeCollection.
Returns:
the new XNodeCollection
Throws:
XNodeException - if unable to create the XNodeCollection

getCollection

public XNodeCollection getCollection(String cid)
                              throws XNodeException
Load and return an existing XML database XNodeCollection cid, returning null if a matching XNodeCollection does not exist.

(This is an XNode API method)

Specified by:
getCollection in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
Returns:
the XNodeCollection matching ID 'cid'.
Throws:
XNodeException - if unable to locate the XNodeCollection

getIndex

public List getIndex(String cid)
              throws XNodeException
Return a List containing the index of XNode IDs within the XNodeCollection cid. This returns an empty List rather than null if the collection is empty.

(This is an XNode API method)

Specified by:
getIndex in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
Returns:
an Iterator containing the IDs of all XNodes in the XNodeCollection.
Throws:
XNodeException - if the XNodeCollection ID is invalid or the XNodeCollection(s) did not exist.

closeCollection

public boolean closeCollection(String cid)
                        throws XNodeException
Close an existing XNodeCollection cid. If the value is XNodeState.ALL_COLLECTIONS, will close all open XNodeCollections.

(This is an XNode API method)

Specified by:
closeCollection in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
Returns:
true if the XNodeCollection was successfully closed.
Throws:
XNodeException - if the XNodeCollection ID is invalid or the XNodeCollection(s) did not exist.
See Also:
XNodeState

closeDatabase

public void closeDatabase(XNodeCollection collection)
                   throws XNodeException
Close the XNodeCollection's database. Once done, access to the Database content is unavailable.

This is not an XNode API method.

Throws:
XNodeException - if an error occurs during closing of the Database.

deleteCollection

public void deleteCollection(String cid)
                      throws XNodeException
Delete an existing XML database XNodeCollection cid. If the ID value is ALL_COLLECTIONS, will delete all existing XNodeCollections.

(This is an XNode API method)

Specified by:
deleteCollection in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
Throws:
XNodeException - if the XNodeCollection ID is invalid, the XNodeCollection(s) did not exist, or an error occurred.

setCollectionMetadata

public void setCollectionMetadata(String cid,
                                  String name,
                                  String value)
                           throws XNodeException
Set a metadata property of XNodeCollection metadata (a name-value pair) for the XNodeCollection whose ID is cid. This writes the result to the underlying Database.

Specified by:
setCollectionMetadata in interface XNodeStore
Throws:
XNodeException

getCollectionMetadata

public String getCollectionMetadata(String cid,
                                    String name)
                             throws XNodeException
Return the value of the XNodeCollection metadata property name for the XNodeCollection whose ID is cid, null if it has not been set.

Specified by:
getCollectionMetadata in interface XNodeStore
Throws:
XNodeException

hasXNode

public boolean hasXNode(XNodeID xid)
Returns true if an XNode matching the XNodeID xid exists, false if not.

(This is an XNode API method)

Specified by:
hasXNode in interface XNodeStore
Parameters:
xid - the XNodeID.
Returns:
true if the XNode exists.

hasXNode

public boolean hasXNode(String cid,
                        String nid)
                 throws XNodeException
Returns true if an XNode with ID nid from XNodeCollection with ID cid exists, false if not.

(This is an XNode API method)

Specified by:
hasXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the XNode ID String.
Returns:
true if the XNode exists.
Throws:
XNodeException - if either ID is invalid.

getXNode

public XNode getXNode(String cid,
                      String nid)
               throws XNodeException
Retrieves an XNode with ID nid from XNodeCollection with ID cid, or null if unable to retrieve.

(This is an XNode API method)

Specified by:
getXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the XNode ID String.
Returns:
the retrieved XNode.
Throws:
XNodeException - if the XNodeCollection is unavailable or either ID is invalid.

getXNode

public XNode getXNode(XNodeID xid)
               throws XNodeException
Retrieves an XNode specified via the XNodeID xid, or null if unable to retrieve.

(This is an XNode API method)

Specified by:
getXNode in interface XNodeStore
Parameters:
xid - the XNodeID.
Returns:
the retrieved XNode.
Throws:
XNodeException - if an error occurs retrieving the XNodeCollection or XNode.

getXNodeContent

public Node getXNodeContent(XNodeID xid)
                     throws XNodeException
Returns the DOM Node node envelope provided an XNodeID. This is a convenience method, passing off the work to the XNodeFactory.

This is not an XNode API method.

Parameters:
xid - the XNodeID of the XNode to be processed
Returns:
the created DOM node.
Throws:
XNodeException - if an error occurs during recreation.

getXNodeContent

public Node getXNodeContent(XNode xnode)
                     throws XNodeException
Returns the DOM Node node envelope provided an XNode. This is a convenience method, passing off the work to the XNodeFactory.

(This is an XNode API method)

Specified by:
getXNodeContent in interface XNodeStore
Parameters:
xnode - the XNode to be processed
Returns:
the created DOM node.
Throws:
XNodeException - if an error occurs during recreation.

addXNode

public XNode addXNode(String cid,
                      String nid,
                      String content)
               throws XNodeException
Insert a new XNode with ID nid whose content is the String content, into the XNodeCollection with ID cid.

Note: This method implies that the supplied content String be well-formed XML, as it will by necessity be parsed into a DOM Node. This is a convenience class for those unwilling to parse their own content, the downside being that if the content is not well-formed, an exception is thrown and nothing gets stored. Of course, if the content isn't well-formed, it has to be fixed anyway (unless one wants to store it as text/plain by wrapping it in a CDATA section).

(This is an XNode API method)

Specified by:
addXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the ID String of the stored XNode.
content - the String content to be parsed into a DOM Node.
Returns:
the new XNode.
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.

addXNode

public XNode addXNode(String cid,
                      String nid,
                      Node node)
               throws XNodeException
Insert a new XNode with ID nid and DOM Node node content into the XNodeCollection with ID cid.

(This is an XNode API method)

Specified by:
addXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the ID String for the stored XNode.
node - the DOM Node content.
Returns:
the new XNode.
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.

modifyXNode

public XNode modifyXNode(String cid,
                         String nid,
                         String content)
                  throws XNodeException
Modify an XNode with ID nid in XNodeCollection cid, replacing its contents with the contents of the String content, returning the modified XNode.

(This is an XNode API method)

Specified by:
modifyXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the ID String of the stored XNode.
content - the String content to be parsed into a DOM Node.
Returns:
the modified XNode.
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.

modifyXNode

public XNode modifyXNode(String cid,
                         String nid,
                         Node node)
                  throws XNodeException
Modify an XNode with ID nid in the XNodeCollection cid, replacing its content with the DOM Node node, returning the modified XNode.

(This is an XNode API method)

Specified by:
modifyXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the ID String for the stored XNode.
node - the new DOM Node content.
Returns:
the modified XNode
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.

modifyXNode

public XNode modifyXNode(XNodeID xid,
                         Node node)
                  throws XNodeException
Modify an XNode with XNodeID xid, replacing its content with the DOM Node node, returning the modified XNode.

(This is an XNode API method)

Specified by:
modifyXNode in interface XNodeStore
Parameters:
xid - the XNode identifier.
node - the new DOM Node content.
Returns:
the modified XNode
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.

getClock

public Clock getClock()
Returns the Clock used to provide timestamps.

This is not an XNode API method.


writeXNode

public XNode writeXNode(String cid,
                        XNode xnode)
                 throws XNodeException
Write the XNode xnode to the XNodeCollection cid. This locates any existing XNode by ID and replaces it with the provided one. Use with discretion — this is generally meant to rewrite a modified XNode, not write an entirely new XNode. For performance reasons no checking of this identity is done.

Note:

This method is generally used to set metadata on an existing XNode, so document-level metadata (e.g., creation or modification timestamps) are not altered by this method — this just writes the XNode to the XNodeCollection.

(This is an XNode API method)

Specified by:
writeXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String
xnode - the XNode to be written.
Returns:
the stored XNode.
Throws:
XNodeException - if unable to add the XNode to the XNodeCollection.
Since:
XNode 1.0

getContentSize

public int getContentSize(String did,
                          String rid)
Essential access to org.purl.xnode.XNodeProvider#getContentSize(String,String).


getContent

protected String getContent(String did,
                            String rid)
                     throws XNodeException
Essential access to org.purl.xnode.XNodeProvider#getContent(String,String).

Throws:
XNodeException

deleteContent

protected void deleteContent(String did,
                             String rid)
                      throws XNodeException
Essential access to org.purl.xnode.XNodeProvider#deleteContent(String,String).

Throws:
XNodeException

writeXNodeToDatabase

protected void writeXNodeToDatabase(XNode xnode,
                                    XNodeCollection collection,
                                    boolean overwrite)
                             throws XNodeException
Essential access to org.purl.xnode.XNodeProvider#writeXNodeToDatabase(XNode,XNodeCollection,boolean).

Throws:
XNodeException

getStorageRatio

public float getStorageRatio()
Non-essential access to BerkeleyDBProvider.getStorageRatio(). This is currently considered a temporary method.


optimize

public void optimize(ActionListener listener)
Non-essential access to BerkeleyDBProvider.optimize(ActionListener). This is currently considered a temporary method.


canOptimize

public boolean canOptimize()
Returns true if the current provider is capable of optimization.


touch

public boolean touch(String cid,
                     XNode xnode)
              throws XNodeException
Touches (updates the modification date of) the XNode xnode in the XNodeCollection cid and if the XNode exists, sets the state to XNode.NODE_MODIFY. This does not write to the database.

NOTE: this is a temporary method.

This is not an XNode API method.

Parameters:
cid - the XNodeCollection ID String
xnode - the XNode to be added
Returns:
true if touched (i.e., the XNode existed)
Throws:
XNodeException - if unable to touch the XNode.

createXNode

public XNode createXNode(String nid,
                         Node node)
                  throws XNodeException
Returns an XNode provided a DOM Node node. Unlike recreateXNode(Node), the provided content does not include the XNode; it is the content meant to be enclosed in the envelope. The Node is optional; if not provided, an empty XNode is returned. The XNode is created but not written to the XNodeStore.

(This is an XNode API method)

Specified by:
createXNode in interface XNodeStore
Parameters:
node - the DOM Node to be used as the XNode source.
nid - the ID String of the stored XNode.
Returns:
the recreated XNode.
Throws:
XNodeException - if unable to recreate the XNode.

recreateXNode

public XNode recreateXNode(Node node)
                    throws XNodeException
Returns an XNode provided a DOM Node node, assuming the provided node's content is a serialization of an XNode (some minor validation will necessarily occur). The XNode is recreated but not written to the XNodeStore.

This is not an XNode API method.

Parameters:
node - the DOM Node to be used as the XNode source.
Returns:
the recreated XNode.
Throws:
XNodeException - if unable to recreate the XNode.

deleteXNode

public void deleteXNode(String cid,
                        String nid)
                 throws XNodeException
Delete the XNode identified by ID nid from the XNodeCollection cid.

(This is an XNode API method)

Specified by:
deleteXNode in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the XNode ID String.
Throws:
XNodeException - if the XNodeCollection is unavailable, either ID is invalid, or otherwise unable to delete.

deleteXNode

public void deleteXNode(XNodeID xid)
                 throws XNodeException
Delete the XNode identified by the XNodeID xid.

(This is an XNode API method)

Specified by:
deleteXNode in interface XNodeStore
Parameters:
xid - the XNodeID identifier for the XNode.
Throws:
XNodeException - if the XNode does not exist or otherwise unable to delete.

setXNodeProperty

public void setXNodeProperty(XNode xnode,
                             String name,
                             String value)
                      throws XNodeException
For an XNode with ID nid in XNodeCollection cid, set the named property name whose value is the String value.

Note: this only modifies the property of the supplied XNode and does not involve any transactions with the database, which must be performed separately.

(This is an XNode API method)

Specified by:
setXNodeProperty in interface XNodeStore
Parameters:
xnode - the XNode to which the property is to be set.
name - the name of the property.
value - the value of the property.
Throws:
XNodeException - if the XNode does not exist or the property is invalid.

setXNodeProperties

public void setXNodeProperties(XNode xnode,
                               Map properties)
                        throws XNodeException
For an XNode with ID nid in XNodeCollection cid, set the named properties provided by the key-value pairs found in the Map properties. This is to provide some efficiency over setting properties individually, which absent caching would require an XNode retrieval for each operation. This does not remove any existing properties, only write the provided ones to the XNode. Any of the named properties in the provided Map will overwrite any existing property with the same name. A null value will clear the property.

This also modifies the DOM Elements for these properties.

Note: this only modifies the properties of the supplied XNode and does not involve any transactions with the database, which must be performed separately.

(This is an XNode API method)

Specified by:
setXNodeProperties in interface XNodeStore
Parameters:
xnode - the XNode to which the properties are to be set.
properties - the Map containing the properties.
Throws:
XNodeException - if the XNode does not exist or any of the properties are invalid.

getRootURI

public String getRootURI()
Return the URL of the root XNodeCollection as a String.

(This is an XNode API method)

Specified by:
getRootURI in interface XNodeStore
Returns:
the URI of the root XNodeCollection.

getTextDocument

public Document getTextDocument()
Returns a blank Document containing a <xnode:Text> Element wrapping an empty CDATA section. This does not include the XNode wrapper, just the Text element.


getDatabaseURI

public String getDatabaseURI(XNodeID xid)
Returns a URI-like String representing the XNodeID xid using using the currently available database (if DB services are unavailable, returns null).

(This is an XNode API method)

Parameters:
xid - the XNodeID
Returns:
a URI (as a String).

getDatabaseURI

public String getDatabaseURI(String cid,
                             String nid)
Returns a URI-like String representing the Collection ID cid and Node ID id using the currently available database (if DB services are unavailable, returns null). If nid is null, a URI for the Collection alone is returned. If both cid and nid are null, null is returned.

(This is an XNode API method)

Specified by:
getDatabaseURI in interface XNodeStore
Parameters:
cid - the collection ID.
nid - the node ID.
Returns:
a URI (as a String).

toURI

public String toURI(XNodeID xid)
Returns a URI representation of the XNodeID xid based on the root database URI, eg., ""xnode://db/cid/nid".

(This is an XNode API method)

Specified by:
toURI in interface XNodeStore
Parameters:
xid - the XNodeID to convert to a URI.
Returns:
a URI (as a String).

setState

public void setState(XNodeState state)
Sets the state of this XNodeStore to the XNodeState state. Informs any listeners of this state change.

(This is an XNode API method)

Parameters:
state - an XNodeState indicating the processing state to be set.
See Also:
XNodeState

getState

public XNodeState getState()
Returns the state of this XNodeStore.

(This is an XNode API method)

Specified by:
getState in interface XNodeStore
Returns:
the current state of this XNodeStore
See Also:
XNodeState

setXNodeMetadata

public void setXNodeMetadata(XNode xnode,
                             Document doc,
                             String title,
                             String systemId,
                             String source,
                             String mimetype)
                      throws ProcessException
Sets a subset of the XNode metadata based upon application and Document information, including content type and the DOCTYPE declaration's name and identifiers. This is suitable for the creation of new nodes. Exception for xnode, all parameters are optional (no action is taken).

Three of the metadata fields are Dublin Core Metadata Terms: "title" (DC.title), "systemId" (DC.identifier), and "mimetype" (DC.format).

This is not an XNode API method.

Parameters:
xnode - the XNode in which the metadata is to be stored.
doc - the source document used to obtain DOCTYPE information
title - the optional title of the source document
systemId - the optional system identifier of the stored document
source - the optional system identifier of the source document
mimetype - the optional MIME content type of the document
Throws:
ProcessException - if an error occurs while setting metadata

setXNodeMetadata

public void setXNodeMetadata(XNode xnode,
                             Document doc,
                             Map metadata)
                      throws ProcessException
Sets various XNode metadata based upon application and Document information, including content type and the DOCTYPE declaration's name and identifiers. Exception for xnode, all parameters are optional (no action is taken).

This is not an XNode API method.

Parameters:
xnode - the XNode in which the metadata is to be stored.
doc - the source document used to obtain DOCTYPE information
metadata - a Map containing name-value pairs
Throws:
ProcessException - if an error occurs while setting metadata

getXNodeStoreListeners

public Set getXNodeStoreListeners()
Return a Set containing the XNodeStoreListeners of the XNodeStore. If there are no attached listeners, returns an empty Set rather than null.

This is not an XNode API method.

Returns:
the Set of XNodeStoreListeners.

addXNodeStoreListener

public void addXNodeStoreListener(XNodeStoreListener listener)
Adds listener as a listener for changes to the XNodeStore.

(This is an XNode API method)

Specified by:
addXNodeStoreListener in interface XNodeStore
Parameters:
listener - the XNodeStoreListener to be added
See Also:
XNodeStoreListener

removeXNodeStoreListener

public void removeXNodeStoreListener(XNodeStoreListener listener)
Removes listener from the XNodeStore.

(This is an XNode API method)

Specified by:
removeXNodeStoreListener in interface XNodeStore
Parameters:
listener - the XNodeStoreListener to be removed
See Also:
XNodeStoreListener

fireXNodeStoreEvent

protected void fireXNodeStoreEvent(XNodeState state,
                                   String cid,
                                   String nid)
Notify all listeners having a registered interest in change events occurring in this XNodeStore.


getRevisionManager

public XNodeRevisionManager getRevisionManager()
Returns the XNodeRevisionManager for this XNodeStore, null if revision control is not active or supported.

Specified by:
getRevisionManager in interface XNodeStore
Since:
XNode 1.2

createRevision

public XNode createRevision(String cid,
                            String nid)
                     throws XNodeException
Creates a revision of the specified XNode, storing it internal to the XNode. This does not write to the database. If revision control is inactive, this acts identically to getXNode(String,String).

Specified by:
createRevision in interface XNodeStore
Parameters:
cid - the XNodeCollection ID String.
nid - the XNode ID String.
Returns:
the modified XNode.
Throws:
XNodeException - if an error occurs in creating the revision.
Since:
XNode 1.2

createRevision

public XNode createRevision(XNodeID xid)
                     throws XNodeException
Creates a revision of the specified XNode, storing it internal to the XNode. This does not write to the database. Note that if revision control is not active, this will return the XNode, but unmodified.

Specified by:
createRevision in interface XNodeStore
Parameters:
xid - the XNodeID specifying the XNode.
Returns:
the modified XNode.
Throws:
XNodeException - if an error occurs in creating the revision.
Since:
XNode 1.2

createRevision

public XNode createRevision(XNode xnode)
                     throws XNodeException
Creates a revision of the provided XNode, storing it internal to the XNode. This does not write to the database. Note that if revision control is not active, this will return the XNode, but unmodified.

Specified by:
createRevision in interface XNodeStore
Parameters:
xnode - the XNode to process.
Returns:
the modified XNode.
Throws:
XNodeException - if an error occurs in creating the revision.
Since:
XNode 1.2

copyXNode

public void copyXNode(String scid,
                      String snid,
                      String dcid,
                      String dnid,
                      boolean move,
                      boolean overwrite)
               throws XNodeException
Copy the XNode with ID snid from Collection scid to XNode nid in the Collection ID cid. If move is true, will delete the source XNode once the copy has completed. If overwrite is false, an attempt to overwrite will not succeed (registering an error).

Specified by:
copyXNode in interface XNodeStore
Parameters:
scid - the source Collection ID.
snid - the source XNode ID.
dcid - the destination Collection ID.
dnid - the destination XNode ID.
move - when true, deletes the source XNode
overwrite - when true, will overwrite any existing dcid/dnid
Throws:
XNodeException - if the copy/move is not successful.

copyXNode

public void copyXNode(XNodeID xids,
                      XNodeID xidd,
                      boolean move,
                      boolean overwrite)
               throws XNodeException
Copy the XNode with XNodeID xids to XNodeID xidd. If move is true, will delete the source XNode once the copy has completed. If overwrite is false, an attempt to overwrite will not succeed (registering an error).

Specified by:
copyXNode in interface XNodeStore
Parameters:
xids - the source XNodeID.
xidd - the destination XNodeID.
move - when true, deletes the source XNode.
overwrite - when true, will overwrite any existing XNode.
Throws:
XNodeException - if the copy/move is not successful.

getMessageHandler

public MessageHandler getMessageHandler()
Returns the MessageHandler used by this XNodeStore.


getXMLProcessor

public XMLProcessor getXMLProcessor()
Returns the XMLProcessor used by this XNodeStore.


connect

public void connect(String root,
                    String driver,
                    int timeout)
             throws XNodeException
Make a database connection to the XNodeCollection root and establish service, using timeout as the maximum number of seconds to wait for the collection manager to open before abandoning.

(This is an XNode API method)

This method is unimplemented due to this not being a client-server database, throwing an UnsupportedOperationException.

Specified by:
connect in interface XNodeStore
Parameters:
root - the URI of the root XNodeCollection.
driver - the driver identifier for the database provider
timeout - time in seconds to wait before abandoning.
Throws:
XNodeException - if unable to make the connection.

disconnect

public void disconnect()
                throws XNodeException
Disconnect any connection to the root XNodeCollection and close down all services.

(This is an XNode API method)

This method is unimplemented due to this not being a client-server database, throwing an UnsupportedOperationException.

Specified by:
disconnect in interface XNodeStore
Throws:
XNodeException - if an error occurs during this process.


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.