001: /* $Id: TestRule.java 471661 2006-11-06 08:09:25Z skitching $
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package org.apache.commons.digester;
020:
021: import java.util.List;
022:
023: import org.xml.sax.Attributes;
024:
025: /**
026: * <p>This rule implementation is intended to help test digester.
027: * The idea is that you can test which rule matches by looking
028: * at the identifier.</p>
029: *
030: * @author Robert Burrell Donkin
031: * @revision $Revision: 471661 $ $Date: 2006-11-06 00:09:25 -0800 (Mon, 06 Nov 2006) $
032: */
033:
034: public class TestRule extends Rule {
035:
036: // ----------------------------------------------------- Instance Variables
037:
038: /** String identifing this particular <code>TestRule</code> */
039: private String identifier;
040:
041: /** Used when testing body text */
042: private String bodyText;
043:
044: /** Used when testing call orders */
045: private List order;
046:
047: // ----------------------------------------------------------- Constructors
048:
049: /**
050: * Base constructor.
051: *
052: * @param identifier Used to tell which TestRule is which
053: */
054: public TestRule(String identifier) {
055:
056: this .identifier = identifier;
057: }
058:
059: /**
060: * Constructor sets namespace URI.
061: *
062: * @param digester The digester with which this rule is associated
063: * @param identifier Used to tell which TestRule is which
064: * @param namespaceURI Set rule namespace
065: */
066: public TestRule(String identifier, String namespaceURI) {
067:
068: this .identifier = identifier;
069: setNamespaceURI(namespaceURI);
070:
071: }
072:
073: // ------------------------------------------------ Rule Implementation
074:
075: /**
076: * 'Begin' call.
077: */
078: public void begin(Attributes attributes) {
079: appendCall();
080: }
081:
082: /**
083: * 'Body' call.
084: */
085: public void body(String text) {
086: this .bodyText = text;
087: appendCall();
088: }
089:
090: /**
091: * 'End' call.
092: */
093: public void end() {
094: appendCall();
095: }
096:
097: // ------------------------------------------------ Methods
098:
099: /**
100: * If a list has been set, append this to the list.
101: */
102: protected void appendCall() {
103: if (order != null)
104: order.add(this );
105: }
106:
107: /**
108: * Get the body text that was set.
109: */
110: public String getBodyText() {
111: return bodyText;
112: }
113:
114: /**
115: * Get the identifier associated with this test.
116: */
117: public String getIdentifier() {
118: return identifier;
119: }
120:
121: /**
122: * Get call order list.
123: */
124: public List getOrder() {
125: return order;
126: }
127:
128: /**
129: * Set call order list
130: */
131: public void setOrder(List order) {
132: this .order = order;
133: }
134:
135: /**
136: * Return the identifier.
137: */
138: public String toString() {
139: return identifier;
140: }
141:
142: }
|