org.jscience.ml.cml.cmlimpl
Class CMLBaseImpl

java.lang.Object
  extended by org.jscience.ml.cml.dom.pmr.PMRNodeImpl
      extended by org.jscience.ml.cml.dom.pmr.PMRElementImpl
          extended by org.jscience.ml.cml.cmlimpl.CMLBaseImpl
All Implemented Interfaces:
AbstractBase, CMLNode, org.w3c.dom.Element, org.w3c.dom.Node

public class CMLBaseImpl
extends PMRElementImpl
implements AbstractBase

The base class for all elementObjects mentioned in the Schema

Any CML element may have attributes:titleiddictRefconvention and convenience get/set methods are provided for allAn element (FOO) subclassed from a AbstractBase may be constructed in the following ways:FOO(). Creates a new empty element with null values of the attributes. Required for newInstance(), but use carefully since it has no tagName and no document associated with it.FOO(String tagName, CMLDocument document). Creates an empty element with null attribute names.FOO(org.w3c.dom.Element element). Creates a subclassed Element with the same attribute values as the input Element. Used when a DOM has been created with non-CML-aware software. The routine makeAndProcessSubclass(Element element) will replace the current Element with the appropriate CML subclass.FOO(String title, String id, String dictRef, String convention). Makes subclassed Element and sets attribute values.


Field Summary
protected  boolean arraySyntax
           
protected  boolean debug
           
protected  AbstractCMLDocument ownerDocument
           
protected  java.lang.String tagName
           
protected  BaseTool tool
           
protected  java.lang.String version
           
 
Fields inherited from class org.jscience.ml.cml.dom.pmr.PMRNodeImpl
childNodes, delegateNode, parentNode, pmrDocument, siblingNodes
 
Fields inherited from interface org.jscience.ml.cml.AbstractBase
CML1, CML2, CMLCDK, CONTENT_MODEL, CONVENTION, DICTREF, FLOAT_TYPE, ID, INTEGER_TYPE, NAMESPACE_URI, PACKAGE_NAME, REF, STRING_TYPE, TITLE, UNKNOWN
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Fields inherited from interface org.jscience.ml.cml.CMLNode
ARRAY
 
Constructor Summary
  CMLBaseImpl()
          create a Node WITHOUT tagName OR document Use with care
protected CMLBaseImpl(java.lang.String tagName, AbstractCMLDocument document)
          used when creating new nodes in a DOM
  CMLBaseImpl(java.lang.String tagName, org.w3c.dom.Document document)
           
 
Method Summary
 void addChild(org.w3c.dom.Element elem)
          content model

