Search in sources :

Example 1 with ModuleDependencySpec

use of org.jboss.modules.ModuleDependencySpec in project wildfly by wildfly.

the class ExternalBeanArchiveProcessor method loadModuleDependency.

private Module loadModuleDependency(DependencySpec dep) {
    if (dep instanceof ModuleDependencySpec) {
        ModuleDependencySpec dependency = (ModuleDependencySpec) dep;
        final ModuleLoader loader = dependency.getModuleLoader();
        if (loader != null) {
            try {
                return dependency.getModuleLoader().loadModule(dependency.getIdentifier());
            } catch (ModuleLoadException e) {
                return null;
            }
        }
    }
    return null;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleDependencySpec(org.jboss.modules.ModuleDependencySpec) ModuleLoader(org.jboss.modules.ModuleLoader)

Example 2 with ModuleDependencySpec

use of org.jboss.modules.ModuleDependencySpec in project wildfly by wildfly.

the class BeanDeploymentArchiveImpl method isAccessible.

/**
     * Determines if a class from this {@link BeanDeploymentArchiveImpl} instance can access a class in the
     * {@link BeanDeploymentArchive} instance represented by the specified <code>BeanDeploymentArchive</code> parameter
     * according to the Java EE class accessibility requirements.
     *
     * @param target
     * @return true if an only if a class this archive can access a class from the archive represented by the specified parameter
     */
public boolean isAccessible(BeanDeploymentArchive target) {
    if (this == target) {
        return true;
    }
    BeanDeploymentArchiveImpl that = (BeanDeploymentArchiveImpl) target;
    if (that.getModule() == null) {
        /*
             * The target BDA is the bootstrap BDA - it bundles classes loaded by the bootstrap classloader.
             * Everyone can see the bootstrap classloader.
             */
        return true;
    }
    if (module == null) {
        /*
             * This BDA is the bootstrap BDA - it bundles classes loaded by the bootstrap classloader. We assume that a
             * bean whose class is loaded by the bootstrap classloader can only see other beans in the "bootstrap BDA".
             */
        return that.getModule() == null;
    }
    if (module.equals(that.getModule())) {
        return true;
    }
    // basic check whether the module is our dependency
    for (DependencySpec dependency : module.getDependencies()) {
        if (dependency instanceof ModuleDependencySpec) {
            ModuleDependencySpec moduleDependency = (ModuleDependencySpec) dependency;
            if (moduleDependency.getIdentifier().equals(that.getModule().getIdentifier())) {
                return true;
            }
        }
    }
    /*
         * full check - we try to load a class from the target bean archive and check whether its module
         * is the same as the one of the bean archive
         * See WFLY-4250 for more info
         */
    Iterator<String> iterator = target.getBeanClasses().iterator();
    if (iterator.hasNext()) {
        Class<?> clazz = Reflections.loadClass(iterator.next(), module.getClassLoader());
        if (clazz != null) {
            Module classModule = Module.forClass(clazz);
            return classModule != null && classModule.equals(that.getModule());
        }
    }
    return false;
}
Also used : ModuleDependencySpec(org.jboss.modules.ModuleDependencySpec) DependencySpec(org.jboss.modules.DependencySpec) ModuleDependencySpec(org.jboss.modules.ModuleDependencySpec) Module(org.jboss.modules.Module)

Aggregations

ModuleDependencySpec (org.jboss.modules.ModuleDependencySpec)2 DependencySpec (org.jboss.modules.DependencySpec)1 Module (org.jboss.modules.Module)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 ModuleLoader (org.jboss.modules.ModuleLoader)1