Search in sources :

Example 1 with Remote

use of javax.ejb.Remote in project wildfly by wildfly.

the class BusinessViewAnnotationProcessor method getRemoteBusinessInterfaces.

private Collection<Class<?>> getRemoteBusinessInterfaces(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass) throws DeploymentUnitProcessingException {
    final Remote remoteViewAnnotation = sessionBeanClass.getAnnotation(Remote.class);
    if (remoteViewAnnotation == null) {
        Collection<Class<?>> interfaces = getBusinessInterfacesFromInterfaceAnnotations(sessionBeanClass, Remote.class);
        if (!interfaces.isEmpty()) {
            return interfaces;
        }
        return Collections.emptySet();
    }
    Class<?>[] remoteViews = remoteViewAnnotation.value();
    if (remoteViews == null || remoteViews.length == 0) {
        Set<Class<?>> interfaces = getPotentialBusinessInterfaces(sessionBeanClass);
        // EJB 3.2 allows it (core spec, section 4.9.7)
        if (interfaces.size() != 1 && !isEjbVersionGreaterThanOrEqualTo32(deploymentUnit)) {
            throw EjbLogger.ROOT_LOGGER.beanWithRemoteAnnotationImplementsMoreThanOneInterface(sessionBeanClass);
        }
        return interfaces;
    }
    return Arrays.asList(remoteViews);
}
Also used : Remote(javax.ejb.Remote)

Example 2 with Remote

use of javax.ejb.Remote in project Payara by payara.

the class AbstractEjbHandler method setBusinessAndHomeInterfaces.

