1 24 package org.hammurapi.inspectors; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 29 import org.hammurapi.InspectorBase; 30 31 import com.pavelvlasov.config.ConfigurationException; 32 import com.pavelvlasov.config.Parameterizable; 33 import com.pavelvlasov.jsel.CompilationUnit; 34 35 40 public class RootPackageRule extends InspectorBase implements Parameterizable { 41 private ArrayList rootPackage = new ArrayList (); 43 44 47 public void visit(CompilationUnit compilationUnit) { 48 String packageName=compilationUnit.getPackage().getName(); 49 Iterator it = rootPackage.iterator(); 51 while (it.hasNext()) 52 { 53 String rootPkg = (String )it.next(); 54 if (rootPkg!=null){ 55 if(packageName.equals(rootPkg) || packageName.startsWith(rootPkg+".")) { 56 return; 57 } 58 } 59 else 60 { 61 return; 62 } 63 64 } 65 context.reportViolation(compilationUnit, new Object [] {rootPackage}); 66 } 67 68 70 public boolean setParameter(String name, Object value) throws ConfigurationException { 71 if ("root-package".equals(name)) { 73 if (!rootPackage.contains(value.toString())) { 74 rootPackage.add(value.toString()); 75 } 76 return true; 77 } else { 78 throw new ConfigurationException("Parameter '"+name+"' is not supported"); 79 } 80 } 81 82 85 public String getConfigInfo() { 86 StringBuffer ret=new StringBuffer ("Application root package:\n"); 87 Iterator it=rootPackage.iterator(); 88 while (it.hasNext()) { 89 ret.append(" " + it.next() + "\n"); 90 } 91 return ret.toString(); 92 } 93 } 94 | Popular Tags |