craigmcc 01/08/26 15:13:44
Modified: digester/src/java/org/apache/commons/digester Digester.java
Rule.java RulesBase.java
digester/src/test/org/apache/commons/digester
RuleTestCase.java
Added: digester/src/java/org/apache/commons/digester RuleSet.java
RuleSetBase.java
digester/src/test/org/apache/commons/digester Test2.xml
Test3.xml TestRuleSet.java
Log:
Add notion of a RuleSet that provides a convenient way to package sets of
related rules, optionally associated with a namespace prefix.
Add test cases for RuleSet processing, and fix a couple of bugs in rule
matching. All unit tests now pass for both namespace-unaware processing
(the original functionality of Digester) and namespace-aware processing
(new feature where rules can only match for matching namespace URIs).
Revision Changes Path
1.16 +30 -9
jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
Index: Digester.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Digester.java 2001/08/26 05:09:36 1.15
+++ Digester.java 2001/08/26 22:13:44 1.16
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
1.15 2001/08/26 05:09:36 craigmcc Exp $
- * $Revision: 1.15 $
- * $Date: 2001/08/26 05:09:36 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
1.16 2001/08/26 22:13:44 craigmcc Exp $
+ * $Revision: 1.16 $
+ * $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
@@ -106,7 +106,7 @@
*
* @author Craig McClanahan
* @author Scott Sanders
- * @version $Revision: 1.15 $ $Date: 2001/08/26 05:09:36 $
+ * @version $Revision: 1.16 $ $Date: 2001/08/26 22:13:44 $
*/
public class Digester extends DefaultHandler {
@@ -835,15 +835,13 @@
StringBuffer sb = new StringBuffer(match);
if (match.length() > 0)
sb.append('/');
- if (namespaceAware)
+ if ((localName == null) || (localName.length() < 1))
sb.append(qName);
- else if ((localName == null) || (localName.length() < 1))
- sb.append(qName);
else
sb.append(localName);
match = sb.toString();
- if (debug >= 3)
- log("startElement(" + match + ")");
+ if (debug >= 3)
+ log(" New match='" + match + "'");
// Fire "begin" events for all relevant rules
List rules = getRules().match(namespaceURI, match);
@@ -1165,6 +1163,29 @@
public void addRule(String pattern, Rule rule) {
getRules().add(pattern, rule);
+
+ }
+
+
+
+ /**
+ * Register a set of Rule instances defined in a RuleSet.
+ *
+ * @param ruleSet The RuleSet instance to configure from
+ */
+ public void addRuleSet(RuleSet ruleSet) {
+
+ String oldNamespaceURI = getRuleNamespaceURI();
+ String newNamespaceURI = ruleSet.getNamespaceURI();
+ if (debug >= 3) {
+ if (newNamespaceURI == null)
+ log("addRuleSet() with no namespace URI");
+ else
+ log("addRuleSet() with namespace URI " + newNamespaceURI);
+ }
+ setRuleNamespaceURI(newNamespaceURI);
+ ruleSet.addRuleInstances(this);
+ setRuleNamespaceURI(oldNamespaceURI);
}
1.4 +5 -5
jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java
Index: Rule.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Rule.java 2001/08/26 05:09:36 1.3
+++ Rule.java 2001/08/26 22:13:44 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java,v
1.3 2001/08/26 05:09:36 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/08/26 05:09:36 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java,v
1.4 2001/08/26 22:13:44 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
@@ -71,7 +71,7 @@
* a corresponding nested pattern of XML elements has been matched.
*
* @author Craig McClanahan
- * @version $Revision: 1.3 $ $Date: 2001/08/26 05:09:36 $
+ * @version $Revision: 1.4 $ $Date: 2001/08/26 22:13:44 $
*/
public abstract class Rule {
@@ -139,7 +139,7 @@
*/
public void setNamespaceURI(String namespaceURI) {
- this.namespaceURI = null;
+ this.namespaceURI = namespaceURI;
}
1.3 +12 -9
jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java
Index: RulesBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RulesBase.java 2001/08/26 05:09:36 1.2
+++ RulesBase.java 2001/08/26 22:13:44 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java,v
1.2 2001/08/26 05:09:36 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2001/08/26 05:09:36 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RulesBase.java,v
1.3 2001/08/26 22:13:44 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
@@ -86,7 +86,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2001/08/26 05:09:36 $
+ * @version $Revision: 1.3 $ $Date: 2001/08/26 22:13:44 $
*/
public class RulesBase implements Rules {
@@ -193,8 +193,8 @@
cache.put(pattern, list);
}
list.add(rule);
- rule.setNamespaceURI(namespaceURI);
rules.add(rule);
+ rule.setNamespaceURI(this.namespaceURI);
}
@@ -243,7 +243,7 @@
// List rulesList = (List) this.cache.get(pattern);
List rulesList = lookup(namespaceURI, pattern);
- if (rulesList == null) {
+ if ((rulesList == null) || (rulesList.size() < 1)) {
// Find the longest key, ie more discriminant
String longKey = "";
Iterator keys = this.cache.keySet().iterator();
@@ -295,18 +295,21 @@
// Optimize when no namespace URI is specified
List list = (List) this.cache.get(pattern);
- if (list == null)
+ if (list == null) {
return (null);
- if ((namespaceURI == null) || (namespaceURI.length() == 0))
+ }
+ if ((namespaceURI == null) || (namespaceURI.length() == 0)) {
return (list);
+ }
// Select only Rules that match on the specified namespace URI
ArrayList results = new ArrayList();
Iterator items = list.iterator();
while (items.hasNext()) {
Rule item = (Rule) items.next();
- if (namespaceURI.equals(item.getNamespaceURI()))
+ if (namespaceURI.equals(item.getNamespaceURI())) {
results.add(item);
+ }
}
return (results);
1.1
jakarta-commons/digester/src/java/org/apache/commons/digester/RuleSet.java
Index: RuleSet.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RuleSet.java,v
1.1 2001/08/26 22:13:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.digester;
/**
* <p>Public interface defining a shorthand means of configuring a complete
* set of related <code>Rule</code> definitions, possibly associated with
* a particular namespace URI, in one operation. To use an instance of a
* class that imlements this interface:</p>
* <ul>
* <li>Create a concrete implementation of this interface.</li>
* <li>Optionally, you can configure a <code>RuleSet</code> to be relevant
* only for a particular namespace URI by configuring the value to be
* returned by <code>getNamespaceURI()</code>.</li>
* <li>As you are configuring your Digester instance, call
* <code>digester.addRuleSet()</code> and pass the RuleSet instance.</li>
* <li>Digester will call the <code>addRuleInstances()</code> method of
* your RuleSet to configure the necessary rules.</li>
* </ul>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/08/26 22:13:44 $
*/
public interface RuleSet {
// ------------------------------------------------------------- Properties
/**
* Return the namespace URI that will be applied to all Rule instances
* created from this RuleSet.
*/
public String getNamespaceURI();
// --------------------------------------------------------- Public Methods
/**
* Add the set of Rule instances defined in this RuleSet to the
* specified <code>Digester</code> instance, associating them with
* our namespace URI (if any). This method should only be called
* by a Digester instance.
*
* @param digester Digester instance to which the new Rule instances
* should be added.
*/
public void addRuleInstances(Digester digester);
}
1.1
jakarta-commons/digester/src/java/org/apache/commons/digester/RuleSetBase.java
Index: RuleSetBase.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/RuleSetBase.java,v
1.1 2001/08/26 22:13:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.digester;
/**
* <p>Convenience base class that implements the {@link RuleSet} interface.
* Concrete implementations should list all of their actual rule creation
* logic in the <code>addRuleSet()</code> implementation.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/08/26 22:13:44 $
*/
public abstract class RuleSetBase implements RuleSet {
// ----------------------------------------------------- Instance Variables
/**
* The namespace URI that all Rule instances created by this RuleSet
* will be associated with.
*/
protected String namespaceURI = null;
// ------------------------------------------------------------- Properties
/**
* Return the namespace URI that will be applied to all Rule instances
* created from this RuleSet.
*/
public String getNamespaceURI() {
return (this.namespaceURI);
}
// --------------------------------------------------------- Public Methods
/**
* Add the set of Rule instances defined in this RuleSet to the
* specified <code>Digester</code> instance, associating them with
* our namespace URI (if any). This method should only be called
* by a Digester instance.
*
* @param digester Digester instance to which the new Rule instances
* should be added.
*/
public abstract void addRuleInstances(Digester digester);
}
1.4 +118 -5
jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java
Index: RuleTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RuleTestCase.java 2001/08/20 22:12:02 1.3
+++ RuleTestCase.java 2001/08/26 22:13:44 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.3 2001/08/20 22:12:02 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/08/20 22:12:02 $
+ * $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.4 2001/08/26 22:13:44 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
@@ -70,13 +70,12 @@
import junit.framework.TestSuite;
-
/**
* <p>Test Case for the Digester class. These tests perform parsing of
* XML documents to exercise the built-in rules.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2001/08/20 22:12:02 $
+ * @version $Revision: 1.4 $ $Date: 2001/08/26 22:13:44 $
*/
public class RuleTestCase extends TestCase {
@@ -288,6 +287,120 @@
"Last Name",
employee.getLastName());
+
+ }
+
+
+ /**
+ * Test object creation (and associated property setting) with nothing on
+ * the stack, which should cause an appropriate Employee object to be
+ * returned. The processing rules will process the nested Address elements
+ * as well, but will not attempt to add them to the Employee.
+ */
+ public void testRuleSet1() {
+
+ // Configure the digester as required
+ RuleSet rs = new TestRuleSet();
+ digester.addRuleSet(rs);
+
+ // Parse our test input.
+ Object root = null;
+ try {
+ root = digester.parse(getInputStream("Test1.xml"));
+ } catch (Throwable t) {
+ fail("Digester threw IOException: " + t);
+ }
+
+ assertNotNull("Digester returned an object", root);
+ assertTrue("Digester returned an Employee",
+ root instanceof Employee);
+ Employee employee = (Employee) root;
+ assertEquals("First name is correct",
+ "First Name",
+ employee.getFirstName());
+ assertEquals("Last name is correct",
+ "Last Name",
+ employee.getLastName());
+ assertNotNull("Can retrieve home address",
+ employee.getAddress("home"));
+ assertNotNull("Can retrieve office address",
+ employee.getAddress("office"));
+
+ }
+
+
+ /**
+ * Same as <code>testRuleSet1</code> except using a single namespace.
+ */
+ public void testRuleSet2() {
+
+ // Configure the digester as required
+ digester.setNamespaceAware(true);
+ RuleSet rs = new TestRuleSet(null,
+ "http://jakarta.apache.org/digester/Foo");
+ digester.addRuleSet(rs);
+
+ // Parse our test input.
+ Object root = null;
+ try {
+ root = digester.parse(getInputStream("Test2.xml"));
+ } catch (Throwable t) {
+ fail("Digester threw IOException: " + t);
+ }
+
+ assertNotNull("Digester returned an object", root);
+ assertTrue("Digester returned an Employee",
+ root instanceof Employee);
+ Employee employee = (Employee) root;
+ assertEquals("First name is correct",
+ "First Name",
+ employee.getFirstName());
+ assertEquals("Last name is correct",
+ "Last Name",
+ employee.getLastName());
+ assertNotNull("Can retrieve home address",
+ employee.getAddress("home"));
+ assertNotNull("Can retrieve office address",
+ employee.getAddress("office"));
+
+ }
+
+
+ /**
+ * Same as <code>testRuleSet2</code> except using a namespace
+ * for employee that we should recognize, and a namespace for
+ * address that we should skip.
+ */
+ public void testRuleSet3() {
+
+ // Configure the digester as required
+ digester.setNamespaceAware(true);
+ RuleSet rs = new TestRuleSet(null,
+ "http://jakarta.apache.org/digester/Foo");
+ digester.addRuleSet(rs);
+
+ // Parse our test input.
+ Object root = null;
+ try {
+ root = digester.parse(getInputStream("Test3.xml"));
+ } catch (Throwable t) {
+ fail("Digester threw IOException: " + t);
+ }
+
+ assertNotNull("Digester returned an object", root);
+ assertTrue("Digester returned an Employee",
+ root instanceof Employee);
+ Employee employee = (Employee) root;
+ assertEquals("First name is correct",
+ "First Name",
+ employee.getFirstName());
+ assertEquals("Last name is correct",
+ "Last Name",
+ employee.getLastName());
+ assertNull("Can not retrieve home address",
+ employee.getAddress("home"));
+ assertNull("Can not retrieve office address",
+ employee.getAddress("office"));
}
1.1
jakarta-commons/digester/src/test/org/apache/commons/digester/Test2.xml
Index: Test2.xml
===================================================================
<?xml version="1.0"?>
<test:employee firstName="First Name" lastName="Last Name"
xmlns:test="http://jakarta.apache.org/digester/Foo">
<test:address type="home" street="Home Street" city="Home City"
state="HS" zipCode="HmZip"/>
<test:address type="office" street="Office Street" city="Office City"
state="OS" zipCode="OfZip"/>
</test:employee>
1.1
jakarta-commons/digester/src/test/org/apache/commons/digester/Test3.xml
Index: Test3.xml
===================================================================
<?xml version="1.0"?>
<foo:employee firstName="First Name" lastName="Last Name"
xmlns:foo="http://jakarta.apache.org/digester/Foo"
xmlns:bar="http://jakarta.apache.org/digester/Bar">
<bar:address type="home" street="Home Street" city="Home City"
state="HS" zipCode="HmZip"/>
<bar:address type="office" street="Office Street" city="Office City"
state="OS" zipCode="OfZip"/>
</foo:employee>
1.1
jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java
Index: TestRuleSet.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRuleSet.java,v
1.1 2001/08/26 22:13:44 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/26 22:13:44 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.digester;
/**
* RuleSet that mimics the rules set used for Employee and Address creation,
* optionally associated with a particular namespace URI.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2001/08/26 22:13:44 $
*/
public class TestRuleSet extends RuleSetBase {
// ----------------------------------------------------------- Constructors
/**
* Construct an instance of this RuleSet with default values.
*/
public TestRuleSet() {
this(null, null);
}
/**
* Construct an instance of this RuleSet associated with the specified
* prefix, associated with no namespace URI.
*
* @param prefix Matching pattern prefix (must end with '/') or null.
*/
public TestRuleSet(String prefix) {
this(prefix, null);
}
/**
* Construct an instance of this RuleSet associated with the specified
* prefix and namespace URI.
*
* @param prefix Matching pattern prefix (must end with '/') or null.
* @param namespaceURI The namespace URI these rules belong to
*/
public TestRuleSet(String prefix, String namespaceURI) {
super();
if (prefix == null)
this.prefix = "";
else
this.prefix = prefix;
this.namespaceURI = namespaceURI;
}
// ----------------------------------------------------- Instance Variables
/**
* The prefix for each matching pattern added to the Digester instance,
* or an empty String for no prefix.
*/
protected String prefix = null;
// --------------------------------------------------------- Public Methods
/**
* Add the set of Rule instances defined in this RuleSet to the
* specified <code>Digester</code> instance, associating them with
* our namespace URI (if any). This method should only be called
* by a Digester instance.
*
* @param digester Digester instance to which the new Rule instances
* should be added.
*/
public void addRuleInstances(Digester digester) {
digester.addObjectCreate(prefix + "employee",
"org.apache.commons.digester.Employee");
digester.addSetProperties(prefix + "employee");
digester.addObjectCreate("employee/address",
"org.apache.commons.digester.Address");
digester.addSetProperties(prefix + "employee/address");
digester.addSetNext(prefix + "employee/address",
"addAddress");
}
}