}
};
- List definitions = parseDefinitions(classLoader);
+ List definitions = weavingContext.getDefinitions(classLoader,this);
if (definitions.isEmpty()) {
disable(); // TODO maw Needed to ensure messages are flushed
if (trace.isTraceEnabled()) trace.exit("initialize",definitions);
* @param weaver
* @param loader
*/
- private List parseDefinitions(final ClassLoader loader) {
+ List parseDefinitions(final ClassLoader loader) {
if (trace.isTraceEnabled()) trace.enter("parseDefinitions",this,loader);
List definitions = new ArrayList();
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
+import java.util.List;
+
+import org.aspectj.weaver.tools.Trace;
+import org.aspectj.weaver.tools.TraceFactory;
+import org.aspectj.weaver.tools.WeavingAdaptor;
/**
* Use in non-OSGi environment
* @author David Knibb
*/
public class DefaultWeavingContext implements IWeavingContext {
-
+
protected ClassLoader loader;
-
private String shortName;
+ private static Trace trace = TraceFactory.getTraceFactory().getTrace(DefaultWeavingContext.class);
+
/**
* Construct a new WeavingContext to use the specifed ClassLoader
* This is the constructor which should be used.
* @param loader
*/
public DefaultWeavingContext(ClassLoader loader) {
+ super();
this.loader = loader;
}
}
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[] { loader, adaptor });
+
+ List definitions = ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
+
+ if (trace.isTraceEnabled()) trace.exit("getDefinitions",definitions);
+ return definitions;
+ }
}
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Enumeration;
+import java.util.List;
import junit.framework.TestCase;
+import org.aspectj.weaver.tools.WeavingAdaptor;
+
public class WeavingContextTest extends TestCase {
private boolean called;
assertTrue("IWeavingContext not called",called);
}
+ public void testGetDefinitions () throws Exception {
+ File file = new File("../loadtime/testdata");
+ URL fileURL = file.getCanonicalFile().toURL();
+ URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null);
+ IWeavingContext context = new TestWeavingContext(loader) {
+
+ public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+ called = true;
+ return super.getDefinitions(loader,adaptor);
+ }
+
+ };
+ ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+ adaptor.initialize(loader,context);
+
+ assertTrue("getDefinitions not called",called);
+ }
+
private static class TestWeavingContext implements IWeavingContext {
private ClassLoader loader;
}
return isLocallyDefined;
}
+
+ public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+ return ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
+ }
}
protected void setUp() throws Exception {