gdaniels 02/02/18 15:44:17
Modified: java build.xml
java/src/org/apache/axis/utils JWSClassLoader.java
java/src/org/apache/axis/utils/compiler
AbstractCompiler.java
java/src/org/apache/axis/wsdl/fromJava ClassRep.java
Added: java/lib tt-bytecode.jar
Log:
BCEL -> tt-bytecode
Use tt-bytecode library (http://tt-bytecode.sf.net) instead of BCEL because
a) it's half the size, and b) it can create ByteCode-capable objects from
java.lang.Classes without classloader problems.
- Change JWSClassLoader to customize getResourceAsStream() so we
return the right bytes.
- Add "-g" arg to default compiler args in AbstractCompiler
- Revamp ClassRep to use tt-bytecode APIs
- Adjust build.xml to match
Revision Changes Path
1.109 +5 -5 xml-axis/java/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-axis/java/build.xml,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- build.xml 15 Feb 2002 22:02:19 -0000 1.108
+++ build.xml 18 Feb 2002 23:44:17 -0000 1.109
@@ -78,7 +78,7 @@
<property name="wsdl4j.jar" value="lib/wsdl4j.jar"/>
<property name="log4j-core.jar" value="lib/log4j-core.jar"/>
<property name="clutil.jar" value="lib/clutil.jar"/>
- <property name="bcel.jar" value="lib/bcel.jar"/>
+ <property name="tt-bytecode.jar" value="lib/tt-bytecode.jar"/>
<property name="junit.jar" value="lib/junit.jar"/>
@@ -138,8 +138,8 @@
classname="org.apache.avalon.excalibur.cli.CLUtil"
classpathref="classpath"/>
- <available property="bcel.present"
- classname="org.apache.bcel.Repository"
+ <available property="tt-bytecode.present"
+ classname="com.techtrader.modules.tools.bytecode.BCClass"
classpathref="classpath"/>
<available property="activation.present"
@@ -179,7 +179,7 @@
<echo message="wsdl4j.present=${wsdl4j.present}" />
<echo message="log4j.present=${log4j.present}" />
<echo message="clutil.present=${clutil.present}" />
- <echo message="bcel.present=${bcel.present}" />
+ <echo message="tt-bytecode.present=${tt-bytecode.present}" />
<echo message=""/>
<echo message="--- Optional Libraries ---" />
<echo message="servlet.present=${servlet.present}" />
@@ -256,7 +256,7 @@
<copy file="${wsdl4j.jar}" toDir="${build.lib}"/>
<copy file="${log4j-core.jar}" toDir="${build.lib}"/>
<copy file="${clutil.jar}" toDir="${build.lib}"/>
- <copy file="${bcel.jar}" toDir="${build.lib}"/>
+ <copy file="${tt-bytecode.jar}" toDir="${build.lib}"/>
<antcall target="post-compile"/>
</target>
1.1 xml-axis/java/lib/tt-bytecode.jar
<<Binary file>>
1.2 +25 -4 xml-axis/java/src/org/apache/axis/utils/JWSClassLoader.java
Index: JWSClassLoader.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/JWSClassLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JWSClassLoader.java 8 Feb 2002 03:09:26 -0000 1.1
+++ JWSClassLoader.java 18 Feb 2002 23:44:17 -0000 1.2
@@ -55,10 +55,7 @@
package org.apache.axis.utils;
import java.util.Hashtable;
-import java.io.FileInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.*;
/**
* Class loader for JWS files. There is one of these per JWS class, and
@@ -74,6 +71,9 @@
public class JWSClassLoader extends ClassLoader {
private static Hashtable classloaders = new Hashtable();
+ private String classFile = null;
+ private String name = null;
+
/**
* Construct a JWSClassLoader with a class name, a parent ClassLoader,
* and a filename of a .class file containing the bytecode for the class.
@@ -91,6 +91,9 @@
{
super(cl);
+ this.name = name + ".class";
+ this.classFile = classFile;
+
FileInputStream fis = new FileInputStream( classFile );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
@@ -127,5 +130,23 @@
public static void removeClassLoader(String className)
{
classloaders.remove(className);
+ }
+
+ /**
+ * Overloaded getResourceAsStream() so we can be sure to return the
+ * correct class file regardless of where it might live on our hard
+ * drive.
+ *
+ * @param resourceName the resource to load (should be "classname.class")
+ * @return an InputStream of the class bytes, or null
+ */
+ public InputStream getResourceAsStream(String resourceName) {
+ try {
+ if (resourceName.equals(name))
+ return new FileInputStream( classFile );
+ } catch (FileNotFoundException e) {
+ // Fall through, return null.
+ }
+ return null;
}
}
1.2 +4 -1
xml-axis/java/src/org/apache/axis/utils/compiler/AbstractCompiler.java
Index: AbstractCompiler.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/utils/compiler/AbstractCompiler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractCompiler.java 10 Dec 2001 22:25:53 -0000 1.1
+++ AbstractCompiler.java 18 Feb 2002 23:44:17 -0000 1.2
@@ -65,7 +65,7 @@
* This class implements the functionality common to all Java compilers.
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/18 23:44:17 $
* @since 2.0
*/
public abstract class AbstractCompiler implements Compiler {
@@ -193,6 +193,9 @@
// add optimization (for what is worth)
arguments.add("-O");
+
+ // add debug option
+ arguments.add("-g");
// add encoding if set
if (encoding != null) {
1.15 +54 -38 xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java
Index: ClassRep.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/ClassRep.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ClassRep.java 14 Feb 2002 22:46:34 -0000 1.14
+++ ClassRep.java 18 Feb 2002 23:44:17 -0000 1.15
@@ -54,19 +54,21 @@
*/
package org.apache.axis.wsdl.fromJava;
-import java.lang.reflect.Constructor;
+import com.techtrader.modules.tools.bytecode.BCClass;
+import com.techtrader.modules.tools.bytecode.BCMethod;
+import com.techtrader.modules.tools.bytecode.Code;
+import com.techtrader.modules.tools.bytecode.Constants;
+import com.techtrader.modules.tools.bytecode.LocalVariable;
+import com.techtrader.modules.tools.bytecode.LocalVariableTableAttribute;
+import org.apache.axis.utils.JavaUtils;
+import org.apache.axis.wsdl.Skeleton;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.Field;
-import java.util.Vector;
import java.util.HashMap;
-
-import org.apache.axis.utils.JavaUtils;
-import org.apache.axis.wsdl.Skeleton;
-import org.apache.bcel.classfile.JavaClass;
-import org.apache.bcel.classfile.LocalVariableTable;
-import org.apache.bcel.classfile.LocalVariable;
-import org.apache.bcel.Repository;
+import java.util.Vector;
/**
* ClassRep is the representation of a class used inside the Java2WSDL
@@ -590,39 +592,53 @@
public String[] getParameterNames(java.lang.reflect.Method method) {
Class c = method.getDeclaringClass();
int numParams = method.getParameterTypes().length;
-
+
+ // Don't worry about it if there are no params.
if (numParams == 0)
return null;
-
- JavaClass jc = Repository.lookupClass(c.getName());
- if (jc == null)
+
+ // Try to make a tt-bytecode
+ BCMethod bmeth = null;
+ BCClass bclass = null;
+ try {
+ bclass = new BCClass(c);
+ } catch (IOException e) {
+ return null; // no dice
+ }
+
+ // Obtain the exact method we're interested in.
+ bmeth = bclass.getMethod(method.getName(), method.getParameterTypes());
+
+ if (bmeth == null)
return null;
- org.apache.bcel.classfile.Method [] methods = jc.getMethods();
- for (int i = 0; i < methods.length; i++) {
- org.apache.bcel.classfile.Method meth = methods[i];
- if (!meth.getName().equals(method.getName()))
- continue;
-
- LocalVariableTable lt = meth.getLocalVariableTable();
- if (lt == null)
- continue;
- LocalVariable [] vars = lt.getLocalVariableTable();
- if (vars.length == numParams + 1) {
- String [] argNames = new String[numParams + 1];
- argNames[0] = null; // don't know return name
- int idx = 1;
- // This is it? Check types?
- for (int j = 0; j < vars.length; j++) {
- LocalVariable var = vars[j];
- if (var.getName().equals("this"))
- continue;
- argNames[var.getIndex()] = var.getName();
- }
- return argNames;
+
+ // Get the Code object, which contains the local variable table.
+ Code code = bmeth.getCode();
+ LocalVariableTableAttribute attr =
+
(LocalVariableTableAttribute)code.getAttribute(Constants.ATTR_LOCALS);
+
+ if (attr == null)
+ return null;
+
+ // OK, found it. Now scan through the local variables and record
+ // the names in the right indices.
+ LocalVariable [] vars = attr.getLocalVariables();
+
+ String [] argNames = new String[numParams + 1];
+ argNames[0] = null; // don't know return name
+
+ // NOTE: we scan through all the variables here, because I have been
+ // told that jikes sometimes produces unpredictable ordering of the
+ // local variable table.
+ for (int j = 0; j < vars.length; j++) {
+ LocalVariable var = vars[j];
+ if (var.getIndex() <= numParams) {
+ if (var.getName().equals("this"))
+ continue;
+ argNames[var.getIndex()] = var.getName();
}
}
-
- return null;
+ return argNames;
}
};