You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ne...@apache.org on 2003/06/01 15:32:09 UTC
cvs commit: avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/factory BCELWrapperGenerator.java
neeme 2003/06/01 06:32:09
Modified: fortress/src/java/org/apache/avalon/fortress/impl/factory
BCELWrapperGenerator.java
Log:
replace the use of static Repository.lookupClass(String) with a threadcontext sensitive approach.
now uses current thread context classloader for loading classes.
previous approach didn't work in managed environments like JBoss.
Revision Changes Path
1.7 +21 -3 avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/factory/BCELWrapperGenerator.java
Index: BCELWrapperGenerator.java
===================================================================
RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/factory/BCELWrapperGenerator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BCELWrapperGenerator.java 31 May 2003 15:39:26 -0000 1.6
+++ BCELWrapperGenerator.java 1 Jun 2003 13:32:09 -0000 1.7
@@ -50,10 +50,11 @@
package org.apache.avalon.fortress.impl.factory;
import org.apache.bcel.Constants;
-import org.apache.bcel.Repository;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.ClassGen;
+import org.apache.bcel.util.ClassLoaderRepository;
+import org.apache.bcel.util.Repository;
/**
* Create the BCELWrapper for the component
@@ -66,6 +67,12 @@
{
/**
+ * The BCEL util.Repository instance to use when loading JavaClass instances.
+ * Default is to use util.ClassLoaderRepository with thread context classloader.
+ */
+ private Repository m_repository = null;
+
+ /**
* The suffix to be appended to the name of the wrapped class when creating
* the name of the wrapper class.
*/
@@ -208,8 +215,11 @@
public BCELWrapperGenerator()
{
m_codeGenerator = new BCELCodeGenerator();
+ ClassLoader contextClassLoader =
+ Thread.currentThread().getContextClassLoader();
+ m_repository = new ClassLoaderRepository( contextClassLoader );
m_bcelClassLoader =
- new BCELClassLoader( Thread.currentThread().getContextClassLoader() );
+ new BCELClassLoader( contextClassLoader );
}
/**
@@ -277,7 +287,15 @@
*/
private JavaClass lookupClass( final Class clazz ) throws Exception
{
- return Repository.lookupClass( clazz.getName() );
+ String className = clazz.getName();
+ try
+ {
+ JavaClass jClazz = m_repository.findClass( className );
+ if ( jClazz == null )
+ return m_repository.loadClass( className );
+ else
+ return jClazz;
+ } catch ( ClassNotFoundException e ) { return null; }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org