org.jvnet.hk2.osgiadapter
Class OSGiModulesRegistryImpl

java.lang.Object
  extended by com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl
      extended by org.jvnet.hk2.osgiadapter.OSGiModulesRegistryImpl
All Implemented Interfaces:
ModuleChangeListener, ModulesRegistry, EventListener, HabitatFactory, InhabitantsParserFactory, org.osgi.framework.BundleListener, org.osgi.framework.SynchronousBundleListener

public class OSGiModulesRegistryImpl
extends AbstractModulesRegistryImpl
implements org.osgi.framework.SynchronousBundleListener

This is an implementation of ModulesRegistry. It uses OSGi extender pattern to do necessary parsing of OSGi bundles.

Author:
Sanjeeb.Sahoo@Sun.COM

Field Summary
 
Fields inherited from class com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl
modules, parent, providers, repositories
 
Method Summary
protected  void add(Module newModule)
           
 void addModuleChangeListener(ModuleChangeListener listener, OSGiModuleImpl module)
           
 void bundleChanged(org.osgi.framework.BundleEvent event)
           
 ModulesRegistry createChild()
           
 void detachAll()
           
 Module find(Class clazz)
           
 ClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> defs)
          Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition
 ClassLoader getModulesClassLoader(ClassLoader parent, Collection<ModuleDefinition> mds, URL[] urls)
          Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition and also load new urls.
 org.osgi.service.packageadmin.PackageAdmin getPackageAdmin()
           
 ClassLoader getParentClassLoader()
          Returns the parent class loader parenting the class loaders created by modules associated with this registry.
protected  Module newModule(ModuleDefinition moduleDef)
           
 void parseInhabitants(Module module, String name, InhabitantsParser inhabitantsParser)
           
 void register(ModuleLifecycleListener listener)
           
 void remove(Module module)
           
 boolean removeModuleChangeListener(ModuleChangeListener listener)
           
 void setParentClassLoader(ClassLoader parent)
          Sets the classloader parenting the class loaders created by the modules associated with this registry.
 void shutdown()
           
 void unregister(ModuleLifecycleListener listener)
           
 
Methods inherited from class com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl
add, add, addRepository, addRepository, changed, createHabitat, createHabitat, createHabitat, createInhabitantsParser, dumpState, getModules, getModules, getModulesProvider, getProvidersClass, getProvidingModule, getRepository, getRunningServices, initializeHabitat, loadFromRepository, makeModuleFor, makeModuleFor, makeModuleFor, newHabitat, populateConfig, print, registerRunningService, removeRepository, unregisterRunningService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bundleChanged

public void bundleChanged(org.osgi.framework.BundleEvent event)
Specified by:
bundleChanged in interface org.osgi.framework.BundleListener

add

protected void add(Module newModule)
Overrides:
add in class AbstractModulesRegistryImpl

remove

public void remove(Module module)
Overrides:
remove in class AbstractModulesRegistryImpl

newModule

protected Module newModule(ModuleDefinition moduleDef)
Specified by:
newModule in class AbstractModulesRegistryImpl

parseInhabitants

public void parseInhabitants(Module module,
                             String name,
                             InhabitantsParser inhabitantsParser)
                      throws IOException
Specified by:
parseInhabitants in class AbstractModulesRegistryImpl
Throws:
IOException

createChild

public ModulesRegistry createChild()
Specified by:
createChild in interface ModulesRegistry

detachAll

public void detachAll()
Specified by:
detachAll in interface ModulesRegistry

shutdown

public void shutdown()
Specified by:
shutdown in interface ModulesRegistry

setParentClassLoader

public void setParentClassLoader(ClassLoader parent)
Sets the classloader parenting the class loaders created by the modules associated with this registry.

Specified by:
setParentClassLoader in interface ModulesRegistry
Parameters:
parent - parent class loader

getParentClassLoader

public ClassLoader getParentClassLoader()
Returns the parent class loader parenting the class loaders created by modules associated with this registry.

Specified by:
getParentClassLoader in interface ModulesRegistry
Returns:
the parent classloader

getModulesClassLoader

public ClassLoader getModulesClassLoader(ClassLoader parent,
                                         Collection<ModuleDefinition> mds,
                                         URL[] urls)
                                  throws ResolveError
Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition and also load new urls.

Specified by:
getModulesClassLoader in interface ModulesRegistry
Parameters:
parent - the parent class loader for the returned class loader instance
mds - module definitions for all modules this classloader should be capable of loading
urls - urls to be added to the module classloader
Returns:
class loader instance
Throws:
ResolveError - if one of the provided module definition cannot be resolved

getModulesClassLoader

public ClassLoader getModulesClassLoader(ClassLoader parent,
                                         Collection<ModuleDefinition> defs)
                                  throws ResolveError
Returns a ClassLoader capable of loading classes from a set of modules identified by their module definition

Specified by:
getModulesClassLoader in interface ModulesRegistry
Parameters:
parent - the parent class loader for the returned class loader instance
defs - module definitions for all modules this classloader should be capable of loading classes from
Returns:
class loader instance
Throws:
ResolveError - if one of the provided module definition cannot be resolved

find

public Module find(Class clazz)
Specified by:
find in interface ModulesRegistry

getPackageAdmin

public org.osgi.service.packageadmin.PackageAdmin getPackageAdmin()

addModuleChangeListener

public void addModuleChangeListener(ModuleChangeListener listener,
                                    OSGiModuleImpl module)

removeModuleChangeListener

public boolean removeModuleChangeListener(ModuleChangeListener listener)

register

public void register(ModuleLifecycleListener listener)
Specified by:
register in interface ModulesRegistry

unregister

public void unregister(ModuleLifecycleListener listener)
Specified by:
unregister in interface ModulesRegistry


Copyright © 2011 Oracle Corporation. All Rights Reserved.