org.ceryle.xnode
Class XNodeFactoryImpl

java.lang.Object
  extended by org.ceryle.xnode.XNodeFactoryImpl
All Implemented Interfaces:
XNodeFactory
Direct Known Subclasses:
XNodeCollectionFactoryImpl

public class XNodeFactoryImpl
extends Object
implements XNodeFactory

Provides an implementation of the XNodeFactory API as a factory for creating XNode objects.

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.

Since:
JDK1.3
Version:
$Id: XNodeFactoryImpl.java,v 3.14 2007-06-15 12:10:31 altheim Exp $
Author:
Murray Altheim

Field Summary
protected  XNodeStore m_xns
           
protected  String MARKUP_1
           
protected  String MARKUP_2
           
static String TEXT_NODE
          A String used as a base document element for text-based XNodes.
static String XNODE_TEXT_TAGNAME
          The String "xnode:Text".
protected  XMLProcessor xp
           
 
Constructor Summary
XNodeFactoryImpl(XNodeStore xnodestore, XMLProcessor xmlprocessor)
          A constructor for a XNodeFactoryImpl, provided with an optional XMLProcessor.
 
Method Summary
 XNode createXNode(String id)
          Returns a new, empty XNode, provided a String ID id.
 XNode createXNode(String id, Node node)
          Return an XNode provided a String id and a DOM Node node.
 Document getTextDocument()
          Generates a blank Document containing a <xnode:Text> Element wrapping an empty CDATA section.
 Node getXNodeContent(XNode xnode, boolean includeEnvelope)
          Returns a DOM node representation of the provided XNode, including the XNode envelope if includeEnvelope is true.
protected  Document getXNodeEnvelope(String id, String created, String modified)
          Returns an empty XNode XML DOM Document.
 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).
 XNode recreateXNode(String content)
          Returns an XNode provided a String containing its content, assuming the provided content is a serialization of an XNode.
 String serializeXNode(XNode xnode, boolean includeEnvelope)
          Provided with an XNode xnode, returns an XML serialization as a String.
 boolean serializeXNode(XNode xnode, Writer writer, boolean includeEnvelope)
          Writes an XML serialization of the XNode xnode to the supplied Writer writer.
protected  void setMetadataFromHeader(XNode xnode, Element header)
          Provided with an XNode (generally during re-creation), sets its metadata by parsing the content of the xnode:Header DOM Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_xns

protected XNodeStore m_xns

xp

protected XMLProcessor xp

TEXT_NODE

public static final String TEXT_NODE
A String used as a base document element for text-based XNodes. In XNode 1.2 documents, this <xnode:Text> node should have a single CDATASection child node as a container for all non-XML content.
    <xnode:Text xmlns:xnode="http://purl.org/xnode/1.2"/> 
  


XNODE_TEXT_TAGNAME

public static final String XNODE_TEXT_TAGNAME
The String "xnode:Text".


MARKUP_1

protected final String MARKUP_1

MARKUP_2

protected final String MARKUP_2
Constructor Detail

XNodeFactoryImpl

public XNodeFactoryImpl(XNodeStore xnodestore,
                        XMLProcessor xmlprocessor)
                 throws XNodeException
A constructor for a XNodeFactoryImpl, provided with an optional XMLProcessor.

Parameters:
xnodestore - the XNodeStore supporting the database.
xmlprocessor - an optional XMLProcessor instance.
Throws:
XNodeException - if the XML processor or XNode factory cannot be established.
Method Detail

getXNodeEnvelope

protected Document getXNodeEnvelope(String id,
                                    String created,
                                    String modified)
                             throws XNodeException
Returns an empty XNode XML DOM Document. The xnode:Envelope's xnode:id attribute, xnode:created, and xnode:modified attributes are included, the latter being optional.

(this is not an XNode API method)

Parameters:
id - the XNode unique identifier
created - the XNode creation timestamp
modified - the XNode modification timestamp (optional)
Returns:
a DOM Document object
Throws:
XNodeException

createXNode

public XNode createXNode(String id)
                  throws XNodeException
Returns a new, empty XNode, provided a String ID id.

(this is an XNode API method)

