1 17 18 package org.apache.commons.digester; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 34 35 public class RegexRules extends AbstractRulesImpl { 36 37 39 40 private ArrayList registeredRules = new ArrayList (); 41 42 private RegexMatcher matcher; 43 44 46 52 public RegexRules(RegexMatcher matcher) { 53 setRegexMatcher(matcher); 54 } 55 56 58 61 public RegexMatcher getRegexMatcher() { 62 return matcher; 63 } 64 65 71 public void setRegexMatcher(RegexMatcher matcher) { 72 if (matcher == null) { 73 throw new IllegalArgumentException ("RegexMatcher must not be null."); 74 } 75 this.matcher = matcher; 76 } 77 78 80 86 protected void registerRule(String pattern, Rule rule) { 87 registeredRules.add(new RegisteredRule(pattern, rule)); 88 } 89 90 93 public void clear() { 94 registeredRules.clear(); 95 } 96 97 107 public List match(String namespaceURI, String pattern) { 108 ArrayList rules = new ArrayList (registeredRules.size()); 117 Iterator it = registeredRules.iterator(); 118 while (it.hasNext()) { 119 RegisteredRule next = (RegisteredRule) it.next(); 120 if (matcher.match(pattern, next.pattern)) { 121 rules.add(next.rule); 122 } 123 } 124 return rules; 125 } 126 127 128 135 public List rules() { 136 ArrayList rules = new ArrayList (registeredRules.size()); 137 Iterator it = registeredRules.iterator(); 138 while (it.hasNext()) { 139 rules.add(((RegisteredRule) it.next()).rule); 140 } 141 return rules; 142 } 143 144 145 private class RegisteredRule { 146 String pattern; 147 Rule rule; 148 149 RegisteredRule(String pattern, Rule rule) { 150 this.pattern = pattern; 151 this.rule = rule; 152 } 153 } 154 } 155 | Popular Tags |