commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Art Gramlich <...@gramlich-net.com>
Subject [javaflow] Transforming classes that implement Continuable
Date Mon, 21 Feb 2005 04:39:32 GMT
While playing with javaflow, I found out the hard way that the  
ContinuationClassLoader
is only transforming java that is in a certain package.  I made this  
patch to transform
classes that implement Continuable and leave the others alone.  This  
seems like the
correct way to do it, but I may be missing consequences of doing it  
this way.

Art Gramlich



Index:  
org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java
===================================================================
---  
src/java/org/apache/commons/javaflow/bytecode/bcel/ 
BcelClassTransformer.java	(revision 154619)
+++  
src/java/org/apache/commons/javaflow/bytecode/bcel/ 
BcelClassTransformer.java	(working copy)
@@ -100,6 +100,22 @@

      private boolean currentMethodStatic = false;
      private boolean debug = true;
+
+    private boolean implementsContinuable(JavaClass javaClazz) {
+        boolean continuable = false;
+        try {
+            JavaClass[] interfaces = javaClazz.getAllInterfaces();
+            for (int i=0; i<interfaces.length; i++) {
+                 if  
(CONTINUABLE_CLASS.equals(interfaces[i].getClassName())) {
+                     continuable = true;
+                     break;
+                 }
+            }
+        } catch (ClassNotFoundException e) {
+            log.error(e.getMessage(),e);
+        }
+        return continuable;
+    }

      public byte[] transform(final InputStream is) {

@@ -115,6 +131,10 @@

          Repository.addClass(javaClazz);

+        if (!implementsContinuable(javaClazz)) {
+            return javaClazz.getBytes();	
+        }
+

          log.debug("transforming class " + javaClazz.getClassName());

Index: org/apache/commons/javaflow/ContinuationClassLoader.java
===================================================================
---  
src/java/org/apache/commons/javaflow/ContinuationClassLoader.java	 
(revision 154619)
+++  
src/java/org/apache/commons/javaflow/ContinuationClassLoader.java	 
(working copy)
@@ -15,10 +15,8 @@
   */
  package org.apache.commons.javaflow;

-import java.io.IOException;
  import java.io.InputStream;

-import org.apache.commons.io.IOUtils;
  import org.apache.commons.javaflow.bytecode.ClassTransformer;
  import org.apache.commons.javaflow.bytecode.bcel.BcelClassTransformer;
  import org.apache.commons.logging.Log;
@@ -56,23 +54,8 @@
                  final InputStream is =  
super.getResourceAsStream(name.replace('.','/') + ".class");

                  if (is != null) {
-
-                    if  
(name.startsWith("org.apache.commons.javaflow.testcode")) {
-                        //log.debug("transforming " + name);
-
-                        final byte data[] = transformer.transform(is);
-                        return defineClass(name, data, 0, data.length);
-                    }
-
-                    try {
-                        final byte data[] = IOUtils.toByteArray(is);
-
-                        //log.debug("loading "+ name);
-
-                        return defineClass(name, data, 0, data.length);
-                    } catch (final IOException e) {
-                        throw new ClassNotFoundException("could not  
read class", e);
-                    }
+                    final byte data[] = transformer.transform(is);
+                    return defineClass(name, data, 0, data.length);
                  } else {
                      log.debug("could not find " + name);
                  }


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message