Package kilim
Class WeavingClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- kilim.KilimClassLoader
-
- kilim.WeavingClassLoader
-
public class WeavingClassLoader extends KilimClassLoader
Classloader that loads classes from the classpath spec given by the system property "kilim.class.path" and weaves them dynamically.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceWeavingClassLoader.Excludable
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.net.URL,java.security.ProtectionDomain>cacheprivate WeavingClassLoader.Excludablecheckerstatic java.lang.StringKILIM_CLASSPATH(package private) java.lang.ClassLoaderpcl(package private) static java.lang.ClassLoaderplatform(package private) java.net.URLClassLoaderproxy(package private) Weaverweaver
-
Constructor Summary
Constructors Constructor Description WeavingClassLoader()WeavingClassLoader(java.lang.ClassLoader loader, java.net.URLClassLoader $proxy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class<?>define(java.lang.String name, byte[] code)private java.lang.ClassdefineAll(java.lang.String name, ClassWeaver cw)WeavingClassLoaderexclude(WeavingClassLoader.Excludable exclude)replace the exclude filter which determines whether a named class should be defined definitively by this loader or instead delegated to the parent loader.protected java.lang.Class<?>findClass(java.lang.String name)static byte[]findCode(java.lang.ClassLoader loader, java.lang.String name)read bytecode for the named class from a source classloaderprivate java.security.ProtectionDomainget(java.lang.String name)static java.io.InputStreamgetByteStream(java.lang.ClassLoader cl, java.lang.String name, java.lang.String cname, boolean system)private static java.net.URLClassLoadergetProxy()java.io.InputStreamgetResourceAsStream(java.lang.String cname)static java.net.URL[]getURLs(java.lang.String[] classPaths)java.lang.Class<?>loadClass(java.lang.String name, boolean resolve)static java.lang.StringmakeResourceName(java.lang.String name)convert a fully qualified class name to a resource name.private booleanproxy(java.lang.String cname)static byte[]readFully(java.io.InputStream is)static byte[]readFully(FileLister.Entry fe)voidrun(java.lang.String className, java.lang.String method, java.lang.String... args)run static method className.method(args) using reflection and this WeavingClassLoaderstatic java.lang.StringunmakeResourceName(java.lang.String cname)java.net.URLurl(java.lang.String name)ClassWeaverweaveClass(java.lang.String name)load the bytecode for a class of a given name from the classpath and weave it-
Methods inherited from class kilim.KilimClassLoader
isLoaded
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
KILIM_CLASSPATH
public static final java.lang.String KILIM_CLASSPATH
- See Also:
- Constant Field Values
-
weaver
Weaver weaver
-
proxy
java.net.URLClassLoader proxy
-
pcl
java.lang.ClassLoader pcl
-
platform
static java.lang.ClassLoader platform
-
checker
private WeavingClassLoader.Excludable checker
-
cache
private final java.util.HashMap<java.net.URL,java.security.ProtectionDomain> cache
-
-
Method Detail
-
readFully
public static byte[] readFully(java.io.InputStream is)
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String cname)
- Overrides:
getResourceAsStreamin classjava.lang.ClassLoader
-
getURLs
public static java.net.URL[] getURLs(java.lang.String[] classPaths)
-
getProxy
private static java.net.URLClassLoader getProxy()
-
run
public void run(java.lang.String className, java.lang.String method, java.lang.String... args) throws java.lang.Exceptionrun static method className.method(args) using reflection and this WeavingClassLoader- Throws:
java.lang.Exception
-
exclude
public WeavingClassLoader exclude(WeavingClassLoader.Excludable exclude)
replace the exclude filter which determines whether a named class should be defined definitively by this loader or instead delegated to the parent loader. this is sometimes necessary to work with classes that may have been previously loaded, eg because they were used as a java agent- Parameters:
exclude- the filter to run- Returns:
-
loadClass
public java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException- Overrides:
loadClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
proxy
private boolean proxy(java.lang.String cname)
-
defineAll
private java.lang.Class defineAll(java.lang.String name, ClassWeaver cw)
-
getByteStream
public static java.io.InputStream getByteStream(java.lang.ClassLoader cl, java.lang.String name, java.lang.String cname, boolean system)
-
weaveClass
public ClassWeaver weaveClass(java.lang.String name)
load the bytecode for a class of a given name from the classpath and weave it- Parameters:
name- the fully qualified class name- Returns:
- the weaver
-
findClass
protected java.lang.Class<?> findClass(java.lang.String name) throws java.lang.ClassNotFoundException- Overrides:
findClassin classjava.lang.ClassLoader- Throws:
java.lang.ClassNotFoundException
-
get
private java.security.ProtectionDomain get(java.lang.String name)
-
define
public java.lang.Class<?> define(java.lang.String name, byte[] code)
-
makeResourceName
public static java.lang.String makeResourceName(java.lang.String name)
convert a fully qualified class name to a resource name. Note: the Class and ClassLoader javadocs don't explicitly specify the string formats used for the various methods, so this conversion is potentially fragile- Parameters:
name- as returned by Class.getName- Returns:
- the name in a format suitable for use with the various ClassLoader.getResource methods
-
unmakeResourceName
public static java.lang.String unmakeResourceName(java.lang.String cname)
-
findCode
public static byte[] findCode(java.lang.ClassLoader loader, java.lang.String name)read bytecode for the named class from a source classloader- Parameters:
loader- the classloader to get the bytecode from, or null for the current classloadername- the internal name for the class as would be passed to loadClass- Returns:
- a new instance, or null if the bytecode is not found
-
url
public java.net.URL url(java.lang.String name)
-
readFully
public static byte[] readFully(FileLister.Entry fe) throws java.io.IOException
- Throws:
java.io.IOException
-
-