use of com.sun.enterprise.module.common_impl.Tokenizer in project Payara by payara.
the class ClassLoaderHierarchyImpl method createApplicationParentCL.
/**
* Sets up the parent class loader for the application class loader.
* Application class loader are under the control of the ArchiveHandler since
* a special archive file format will require a specific class loader.
*
* However GlassFish needs to be able to add capabilities to the application
* like adding APIs accessibility, this is done through its parent class loader
* which we create and maintain.
*
* @param parent the parent class loader
* @param context deployment context
* @return class loader capable of loading public APIs identified by the deployers
* @throws ResolveError if one of the deployer's public API module is not found.
*/
@Override
public ClassLoader createApplicationParentCL(ClassLoader parent, DeploymentContext context) throws ResolveError {
final ReadableArchive source = context.getSource();
List<ModuleDefinition> defs = new ArrayList<ModuleDefinition>();
// now let's see if the application is requesting any module imports
Manifest m = null;
try {
m = source.getManifest();
} catch (IOException e) {
logger.log(Level.SEVERE, "Cannot load application's manifest file :", e.getMessage());
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, e.getMessage(), e);
}
}
if (m != null) {
String importedBundles = m.getMainAttributes().getValue(ManifestConstants.BUNDLE_IMPORT_NAME);
if (importedBundles != null) {
for (String token : new Tokenizer(importedBundles, ",")) {
Collection<Module> modules = modulesRegistry.getModules(token);
if (modules.size() == 1) {
defs.add(modules.iterator().next().getModuleDefinition());
} else {
throw new ResolveError("Not able to locate a unique module by name " + token);
}
}
}
// Applications can add an additional osgi repos...
String additionalRepo = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY);
if (additionalRepo != null) {
for (String token : new Tokenizer(additionalRepo, ",")) {
// Each entry should be name=path
int equals = token.indexOf('=');
if (equals == -1) {
// Missing '='...
throw new IllegalArgumentException("\"" + org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY + ": " + additionalRepo + "\" is missing an '='. " + "It must be in the format: name=path[,name=path]...");
}
String name = token.substring(0, equals);
String path = token.substring(++equals);
addRepository(name, resolver.translate(path));
}
}
// Applications can also request to be wired to implementors of certain services.
// That means that any module implementing the requested service will be accessible
// by the parent class loader of the application.
String requestedWiring = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_SERVICES);
if (requestedWiring != null) {
for (String token : new Tokenizer(requestedWiring, ",")) {
for (Object impl : habitat.getAllServices(BuilderHelper.createContractFilter(token))) {
Module wiredBundle = modulesRegistry.find(impl.getClass());
if (wiredBundle != null) {
defs.add(wiredBundle.getModuleDefinition());
}
}
}
}
}
if (defs.isEmpty()) {
return parent;
} else {
return modulesRegistry.getModulesClassLoader(parent, defs);
}
}
Aggregations