adds a child to the element content.

 void addTextChild(java.lang.String value)
          Deprecated. use setTextChild instead
 org.w3c.dom.Node appendChild(org.w3c.dom.Element elem)
          traps the addition of an child to the element content By default this will be routed to addChild() and org.w3c.dom.Node.appendChild(), but other element-specific stuff can be interposed (within the Cont
 void characters(SaxHandler saxHandler, java.lang.String content)
          SAX2 parsing routine called from characters() callback NOT namespace aware
static java.lang.String createToolClassName(AbstractBase abstractBase)
          constructs a class name for tool

at present converts some.where.bar.FooImpl to some.where.tool.FooToolImpl

protected  void debug(java.lang.String s)
          output string if debug set
 AbstractBase deepCopy()
          deep clones an element including subclassing.
 AbstractBase deepCopy(AbstractCMLDocument document)
          deep clones an element including subclassing

uses intermediate XML serialization object is owned by document

 void deleteChild(org.w3c.dom.Element elem)
          delete an element The element must have been previously created and present in the DOM
 void endElement(SaxHandler saxHandler)
          SAX2 parsing routine called from endElement() callback NOT namespace aware
 org.w3c.dom.Element[] getChildList(java.lang.String elementName)
          gets a (typed) list of child elements with a given name
 java.util.Vector getChildVector(java.lang.String elementName)
          gets a Vector of all child elements with this name
 java.lang.String getClassTagName()
           
 AbstractCMLDocument getCMLDocument()
          get owner document as CMLDocument.
 java.lang.String getContentValue()
          gets text content from an element should only be used for text-only or mixed content.
 boolean getDebug()
          debug status
 org.w3c.dom.Element getFirstChild(java.lang.String elementName)
          gets the first Child of a given type (by elementName) This method will normally be used when there is a single child of this type
 org.w3c.dom.Element getOrCreateChild(java.lang.String elemName)
          get a child of a given name If it doesn't exist, create and add it
 BaseTool getOrCreateTool()
          get or create tool.
 BaseTool getTool()
          get tool.
protected  void init()
           
static void outputChildren(org.w3c.dom.Element elem, java.io.Writer w, java.lang.String control)
           
 void removeTextChildren()
          removes whitespace nodes or throws any Exception for non-whitespace ones
 void setArraySyntax(boolean syntax)
          set array syntax

set CML array syntax (default false)

 void setAttribute(java.lang.String name, java.lang.String value)
          set attribute.
 void setContentValue(java.lang.String value)
          adds text content to an element should only be used for text-only or mixed content.
 void setDebug(boolean d)
          toggle debugging
 void setTextChild(java.lang.String value)
          addStringContent to Element

if no Text child, creates one if Text child, resets value if existing non-Text children, no action

 void setTool(BaseTool t)
          set tool

not user-callable

 void setVersion(java.lang.String v)
          set CML version

1 or 2 at present (default 2)

 void startElement(SaxHandler saxHandler, org.xml.sax.Attributes attributes)
          SAX2 parsing routine called from startElement() callback NOT namespace aware
 void updateDelegateAttributes()
          update delegate attributes.
 void updateDelegateContent()
          update delegate content.
 void updateDelegates()
          update delegates.
 void updateDOM()
          update DOM.
 void updateDOMAttributes()
          update DOM attributes.
 void updateDOMContent()
          update DOM content.
 void writeXML(java.io.Writer w)
          write XML use current control (version and syntax)
 void writeXML(java.io.Writer w, java.lang.String control)
          write XML (allows for syntactic variants)
static void writeXML0(org.w3c.dom.Element elem, java.io.Writer w, java.lang.String control)
           
 
Methods inherited from class org.jscience.ml.cml.dom.pmr.PMRElementImpl
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
 
Methods inherited from class org.jscience.ml.cml.dom.pmr.PMRNodeImpl
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getDelegateNode, getDelegateParentNode, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, removeChild, replaceChild, setDelegateNode, setNodeValue, setOwnerDocument, setOwnerDocumentRecursively, setPrefix, setTextContent, setUserData, toString, wrapRecursively
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jscience.ml.cml.AbstractBase
getAttribute
 
Methods inherited from interface org.w3c.dom.Element
getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Field Detail

version

protected java.lang.String version

arraySyntax

protected boolean arraySyntax

tool

protected BaseTool tool

debug

protected boolean debug

tagName

protected java.lang.String tagName

ownerDocument

protected AbstractCMLDocument ownerDocument
Constructor Detail

CMLBaseImpl

public CMLBaseImpl()
create a Node WITHOUT tagName OR document Use with care


CMLBaseImpl

protected CMLBaseImpl(java.lang.String tagName,
                      AbstractCMLDocument document)
used when creating new nodes in a DOM


CMLBaseImpl

public CMLBaseImpl(java.lang.String tagName,
                   org.w3c.dom.Document document)
Method Detail

init

protected void init()

getCMLDocument

public AbstractCMLDocument getCMLDocument()
Description copied from interface: AbstractBase
get owner document as CMLDocument.

Specified by:
getCMLDocument in interface AbstractBase
Returns:
the document

getClassTagName

public java.lang.String getClassTagName()

addChild

public void addChild(org.w3c.dom.Element elem)
              throws CMLException
content model

adds a child to the element content. The elementName is checked for validity (but not its position in the list of children). It will always be added at the end. Therefore when building a DOM the author must ensure that all elements are added in correct order or must validate after addition. The count will be taken from the sum of the allowed children. Thus foo, bar, foo* will allow the addition of 1 bar and many foos.

Parameters:
elem - the element to add (identified by elementName not class)
Throws:
CMLException - element cannot be added (violates content model)

deleteChild

public void deleteChild(org.w3c.dom.Element elem)
                 throws CMLException
delete an element The element must have been previously created and present in the DOM

Parameters:
elem - element to be deleted.
Throws:
CMLException - element would leave invalid content

getFirstChild

public org.w3c.dom.Element getFirstChild(java.lang.String elementName)
gets the first Child of a given type (by elementName) This method will normally be used when there is a single child of this type

Parameters:
elementName -
Returns:
null if no elements of this type

getChildVector

public java.util.Vector getChildVector(java.lang.String elementName)
gets a Vector of all child elements with this name

Parameters:
elementName -
Returns:
if no children an empty vector (not null) is returned

getChildList

public org.w3c.dom.Element[] getChildList(java.lang.String elementName)
gets a (typed) list of child elements with a given name

Parameters:
elementName -
Returns:
returns a zero length list if none found

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Element elem)
                             throws CMLException
