@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2011 the original author or authors .
* Copyright 2002 - 20 11 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -23,26 +23,24 @@ import java.security.CodeSource;
@@ -23,26 +23,24 @@ import java.security.CodeSource;
import org.springframework.util.FileCopyUtils ;
/ * *
* Adapter that implements WebSphere 7 . 0 ClassPreProcessPlugin interface , delegating to a
* standard JDK { @link ClassFileTransformer } underneath .
* Adapter that implements WebSphere 7 . 0 ClassPreProcessPlugin interface ,
* delegating to a standard JDK { @link ClassFileTransformer } underneath .
*
* < p > To avoid compile time checks again the vendor API , a dynamic proxy is
* being used .
*
* @author Costin Leau
* @since 3 . 1
* /
class WebSphereClassPreDefinePlugin implements InvocationHandler {
private final ClassFileTransformer transformer ;
private class Dummy {
}
/ * *
* Creates a new { @link WebSphereClassPreDefinePlugin } .
*
* @param transformer the { @link ClassFileTransformer } to be adapted ( must
* not be < code > null < / code > )
* Create a new { @link WebSphereClassPreDefinePlugin } .
* @param transformer the { @link ClassFileTransformer } to be adapted
* ( must not be < code > null < / code > )
* /
public WebSphereClassPreDefinePlugin ( ClassFileTransformer transformer ) {
this . transformer = transformer ;
@ -53,33 +51,37 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
@@ -53,33 +51,37 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
String dummyClass = Dummy . class . getName ( ) . replace ( '.' , '/' ) ;
byte [ ] bytes = FileCopyUtils . copyToByteArray ( classLoader . getResourceAsStream ( dummyClass + ".class" ) ) ;
transformer . transform ( classLoader , dummyClass , null , null , bytes ) ;
} catch ( Throwable ex ) {
}
catch ( Throwable ex ) {
throw new IllegalArgumentException ( "Cannot load transformer" , ex ) ;
}
}
public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable {
String name = method . getName ( ) ;
if ( "equals" . equals ( name ) ) {
return ( Boolean . valueOf ( proxy = = args [ 0 ] ) ) ;
} else if ( "hashCode" . equals ( name ) ) {
return ( proxy = = args [ 0 ] ) ;
}
else if ( "hashCode" . equals ( name ) ) {
return hashCode ( ) ;
} else if ( "toString" . equals ( name ) ) {
}
else if ( "toString" . equals ( name ) ) {
return toString ( ) ;
} else if ( "transformClass" . equals ( name ) ) {
}
else if ( "transformClass" . equals ( name ) ) {
return transform ( ( String ) args [ 0 ] , ( byte [ ] ) args [ 1 ] , ( CodeSource ) args [ 2 ] , ( ClassLoader ) args [ 3 ] ) ;
} else {
}
else {
throw new IllegalArgumentException ( "Unknown method: " + method ) ;
}
}
public byte [ ] transform ( String className , byte [ ] classfileBuffer , CodeSource codeSource , ClassLoader classLoader )
protected byte [ ] transform ( String className , byte [ ] classfileBuffer , CodeSource codeSource , ClassLoader classLoader )
throws Exception {
// NB: WebSphere passes className as "." without class while the
// transformer expects a VM, "/" format
byte [ ] result = transformer . transform ( classLoader , className . replace ( '.' , '/' ) , null , null , classfileBuffer ) ;
// NB: WebSphere passes className as "." without class while the transformer expects a VM, "/" format
byte [ ] result = transformer . transform ( classLoader , className . replace ( '.' , '/' ) , null , null , classfileBuffer ) ;
return ( result ! = null ? result : classfileBuffer ) ;
}
@ -90,4 +92,9 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
@@ -90,4 +92,9 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
builder . append ( this . transformer ) ;
return builder . toString ( ) ;
}
}
private static class Dummy {
}
}