View Javadoc

1   /* $Id: TestRuleSet.java 1212599 2011-12-09 19:46:42Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.commons.digester3;
20  
21  import org.apache.commons.digester3.Digester;
22  import org.apache.commons.digester3.RuleSetBase;
23  
24  /**
25   * RuleSet that mimics the rules set used for Employee and Address creation, optionally associated with a particular
26   * namespace URI.
27   *
28   * @author Craig R. McClanahan
29   */
30  public class TestRuleSet
31      extends RuleSetBase
32  {
33  
34      // ----------------------------------------------------------- Constructors
35  
36      /**
37       * Construct an instance of this RuleSet with default values.
38       */
39      public TestRuleSet()
40      {
41  
42          this( null, null );
43  
44      }
45  
46      /**
47       * Construct an instance of this RuleSet associated with the specified prefix, associated with no namespace URI.
48       *
49       * @param prefix Matching pattern prefix (must end with '/') or null.
50       */
51      public TestRuleSet( String prefix )
52      {
53  
54          this( prefix, null );
55  
56      }
57  
58      /**
59       * Construct an instance of this RuleSet associated with the specified prefix and namespace URI.
60       *
61       * @param prefix Matching pattern prefix (must end with '/') or null.
62       * @param namespaceURI The namespace URI these rules belong to
63       */
64      public TestRuleSet( String prefix, String namespaceURI )
65      {
66  
67          super(namespaceURI);
68          if ( prefix == null )
69          {
70              this.prefix = "";
71          }
72          else
73          {
74              this.prefix = prefix;
75          }
76  
77      }
78  
79      // ----------------------------------------------------- Instance Variables
80  
81      /**
82       * The prefix for each matching pattern added to the Digester instance, or an empty String for no prefix.
83       */
84      protected String prefix = null;
85  
86      // --------------------------------------------------------- Public Methods
87  
88      /**
89       * {@inheritDoc}
90       */
91      public void addRuleInstances( Digester digester )
92      {
93  
94          digester.addObjectCreate( prefix + "employee", Employee.class );
95          digester.addSetProperties( prefix + "employee" );
96          digester.addObjectCreate( "employee/address", "org.apache.commons.digester3.Address" );
97          digester.addSetProperties( prefix + "employee/address" );
98          digester.addSetNext( prefix + "employee/address", "addAddress" );
99  
100     }
101 
102 }