1 18 19 package org.apache.tomcat.util.digester; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 49 50 public class WithDefaultsRulesWrapper implements Rules { 51 52 54 55 private Rules wrappedRules; 56 57 private List defaultRules = new ArrayList (); 58 59 private List allRules = new ArrayList (); 60 61 63 69 public WithDefaultsRulesWrapper(Rules wrappedRules) { 70 if (wrappedRules == null) { 71 throw new IllegalArgumentException ("Wrapped rules must not be null"); 72 } 73 this.wrappedRules = wrappedRules; 74 } 75 76 78 79 public Digester getDigester() { 80 return wrappedRules.getDigester(); 81 } 82 83 84 public void setDigester(Digester digester) { 85 wrappedRules.setDigester(digester); 86 Iterator it = defaultRules.iterator(); 87 while (it.hasNext()) { 88 Rule rule = (Rule) it.next(); 89 rule.setDigester(digester); 90 } 91 } 92 93 94 public String getNamespaceURI() { 95 return wrappedRules.getNamespaceURI(); 96 } 97 98 99 public void setNamespaceURI(String namespaceURI) { 100 wrappedRules.setNamespaceURI(namespaceURI); 101 } 102 103 104 public List getDefaults() { 105 return defaultRules; 106 } 107 108 110 public List match(String pattern) { 111 return match("", pattern); 112 } 113 114 119 public List match(String namespaceURI, String pattern) { 120 List matches = wrappedRules.match(namespaceURI, pattern); 121 if (matches == null || matches.isEmpty()) { 122 return new ArrayList (defaultRules); 124 } 125 return matches; 127 } 128 129 130 public void addDefault(Rule rule) { 131 if (wrappedRules.getDigester() != null) { 133 rule.setDigester(wrappedRules.getDigester()); 134 } 135 136 if (wrappedRules.getNamespaceURI() != null) { 137 rule.setNamespaceURI(wrappedRules.getNamespaceURI()); 138 } 139 140 defaultRules.add(rule); 141 allRules.add(rule); 142 } 143 144 145 public List rules() { 146 return allRules; 147 } 148 149 150 public void clear() { 151 wrappedRules.clear(); 152 allRules.clear(); 153 defaultRules.clear(); 154 } 155 156 160 public void add(String pattern, Rule rule) { 161 wrappedRules.add(pattern, rule); 162 allRules.add(rule); 163 } 164 } 165 | Popular Tags |