001/* $Id: TestRuleSet.java 1212599 2011-12-09 19:46:42Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.commons.digester3;
020
021import org.apache.commons.digester3.Digester;
022import org.apache.commons.digester3.RuleSetBase;
023
024/**
025 * RuleSet that mimics the rules set used for Employee and Address creation, optionally associated with a particular
026 * namespace URI.
027 *
028 * @author Craig R. McClanahan
029 */
030public class TestRuleSet
031    extends RuleSetBase
032{
033
034    // ----------------------------------------------------------- Constructors
035
036    /**
037     * Construct an instance of this RuleSet with default values.
038     */
039    public TestRuleSet()
040    {
041
042        this( null, null );
043
044    }
045
046    /**
047     * Construct an instance of this RuleSet associated with the specified prefix, associated with no namespace URI.
048     *
049     * @param prefix Matching pattern prefix (must end with '/') or null.
050     */
051    public TestRuleSet( String prefix )
052    {
053
054        this( prefix, null );
055
056    }
057
058    /**
059     * Construct an instance of this RuleSet associated with the specified prefix and namespace URI.
060     *
061     * @param prefix Matching pattern prefix (must end with '/') or null.
062     * @param namespaceURI The namespace URI these rules belong to
063     */
064    public TestRuleSet( String prefix, String namespaceURI )
065    {
066
067        super(namespaceURI);
068        if ( prefix == null )
069        {
070            this.prefix = "";
071        }
072        else
073        {
074            this.prefix = prefix;
075        }
076
077    }
078
079    // ----------------------------------------------------- Instance Variables
080
081    /**
082     * The prefix for each matching pattern added to the Digester instance, or an empty String for no prefix.
083     */
084    protected String prefix = null;
085
086    // --------------------------------------------------------- Public Methods
087
088    /**
089     * {@inheritDoc}
090     */
091    public void addRuleInstances( Digester digester )
092    {
093
094        digester.addObjectCreate( prefix + "employee", Employee.class );
095        digester.addSetProperties( prefix + "employee" );
096        digester.addObjectCreate( "employee/address", "org.apache.commons.digester3.Address" );
097        digester.addSetProperties( prefix + "employee/address" );
098        digester.addSetNext( prefix + "employee/address", "addAddress" );
099
100    }
101
102}