1 19 20 package org.objectweb.jac.core; 21 22 import gnu.regexp.RE; 23 import gnu.regexp.REException; 24 import java.util.*; 25 import org.apache.log4j.Logger; 26 import org.objectweb.jac.util.Strings; 27 28 39 40 public abstract class JacPropLoader extends JacPropTools { 41 static Logger logger = Logger.getLogger("props"); 42 43 46 47 48 public final static String propFileName = "jac.prop"; 49 50 51 public final static String toNotAdaptProp = "jac.toNotAdapt"; 52 53 54 public final static String toAdaptProp = "jac.toAdapt"; 55 56 57 public final static String wrappableMethodsProp = "jac.wrappableMethods"; 58 59 60 public final static String dontTranslateFieldsProp = "jac.dontTranslateField"; 61 62 63 public final static String toWrapProp = "jac.toWrap"; 64 65 67 public final static String topologyProp = "jac.topology"; 68 69 72 public final static String acsProp = "jac.acs"; 73 74 77 public final static String startWeavingPlacesProp = "jac.startWeavingPlaces"; 78 79 82 public final static String compositionAspectProp = "jac.comp.compositionAspect"; 83 84 85 86 public final static String wrappingOrderProp = "jac.comp.wrappingOrder"; 87 88 89 public final static String incompatibleACsProp = "jac.comp.imcompatibleACs"; 90 91 92 public final static String dependentACsProp = "jac.comp.dependentACs"; 93 94 95 public final static String bytecodeModifierProp = "jac.bytecodeModifier"; 96 97 98 public static final String remRefClassProp = "jac.remoteRefClass"; 99 100 101 public static final String remRefDefaultClassName = "org.objectweb.jac.core.dist.rmi.RMIRemoteRef"; 102 103 104 public static final String namingClassProp = "org.objectweb.jac.core.dist.namingClass"; 105 106 107 public static final String namingClassDefaultName = "org.objectweb.jac.core.dist.rmi.RMINaming"; 108 109 110 public static Properties props = new Properties(); 111 112 114 public static HashSet packagesToAdapt = new HashSet(); 115 116 118 public static HashSet packagesToNotAdapt = new HashSet(); 119 120 121 public static Hashtable wrappableMethods = new Hashtable(); 122 123 124 public static HashSet dontTranslateFields = new HashSet(); 125 126 public static HashSet packagesToWrap = new HashSet(); 127 128 public static String compositionAspect = null; 129 130 131 public static String bytecodeModifier = null; 132 133 public static String remoteRefClassName = null; 134 135 public static String namingClassName = null; 136 137 138 public static Hashtable declaredACs = new Hashtable(); 139 140 141 public static Vector wrappingOrder = new Vector(); 142 143 144 public static Vector incompatibleACs = new Vector(); 145 146 147 public static Vector dependentACs = new Vector(); 148 149 public static int acs_count=0; 150 151 static HashSet packagesToAdaptRE = new HashSet(); 152 153 static HashSet packagesToNotAdaptRE = new HashSet(); 154 155 160 public static boolean addProps(Properties ps) { 161 String tmp; 162 if (ps==null) 163 return false; 164 for (Enumeration e = ps.propertyNames() ; e.hasMoreElements() ;) { 165 String key=(String )e.nextElement(); 166 String value=ps.getProperty(key); 167 if (value!=null) 168 props.setProperty(key,value); 169 } 170 171 fillSetProps(packagesToNotAdapt, ps, toNotAdaptProp, false); 173 Iterator i = packagesToNotAdapt.iterator(); 174 packagesToNotAdaptRE.clear(); 175 while (i.hasNext()) { 176 String pkg = (String )i.next(); 177 try { 178 packagesToNotAdaptRE.add(new RE("^"+Strings.replace(Strings.replace(Strings.replace(pkg,"$","\\$"),".","\\."),"*",".*")+"$")); 179 } catch(REException e) { 180 logger.warn("RE exception: "+e); 181 } 182 } 183 184 fillSetProps(packagesToAdapt, ps, toAdaptProp, false); 186 i = packagesToAdapt.iterator(); 187 packagesToAdaptRE.clear(); 188 while (i.hasNext()) { 189 String pkg = (String )i.next(); 190 try { 191 packagesToAdaptRE.add(new RE("^"+Strings.replace(Strings.replace(Strings.replace(pkg,"$","\\$"),".","\\."),"*",".*")+"$")); 192 } catch(REException e) { 193 logger.warn("RE exception: "+e); 194 } 195 } 196 197 fillSetProps(packagesToWrap, ps, toWrapProp, true); 199 200 fillMapProps(wrappableMethods, ps, wrappableMethodsProp, 0, false); 202 203 fillSetProps(dontTranslateFields,ps,dontTranslateFieldsProp,false); 205 206 fillMapProps(declaredACs, ps, acsProp, 1, false); 208 209 fillListStringProps(wrappingOrder, ps, wrappingOrderProp, false); 211 212 fillListStringProps(dependentACs, ps, dependentACsProp, false); 213 214 fillListStringProps(incompatibleACs, ps, incompatibleACsProp, false); 215 216 tmp=fillStringProp(ps, compositionAspectProp); 217 if (tmp!=null) compositionAspect = tmp; 218 219 220 tmp= fillStringProp (ps, bytecodeModifierProp); 222 if (tmp!=null) bytecodeModifier = tmp; 223 224 225 tmp= fillStringProp (ps, remRefClassProp); 227 if (tmp!=null) bytecodeModifier = tmp; 228 229 tmp= fillStringProp (ps, namingClassProp); 231 if (tmp!=null) bytecodeModifier = tmp; 232 233 return true; 234 } 235 236 public static void loadProps(boolean d) { 237 loadProps(); 238 } 239 240 245 public static void loadProps() { 246 boolean propsInMemory = false; 247 249 260 261 if (!Strings.isEmpty(Jac.getJacRoot())) 266 propsInMemory |= addProps(getPropsFrom(Jac.getJacRoot(), propFileName)); 267 268 String directory; 269 directory = System.getProperty("JAC_ROOT",null); 270 if (directory != null) 271 propsInMemory |= addProps(getPropsFrom(directory, propFileName)); 272 273 274 directory = System.getProperty("user.home",null); 276 if (directory!=null) 277 propsInMemory|=addProps(getPropsFrom(directory, propFileName)); 278 279 propsInMemory |= addProps(getPropsFrom("./", propFileName)); 281 282 if (!propsInMemory) 285 { 286 logger.warn("Can not find the '"+propFileName+"' file."); 287 } 288 289 acs_count=declaredACs.size(); 290 if (bytecodeModifier == null) 291 bytecodeModifier = "BCEL"; 292 293 if (remoteRefClassName == null) 294 remoteRefClassName = remRefDefaultClassName; 295 296 if (namingClassName == null) 297 namingClassName = namingClassDefaultName; 298 } 299 300 303 public static boolean translateFields(String className) { 304 Iterator i = dontTranslateFields.iterator(); 305 while (i.hasNext()) { 306 try { 307 RE dontTranslate = new RE((String )i.next()); 308 logger.debug("Testing "+dontTranslate); 309 if (dontTranslate.isMatch(className)) { 310 logger.debug("Do not translate fields for "+className); 311 return false; 312 } 313 } catch (REException e) { 314 logger.warn("RE exception: "+e); 315 } 316 } 317 logger.debug("Translate fields for "+className); 318 return true; 319 } 320 321 324 public static boolean adaptClass(String className) { 325 logger.debug("Adapt class "+className+" ???"); 326 Iterator i = packagesToAdaptRE.iterator(); 327 while (i.hasNext()) { 328 RE regexp = (RE)i.next(); 329 logger.debug("Testing "+regexp); 330 if (regexp.isMatch(className)) { 331 logger.debug("Adapt "+className); 332 return true; 333 } 334 } 335 logger.debug("Do not force adaptation of "+className); 336 return false; 337 } 338 339 342 public static boolean doNotAdaptClass(String className) { 343 logger.debug("Do not adapt class "+className+" ???"); 344 Iterator i = packagesToNotAdaptRE.iterator(); 345 while (i.hasNext()) { 346 RE regexp = (RE)i.next(); 347 logger.debug("Testing "+regexp); 348 if (regexp.isMatch(className)) { 349 logger.debug("Do not adapt "+className); 350 return true; 351 } 352 } 353 logger.debug("Adaptation not disabled for "+className); 354 return false; 355 } 356 } 357 | Popular Tags |