|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ClassLoader
org.entityfs.util.lang.EntityClassLoader
public class EntityClassLoader
This is a class loader that reads classes from Directory
:s and Zip
files. It does not support resolving resources to URL
:s (there is no
way to create generic URL:s that point to EntityFS entities), but it supports
getResourceAsStream()
.
To release all resources when this class loader should not be used anymore,
call close
on it.
Constructor Summary | |
---|---|
EntityClassLoader(LogAdapterHolder lah)
Create an entity class loader with an empty class path. |
|
EntityClassLoader(LogAdapterHolder lah,
ClassLoader parent)
Create an entity class loader with an empty class path. |
|
EntityClassLoader(LogAdapterHolder lah,
ClassLoader parent,
Collection<? extends EntityView> classpath)
Create an entity class loader with a class path that consists of the entities returned from the collection, in that order. |
|
EntityClassLoader(LogAdapterHolder lah,
Collection<? extends EntityView> classpath)
Create an entity class loader with a class path that consists of the entities returned from the collection, in that order. |
Method Summary | |
---|---|
EntityClassLoader |
addToClasspath(EntityView ev)
Add a directory or a Zip (or Jar) file to the classpath. |
void |
close()
Close this class loader and release all its resources. |
protected Class<?> |
defineClass(String name,
EFile f)
Define the class found in the provided file. |
protected Package |
definePackage(String name,
String specTitle,
String specVersion,
String specVendor,
String implTitle,
String implVersion,
String implVendor,
URL sealBase)
|
protected void |
finalize()
|
protected Class<?> |
findClass(String name)
|
protected EFile |
findFileInClasspath(RelativeLocation rel)
This is used by all methods to find a file in the class path. |
Class<?> |
getClassOrNull(String name)
Get the class definition if it is loaded by this class loader. |
protected List<DirectoryView> |
getClasspath()
Subclasses call this to get the root directories of this class loader's class path. |
protected LogAdapter |
getLogAdapter()
Get the current log adapter, or null if no log adapter holder is
set. |
protected Package |
getPackage(String name)
|
protected Package[] |
getPackages()
|
InputStream |
getResourceAsStream(String name)
Return an open InputStream for the contents of a resource in the
classpath. |
protected boolean |
isDebugLoggingEnabled()
Check if a log adapter is set and it will accept debug logs. |
protected boolean |
isFinerLoggingEnabled()
Check if a log adapter is set and it will accept finer logs. |
protected boolean |
isTraceLoggingEnabled()
Check if a log adapter is set and it will accept trace logs. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EntityClassLoader(LogAdapterHolder lah)
lah
- An adapter for logging. Set to null
to disable logging
from this class loader.public EntityClassLoader(LogAdapterHolder lah, Collection<? extends EntityView> classpath) throws UnsupportedEntityTypeException
classpath
- The collection of initial class path entries.lah
- An adapter for logging. Set to null
to disable logging
from this class loader.
UnsupportedEntityTypeException
- If the entity collection contains
an entity that is not a directory or a Zip (or Jar) file.public EntityClassLoader(LogAdapterHolder lah, ClassLoader parent)
lah
- An adapter for logging. Set to null
to disable logging
from this class loader.parent
- The parent class loader.public EntityClassLoader(LogAdapterHolder lah, ClassLoader parent, Collection<? extends EntityView> classpath) throws UnsupportedEntityTypeException
lah
- An adapter for logging. Set to null
to disable logging
from this class loader.parent
- The parent class loader.classpath
- The collection of initial class path entries.
UnsupportedEntityTypeException
- If the entity collection contains
an entity that is not a directory or a Zip (or Jar) file.Method Detail |
---|
protected boolean isDebugLoggingEnabled()
true
if a log adapter is set and it will accept debug
logs.protected boolean isFinerLoggingEnabled()
true
if a log adapter is set and it will accept finer
logs.protected boolean isTraceLoggingEnabled()
true
if a log adapter is set and it will accept trace
logs.protected LogAdapter getLogAdapter()
null
if no log adapter holder is
set.
protected List<DirectoryView> getClasspath()
public EntityClassLoader addToClasspath(EntityView ev) throws UnsupportedEntityTypeException
ev
- The entity to add to the end of the classpath.
UnsupportedEntityTypeException
- If the entity type is not
supported.public void close()
protected Class<?> defineClass(String name, EFile f)
ProtectionDomain
, for instance).
name
- The fully qualified name of the class.f
- The class file.
public Class<?> getClassOrNull(String name)
This can be used by other class loaders that want to be able to delegate
to several different EntityClassLoader
:s.
A typical usage (in that class loader's findClass(String)
method) may be: m_entityClassLoaders) Class c =
cl.getClassOrNull(name); if (c !=
null) return c; } throw new ClassNotFoundException(…);
name
- The binary name of the class.
null
otherwise.protected EFile findFileInClasspath(RelativeLocation rel)
rel
- The location of the file relative to the class path root
directory.
null
if the file cannot be found.protected Class<?> findClass(String name) throws ClassNotFoundException
findClass
in class ClassLoader
ClassNotFoundException
public InputStream getResourceAsStream(String name)
InputStream
for the contents of a resource in the
classpath. The resource is resolved as described in the java.lang.ClassLoader
Javadocs.
If the returned stream is for a resource in this class loader's classpath, the resource is locked for reading and the returned stream is lock aware. The lock on the resource will be released when the stream is closed.
Note: This method does not look up package-local resources. See this JavaWorld article.
getResourceAsStream
in class ClassLoader
InputStream
for the resource's contents (lock aware if
the resource is an EntityFS entity (file)), or null
if the
resource cannot be found.protected Package getPackage(String name)
getPackage
in class ClassLoader
protected Package[] getPackages()
getPackages
in class ClassLoader
protected Package definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)
definePackage
in class ClassLoader
protected void finalize() throws Throwable
finalize
in class Object
Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |