org.jboss.modules.Module.getClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.jboss.modules.Module.getClassLoader()方法的一些代码示例,展示了Module.getClassLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Module.getClassLoader()方法的具体详情如下:
包路径:org.jboss.modules.Module
类名称:Module
方法名:getClassLoader

Module.getClassLoader介绍

[英]Get the class loader for a module. The class loader can be used to access non-exported classes and resources of the module.

If a security manager is present, then this method invokes the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to verify access to the class loader. If access is not granted, a SecurityException will be thrown.
[中]获取模块的类加载器。类加载器可用于访问模块的非导出类和资源。
如果存在安全管理器,则此方法使用RuntimePermission("getClassLoader")权限调用安全管理器的checkPermission方法,以验证对类加载器的访问。如果未授予访问权限,将抛出SecurityException。

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
  public ClassLoader getValue() throws IllegalStateException, IllegalArgumentException {
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    return module != null ? module.getClassLoader() : null;
  }
};

代码示例来源:origin: wildfly/wildfly

/**
   * Return the class loader associated to the JBoss Module identified by the {@code moduleName}
   *
   * @param moduleName the name of the module (can not be {@code null}
   * @return the class loader associated to the JBoss Module
   * @throws IOException if the module can not be loaded or if JBoss Modules is not present
   */
  static ClassLoader getClassLoaderFromModule(String moduleName) throws IOException{
    try {
      return Module.getCallerModuleLoader().loadModule(moduleName).getClassLoader();
    } catch (ModuleLoadException e) {
      throw new IOException("Failed to create endpoint", e);
    } catch (LinkageError e) {
      throw new IOException("Failed to create endpoint: JBoss Modules is not present", e);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

private void processModuleDescription(final EEModuleDescription moduleDescription, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext) {
  final ConcurrentContext concurrentContext = moduleDescription.getConcurrentContext();
  // setup context
  setupConcurrentContext(concurrentContext, moduleDescription.getApplicationName(), moduleDescription.getModuleName(), null, deploymentUnit.getAttachment(MODULE).getClassLoader(), moduleDescription.getNamespaceContextSelector(), deploymentUnit, phaseContext.getServiceTarget());
  // add setup action for web modules
  final ConcurrentContextSetupAction setupAction = new ConcurrentContextSetupAction(concurrentContext);
  deploymentUnit.getAttachmentList(Attachments.WEB_SETUP_ACTIONS).add(setupAction);
}

代码示例来源:origin: wildfly/wildfly

/**
 * Create the CdiValidatorFactoryService instance.
 *
 * @param deploymentUnit the deployment unit
 */
public CdiValidatorFactoryService(final DeploymentUnit deploymentUnit, final Supplier<BeanManager> beanManagerSupplier) {
  this.deploymentUnit = deploymentUnit;
  final Module module = this.deploymentUnit.getAttachment(Attachments.MODULE);
  this.classLoader = module.getClassLoader();
  this.beanManagerSupplier = beanManagerSupplier;
}

代码示例来源:origin: wildfly/wildfly

private boolean isJSF12(ModuleDependency moduleDependency, String identifier) throws ModuleLoadException {
  // The class javax.faces.event.NamedEvent was introduced in JSF 2.0
  return (moduleDependency.getModuleLoader().loadModule(identifier)
              .getClassLoader().getResource("/javax/faces/event/NamedEvent.class") == null);
}

代码示例来源:origin: wildfly/wildfly

return deploymentUnit.getAttachment(BatchAttachments.JOB_XML_RESOLVER);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ClassLoader classLoader = module.getClassLoader();
WildFlyJobXmlResolver resolver;
    resolver = create(classLoader, deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS));
  } else {
    resolver = create(classLoader, Collections.singletonList(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT)));

代码示例来源:origin: wildfly/wildfly

@Override
public void undeploy(final DeploymentUnit context) {
  //clear data from the relevant caches
  Module module = context.getAttachment(Attachments.MODULE);
  if(module == null) {
    return;
  }
  ExceptionAnalysis.clearCache(module.getClassLoader());
  InterfaceAnalysis.clearCache(module.getClassLoader());
  ValueAnalysis.clearCache(module.getClassLoader());
}

代码示例来源:origin: wildfly/wildfly

