001 package org.shiftone.jrat.core.config;
002
003 import org.shiftone.jrat.core.criteria.*;
004 import org.shiftone.jrat.util.log.Logger;
005 import org.shiftone.jrat.util.regex.GlobMatcher;
006
007 import java.util.ArrayList;
008 import java.util.List;
009
010
011 /**
012 * This class represents the overall configuration of which handlers should be
013 * associated to which methods/classes. The MethodCriteria methods on this
014 * class can be used to determine what classes and methods jrat cares about
015 * at a high level - perhaps to govern the behavior of injection.
016 *
017 * @author jeff@shiftone.org (Jeff Drost)
018 */
019 public class Configuration implements MethodCriteria {
020
021 private static final Logger LOG = Logger.getLogger(Configuration.class);
022 private Settings settings = new Settings();
023 private AndMethodCriteria methodCriteria = new AndMethodCriteria();
024 private OrMethodCriteria profilesCriteria = new OrMethodCriteria();
025 private OrMethodCriteria excludeCriteria = new OrMethodCriteria();
026 private List profiles = new ArrayList();
027
028
029 public Configuration() {
030
031 methodCriteria.addCriteria(profilesCriteria);
032 methodCriteria.addCriteria(new NotMethodCriteria(excludeCriteria));
033 // addClassExclude("bsh.*");
034 // addClassExclude("com.sun.*");
035 // addClassExclude("EDU.oswego.*");
036 // addClassExclude("gnu.*");
037 // addClassExclude("org.apache.*");
038 // addClassExclude("org.dom4j.*");
039 // addClassExclude("org.hsqldb.*");
040 // addClassExclude("org.jboss.*");
041 // addClassExclude("org.jnp.*");
042 // addClassExclude("$Proxy*");
043 addClassExclude("java.*");
044 addClassExclude("javax.*");
045 }
046
047 protected void addClassExclude(String className) {
048
049 LOG.info("exclude " + className);
050
051 excludeCriteria.addCriteria(
052 new ClassMatcherMethodCriteria(
053 new GlobMatcher(className)
054 )
055 );
056 }
057
058 protected Profile createProfile() {
059 Profile profile = new Profile();
060 profiles.add(profile);
061 profilesCriteria.addCriteria(profile);
062 return profile;
063 }
064
065
066 public boolean isMatch(String className, long modifier) {
067 return methodCriteria.isMatch(className, modifier);
068 }
069
070 public boolean isMatch(String className, String methodName, String signature, long modifier) {
071 return methodCriteria.isMatch(className, methodName, signature, modifier);
072 }
073
074
075 protected List getProfiles() {
076 return profiles;
077 }
078
079 public Settings getSettings() {
080 return settings;
081 }
082
083 }