org.ungoverned.oscar
Class OSGiImportSearchPolicy
java.lang.Object
org.ungoverned.moduleloader.search.ImportSearchPolicy
org.ungoverned.oscar.OSGiImportSearchPolicy
- All Implemented Interfaces:
- java.util.EventListener, ModuleListener, SearchPolicy
- public class OSGiImportSearchPolicy
- extends ImportSearchPolicy
This class extends ImportSearchPolicy in order to implement
dynamic package import as defined by the OSGi specification. It does this
by overriding the ImportSearchPolicy.findClass() and
ImportSearchPolicy.findResource() methods. By default, this
class lets requests fall through to the super class, but if either
method throws an exception or returns null, then it checks
the dynamic import meta-data for the associated bundle.
Field Summary |
static java.lang.String |
DYNAMIC_IMPORTS_ATTR
This is the name of the "dynamic-imports" meta-data attribute that
should be attached to each module. |
Method Summary |
java.lang.Class |
findClass(Module module,
java.lang.String name)
This method is part of the SearchPolicy interface; it
should not be called directly. |
protected java.lang.Class |
findClassDynamic(Module module,
java.lang.String name)
|
java.net.URL |
findResource(Module module,
java.lang.String name)
This method is part of the SearchPolicy interface; it
should not be called directly. |
protected java.net.URL |
findResourceDynamic(Module module,
java.lang.String name)
|
static java.lang.String[] |
getDynamicImports(Module module)
Utility method that returns the DYNAMIC_IMPORTS_ATTR
attribute for the specified module. |
Methods inherited from class org.ungoverned.moduleloader.search.ImportSearchPolicy |
addValidationListener, createImporterList, doesImport, fireModuleInvalidated, fireModuleValidated, getCompatibilityPolicy, getCompatibleModules, getExportResolvingModule, getExportsAttribute, getExportVersion, getImportResolvingModule, getImportsAttribute, getImportsOrExports, getImportVersion, getPropagatesAttribute, getSelectionPolicy, getValidAttribute, invalidate, moduleAdded, moduleRemoved, moduleReset, removeValidationListener, resolveImportTarget, setModuleManager, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DYNAMIC_IMPORTS_ATTR
public static final java.lang.String DYNAMIC_IMPORTS_ATTR
- This is the name of the "dynamic-imports" meta-data attribute that
should be attached to each module. The value of this attribute
is of type String[] and contains dynamic import package
specs as defined by the OSGi bundle manifest specification.
- See Also:
- Constant Field Values
OSGiImportSearchPolicy
public OSGiImportSearchPolicy(Oscar oscar)
findClass
public java.lang.Class findClass(Module module,
java.lang.String name)
throws java.lang.ClassNotFoundException
- Description copied from class:
ImportSearchPolicy
- This method is part of the SearchPolicy interface; it
should not be called directly. This method finds a class
based on the import/export meta-data attached to the module.
It first attempts to validate the target module, if it cannot
be validated, then a ClassNotFoundException is thrown.
Once the module is validated, the module's imports are searched
for the target class, then the module's exports are searched.
If the class is found in either place, then it is returned;
otherwise, null is returned.
- Specified by:
findClass
in interface SearchPolicy
- Overrides:
findClass
in class ImportSearchPolicy
- Parameters:
module
- the target module that is loading the class.name
- the name of the class being loaded.
- Returns:
- the class if found, null otherwise.
- Throws:
java.lang.ClassNotFoundException
- if the target module
could not be validated.
findResource
public java.net.URL findResource(Module module,
java.lang.String name)
throws ResourceNotFoundException
- Description copied from class:
ImportSearchPolicy
- This method is part of the SearchPolicy interface; it
should not be called directly. This method finds a resource
based on the import/export meta-data attached to the module.
It first attempts to validate the target module, if it cannot
be validated, then it returns null. Once the module is
validated, the module's imports are searched for the target
resource, then the module's exports are searched. If the resource
is found in either place, then a URL to is is returned;
otherwise, null is returned.
- Specified by:
findResource
in interface SearchPolicy
- Overrides:
findResource
in class ImportSearchPolicy
- Parameters:
module
- the target module that is loading the resource.name
- the name of the resource being loaded.
- Returns:
- a URL to the resource if found, null otherwise.
- Throws:
ResourceNotFoundException
findClassDynamic
protected java.lang.Class findClassDynamic(Module module,
java.lang.String name)
findResourceDynamic
protected java.net.URL findResourceDynamic(Module module,
java.lang.String name)
getDynamicImports
public static java.lang.String[] getDynamicImports(Module module)
- Utility method that returns the DYNAMIC_IMPORTS_ATTR
attribute for the specified module.
- Parameters:
module
- the module whose DYNAMIC_IMPORTS_ATTR
attribute is to be retrieved.
- Returns:
- an String[].