Version: ${maven.project.version}

org.soaplab.services.metadata
Class TagTracer

java.lang.Object
  extended by org.soaplab.services.metadata.TagTracer

public class TagTracer
extends java.lang.Object

The class represents a stack of visited tags when parsing an XML source. It helps when the same named tags appear in various parts of the parsed source.

One can push() (at the beginning of every DocumentHandler.startElement()) and pop() (at the end of each DocumentHandler.endElement()) and thus keep track of the currently processed tag and its path.

The TagTracer can also show the whole path, or just compare if a given tag path is a current one.

Here is an example how to use it:

    TagTracer tt;

    private static final String[] ANALYSIS_PATH = new String[] { "DsLSRAnalysis", "analysis" };
    private static final String[] EXT_PATH      = UUtils.join (ANALYSIS_PATH, new String[] { "analysis_extension" });
    private static final String[] APP_INFO_PATH = UUtils.join (EXT_PATH,      new String[] { "app_info" });
    private static final String[] EVENT_PATH    = UUtils.join (EXT_PATH,      new String[] { "event" });
    ...

    public void startElement (String name, AttributeList attrs) {
        tt.push (name);

    if (tt.is (ANALYSIS_PATH)) {
            // do something for "analysis"
            // ...
        }

    public void endElement (String name) {
        // ...
        tt.pop();
    }

Version:
$Id: TagTracer.java,v 1.1.1.1 2006/11/03 09:15:01 marsenger Exp $
Author:
Martin Senger

Field Summary
static java.lang.String VERSION
          Version and date of last update of this class.
 
Constructor Summary
TagTracer()
          A default constructor.
 
Method Summary
 java.lang.String[] getPath()
          Gets contents of the whole stack.
 boolean is(java.lang.String[] tagPath)
          Compares the contents of the current stack with the given list of tag names.
 java.lang.String peek()
          Looks at the tag name at the top of this stack without removing it from the stack.
 java.lang.String pop()
          Removes the tag name from the top of this stack and returns it.
 void push(java.lang.String name)
          Pushes a tag name onto the top of this stack.
 void reset()
          Removes all elements fom the stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Version and date of last update of this class.

See Also:
Constant Field Values
Constructor Detail

TagTracer

public TagTracer()
A default constructor.

Method Detail

push

public void push(java.lang.String name)
Pushes a tag name onto the top of this stack.

Parameters:
name - a tag name (usually of the currently visited tag) to be put on the stact

pop

public java.lang.String pop()
Removes the tag name from the top of this stack and returns it.

Returns:
the removed tag name
Throws:
EmptyStackException - if there is no element on the stack

peek

public java.lang.String peek()
Looks at the tag name at the top of this stack without removing it from the stack.

Returns:
the currently last tag name on the stac
Throws:
EmptyStackException - if there is no element on the stack

is

public boolean is(java.lang.String[] tagPath)
Compares the contents of the current stack with the given list of tag names.

TBD: to allow '*' in tagPath> to represents 'anything' - even more elements in a sequence (but then again - I do not want to simulate here the whole XPath :-) )

Parameters:
tagPath - a list of tag names to be compared with the contents of the stack
Returns:
true if the contents of the current stack is the same as the given tagPath.

getPath

public java.lang.String[] getPath()
Gets contents of the whole stack.

Returns:
list of all tag names currently being in the stack

reset

public void reset()
Removes all elements fom the stack.


Version: ${maven.project.version}

Submit a bug or feature
Generated: Tue Jun 14 15:18:14 AST 2011