org.ceryle.xnode
Class XNodeImpl

java.lang.Object
  extended by org.purl.xnode.XNode
      extended by org.ceryle.xnode.XNodeImpl
Direct Known Subclasses:
XNodeCollectionImpl

public class XNodeImpl
extends XNode

An implementation of the XNode API, which acts as a container for XML content by providing an envelope element and metadata attributes such as a node ID, a creation timestamp, etc. XNode extensions included here use a Ceryle PSI identifier whose base is http://purl.org/ceryle/xnode/ (see PROPERTY_EXTENSION).

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:
XNode 1.0
Version:
$Id: XNodeImpl.java,v 3.10 2007-06-20 01:28:41 altheim Exp $
Author:
Murray Altheim
See Also:
XNode

Field Summary
protected  Node m_content
           
protected  Document m_document
           
static boolean PERMIT_XML_CONTENT
          When true, permit arbitrary XML as XNode content rather than restricting it to <xnode:Text> or <xnode:Collection> elements.
static String PFX_ATTR_created
          A String containing the attribute name "xnode:created".
static String PFX_ATTR_modified
          A String containing the attribute name "xnode:modified".
static String PFX_ATTR_xmlns
          A String containing "xmlns:xnode".
static String PFX_ELT_link
          A String containing the element name "xnode:Link".
static String PFX_ELT_property
          A String containing the element name "xnode:Property".
static boolean PRESERVE_WS
          When true, XNode content will preemptively add an xml:space="preserve" attribute to the document element so that whitespace will be preserved for later serialization.
static String PROPERTY_DOCTYPE_NAME
          A String containing the name of the XNode document type name property, an XNode extension to store the document root name, i.e., the string following the "DOCTYPE" of the DOCTYPE declaration of the source document.
static String PROPERTY_EXTENSION
          Base URI for Ceryle XNode implementation metadata extensions.
static String PROPERTY_PUBLIC_ID
          A String containing the name of the XNode public ID property, an XNode extension to store the PUBLIC identifier of the DOCTYPE declaration of the source document.
static String PROPERTY_SYSTEM_ID
          A String containing the name of the XNode system ID property, an XNode extension to store the SYSTEM identifier of the DOCTYPE declaration of the source document.
static boolean VALUE_STORED_AS_ATTRIBUTE
          When true, XNode properties are stored as attribute values.
 
Fields inherited from class org.purl.xnode.XNode
ATTR_created, ATTR_id, ATTR_index, ATTR_modified, ATTR_name, ATTR_size, ATTR_value, ATTR_version, ATTR_weight, ELT_body, ELT_collection, ELT_envelope, ELT_header, ELT_link, ELT_property, ELT_repository, ELT_revision, ELT_text, VERSION_10, VERSION_11, VERSION_12, VERSION_13, XMLNS_base, XMLNS_pfx, XMLNS_xnode, XMLNS_xnode10, XMLNS_xnode11, XMLNS_xnode12, XMLNS_xnode13
 
Constructor Summary
protected XNodeImpl(String id, String created, Node node)
          Constructor with a required String ID id, required creation timestamp created, and an XML DOM Node node.
 
Method Summary
 Element getBodyElement()
          Returns a DOM Element representation of this XNode's body, or null if unavailable.
 Node getContent()
          Returns a DOM Node representation of this XNode's content.
 String getCreated()
          Returns the creation date of this XNode as a String.
 Document getDocument()
           
 Element getEnvelopeElement()
          Returns a DOM Element representation of this XNode's envelope.
 Element getHeaderElement()
          Returns a DOM Element representation of this XNode's header.
 String getID()
          Returns the ID of this XNode.
 String getModified()
          Returns the modification date of this XNode as a String, null if has not been set.
 Set getProperties()
          Returns a Set containing the named properties of this XNode (as Strings), an empty Set (not null) if none have been set.
 Object getProperty(String name)
          Returns the named property name of this XNode as a Object, null if it has not been set.
 List getRepository()
          Returns the List backing this XNode's repository (i.e., the List of individual XNodeRevision objects).
