001: /*
002: * @(#)DigestAction.java 1.2 04/12/06
003: *
004: * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * See the file "LICENSE.txt" for information on usage and redistribution
007: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008: */
009: package pnuts.xml;
010:
011: import org.xml.sax.*;
012: import java.util.*;
013:
014: /**
015: * A DigestAction is associated with a path pattern and defines an action that
016: * is invoked when a XML parser sees beginning/end of the XML elements that match the pattern.
017: *
018: * @see DigestHandler
019: */
020: public class DigestAction {
021:
022: protected DigestHandler handler;
023:
024: public DigestAction() {
025: }
026:
027: /**
028: * The method called when XML parser looks an element of the associated path starts.
029: *
030: * @param path the path of the element, which the element hierarchy is
031: * denoted as a '/'-separated string.
032: * @param key the key to acces the result.
033: * @param attributeMap a Map object created from org.xml.sax.Attributes object.
034: * @param top the top of the value stack.
035: */
036: public void start(String path, String key, Map attributeMap,
037: Object top) throws Exception {
038: }
039:
040: /**
041: * The method called when XML parser looks an element of the associated path ends.
042: *
043: * @param path the path of the element, which the element hierarchy is
044: * denoted as a '/'-separated string.
045: * @param key the key to acces the result.
046: * @param text the text element as a String object
047: * @param top the top of the value stack.
048: */
049: public void end(String path, String key, String text, Object top)
050: throws Exception {
051: }
052:
053: /**
054: * Pushes a values to the stack top.
055: *
056: * @param path the associated path
057: * @param value the value to be pushed
058: */
059: protected void push(String path, Object value) {
060: handler.pushValue(path, value);
061: }
062:
063: /**
064: * Pushes a values to the stack top.
065: *
066: * @param value the value to be pushed
067: */
068: protected void push(Object value) {
069: push(handler.getStackTopPath(), value);
070: }
071:
072: /**
073: * Pops a value from the stack top
074: *
075: * @return the value
076: */
077: protected Object pop() {
078: return handler.popValue();
079: }
080:
081: /**
082: * Gets the stack top without poping
083: *
084: * @return the object at the stack top
085: */
086: protected Object getStackTopValue() {
087: return handler.getStackTopValue();
088: }
089:
090: /**
091: * Gets the associated path of the stack top object
092: *
093: * @return the path
094: */
095: protected String getStackTopPath() {
096: return handler.getStackTopPath();
097: }
098:
099: /**
100: * Registers <em>list</em> for the specified <em>path</em>.
101: * The registered <em>list</em> is unregistered when different branch from the one
102: * the list is registered with, or an element of parent path is found by the parser.
103: */
104: protected void registerListPath(String path, Object list) {
105: handler.registerListPath(path, list);
106: }
107:
108: /**
109: * Checks if the list registered with <em>path</em> is still managed by the DigestReader.
110: *
111: * @param path the path
112: * @return true if it is still managed by the DigestReader.
113: */
114: protected boolean listAlive(String path) {
115: return handler.listAlive(path);
116:
117: }
118:
119: /**
120: * Returns the most recent managed list.
121: *
122: * @return the list object
123: */
124: protected Object currentListValue() {
125: return handler.currentListValue();
126: }
127: }
|