XML for Java Compatibility API 2.0.11

com.ibm.xml.parser
Class MakeDigestVisitor

java.lang.Object
  |
  +--com.ibm.xml.parser.NOOPVisitor
        |
        +--com.ibm.xml.parser.MakeDigestVisitor

public class MakeDigestVisitor
extends NOOPVisitor
implements Visitor

MakeDigestVisitor implements the Visitor interface in the visitor design pattern for the purpose of calculating and storing a digest on the various DOM- and XML4J-defined Nodes as the document object tree is traversed. Digests are calculated usng the message digest passed on the constructor.

Digests can be made for the following Node types:

The following sample code uses the MakeDigestVisitor on a hierarchy of nodes:


 MakeDigestVisitor makeDigestVisitor = new MakeDigestVisitor(this.getFactory().createMessageDigest());
 new NonRecursivePreorderTreeTraversal(makeDigestVisitor).traverse(this);

 

Version:
Revision: 75 1.6 src/com/ibm/xml/parser/MakeDigestVisitor.java, parser, xml4j2, xml4j2_0_11
See Also:
Visitor, NOOPVisitor, TreeTraversal, NonRecursivePreorderTreeTraversal

Field Summary
protected  java.security.MessageDigest messageDigest
           
 
Constructor Summary
MakeDigestVisitor(java.security.MessageDigest messageDigest)
          Constructor.
 
Method Summary
static java.lang.String getExpandedName(org.w3c.dom.Node node)
           
 void visitAttributePre(TXAttribute attribute)
          Calculates and sets a digest for the specified attribute.
 void visitCommentPre(TXComment comment)
          Calculates and sets a digest for the specified comment.
 void visitElementPost(TXElement element)
          Calculates and sets a digest for the specified element.
 void visitElementPre(TXElement element)
          If the specified element already has a calculated digest, throw an exception to avoid unnecessary traversal of children.
 void visitGeneralReferencePre(GeneralReference generalReference)
          Do nothing.
 void visitPIPre(TXPI pi)
          Calculates and sets a digest for the specified pi.
 void visitTextPre(TXText text)
          Calculates and sets a digest for the specified text.
 
Methods inherited from class com.ibm.xml.parser.NOOPVisitor
visitAttDefPost, visitAttDefPre, visitAttlistPost, visitAttlistPre, visitAttributePost, visitCommentPost, visitDocumentFragmentPost, visitDocumentFragmentPre, visitDocumentPost, visitDocumentPre, visitDTDPost, visitDTDPre, visitElementDeclPost, visitElementDeclPre, visitEntityDeclPost, visitEntityDeclPre, visitGeneralReferencePost, visitNotationPost, visitNotationPre, visitPIPost, visitPseudoNodePost, visitPseudoNodePre, visitTextPost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageDigest

protected java.security.MessageDigest messageDigest
Constructor Detail

MakeDigestVisitor

public MakeDigestVisitor(java.security.MessageDigest messageDigest)
Constructor.
Parameters:
messageDigest - Message digest instance to use when visitting.
See Also:
TXDocument.createMessageDigest()
Method Detail

visitElementPre

public void visitElementPre(TXElement element)
                     throws java.lang.Exception
If the specified element already has a calculated digest, throw an exception to avoid unnecessary traversal of children.
Specified by:
visitElementPre in interface Visitor
Parameters:
element - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node already has a digest.
Overrides:
visitElementPre in class NOOPVisitor
See Also:
TXElement, visitElementPost(com.ibm.xml.parser.TXElement)

visitElementPost

public void visitElementPost(TXElement element)
                      throws java.lang.Exception
Calculates and sets a digest for the specified element.

A digest of a TXElement Node consists of its:

Specified by:
visitElementPost in interface Visitor
Parameters:
element - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of a problem in calculating the digest. Often, this is because the message digest specified on the constructor is invalid, the JVM does not support UnicodeBigUnmarked encoding, or the JVM does not have the required security providers for the message digest.
Overrides:
visitElementPost in class NOOPVisitor
See Also:
TXElement, visitElementPre(com.ibm.xml.parser.TXElement)

visitAttributePre

public void visitAttributePre(TXAttribute attribute)
                       throws java.lang.Exception
Calculates and sets a digest for the specified attribute.

A digest of a TXAttribute Node consists of its Node type, its name, and its value.

Note that TXAttribute Nodes are not parsed into the document object hierarchy by the XML4J parser; attributes exist as part of a TXElement Node.

Specified by:
visitAttributePre in interface Visitor
Parameters:
attribute - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of a problem in calculating the digest. Often, this is because the message digest specified on the constructor is invalid, the JVM does not support UnicodeBigUnmarked encoding, or the JVM does not have the required security providers for the message digest.
Overrides:
visitAttributePre in class NOOPVisitor
See Also:
TXAttribute

visitPIPre

public void visitPIPre(TXPI pi)
                throws java.lang.Exception
Calculates and sets a digest for the specified pi.

A digest of a TXPI Node consists of its Node type, its name, and its data.

Specified by:
visitPIPre in interface Visitor
Parameters:
pi - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of a problem in calculating the digest. Often, this is because the message digest specified on the constructor is invalid, the JVM does not support UnicodeBigUnmarked encoding, or the JVM does not have the required security providers for the message digest.
Overrides:
visitPIPre in class NOOPVisitor
See Also:
TXPI

visitCommentPre

public void visitCommentPre(TXComment comment)
                     throws java.lang.Exception
Calculates and sets a digest for the specified comment.

A digest of a TXComment Node consists of its Node type and its data.

Specified by:
visitCommentPre in interface Visitor
Parameters:
comment - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of a problem in calculating the digest. Often, this is because the message digest specified on the constructor is invalid, the JVM does not support UnicodeBigUnmarked encoding, or the JVM does not have the required security providers for the message digest.
Overrides:
visitCommentPre in class NOOPVisitor
See Also:
TXComment

visitTextPre

public void visitTextPre(TXText text)
                  throws java.lang.Exception
Calculates and sets a digest for the specified text.

A digest of a TXText Node consists of its Node type and its data.

Specified by:
visitTextPre in interface Visitor
Parameters:
text - Node to calculate and set a digest.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of a problem in calculating the digest. Often, this is because the message digest specified on the constructor is invalid, the JVM does not support UnicodeBigUnmarked encoding, or the JVM does not have the required security providers for the message digest.
Overrides:
visitTextPre in class NOOPVisitor
See Also:
TXText

visitGeneralReferencePre

public void visitGeneralReferencePre(GeneralReference generalReference)
                              throws java.lang.Exception
Do nothing.
Specified by:
visitGeneralReferencePre in interface Visitor
Overrides:
visitGeneralReferencePre in class NOOPVisitor

getExpandedName

public static java.lang.String getExpandedName(org.w3c.dom.Node node)

XML for Java Compatibility API 2.0.11