private List<String> includeExactName = new ArrayList<String>();
private boolean includeStar = false;
- private List m_aspectExcludeTypePattern = new ArrayList();
- private List m_aspectExcludeStartsWith = new ArrayList();
- private List m_aspectIncludeTypePattern = new ArrayList();
- private List m_aspectIncludeStartsWith = new ArrayList();
+ private List<TypePattern> m_aspectExcludeTypePattern = new ArrayList<TypePattern>();
+ private List<String> m_aspectExcludeStartsWith = new ArrayList<String>();
+ private List<TypePattern> m_aspectIncludeTypePattern = new ArrayList<TypePattern>();
+ private List<String> m_aspectIncludeStartsWith = new ArrayList<String>();
private StringBuffer namespace;
private IWeavingContext weavingContext;
* @param weaver
* @param loader
*/
- List parseDefinitions(final ClassLoader loader) {
+ List<Definition> parseDefinitions(final ClassLoader loader) {
if (trace.isTraceEnabled()) {
trace.enter("parseDefinitions", this);
}
- List definitions = new ArrayList();
+ List<Definition> definitions = new ArrayList<Definition>();
try {
info("register classloader " + getClassLoaderName(loader));
// TODO av underoptimized: we will parse each XML once per CL that see it
error("malformed definition url: " + nextDefinition);
}
} else {
- Enumeration xmls = weavingContext.getResources(nextDefinition);
+ Enumeration<URL> xmls = weavingContext.getResources(nextDefinition);
// System.out.println("? registerDefinitions: found-aop.xml=" + xmls.hasMoreElements() + ", loader=" + loader);
- Set seenBefore = new HashSet();
+ Set<URL> seenBefore = new HashSet<URL>();
while (xmls.hasMoreElements()) {
- URL xml = (URL) xmls.nextElement();
+ URL xml = xmls.nextElement();
if (trace.isTraceEnabled()) {
trace.event("parseDefinitions", this, xml);
}
return definitions;
}
- private boolean registerDefinitions(final BcelWeaver weaver, final ClassLoader loader, List definitions) {
+ private boolean registerDefinitions(final BcelWeaver weaver, final ClassLoader loader, List<Definition> definitions) {
if (trace.isTraceEnabled()) {
trace.enter("registerDefinitions", this, definitions);
}
// TODO proceedOnError option
}
- private void registerAspectExclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
+ private void registerAspectExclude(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
String fastMatchInfo = null;
- for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
- Definition definition = (Definition) iterator.next();
- for (Iterator iterator1 = definition.getAspectExcludePatterns().iterator(); iterator1.hasNext();) {
- String exclude = (String) iterator1.next();
+ for (Definition definition : definitions) {
+ for (String exclude : definition.getAspectExcludePatterns()) {
TypePattern excludePattern = new PatternParser(exclude).parseTypePattern();
m_aspectExcludeTypePattern.add(excludePattern);
fastMatchInfo = looksLikeStartsWith(exclude);
}
}
- private void registerAspectInclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
+ private void registerAspectInclude(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
String fastMatchInfo = null;
- for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
- Definition definition = (Definition) iterator.next();
- for (Iterator iterator1 = definition.getAspectIncludePatterns().iterator(); iterator1.hasNext();) {
- String include = (String) iterator1.next();
+ for (Definition definition : definitions) {
+ for (String include : definition.getAspectIncludePatterns()) {
TypePattern includePattern = new PatternParser(include).parseTypePattern();
m_aspectIncludeTypePattern.add(includePattern);
fastMatchInfo = looksLikeStartsWith(include);
* @param loader
* @param definitions
*/
- private boolean registerAspects(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
+ private boolean registerAspects(final BcelWeaver weaver, final ClassLoader loader, final List<Definition> definitions) {
if (trace.isTraceEnabled()) {
trace.enter("registerAspects", this, new Object[] { weaver, loader, definitions });
}
// iterate aspectClassNames
// exclude if in any of the exclude list
- for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
- Definition definition = (Definition) iterator.next();
- for (Iterator aspects = definition.getAspectClassNames().iterator(); aspects.hasNext();) {
- String aspectClassName = (String) aspects.next();
+ for (Definition definition : definitions) {
+ for (String aspectClassName : definition.getAspectClassNames()) {
if (acceptAspect(aspectClassName)) {
info("register aspect " + aspectClassName);
// System.err.println("? ClassLoaderWeavingAdaptor.registerAspects() aspectName=" + aspectClassName +
// ", loader=" + loader + ", bundle=" + weavingContext.getClassLoaderName());
- /* ResolvedType aspect = */weaver.addLibraryAspect(aspectClassName);
+ // ResolvedType aspect =
+ weaver.addLibraryAspect(aspectClassName);
// generate key for SC
if (namespace == null) {
namespace = new StringBuffer(aspectClassName);
} else {
- namespace = namespace.append(";" + aspectClassName);
+ namespace = namespace.append(";").append(aspectClassName);
+ }
+
+ String definedScope = definition.getScopeForAspect(aspectClassName);
+ if (definedScope != null) {
+ ((BcelWorld) weaver.getWorld()).addScopedAspect(aspectClassName, definedScope);
}
} else {
// warn("aspect excluded: " + aspectClassName);
// iterate concreteAspects
// exclude if in any of the exclude list - note that the user defined name matters for that to happen
- for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
- Definition definition = (Definition) iterator.next();
+ for (Definition definition : definitions) {
for (Definition.ConcreteAspect concreteAspect : definition.getConcreteAspects()) {
if (acceptAspect(concreteAspect.name)) {
info("define aspect " + concreteAspect.name);
// EXCLUDE: if one match then reject
String fastClassName = aspectClassName.replace('/', '.').replace('.', '$');
for (int i = 0; i < m_aspectExcludeStartsWith.size(); i++) {
- if (fastClassName.startsWith((String) m_aspectExcludeStartsWith.get(i))) {
+ if (fastClassName.startsWith(m_aspectExcludeStartsWith.get(i))) {
return false;
}
}
// INCLUDE: if one match then accept
for (int i = 0; i < m_aspectIncludeStartsWith.size(); i++) {
- if (fastClassName.startsWith((String) m_aspectIncludeStartsWith.get(i))) {
+ if (fastClassName.startsWith(m_aspectIncludeStartsWith.get(i))) {
return true;
}
}
import java.util.List;
import org.aspectj.weaver.bcel.BcelWeakClassLoaderReference;
+import org.aspectj.weaver.loadtime.definition.Definition;
import org.aspectj.weaver.tools.Trace;
import org.aspectj.weaver.tools.TraceFactory;
import org.aspectj.weaver.tools.WeavingAdaptor;
private static Trace trace = TraceFactory.getTraceFactory().getTrace(DefaultWeavingContext.class);
/**
- * Construct a new WeavingContext to use the specified ClassLoader
- * This is the constructor which should be used.
+ * Construct a new WeavingContext to use the specified ClassLoader This is the constructor which should be used.
+ *
* @param loader
*/
public DefaultWeavingContext(ClassLoader loader) {
*/
public String getClassLoaderName() {
ClassLoader loader = getClassLoader();
- return ((loader!=null)?loader.getClass().getName()+"@"+Integer.toHexString(System.identityHashCode(loader)):"null");
+ return ((loader != null) ? loader.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(loader))
+ : "null");
}
-
- public ClassLoader getClassLoader() {
+ public ClassLoader getClassLoader() {
return loaderRef.getClassLoader();
}
* @return filename
*/
public String getFile(URL url) {
- return url.getFile();
+ return url.getFile();
}
/**
- * @return unqualifiedclassname@hashcode
+ * @return unqualifiedclassname@hashcode
*/
- public String getId () {
+ public String getId() {
if (shortName == null) {
- shortName = getClassLoaderName().replace('$','.');
+ shortName = getClassLoaderName().replace('$', '.');
int index = shortName.lastIndexOf(".");
- if (index!=-1) {
+ if (index != -1) {
shortName = shortName.substring(index + 1);
}
}
return shortName;
}
-
- public String getSuffix () {
+
+ public String getSuffix() {
return getClassLoaderName();
}
public boolean isLocallyDefined(String classname) {
- String asResource = classname.replace('.', '/').concat(".class");
- ClassLoader loader = getClassLoader();
- URL localURL = loader.getResource(asResource);
- if (localURL == null) return false;
+ String asResource = classname.replace('.', '/').concat(".class");
+ ClassLoader loader = getClassLoader();
+ URL localURL = loader.getResource(asResource);
+ if (localURL == null) {
+ return false;
+ }
boolean isLocallyDefined = true;
-
- ClassLoader parent = loader.getParent();
- if (parent != null) {
- URL parentURL = parent.getResource(asResource);
- if (localURL.equals(parentURL)) isLocallyDefined = false;
- }
- return isLocallyDefined;
+
+ ClassLoader parent = loader.getParent();
+ if (parent != null) {
+ URL parentURL = parent.getResource(asResource);
+ if (localURL.equals(parentURL)) {
+ isLocallyDefined = false;
+ }
+ }
+ return isLocallyDefined;
}
/**
* Simply call weaving adaptor back to parse aop.xml
- *
+ *
* @param weaver
* @param loader
*/
- public List getDefinitions(final ClassLoader loader, final WeavingAdaptor adaptor) {
- if (trace.isTraceEnabled()) trace.enter("getDefinitions", this, new Object[] { "goo", adaptor });
-
- List definitions = ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
-
- if (trace.isTraceEnabled()) trace.exit("getDefinitions",definitions);
- return definitions;
- }
+ public List<Definition> getDefinitions(final ClassLoader loader, final WeavingAdaptor adaptor) {
+ if (trace.isTraceEnabled()) {
+ trace.enter("getDefinitions", this, new Object[] { "goo", adaptor });
+ }
+
+ List<Definition> definitions = ((ClassLoaderWeavingAdaptor) adaptor).parseDefinitions(loader);
+
+ if (trace.isTraceEnabled()) {
+ trace.exit("getDefinitions", definitions);
+ }
+ return definitions;
+ }
}