KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: TestRuleSet.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 /**
23  * RuleSet that mimics the rules set used for Employee and Address creation,
24  * optionally associated with a particular namespace URI.
25  *
26  * @author Craig R. McClanahan
27  * @version $Revision$ $Date: 2005-02-26 04:58:36 -0800 (Sat, 26 Feb 2005) $
28  */

29
30 public class TestRuleSet extends RuleSetBase {
31
32
33     // ----------------------------------------------------------- Constructors
34

35
36     /**
37      * Construct an instance of this RuleSet with default values.
38      */

39     public TestRuleSet() {
40
41         this(null, null);
42
43     }
44
45
46     /**
47      * Construct an instance of this RuleSet associated with the specified
48      * prefix, associated with no namespace URI.
49      *
50      * @param prefix Matching pattern prefix (must end with '/') or null.
51      */

52     public TestRuleSet(String JavaDoc prefix) {
53
54         this(prefix, null);
55
56     }
57
58
59     /**
60      * Construct an instance of this RuleSet associated with the specified
61      * prefix and namespace URI.
62      *
63      * @param prefix Matching pattern prefix (must end with '/') or null.
64      * @param namespaceURI The namespace URI these rules belong to
65      */

66     public TestRuleSet(String JavaDoc prefix, String JavaDoc namespaceURI) {
67
68         super();
69         if (prefix == null)
70             this.prefix = "";
71         else
72             this.prefix = prefix;
73         this.namespaceURI = namespaceURI;
74
75     }
76
77
78     // ----------------------------------------------------- Instance Variables
79

80
81     /**
82      * The prefix for each matching pattern added to the Digester instance,
83      * or an empty String for no prefix.
84      */

85     protected String JavaDoc prefix = null;
86
87
88     // --------------------------------------------------------- Public Methods
89

90
91     /**
92      * Add the set of Rule instances defined in this RuleSet to the
93      * specified <code>Digester</code> instance, associating them with
94      * our namespace URI (if any). This method should only be called
95      * by a Digester instance.
96      *
97      * @param digester Digester instance to which the new Rule instances
98      * should be added.
99      */

100     public void addRuleInstances(Digester digester) {
101
102         digester.addObjectCreate(prefix + "employee", Employee.class);
103         digester.addSetProperties(prefix + "employee");
104         digester.addObjectCreate("employee/address",
105                 "org.apache.commons.digester.Address");
106         digester.addSetProperties(prefix + "employee/address");
107         digester.addSetNext(prefix + "employee/address",
108                 "addAddress");
109
110     }
111     
112
113 }
114
Popular Tags