Search in sources :

Example 1 with DefaultBeanArchiveInformation

use of org.apache.webbeans.xml.DefaultBeanArchiveInformation in project tomee by apache.

the class OpenEJBBeanInfoService method createBeanArchiveInformation.

public DefaultBeanArchiveInformation createBeanArchiveInformation(final BeansInfo.BDAInfo bda, final BeansInfo info, final ClassLoader loader) {
    final String mode = bda.discoveryMode == null ? "ALL" : bda.discoveryMode;
    if (info != null && info.version != null && !"1.0".equals(info.version) && info.discoveryMode == null) {
        throw new WebBeansConfigurationException("beans.xml with version 1.1 and higher must declare a bean-discovery-mode!");
    }
    final DefaultBeanArchiveInformation information = new DefaultBeanArchiveInformation(bda.uri.toASCIIString());
    information.setVersion(info == null ? "1.1" : info.version);
    information.setBeanDiscoveryMode(BeanDiscoveryMode.valueOf(mode.trim().toUpperCase(Locale.ENGLISH)));
    information.setDecorators(bda.decorators);
    information.setInterceptors(bda.interceptors);
    if (info != null) {
        information.getAlternativeClasses().addAll(bda.alternatives);
        information.getAlternativeStereotypes().addAll(bda.stereotypeAlternatives);
        for (final BeansInfo.ExclusionEntryInfo exclusionInfo : info.excludes) {
            boolean skip = false;
            for (final String n : exclusionInfo.exclusion.availableClasses) {
                if (!isClassAvailable(loader, n)) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                for (final String n : exclusionInfo.exclusion.notAvailableClasses) {
                    if (isClassAvailable(loader, n)) {
                        skip = true;
                        break;
                    }
                }
            }
            if (!skip) {
                for (final String n : exclusionInfo.exclusion.systemPropertiesPresence) {
                    // our system instance is more powerful here
                    if (SystemInstance.get().getProperty(n) == null) {
                        skip = true;
                        break;
                    }
                }
            }
            if (!skip) {
                for (final String n : exclusionInfo.exclusion.systemProperties.stringPropertyNames()) {
                    // our system instance is more powerful here
                    if (!exclusionInfo.exclusion.systemProperties.getProperty(n).equals(SystemInstance.get().getProperty(n))) {
                        skip = true;
                        break;
                    }
                }
            }
            if (skip) {
                continue;
            }
            final String name = exclusionInfo.name;
            if (name.endsWith(".*")) {
                information.addClassExclude(name.substring(0, name.length() - 2));
            } else if (name.endsWith(".**")) {
                information.addPackageExclude(name.substring(0, name.length() - 3));
            } else {
                information.addClassExclude(name);
            }
        }
    }
    return information;
}
Also used : WebBeansConfigurationException(org.apache.webbeans.exception.WebBeansConfigurationException) BeansInfo(org.apache.openejb.assembler.classic.BeansInfo) DefaultBeanArchiveInformation(org.apache.webbeans.xml.DefaultBeanArchiveInformation)

Aggregations

BeansInfo (org.apache.openejb.assembler.classic.BeansInfo)1 WebBeansConfigurationException (org.apache.webbeans.exception.WebBeansConfigurationException)1 DefaultBeanArchiveInformation (org.apache.webbeans.xml.DefaultBeanArchiveInformation)1