traps the addition of an child to the element content By default this will be routed to addChild() and org.w3c.dom.Node.appendChild(), but other element-specific stuff can be interposed (within the Cont

Parameters:
elem - the element to add (identified by elementName not class)
Throws:
CMLException - element cannot be added (violates content model)

getOrCreateChild

public org.w3c.dom.Element getOrCreateChild(java.lang.String elemName)
                                     throws CMLException
get a child of a given name If it doesn't exist, create and add it

Specified by:
getOrCreateChild in interface AbstractBase
Parameters:
elemName - the elementName to get/create (identified by elementName not class)
Returns:
the Element
Throws:
CMLException - element cannot be added (violates content model)

setContentValue

public void setContentValue(java.lang.String value)
adds text content to an element should only be used for text-only or mixed content.

Specified by:
setContentValue in interface AbstractBase
Parameters:
value - the content
Throws:
CMLException - thrown by subclasses

getContentValue

public java.lang.String getContentValue()
gets text content from an element should only be used for text-only or mixed content.

Specified by:
getContentValue in interface AbstractBase
Returns:
value the content; "" if none
Throws:
CMLException - thrown by subclasses

removeTextChildren

public void removeTextChildren()
                        throws CMLException
removes whitespace nodes or throws any Exception for non-whitespace ones

Specified by:
removeTextChildren in interface AbstractBase
Throws:
CMLException - non-whitespace Text node

characters

public void characters(SaxHandler saxHandler,
                       java.lang.String content)
                throws CMLException
SAX2 parsing routine called from characters() callback NOT namespace aware

Specified by:
characters in interface AbstractBase
Parameters:
saxHandler - SaxHandler
content - throws exception (probably application specific)
Throws:
CMLException

endElement

public void endElement(SaxHandler saxHandler)
                throws CMLException
SAX2 parsing routine called from endElement() callback NOT namespace aware

Specified by:
endElement in interface AbstractBase
Parameters:
saxHandler - Saxhandler throws exception (probably application specific)
Throws:
CMLException

startElement

public void startElement(SaxHandler saxHandler,
                         org.xml.sax.Attributes attributes)
                  throws CMLException
SAX2 parsing routine called from startElement() callback NOT namespace aware

Specified by:
startElement in interface AbstractBase
Parameters:
saxHandler - Saxhandler
attributes - the attribute list throws exception (probably application specific)
Throws:
CMLException

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
set attribute. do not use. may be called by autogenerated code. reroutes calls to attribute "elementContent" to setTextChild

Specified by:
setAttribute in interface AbstractBase
Specified by:
setAttribute in interface org.w3c.dom.Element
Overrides:
setAttribute in class PMRElementImpl
Parameters:
name - The name of the attribute to create or alter.
value - Value to set in string form.

addTextChild

public void addTextChild(java.lang.String value)
Deprecated. use setTextChild instead

addStringContent to Element

if no Text child, creates one if Text child, resets value if existing non-Text children, no action

Parameters:
value - to add

setTextChild

public void setTextChild(java.lang.String value)
addStringContent to Element

if no Text child, creates one if Text child, resets value if existing non-Text children, no action

Specified by:
setTextChild in interface AbstractBase
Parameters:
value - to add

setDebug

public void setDebug(boolean d)
toggle debugging

Specified by:
setDebug in interface AbstractBase
Parameters:
d - debug

getDebug

public boolean getDebug()
debug status

Specified by:
getDebug in interface AbstractBase
Returns:
is debug set

debug

protected void debug(java.lang.String s)
output string if debug set

Parameters:
s - string to output

setVersion

public void setVersion(java.lang.String v)
                throws CMLException
set CML version

1 or 2 at present (default 2)

Specified by:
setVersion in interface CMLNode
Parameters:
v - version
Throws:
unsupported - version
CMLException

setArraySyntax

public void setArraySyntax(boolean syntax)
set array syntax

set CML array syntax (default false)

Specified by:
setArraySyntax in interface CMLNode
Parameters:
syntax -

writeXML

public void writeXML(java.io.Writer w,
                     java.lang.String control)
              throws CMLException,
                     java.io.IOException
write XML (allows for syntactic variants)

Specified by:
writeXML in interface CMLNode
Parameters:
control - - application specific string for example "CML1 array" or "CML2"
w - - output
Throws:
java.io.IOException
CMLException

writeXML

public void writeXML(java.io.Writer w)
              throws CMLException,
                     java.io.IOException
write XML use current control (version and syntax)

Specified by:
writeXML in interface AbstractBase
Specified by:
writeXML in interface CMLNode
Parameters:
w - - output
Throws:
CMLException
java.io.IOException

writeXML0

public static void writeXML0(org.w3c.dom.Element elem,
                             java.io.Writer w,
                             java.lang.String control)
                      throws java.io.IOException,
                             CMLException
Throws:
java.io.IOException
CMLException

outputChildren

public static void outputChildren(org.w3c.dom.Element elem,
                                  java.io.Writer w,
                                  java.lang.String control)
                           throws java.io.IOException,
                                  CMLException
Throws:
java.io.IOException
CMLException

deepCopy

public AbstractBase deepCopy()
deep clones an element including subclassing.

uses intermediate XML serialization object is owned by a new document all CML elements have correct subclass

Specified by:
deepCopy in interface AbstractBase
Returns:
the copied object

deepCopy

public AbstractBase deepCopy(AbstractCMLDocument document)
deep clones an element including subclassing

uses intermediate XML serialization object is owned by document

Specified by:
deepCopy in interface AbstractBase
Parameters:
document - ownerDocument
Returns:
the copied object

getTool

public BaseTool getTool()
get tool.

creates one if not already created do not use if subclass is known to compiler (use FooToolImpl.getTool(foo) instead)

Specified by:
getTool in interface AbstractBase
Returns:
the tool

getOrCreateTool

public BaseTool getOrCreateTool()
get or create tool.

creates one if not already created should only be used when the subclass is not known to the compiler i.e. where an abstractBase is found

Specified by:
getOrCreateTool in interface AbstractBase
Returns:
the tool

setTool

public void setTool(BaseTool t)
set tool

not user-callable

Specified by:
setTool in interface AbstractBase
Parameters:
t - tool

createToolClassName

public static java.lang.String createToolClassName(AbstractBase abstractBase)
constructs a class name for tool

at present converts some.where.bar.FooImpl to some.where.tool.FooToolImpl

Parameters:
abstractBase - class object
Returns:
class name

updateDelegates

public void updateDelegates()
update delegates. updates this delegates (content and attributes) then recurses through children

Specified by:
updateDelegates in interface AbstractBase

updateDOM

public void updateDOM()
update DOM. updates this DOM (content and attributes) then recurses through children

Specified by:
updateDOM in interface AbstractBase

updateDelegateContent

public void updateDelegateContent()
update delegate content.

Specified by:
updateDelegateContent in interface AbstractBase

updateDelegateAttributes

public void updateDelegateAttributes()
update delegate attributes.

Specified by:
updateDelegateAttributes in interface AbstractBase

updateDOMContent

public void updateDOMContent()
update DOM content.

Specified by:
updateDOMContent in interface AbstractBase

updateDOMAttributes

public void updateDOMAttributes()
update DOM attributes.

Specified by:
updateDOMAttributes in interface AbstractBase