Specified by:
createXNode in interface XNodeFactory
Parameters:
id - the XNode unique identifier
Returns:
an XNode whose ID is 'id'
Throws:
XNodeException - if an error occurs during creation

createXNode

public XNode createXNode(String id,
                         Node node)
                  throws XNodeException
Return an XNode provided a String id and a DOM Node node. If node is null, this method will act exactly as createXNode(String), i.e., provide an empty XNode.

Note that this contains an additional non-API feature, whereby if the incoming Node is an <xnode:Text> Element (which is one way content is provided in normally) but contains a bogus xnode:created attribute, it will be treated as a carrier for the XNode's 'created' property and subsequently removed from the DOM Element. This is the only way a new XNode's 'created' property can be set when the XNode envelope itself is not provided.

(this is an XNode API method)

Specified by:
createXNode in interface XNodeFactory
Parameters:
id - the XNode ID.
node - the DOM Node to be enclosed in the XNode.
Returns:
the created XNode.
Throws:
XNodeException - if an error occurs during creation.

recreateXNode

public XNode recreateXNode(String content)
                    throws XNodeException
Returns an XNode provided a String containing its content, assuming the provided content is a serialization of an XNode.

(this is not an XNode API method)

Parameters:
content - the String to be processed as XNode content.
Returns:
the recreated XNode.
Throws:
XNodeException - if an error occurs during recreation.

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). This method will also return a recreated XNodeCollection, if the supplied Node uses an <xnode:Collection> element rather than a <xnode:Body>.

(this is an XNode API method)

Specified by:
recreateXNode in interface XNodeFactory
Parameters:
node - the DOM Node to be processed as XNode content.
Returns:
the recreated XNode.
Throws:
XNodeException - if an error occurs during recreation.

setMetadataFromHeader

protected void setMetadataFromHeader(XNode xnode,
                                     Element header)
                              throws XNodeException
Provided with an XNode (generally during re-creation), sets its metadata by parsing the content of the xnode:Header DOM Element. Note that the XNode is assumed to already contain its ID, which is on the xnode:Envelope Element.

This permits either <Property> or <xnode:Property> for the property element tag name (in the interest of being easy with what we accept, backwards-compatibility-wise).

(this is not an XNode API method)

Parameters:
xnode - the XNode to populate with metadata
header - the DOM Element (an xnode:Header) containing metadata.
Throws:
XNodeException - if an error occurs during the process.

getTextDocument

public Document getTextDocument()
Generates a blank Document containing a <xnode:Text> Element wrapping an empty CDATA section.


getXNodeContent

public Node getXNodeContent(XNode xnode,
                            boolean includeEnvelope)
                     throws XNodeException
Returns a DOM node representation of the provided XNode, including the XNode envelope if includeEnvelope is true.

(this is an XNode API method)

Specified by:
getXNodeContent in interface XNodeFactory
Parameters:
xnode - the XNode to be processed.
includeEnvelope - if true, include the xnode:Envelope.
Returns:
a DOM Document representation of the XNode.
Throws:
XNodeException - if an error occurs during processing.

serializeXNode

public boolean serializeXNode(XNode xnode,
                              Writer writer,
                              boolean includeEnvelope)
                       throws XNodeException
Writes an XML serialization of the XNode xnode to the supplied Writer writer. If includeEnvelope is true, the <xnode:Envelope> will be included.

(this is an XNode API method)

Specified by:
serializeXNode in interface XNodeFactory
Parameters:
xnode - the XNode to be serialized
writer - the Writer receiving the output
includeEnvelope - if true, include the xnode:Envelope
Returns:
true if successful
Throws:
XNodeException - if an error occurs during serialization

serializeXNode

public String serializeXNode(XNode xnode,
                             boolean includeEnvelope)
                      throws XNodeException
Provided with an XNode xnode, returns an XML serialization as a String. If includeEnvelope is true, the xnode:Envelope will be included.

(this is an XNode API method)

Specified by:
serializeXNode in interface XNodeFactory
Parameters:
xnode - the XNode to be serialized.
includeEnvelope - if true, include the xnode:Envelope.
Returns:
the String representation of the XNode.
Throws:
XNodeException - if an error occurs during serialization.


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