1 17 package org.apache.forrest.sourcetype; 18 19 import org.apache.avalon.framework.configuration.*; 20 21 import java.util.*; 22 23 27 public class SourceType implements Configurable 28 { 29 protected List rules = new ArrayList(); 30 protected String name; 31 32 public void configure(Configuration configuration) throws ConfigurationException 33 { 34 name = configuration.getAttribute("name"); 35 36 Configuration[] ruleConfs = configuration.getChildren(); 37 for (int i = 0; i < ruleConfs.length; i++) 38 { 39 SourceTypeRule rule; 40 if (ruleConfs[i].getName().equals("document-declaration")) 41 rule = new DocDeclRule(); 42 else if (ruleConfs[i].getName().equals("processing-instruction")) 43 rule = new ProcessingInstructionRule(); 44 else if (ruleConfs[i].getName().equals("w3c-xml-schema")) 45 rule = new ProcessingInstructionRule(); 46 else if (ruleConfs[i].getName().equals("document-element")) 47 rule = new DocumentElementRule(); 48 else 49 throw new ConfigurationException("Unsupported element " + ruleConfs[i].getName() + " at " 50 + ruleConfs[i].getLocation()); 51 52 rule.configure(ruleConfs[i]); 53 rules.add(rule); 54 } 55 } 56 57 public boolean matches(SourceInfo sourceInfo) 58 { 59 Iterator rulesIt = rules.iterator(); 60 boolean matches = true; 61 while (rulesIt.hasNext()) 62 { 63 SourceTypeRule rule = (SourceTypeRule)rulesIt.next(); 64 matches = matches && rule.matches(sourceInfo); 65 if (!matches) 66 return false; 67 } 68 return matches; 69 } 70 71 public String getName() 72 { 73 return name; 74 } 75 } 76 | Popular Tags |