KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > TestRule


1 /* $Id: TestRule.java 155412 2005-02-26 12:58:36Z dirkv $
2  *
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.commons.digester;
20
21
22 import java.util.List JavaDoc;
23
24 import org.xml.sax.Attributes JavaDoc;
25
26
27 /**
28  * <p>This rule implementation is intended to help test digester.
29  * The idea is that you can test which rule matches by looking
30  * at the identifier.</p>
31  *
32  * @author Robert Burrell Donkin
33  * @revision $Revision$ $Date: 2005-02-26 04:58:36 -0800 (Sat, 26 Feb 2005) $
34  */

35
36 public class TestRule extends Rule {
37
38     // ----------------------------------------------------- Instance Variables
39

40
41     /** String identifing this particular <code>TestRule</code> */
42     private String JavaDoc identifier;
43
44     /** Used when testing body text */
45     private String JavaDoc bodyText;
46
47     /** Used when testing call orders */
48     private List JavaDoc order;
49
50     // ----------------------------------------------------------- Constructors
51

52     /**
53      * Base constructor.
54      *
55      * @param identifier Used to tell which TestRule is which
56      */

57     public TestRule(String JavaDoc identifier) {
58         
59         this.identifier = identifier;
60     }
61
62     /**
63      * Constructor sets namespace URI.
64      *
65      * @param digester The digester with which this rule is associated
66      * @param identifier Used to tell which TestRule is which
67      * @param namespaceURI Set rule namespace
68      */

69     public TestRule(
70                     String JavaDoc identifier,
71                     String JavaDoc namespaceURI) {
72
73         this.identifier = identifier;
74         setNamespaceURI(namespaceURI);
75
76     }
77
78
79     // ------------------------------------------------ Rule Implementation
80

81
82     /**
83      * 'Begin' call.
84      */

85     public void begin(Attributes JavaDoc attributes) {
86         appendCall();
87     }
88
89
90     /**
91      * 'Body' call.
92      */

93     public void body(String JavaDoc text) {
94         this.bodyText = text;
95         appendCall();
96     }
97
98
99     /**
100      * 'End' call.
101      */

102     public void end() {
103         appendCall();
104     }
105
106
107     // ------------------------------------------------ Methods
108

109
110     /**
111      * If a list has been set, append this to the list.
112      */

113     protected void appendCall() {
114         if (order != null)
115             order.add(this);
116     }
117
118
119     /**
120      * Get the body text that was set.
121      */

122     public String JavaDoc getBodyText() {
123         return bodyText;
124     }
125
126
127     /**
128      * Get the identifier associated with this test.
129      */

130     public String JavaDoc getIdentifier() {
131         return identifier;
132     }
133
134
135     /**
136      * Get call order list.
137      */

138     public List JavaDoc getOrder() {
139         return order;
140     }
141
142
143     /**
144      * Set call order list
145      */

146     public void setOrder(List JavaDoc order) {
147         this.order = order;
148     }
149
150
151     /**
152      * Return the identifier.
153      */

154     public String JavaDoc toString() {
155         return identifier;
156     }
157
158
159 }
160
Popular Tags