private static Class unwrapClass(ModelNode classModel) throws OperationFailedException {
    String className = classModel.get(NAME).asString();
    String moduleName = classModel.get(MODULE).asString();
    try {
      ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
      Module module = Module.getCallerModuleLoader().loadModule(moduleID);
      Class<?> clazz = module.getClassLoader().loadClass(className);
      return clazz;
    } catch (Exception e) {
      throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
weldStartCompletionServiceBuilder.requires(weldStartServiceName);
weldStartCompletionServiceBuilder.setInstance(new WeldStartCompletionService(bootstrapSupplier, executorServiceSupplier,
    WeldDeploymentProcessor.getSetupActions(deploymentUnit), module.getClassLoader(), serviceControllers));
weldStartCompletionServiceBuilder.install();

代码示例来源:origin: wildfly/wildfly

@Override
  public void undeploy(DeploymentUnit context) {
    if (context.hasAttachment(Attachments.MODULE)) {
      selector.unregisterContext(context.getAttachment(Attachments.MODULE).getClassLoader());
    }
  }
}

代码示例来源:origin: wildfly/wildfly

static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException {
    String className = protocolName;
    if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) {
      className = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, protocolName);
    }

    try {
      return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class);
    } catch (ClassNotFoundException | ModuleLoadException e) {
      throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if(module == null) {
  return;
final ClassLoader moduleClassLoader = module.getClassLoader();
if (componentDescriptions != null) {
  for (ComponentDescription componentDescription : componentDescriptions) {

代码示例来源:origin: wildfly/wildfly

@Override
public Collection<Service> getServices(DeploymentUnit rootDeploymentUnit, DeploymentUnit deploymentUnit, Module module, ResourceRoot resourceRoot) {
  List<Service> services = new ArrayList<>();
  // ResourceInjectionServices
  // TODO I'm not quite sure we should use rootDeploymentUnit here
  services.add(new WeldResourceInjectionServices(rootDeploymentUnit.getServiceRegistry(),
      rootDeploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION), module,
      DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)));
  // ClassFileServices
  final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
  if (index != null) {
    services.add(new WeldClassFileServices(index, module.getClassLoader()));
  }
  return services;
}

代码示例来源:origin: wildfly/wildfly

private static Class unwrapClass(ModelNode classModel) throws OperationFailedException {
    String className = classModel.get(NAME).asString();
    String moduleName = classModel.get(MODULE).asString();
    try {
      ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
      Module module = Module.getCallerModuleLoader().loadModule(moduleID);
      Class<?> clazz = module.getClassLoader().loadClass(className);
      return clazz;
    } catch (Exception e) {
      throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    continue;
  subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
  final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
startService.setInstance(new WeldStartService(bootstrapSupplier, setupActions, module.getClassLoader(), Utils.getRootDeploymentUnit(deploymentUnit).getServiceName()));
startService.install();

代码示例来源:origin: wildfly/wildfly

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
  final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
  if(module == null || moduleDescription == null) {
    return;
  }
  final LazyValidatorFactory factory  = new LazyValidatorFactory(module.getClassLoader());
  deploymentUnit.putAttachment(BeanValidationAttachments.VALIDATOR_FACTORY, factory);
  bindFactoryToJndi(factory,deploymentUnit,phaseContext,moduleDescription);
}

代码示例来源:origin: wildfly/wildfly

static ModuleClassLoader getModuleClassLoader(final ModuleLoader loader, final String moduleSpec) throws ModuleLoadException {
  final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec));
  return WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader();
}

代码示例来源:origin: wildfly/wildfly

private void processDeployment(final WarMetaData warMetaData, final DeploymentUnit deploymentUnit, final ServiceTarget serviceTarget,
                final String deploymentName, final String hostName, final String serverInstanceName)
    throws DeploymentUnitProcessingException {
  ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
  final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
  final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
  if (module == null) {
    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit));
  CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
  ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
  final WebInjectionContainer injectionContainer = new WebInjectionContainer(module.getClassLoader(), componentRegistry);

代码示例来源:origin: wildfly/wildfly

private void handleInfoFile(DeploymentUnit deploymentUnit, Module module) {
  final List<PredicatedHandler> handlerWrappers = new ArrayList<>();
  ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  try {
    ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    VirtualFile config = root.getRoot().getChild(WEB_INF);
    try {
      if (config.exists()) {
        handlerWrappers.addAll(PredicatedHandlersParser.parse(config.openStream(), module.getClassLoader()));
      }
      Enumeration<URL> paths = module.getClassLoader().getResources(META_INF);
      while (paths.hasMoreElements()) {
        URL path = paths.nextElement();
        handlerWrappers.addAll(PredicatedHandlersParser.parse(path.openStream(), module.getClassLoader()));
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    if (!handlerWrappers.isEmpty()) {
      deploymentUnit.putAttachment(PREDICATED_HANDLERS, handlerWrappers);
    }
  } finally {
    Thread.currentThread().setContextClassLoader(oldCl);
  }
}

代码示例来源:origin: wildfly/wildfly

private ObjectFactory factoryFromModularReference(ModularReference modularReference, final Hashtable<?, ?> environment) throws Exception {
  final Module module = Module.getCallerModuleLoader().loadModule(modularReference.getModuleIdentifier());
  final ClassLoader classLoader = module.getClassLoader();
  return factoryFromReference(modularReference, classLoader, environment);
}

相关文章