1 18 19 package alt.jiapi.instrumentor; 20 21 import org.apache.log4j.Category; 22 23 import alt.jiapi.Rule; 24 import alt.jiapi.Runtime; 25 26 33 public abstract class AbstractStrategy implements Strategy { 34 private Instrumentation instrumentation; 35 private static Category log = Runtime.getLogCategory(AbstractStrategy.class); 36 37 40 protected String [] resolutions; 41 42 private boolean reverseMatch; 43 private Rule[] rules; 44 45 50 protected AbstractStrategy() { 51 } 52 53 57 protected AbstractStrategy(String resolution) { 58 this(new String [] {resolution}, false); 59 } 60 61 65 protected AbstractStrategy(String [] resolutions) { 66 this(resolutions, false); 67 } 68 69 78 protected AbstractStrategy(String [] resolutions, boolean reverseMatch) { 79 this.reverseMatch = reverseMatch; 80 81 setResolutions(resolutions); 82 } 83 84 85 89 public void setResolutions(String [] resolutions) { 90 this.resolutions = resolutions; 91 this.reverseMatch = false; 92 93 createRules(resolutions); 94 } 95 96 101 public String [] getResolutions() { 102 return resolutions; 103 } 104 105 106 111 protected boolean match(String name) { 112 if (name == null || rules == null) { 113 return false; 114 } 115 116 boolean b = false; 117 for (int i = 0; i < rules.length; i++) { 118 if (rules[i].match(name)) { 119 b = true; 120 121 break; 122 } 123 } 124 125 b = b ^ reverseMatch; 127 128 return b; 129 } 130 131 132 void setInstrumentation(Instrumentation i) { 133 this.instrumentation = i; 134 } 135 136 137 protected Instrumentation getInstrumentation() { 138 return instrumentation; 139 } 140 141 private void createRules(String [] resolutions) { 143 if(resolutions == null) { 144 return; 145 } 146 147 this.rules = new Rule[resolutions.length]; 148 149 for (int i = 0; i < resolutions.length; i++) { 150 try { 151 rules[i] = new Rule(resolutions[i]); 152 } 153 catch(Exception e) { 154 log.error(e.getMessage()); 155 } 156 } 157 } 158 } 159 | Popular Tags |