1. /* $Id: Rule.java,v 1.15 2004/05/10 06:30:06 skitching Exp $
  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. package org.apache.commons.digester;
  18. import org.xml.sax.Attributes;
  19. /**
  20. * Concrete implementations of this class implement actions to be taken when
  21. * a corresponding nested pattern of XML elements has been matched.
  22. */
  23. public abstract class Rule {
  24. // ----------------------------------------------------------- Constructors
  25. /**
  26. * Constructor sets the associated Digester.
  27. *
  28. * @param digester The digester with which this rule is associated
  29. * @deprecated The digester instance is now set in the {@link Digester#addRule} method. Use {@link #Rule()} instead.
  30. */
  31. public Rule(Digester digester) {
  32. super();
  33. setDigester(digester);
  34. }
  35. /**
  36. * <p>Base constructor.
  37. * Now the digester will be set when the rule is added.</p>
  38. */
  39. public Rule() {}
  40. // ----------------------------------------------------- Instance Variables
  41. /**
  42. * The Digester with which this Rule is associated.
  43. */
  44. protected Digester digester = null;
  45. /**
  46. * The namespace URI for which this Rule is relevant, if any.
  47. */
  48. protected String namespaceURI = null;
  49. // ------------------------------------------------------------- Properties
  50. /**
  51. * Return the Digester with which this Rule is associated.
  52. */
  53. public Digester getDigester() {
  54. return (this.digester);
  55. }
  56. /**
  57. * Set the <code>Digester</code> with which this <code>Rule</code> is associated.
  58. */
  59. public void setDigester(Digester digester) {
  60. this.digester = digester;
  61. }
  62. /**
  63. * Return the namespace URI for which this Rule is relevant, if any.
  64. */
  65. public String getNamespaceURI() {
  66. return (this.namespaceURI);
  67. }
  68. /**
  69. * Set the namespace URI for which this Rule is relevant, if any.
  70. *
  71. * @param namespaceURI Namespace URI for which this Rule is relevant,
  72. * or <code>null</code> to match independent of namespace.
  73. */
  74. public void setNamespaceURI(String namespaceURI) {
  75. this.namespaceURI = namespaceURI;
  76. }
  77. // --------------------------------------------------------- Public Methods
  78. /**
  79. * This method is called when the beginning of a matching XML element
  80. * is encountered.
  81. *
  82. * @param attributes The attribute list of this element
  83. * @deprecated Use the {@link #begin(String,String,Attributes) begin}
  84. * method with <code>namespace</code> and <code>name</code>
  85. * parameters instead.
  86. */
  87. public void begin(Attributes attributes) throws Exception {
  88. ; // The default implementation does nothing
  89. }
  90. /**
  91. * This method is called when the beginning of a matching XML element
  92. * is encountered. The default implementation delegates to the deprecated
  93. * method {@link #begin(Attributes) begin} without the
  94. * <code>namespace</code> and <code>name</code> parameters, to retain
  95. * backwards compatibility.
  96. *
  97. * @param namespace the namespace URI of the matching element, or an
  98. * empty string if the parser is not namespace aware or the element has
  99. * no namespace
  100. * @param name the local name if the parser is namespace aware, or just
  101. * the element name otherwise
  102. * @param attributes The attribute list of this element
  103. * @since Digester 1.4
  104. */
  105. public void begin(String namespace, String name, Attributes attributes)
  106. throws Exception {
  107. begin(attributes);
  108. }
  109. /**
  110. * This method is called when the body of a matching XML element
  111. * is encountered. If the element has no body, this method is
  112. * not called at all.
  113. *
  114. * @param text The text of the body of this element
  115. * @deprecated Use the {@link #body(String,String,String) body} method
  116. * with <code>namespace</code> and <code>name</code> parameters
  117. * instead.
  118. */
  119. public void body(String text) throws Exception {
  120. ; // The default implementation does nothing
  121. }
  122. /**
  123. * This method is called when the body of a matching XML element is
  124. * encountered. If the element has no body, this method is not called at
  125. * all. The default implementation delegates to the deprecated method
  126. * {@link #body(String) body} without the <code>namespace</code> and
  127. * <code>name</code> parameters, to retain backwards compatibility.
  128. *
  129. * @param namespace the namespace URI of the matching element, or an
  130. * empty string if the parser is not namespace aware or the element has
  131. * no namespace
  132. * @param name the local name if the parser is namespace aware, or just
  133. * the element name otherwise
  134. * @param text The text of the body of this element
  135. * @since Digester 1.4
  136. */
  137. public void body(String namespace, String name, String text)
  138. throws Exception {
  139. body(text);
  140. }
  141. /**
  142. * This method is called when the end of a matching XML element
  143. * is encountered.
  144. *
  145. * @deprecated Use the {@link #end(String,String) end} method with
  146. * <code>namespace</code> and <code>name</code> parameters instead.
  147. */
  148. public void end() throws Exception {
  149. ; // The default implementation does nothing
  150. }
  151. /**
  152. * This method is called when the end of a matching XML element
  153. * is encountered. The default implementation delegates to the deprecated
  154. * method {@link #end end} without the
  155. * <code>namespace</code> and <code>name</code> parameters, to retain
  156. * backwards compatibility.
  157. *
  158. * @param namespace the namespace URI of the matching element, or an
  159. * empty string if the parser is not namespace aware or the element has
  160. * no namespace
  161. * @param name the local name if the parser is namespace aware, or just
  162. * the element name otherwise
  163. * @since Digester 1.4
  164. */
  165. public void end(String namespace, String name)
  166. throws Exception {
  167. end();
  168. }
  169. /**
  170. * This method is called after all parsing methods have been
  171. * called, to allow Rules to remove temporary data.
  172. */
  173. public void finish() throws Exception {
  174. ; // The default implementation does nothing
  175. }
  176. }