On Tue, Feb 22, 2005 at 08:08:01PM -0500, WHIRLYCOTT wrote:
> Torsten Curdt wrote:
>
> >While I did some work with ASM I found it
> >very nice to work with ...and so I wanted
> >get rid of a direct BCEL dependency. Which
>
> Fyi, I'm working on porting the current BCEL ClassTransformer over to ASM.
>
> >...but for now I think rewriting on the
> >package name is quite a useable alternative
> >that probably will fit the real world
> >requirements.
>
> You have mentioned this before, but I don't understand how you envision
> this working. Does this mean that a class originally in package
> com.foo.abc would be rewritten to rewritten.package.name by the
> transformer? I'm fairly sure that I am not interpreting your idea
> correctly because this will almost certainly cause problems for
> instances of that class if they need to access package protected methods
> and fields in other classes. If you could go into a bit of detail on
> this, it would be super.
Sorry if I butt in. What we were talking about is how to decide is a class
should be transformed. Right now, the ContinuationClassLoader is checking if
the package name starts with "org.apache.commons.javaflow.testcode" and transforms
it. Just for giggles, I just did a little patch to make that configurable (and a set).
Any opinions?
Art Gramlich
Index: java/org/apache/commons/javaflow/ContinuationClassLoader.java
===================================================================
--- src/java/org/apache/commons/javaflow/ContinuationClassLoader.java (revision 155031)
+++ src/java/org/apache/commons/javaflow/ContinuationClassLoader.java (working copy)
@@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.apache.commons.javaflow.bytecode.ClassTransformer;
@@ -33,10 +34,31 @@
private final static Log log = LogFactory.getLog(ContinuationCompilingClassLoader.class);
private ClassTransformer transformer = new BcelClassTransformer();
+ private Set packagesToTransform;
+ /*
public ContinuationClassLoader(ClassLoader parent) {
+ this(parent, new HashSet());
+ }
+ */
+
+ public ContinuationClassLoader(ClassLoader parent, Set packageNamesToTransform) {
super(parent);
//Repository.setRepository(new ClassLoaderRepository(parent));
+ packagesToTransform = packageNamesToTransform;
+ }
+
+ protected boolean shouldTransform(String name) {
+ int index = name.lastIndexOf('.');
+ String packageName;
+ if (index == -1) {
+ // If the class is in the default package, give the package name a single '.'
+ packageName = ".";
+ } else {
+ packageName = name.substring(0,index);
+ }
+ //log.debug("Checking if we should transform "+packageName);
+ return packagesToTransform.contains(packageName);
}
protected synchronized Class loadClass(String name, boolean resolve)
@@ -57,7 +79,7 @@
if (is != null) {
- if (name.startsWith("org.apache.commons.javaflow.testcode")) {
+ if (shouldTransform(name)) {
//log.debug("transforming " + name);
final byte data[] = transformer.transform(is);
Index: test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java
===================================================================
--- src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java (revision 155031)
+++ src/test/org/apache/commons/javaflow/AbstractClassLoaderTestCase.java (working copy)
@@ -16,7 +16,9 @@
package org.apache.commons.javaflow;
import java.lang.reflect.Method;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
@@ -35,7 +37,9 @@
}
protected void call(final String methodName) throws Exception {
- final ClassLoader cl = new ContinuationClassLoader(getClass().getClassLoader());
+ Set packages = new HashSet();
+ packages.add("org.apache.commons.javaflow.testcode");
+ final ClassLoader cl = new ContinuationClassLoader(getClass().getClassLoader(),
packages);
final Class clazz = cl.loadClass(clazzName);
final Object instance = clazz.newInstance();
assertNotNull(clazz);
>
> phil.
>
> --
> Whirlycott
> Philip Jacob
> phil@whirlycott.com
> http://www.whirlycott.com/phil/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
|