/**
 * MessageDriven bean does not need to invoke this API.
 * @param ejbDesc
 * @param ainfo  for error handling
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult setBusinessAndHomeInterfaces(EjbDescriptor ejbDesc, AnnotationInfo ainfo) throws AnnotationProcessorException {
    Set<Class> localBusIntfs = new HashSet<Class>();
    Set<Class> remoteBusIntfs = new HashSet<Class>();
    Set<Class> clientInterfaces = new HashSet<Class>();
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    // First check for annotations specifying remote/local business intfs.
    // We analyze them here because they are needed during the
    // implements clause processing for beans that specify
    // @Stateless/@Stateful.  In addition, they should *not* be processed
    // if there is no @Stateful/@Stateless annotation.
    Remote remoteBusAnn = (Remote) ejbClass.getAnnotation(Remote.class);
    boolean emptyRemoteBusAnn = false;
    if (remoteBusAnn != null) {
        for (Class next : remoteBusAnn.value()) {
            if (next.getAnnotation(Local.class) != null) {
                AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidbusinessinterface", "The interface {0} cannot be both a local and a remote business interface.", new Object[] { next.getName() }));
                fatalException.setFatal(true);
                throw fatalException;
            }
            clientInterfaces.add(next);
            remoteBusIntfs.add(next);
        }
        emptyRemoteBusAnn = remoteBusIntfs.isEmpty();
    }
    Local localBusAnn = (Local) ejbClass.getAnnotation(Local.class);
    if (localBusAnn != null) {
        for (Class next : localBusAnn.value()) {
            if (next.getAnnotation(Remote.class) != null) {
                AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidbusinessinterface", "The interface {0} cannot be both a local and a remote business interface.", new Object[] { next.getName() }));
                fatalException.setFatal(true);
                throw fatalException;
            }
            clientInterfaces.add(next);
            localBusIntfs.add(next);
        }
    }
    List<Class> imlementingInterfaces = new ArrayList<Class>();
    List<Class> implementedDesignatedInterfaces = new ArrayList<Class>();
    for (Class next : ejbClass.getInterfaces()) {
        if (!excludedFromImplementsClause(next)) {
            if (next.getAnnotation(Local.class) != null || next.getAnnotation(Remote.class) != null) {
                implementedDesignatedInterfaces.add(next);
            }
            imlementingInterfaces.add(next);
        }
    }
    LocalBean localBeanAnn = (LocalBean) ejbClass.getAnnotation(LocalBean.class);
    if (localBeanAnn != null) {
        ejbDesc.setLocalBean(true);
    }
    // total number of local/remote business interfaces declared
    // outside of the implements clause plus implemented designated interfaces
    int designatedInterfaceCount = remoteBusIntfs.size() + localBusIntfs.size() + ejbDesc.getRemoteBusinessClassNames().size() + ejbDesc.getLocalBusinessClassNames().size() + implementedDesignatedInterfaces.size();
    for (Class next : imlementingInterfaces) {
        String nextIntfName = next.getName();
        if (remoteBusIntfs.contains(next) || localBusIntfs.contains(next) || ejbDesc.getRemoteBusinessClassNames().contains(nextIntfName) || ejbDesc.getLocalBusinessClassNames().contains(nextIntfName)) {
        // Interface has already been identified as a Remote/Local
        // business interface, so ignore.
        } else if (next.getAnnotation(Local.class) != null) {
            clientInterfaces.add(next);
            localBusIntfs.add(next);
        } else if (next.getAnnotation(Remote.class) != null) {
            clientInterfaces.add(next);
            remoteBusIntfs.add(next);
        } else {
            if ((designatedInterfaceCount == 0) && (!ejbDesc.isLocalBean())) {
                // it's treated as a local business interface.
                if (emptyRemoteBusAnn) {
                    remoteBusIntfs.add(next);
                } else {
                    localBusIntfs.add(next);
                }
                clientInterfaces.add(next);
            } else {
            // Since the component has at least one other business
            // interface, each implements clause interface that cannot
            // be identified as business interface via the deployment
            // descriptor or a @Remote/@Local annotation is ignored.
            }
        }
    }
    for (Class next : clientInterfaces) {
        if (remoteBusIntfs.contains(next) && localBusIntfs.contains(next)) {
            AnnotationProcessorException fatalException = new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidbusinessinterface", "The interface {0} cannot be both a local and a remote business interface.", new Object[] { next.getName() }));
            fatalException.setFatal(true);
            throw fatalException;
        }
    }
    if (localBusIntfs.size() > 0) {
        for (Class next : localBusIntfs) {
            ejbDesc.addLocalBusinessClassName(next.getName());
        }
    }
    if (remoteBusIntfs.size() > 0) {
        for (Class next : remoteBusIntfs) {
            ejbDesc.addRemoteBusinessClassName(next.getName());
        }
    }
    // Do Adapted @Home / Adapted @LocalHome processing here too since
    // they are logically part of the structural @Stateless/@Stateful info.
    RemoteHome remoteHomeAnn = (RemoteHome) ejbClass.getAnnotation(RemoteHome.class);
    if (remoteHomeAnn != null) {
        Class remoteHome = remoteHomeAnn.value();
        Class remoteIntf = getComponentIntfFromHome(remoteHome);
        if (EJBHome.class.isAssignableFrom(remoteHome) && (remoteIntf != null)) {
            clientInterfaces.add(remoteHome);
            ejbDesc.setHomeClassName(remoteHome.getName());
            ejbDesc.setRemoteClassName(remoteIntf.getName());
        } else {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidremotehome", "Encountered invalid @RemoteHome interface {0}.", new Object[] { remoteHome }));
            return getDefaultFailedResult();
        }
    }
    LocalHome localHomeAnn = (LocalHome) ejbClass.getAnnotation(LocalHome.class);
    if (localHomeAnn != null) {
        Class localHome = localHomeAnn.value();
        Class localIntf = getComponentIntfFromHome(localHome);
        if (EJBLocalHome.class.isAssignableFrom(localHome) && (localIntf != null)) {
            clientInterfaces.add(localHome);
            ejbDesc.setLocalHomeClassName(localHome.getName());
            ejbDesc.setLocalClassName(localIntf.getName());
        } else {
            log(Level.SEVERE, ainfo, localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidlocalhome", "Encountered invalid @LocalHome interface {0}.", new Object[] { localHome }));
            return getDefaultFailedResult();
        }
    }
    // Web Service API might not be available so do a check before looking
    // for @WebService on bean class
    boolean canDoWebServiceAnnCheck = false;
    try {
        canDoWebServiceAnnCheck = (provider.getType("javax.jws.WebService") != null);
    } catch (Exception e) {
        log(Level.FINE, ainfo, e.getMessage());
    }
    if ((!ejbDesc.isLocalBean()) && (clientInterfaces.size() == 0) && !ejbDesc.hasWebServiceEndpointInterface() && (!canDoWebServiceAnnCheck || (ejbClass.getAnnotation(javax.jws.WebService.class) == null))) {
        ejbDesc.setLocalBean(true);
    }
    // If this is a no-Interface local EJB, set all classes for this bean
    if (ejbDesc.isLocalBean()) {
        addNoInterfaceLocalBeanClasses(ejbDesc, ejbClass);
    }
    return getDefaultProcessedResult();
}
Also used : EJBHome(javax.ejb.EJBHome) ArrayList(java.util.ArrayList) LocalBean(javax.ejb.LocalBean) Remote(javax.ejb.Remote) Local(javax.ejb.Local) EJBLocalHome(javax.ejb.EJBLocalHome) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) RemoteHome(javax.ejb.RemoteHome) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) LocalHome(javax.ejb.LocalHome) EJBLocalHome(javax.ejb.EJBLocalHome) HashSet(java.util.HashSet)

Aggregations

Remote (javax.ejb.Remote)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EJBHome (javax.ejb.EJBHome)1 EJBLocalHome (javax.ejb.EJBLocalHome)1 Local (javax.ejb.Local)1 LocalBean (javax.ejb.LocalBean)1 LocalHome (javax.ejb.LocalHome)1 RemoteHome (javax.ejb.RemoteHome)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1