Search in sources :

Example 1 with WebBeansConfigurationException

use of org.apache.webbeans.exception.WebBeansConfigurationException 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)

Example 2 with WebBeansConfigurationException

use of org.apache.webbeans.exception.WebBeansConfigurationException in project tomee by apache.

the class CdiPlugin method validateScope.

private static void validateScope(final CdiEjbBean<?> bean) {
    final Class<? extends Annotation> scope = bean.getScope();
    final BeanType beanType = bean.getBeanContext().getComponentType();
    if (BeanType.STATELESS.equals(beanType) && !Dependent.class.equals(scope)) {
        throw new WebBeansConfigurationException("@Stateless can only be @Dependent");
    }
    if (BeanType.SINGLETON.equals(beanType) && !Dependent.class.equals(scope) && !ApplicationScoped.class.equals(scope)) {
        throw new WebBeansConfigurationException("@Singleton can only be @Dependent or @ApplicationScoped");
    }
}
Also used : WebBeansConfigurationException(org.apache.webbeans.exception.WebBeansConfigurationException) BeanType(org.apache.openejb.BeanType) SessionBeanType(javax.enterprise.inject.spi.SessionBeanType) Dependent(javax.enterprise.context.Dependent)

Aggregations

WebBeansConfigurationException (org.apache.webbeans.exception.WebBeansConfigurationException)2 Dependent (javax.enterprise.context.Dependent)1 SessionBeanType (javax.enterprise.inject.spi.SessionBeanType)1 BeanType (org.apache.openejb.BeanType)1 BeansInfo (org.apache.openejb.assembler.classic.BeansInfo)1 DefaultBeanArchiveInformation (org.apache.webbeans.xml.DefaultBeanArchiveInformation)1