/** * Create a new RequirementDependencyItem. * * @param module the module * @param requirement the requirement * @throws IllegalArgumentException for a null parameter */ public RequirementDependencyItem(Module module, Requirement requirement) { super(module != null ? module.getName() : null, null, CLASSLOADER, CLASSLOADER); if (module == null) throw new IllegalArgumentException("Null module"); if (requirement == null) throw new IllegalArgumentException("Null requirement"); this.module = module; this.requirement = requirement; }
/** * Add a deployment unit * * @param deploymentUnit the deployment unit * @param metadata the classloader metadata * @throws IllegalArgumentException for a null parameter */ public void addDeploymentUnit(DeploymentUnit deploymentUnit, ClassLoaderMetaData metadata) { Module module = new Module(this, deploymentUnit, metadata); deploymentUnit.addAttachment(Module.class, module); units.put(deploymentUnit, module); module.createDependencies(); }
/** * Remove a deployment * * @param module the module * @throws IllegalArgumentException for a null parameter */ protected void removeModule(Module module) { if (module == null) throw new IllegalArgumentException("Null module"); DeploymentUnit unit = module.getDeploymentUnit(); units.remove(unit); } }
/** * Get the parentDomain. * * @return the parentDomain. */ public String getParentDomain() { String parentDomain = getMetadata().getParentDomain(); if (parentDomain == null) { if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDomainName()) == false) return ClassLoaderSystem.DEFAULT_DOMAIN_NAME; } return parentDomain; }
@Override protected VFSClassLoaderPolicy createTopLevelClassLoaderPolicy(DeploymentContext context, Module module) throws Exception { ClassPathVisitor visitor = new ClassPathVisitor(); context.visit(visitor); Set<VirtualFile> classPath = visitor.getClassPath(); VirtualFile[] roots = new VirtualFile[classPath.size() + 1]; int i = 0; for (VirtualFile path : classPath) roots[i++] = path; MemoryContextFactory factory = MemoryContextFactory.getInstance(); factory.createRoot(module.getDynamicClassRoot()); URL url = new URL(module.getDynamicClassRoot() + "/classes"); roots[i++] = factory.createDirectory(url).getVirtualFile(); VFSClassLoaderPolicy policy = new VFSClassLoaderPolicy(module.getName(), roots); policy.setExportAll(module.getExportAll()); policy.setImportAll(module.isImportAll()); // TODO JBMICROCONT-182 more policy from "module" return policy; }
/** * Resolve the requirement * * @param controller the controller * @param module the module * @param requirement the requirement * @return the resolved name or null if not resolved */ protected Object resolve(Controller controller, Module module, Requirement requirement) { // TODO JBMICROCONT-182 - do this properly for (Module other : units.values()) { ClassLoaderMetaData metadata = other.getMetadata(); List<Capability> capabilities = metadata.getCapabilities(); if (capabilities != null) { for (Capability capability : capabilities) { if (capability.resolves(module.getDeploymentUnit(), requirement)) return other.getName(); } } } return null; }
synchronized (this) String domainName = module.getDomainName(); domain = system.getDomain(domainName); if (domain == null) String parentDomain = module.getParentDomain(); if (parentDomain != null) parent = system.getDomain(parentDomain); ParentPolicy parentPolicy = module.getParentPolicy();
/** * Get delegate policy * * @return the delegation policy */ public ParentPolicy getParentPolicy() { if (getMetadata().isJ2seClassLoadingCompliance()) return ParentPolicy.BEFORE; else return ParentPolicy.AFTER; }
/** * Get the domain name. * * @return the domain name. */ public String getDomainName() { return getDomain().getName(); }
/** * Get the delegate loaders for this module * * @return the delegates */ public List<? extends DelegateLoader> getDelegates() { // TODO JBMICROCONT-182 - this should be already determined if (requirementDependencies == null || requirementDependencies.isEmpty()) return null; List<DelegateLoader> result = new ArrayList<DelegateLoader>(); for (RequirementDependencyItem item : requirementDependencies) { String name = (String) item.getIDependOn(); Module module = domain.getModule(name); if (module == null) throw new IllegalStateException("Module not found with name: " + name); result.add(module.getDelegateLoader()); } return result; }
@Override protected void cleanup(DeploymentContext context, Module module) throws Exception { MemoryContextFactory factory = MemoryContextFactory.getInstance(); factory.deleteRoot(module.getDynamicClassRoot()); }
synchronized (this) String domainName = module.getDomainName(); domain = system.getDomain(domainName); if (domain == null) String parentDomain = module.getParentDomain(); if (parentDomain != null) parent = system.getDomain(parentDomain); ParentPolicy parentPolicy = module.getParentPolicy();
/** * Get the export all for the module * * @return the export all */ public ExportAll getExportAll() { return getMetadata().getExportAll(); }
/** * Get a module for a name * * @param name the name * @return the module */ protected Module getModule(String name) { for (Module module : units.values()) { if (name.equals(module.getName())) return module; } return null; }
/** * Get the import all for the module * * @return the import all */ public boolean isImportAll() { return getMetadata().isImportAll(); }