Package org.jibx.extras
Class DomMapperBase
- java.lang.Object
-
- org.jibx.extras.DocumentModelMapperBase
-
- org.jibx.extras.DomMapperBase
-
- Direct Known Subclasses:
DomElementMapper,DomFragmentMapper,DomListMapper
public class DomMapperBase extends DocumentModelMapperBase
Base implementation for custom marshaller/unmarshallers to DOM representation. This provides the basic code used for both single element and content list handling.
- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_defaultNamespaceIndexCurrent default namespace index.protected java.lang.Stringm_defaultNamespaceURICurrent default namespace URI (nullif not determined).protected org.w3c.dom.Documentm_documentActual document instance (required by DOM).-
Fields inherited from class org.jibx.extras.DocumentModelMapperBase
m_unmarshalContext, m_xmlWriter, XML_NAMESPACE, XMLNS_NAMESPACE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDomMapperBase()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddNamespace(java.lang.String prefix, java.lang.String uri, java.util.ArrayList nss)Add namespace information to list.private voidaddNamespaceUnique(java.lang.String prefix, java.lang.String uri, java.util.ArrayList nss)Add namespace information to list if not already present.private intfindNamespaceIndex(java.lang.String prefix, java.lang.String uri)Get index number for declared namespace.private booleanisEquivalent(java.lang.String a, java.lang.String b)Check if a pair of strings are equivalent, meaning either equal or one empty and the othernull.protected voidmarshalContent(org.w3c.dom.NodeList content)Marshal node list.protected voidmarshalElement(org.w3c.dom.Element element)Marshal element with all attributes and content.protected voidmarshalNode(org.w3c.dom.Node node)Marshal node.protected voidunmarshalContent(org.w3c.dom.Node parent)Unmarshal node content.protected org.w3c.dom.ElementunmarshalElement()Unmarshal element with all attributes and content.protected org.w3c.dom.NodeunmarshalNode()Unmarshal single node.-
Methods inherited from class org.jibx.extras.DocumentModelMapperBase
accumulateText, getNamespaceUri, getNextNamespaceIndex, isWhitespace
-
-
-
-
Field Detail
-
m_document
protected org.w3c.dom.Document m_document
Actual document instance (required by DOM).
-
m_defaultNamespaceURI
protected java.lang.String m_defaultNamespaceURI
Current default namespace URI (nullif not determined).
-
m_defaultNamespaceIndex
protected int m_defaultNamespaceIndex
Current default namespace index.
-
-
Constructor Detail
-
DomMapperBase
protected DomMapperBase() throws JiBXExceptionConstructor. Initializes the document used by this marshaller/unmarshaller instance as the owner of all DOM components.- Throws:
JiBXException- on error creating document
-
-
Method Detail
-
findNamespaceIndex
private int findNamespaceIndex(java.lang.String prefix, java.lang.String uri)Get index number for declared namespace.- Parameters:
prefix- namespace prefix (nullif none)uri- namespace URI (empty string if none)- Returns:
- namespace index number, or
-1if not declared or masked
-
marshalNode
protected void marshalNode(org.w3c.dom.Node node) throws JiBXException, java.io.IOExceptionMarshal node.- Parameters:
node- node to be marshalled- Throws:
JiBXException- on error in marshallingjava.io.IOException- on error writing to output
-
marshalContent
protected void marshalContent(org.w3c.dom.NodeList content) throws JiBXException, java.io.IOExceptionMarshal node list.- Parameters:
content- list of nodes to marshal- Throws:
JiBXException- on error in marshallingjava.io.IOException- on error writing to output
-
addNamespace
private void addNamespace(java.lang.String prefix, java.lang.String uri, java.util.ArrayList nss)Add namespace information to list.- Parameters:
prefix-uri-nss-
-
isEquivalent
private boolean isEquivalent(java.lang.String a, java.lang.String b)Check if a pair of strings are equivalent, meaning either equal or one empty and the othernull.- Parameters:
a- non-nullvalueb- comparison value (may benull)- Returns:
trueif equivalent,falseif not
-
addNamespaceUnique
private void addNamespaceUnique(java.lang.String prefix, java.lang.String uri, java.util.ArrayList nss)Add namespace information to list if not already present.- Parameters:
prefix-uri-nss-
-
marshalElement
protected void marshalElement(org.w3c.dom.Element element) throws JiBXException, java.io.IOExceptionMarshal element with all attributes and content.- Parameters:
element- element to be marshalled- Throws:
JiBXException- on error in marshallingjava.io.IOException- on error writing to output
-
unmarshalNode
protected org.w3c.dom.Node unmarshalNode() throws JiBXException, java.io.IOExceptionUnmarshal single node. This unmarshals the next node from the input stream, up to the close tag of the containing element.- Returns:
- unmarshalled node
- Throws:
JiBXException- on error in unmarshallingjava.io.IOException- on error reading input
-
unmarshalContent
protected void unmarshalContent(org.w3c.dom.Node parent) throws JiBXException, java.io.IOExceptionUnmarshal node content. This unmarshals everything up to the containing element close tag, adding each component to the content list supplied. On return, the parse position will always be at an END_TAG.- Parameters:
parent- node to which children are to be added- Throws:
JiBXException- on error in unmarshallingjava.io.IOException- on error reading input
-
unmarshalElement
protected org.w3c.dom.Element unmarshalElement() throws JiBXException, java.io.IOExceptionUnmarshal element with all attributes and content. This must be called with the unmarshalling context positioned at a START_TAG event.- Returns:
- unmarshalled element
- Throws:
JiBXException- on error in unmarshallingjava.io.IOException- on error reading input
-
-