/* $Id: WithDefaultsRulesWrapper.java 992060 2010-09-02 19:09:47Z simonetripodi $ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.digester; import java.util.ArrayList; import java.util.List; /** *
Rules
Decorator that returns default rules
* when no matches are returned by the wrapped implementation.
This allows default Rule
instances to be added to any
* existing Rules
implementation. These default Rule
* instances will be returned for any match for which the wrapped
* implementation does not return any matches.
For example, *
* Rule alpha; * ... * WithDefaultsRulesWrapper rules = new WithDefaultsRulesWrapper(new BaseRules()); * rules.addDefault(alpha); * ... * digester.setRules(rules); * ... ** when a pattern does not match any other rule, then rule alpha will be called. * *
WithDefaultsRulesWrapper
follows the Decorator pattern.
Rules
implementation, not null
* @throws IllegalArgumentException when wrappedRules
is null
*/
public WithDefaultsRulesWrapper(Rules wrappedRules) {
if (wrappedRules == null) {
throw new IllegalArgumentException("Wrapped rules must not be null");
}
this.wrappedRules = wrappedRules;
}
// --------------------------------------------------------- Properties
/** Gets digester using these Rules */
public Digester getDigester() {
return wrappedRules.getDigester();
}
/** Sets digeseter using these Rules */
public void setDigester(Digester digester) {
wrappedRules.setDigester(digester);
for (Rule rule : defaultRules) {
rule.setDigester(digester);
}
}
/** Gets namespace to apply to Rule's added */
public String getNamespaceURI() {
return wrappedRules.getNamespaceURI();
}
/** Sets namespace to apply to Rule's added subsequently */
public void setNamespaceURI(String namespaceURI) {
wrappedRules.setNamespaceURI(namespaceURI);
}
/** Gets Rule's which will be fired when the wrapped implementation returns no matches */
public List