Top Description Fields Constructors Methods
org.jruby.embed.osgi.internal

public Class JRubyOSGiBundleClassLoader

extends ClassLoader
implements BundleReference
Class Inheritance
All Implemented Interfaces
org.osgi.framework.BundleReference
Imports
java.io.IOException, java.net.URL, java.util.Collections, .Enumeration, .LinkedHashMap, .LinkedList, .List, org.jruby.embed.ScriptingContainer, org.jruby.util.log.Logger, .LoggerFactory, org.osgi.framework.Bundle, .BundleReference, .FrameworkUtil

Closest thing to JRubyClassLoader's addURL but for OSGi bundles. Used as the parent classloader the usual jruby's bundle's classloader.
Author
hmalphettes

Field Summary

Modifier and TypeField and Description
private LinkedHashMap<Bundle, ClassLoader>
private final boolean
_lookInOsgiFirst

look in OSGi first?

private static final IOSGiClassLoaderAdapter
private static final Logger

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
addBundle(Class<?> classInOsgiBundle)

public boolean
addBundle(Bundle bundle)

protected Class<?>
findClass(String
The binary name of the class
name
)

Overrides java.lang.ClassLoader.findClass.

Finds the class with the specified binary name.

public Bundle

Returns:

The Bundle object associated with this BundleReference.
getBundle
()

Implements org.osgi.framework.BundleReference.getBundle.

Returns the Bundle that defined this web-application.

public URL
getResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.

public Enumeration<URL>
getResources(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResources.

Todo

optimize: we should not have to look for the resources everywhere until called for it.

public boolean
private List<URL>
Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourceAsStreamgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

_librariesback to summary
private LinkedHashMap<Bundle, ClassLoader> _libraries
_lookInOsgiFirstback to summary
private final boolean _lookInOsgiFirst

look in OSGi first? true by default for now. we could look in jruby first if that makes more sense.

ADAPTERback to summary
private static final IOSGiClassLoaderAdapter ADAPTER
LOGback to summary
private static final Logger LOG

Constructor Detail

JRubyOSGiBundleClassLoaderback to summary
public JRubyOSGiBundleClassLoader()
JRubyOSGiBundleClassLoaderback to summary
public JRubyOSGiBundleClassLoader(Bundle creator)

Method Detail

addBundleback to summary
public void addBundle(Class<?> classInOsgiBundle)
addBundleback to summary
public boolean addBundle(Bundle bundle)
findClassback to summary
protected Class<?> findClass(String name) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

Doc from java.lang.ClassLoader.findClass.

Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class.

Parameters
name:String

The binary name of the class

Returns:Class<?>

The resulting Class object

Exceptions
ClassNotFoundException:
If the class could not be found
getBundleback to summary
public Bundle getBundle()

Implements org.osgi.framework.BundleReference.getBundle.

Returns the Bundle that defined this web-application.

Returns:Bundle

The Bundle object associated with this BundleReference.

getResourceback to summary
public URL getResource(String name)

Overrides java.lang.ClassLoader.getResource.

Doc from java.lang.ClassLoader.getResource.

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name that identifies the resource.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
name:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, or the resource is in a package that is not opened unconditionally.

Annotations
@Override
getResourcesback to summary
public Enumeration<URL> getResources(String name) throws IOException

Overrides java.lang.ClassLoader.getResources.

Todo

optimize: we should not have to look for the resources everywhere until called for it.

Parameters
name:String

Doc from java.lang.ClassLoader.getResources.

The resource name

Returns:Enumeration<URL>

Doc from java.lang.ClassLoader.getResources.

An enumeration of URL objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a URL cannot be constructed, or are in a package that is not opened unconditionally, are not returned in the enumeration.

Annotations
@Override
Exceptions
IOException:

Doc from java.lang.ClassLoader.getResources.

If I/O errors occur

removeBundleback to summary
public boolean removeBundle(Bundle bundle) throws IOException
toListback to summary
private List<URL> toList(List<Enumeration<URL>> l)