protected  Element getRepositoryElement()
          Returns the DOM Element representation of this XNode's repository.
 boolean hasRepository()
          Returns true if the repository for this XNode has been generated.
 void modifyContent(Node node)
          Modifies the content of this XNode to the DOM Node node.
 void setContent(Node node)
          Sets the content of this XNode to the Node node (which can be a DOM Document or Element node), throwing an XNodeException if the content is already set.
 void setCreated(String timestamp)
          Sets the creation date of this XNode to the String timestamp.
 void setID(String id)
          Sets the ID of this XNode to the String id, throwing an XNodeException if the value is not an XML Name.
 void setModified(String timestamp)
          Sets the modification date of this XNode to the String timestamp.
 void setProperty(String name, Object value)
          Sets the named property name of this XNode to the Object value.
 String toString()
          Returns a String representation of this XNode, including the XNode markup envelope.
 String toString(boolean includeEnvelope)
          Returns a String representation of this XNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_EXTENSION

public static final String PROPERTY_EXTENSION
Base URI for Ceryle XNode implementation metadata extensions.

Value: http://purl.org/ceryle/xnode/

See Also:
Constant Field Values

PROPERTY_PUBLIC_ID

public static String PROPERTY_PUBLIC_ID
A String containing the name of the XNode public ID property, an XNode extension to store the PUBLIC identifier of the DOCTYPE declaration of the source document. This is generally in the form of a Formal Public Identifier (FPI).

Property name: http://purl.org/ceryle/xnode/publicId


PROPERTY_SYSTEM_ID

public static String PROPERTY_SYSTEM_ID
A String containing the name of the XNode system ID property, an XNode extension to store the SYSTEM identifier of the DOCTYPE declaration of the source document. This is generally in the form of a URI.

Property name: http://purl.org/ceryle/xnode/systemId


PROPERTY_DOCTYPE_NAME

public static String PROPERTY_DOCTYPE_NAME
A String containing the name of the XNode document type name property, an XNode extension to store the document root name, i.e., the string following the "DOCTYPE" of the DOCTYPE declaration of the source document. This indicates the tag name of the document root element.

Property name: http://purl.org/ceryle/xnode/doctypeName


PRESERVE_WS

public static final boolean PRESERVE_WS
When true, XNode content will preemptively add an xml:space="preserve" attribute to the document element so that whitespace will be preserved for later serialization. Default is false.

See Also:
Constant Field Values

VALUE_STORED_AS_ATTRIBUTE

public static final boolean VALUE_STORED_AS_ATTRIBUTE
When true, XNode properties are stored as attribute values. When false, the value is stored as element content. Default is false.

See Also:
Constant Field Values

PERMIT_XML_CONTENT

public static final boolean PERMIT_XML_CONTENT
When true, permit arbitrary XML as XNode content rather than restricting it to <xnode:Text> or <xnode:Collection> elements. Default is true.

See Also:
Constant Field Values

PFX_ATTR_xmlns

public static final String PFX_ATTR_xmlns
A String containing "xmlns:xnode".


PFX_ELT_property

public static final String PFX_ELT_property
A String containing the element name "xnode:Property".


PFX_ELT_link

public static final String PFX_ELT_link
A String containing the element name "xnode:Link".

Since:
XNode 1.3

PFX_ATTR_created

public static final String PFX_ATTR_created
A String containing the attribute name "xnode:created".


PFX_ATTR_modified

public static final String PFX_ATTR_modified
A String containing the attribute name "xnode:modified".


m_document

protected Document m_document

m_content

protected Node m_content
Constructor Detail

XNodeImpl

protected XNodeImpl(String id,
                    String created,
                    Node node)
             throws XNodeException
Constructor with a required String ID id, required creation timestamp created, and an XML DOM Node node. Note that the provided Node should include the XNode envelope.

Throws:
XNodeException
Method Detail

setID

public void setID(String id)
           throws XNodeException
Sets the ID of this XNode to the String id, throwing an XNodeException if the value is not an XML Name.

Overrides:
setID in class XNode
Parameters:
id - the XNode ID.
Throws:
XNodeException - if not an XML Name.

getID

public String getID()
Returns the ID of this XNode.

Overrides:
getID in class XNode
Returns:
the XNode ID.

setContent

public void setContent(Node node)
                throws XNodeException
Sets the content of this XNode to the Node node (which can be a DOM Document or Element node), throwing an XNodeException if the content is already set.

Specified by:
setContent in class XNode
Parameters:
node - the Node to set as the content of this XNode.
Throws:
XNodeException - if there is existing content.

getDocument

public Document getDocument()

getContent

public Node getContent()
                throws XNodeException
Returns a DOM Node representation of this XNode's content.

Specified by:
getContent in class XNode
Returns:
the DOM Node containing this XNode's content.
Throws:
XNodeException

modifyContent

public void modifyContent(Node node)
                   throws XNodeException
Modifies the content of this XNode to the DOM Node node. Note that this does allow the content to be set to null.

Specified by:
modifyContent in class XNode
Parameters:
node - the Node to set as the content of this XNode.
Throws:
XNodeException - if any problem occurs during modification.

getEnvelopeElement

public Element getEnvelopeElement()
                           throws XNodeException
Returns a DOM Element representation of this XNode's envelope.

This is not an API method.

Throws:
XNodeException

getHeaderElement

public Element getHeaderElement()
                         throws XNodeException
Returns a DOM Element representation of this XNode's header.

This is not an API method.

Throws:
XNodeException

getBodyElement

public Element getBodyElement()
                       throws XNodeException
Returns a DOM Element representation of this XNode's body, or null if unavailable.

This is not an API method.

Throws:
XNodeException

getRepositoryElement

protected Element getRepositoryElement()
                                throws XNodeException
Returns the DOM Element representation of this XNode's repository.

This is not an API method.

Throws:
XNodeException

hasRepository

public boolean hasRepository()
Returns true if the repository for this XNode has been generated. (This just permits the List to be lazily generated.)

This is not an XNode API method.


getRepository

public List getRepository()
                   throws XNodeException
Returns the List backing this XNode's repository (i.e., the List of individual XNodeRevision objects). This will return an empty List rather than null if there are no revisions. Note that while creation of the List is the responsibility of the XNode, its population and management is handled entirely by the XNodeRevisionManager.

This is an XNode API method.

Specified by:
getRepository in class XNode
Throws:
XNodeException

setCreated

public void setCreated(String timestamp)
                throws XNodeException
Sets the creation date of this XNode to the String timestamp. In this implementation, calls to this method will throw an XNodeException, as the creation date is set at the time of construction.

Specified by:
setCreated in class XNode
Parameters:
timestamp - the creation timestamp as a String.
Throws:
XNodeException - if already set or an error occurs (such as the timestamp being in an unrecognizable format).

getCreated

public String getCreated()
Returns the creation date of this XNode as a String.

Specified by:
getCreated in class XNode
Returns:
the creation date of this XNode.

setModified

public void setModified(String timestamp)
                 throws XNodeException
Sets the modification date of this XNode to the String timestamp.

Specified by:
setModified in class XNode
Parameters:
timestamp - the modification timestamp as a String.
Throws:
XNodeException - if an error occurs (such as the timestamp being in an unrecognizable format).

getModified

public String getModified()
Returns the modification date of this XNode as a String, null if has not been set.

Specified by:
getModified in class XNode
Returns:
the modification date of this XNode, null if not set.

setProperty

public void setProperty(String name,
                        Object value)
                 throws XNodeException,
                        NullPointerException
Sets the named property name of this XNode to the Object value. If the property has already been set, its value is replaced. If the property has been set and the provided value is null, the named property is removed.

Note: This is the extension mechanism for XNode, storing each property as a <xnode:Property> child element of the <xnode:Header> element.

Note that this method currently only supports String and List (of XNodeLinks) property values.

Specified by:
setProperty in class XNode
Parameters:
name - the property name.
value - the property value, a String or DOM Node.
Throws:
XNodeException - if the property value is invalid.
NullPointerException - if either name or value parameter is null.

getProperty

public Object getProperty(String name)
Returns the named property name of this XNode as a Object, null if it has not been set. The value returned will be either a String or a DOM Node.

Specified by:
getProperty in class XNode
Parameters:
name - the property name.
Returns:
the property value, null if not set.

getProperties

public Set getProperties()
Returns a Set containing the named properties of this XNode (as Strings), an empty Set (not null) if none have been set.

Specified by:
getProperties in class XNode
Returns:
the Set of named properties (as Strings).

toString

public String toString()
Returns a String representation of this XNode, including the XNode markup envelope. If the XNode's content is null or empty, this returns an empty String.

Unimplemented.

Specified by:
toString in class XNode
Returns:
a String representation of this XNode.

toString

public String toString(boolean includeEnvelope)
Returns a String representation of this XNode. If the boolean includeEnvelope is true, the output will include the XNode markup envelope.

Unimplemented. This current just returns some basic information about the XNode, faked as a single XML element.

Specified by:
toString in class XNode
Returns:
a String representation of this XNode.


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