Search in sources :

Example 51 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class SingletonHandler method createEjbDescriptor.

/**
 * Create a new EjbDescriptor for a given elementName and AnnotationInfo.
 * @param elementName
 * @param ainfo
 * @return a new EjbDescriptor
 */
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Class ejbClass = (Class) ae;
    EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
    newDescriptor.setName(elementName);
    newDescriptor.setEjbClassName(ejbClass.getName());
    newDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
    doSingletonSpecificProcessing(newDescriptor, ejbClass);
    return newDescriptor;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 52 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class SingletonHandler method setEjbDescriptorInfo.

/**
 * Set Annotation information to Descriptor.
 * This method will also be invoked for an existing descriptor with
 * annotation as user may not specific a complete xml.
 * @param ejbDesc
 * @param ainfo
 * @return HandlerProcessingResult
 */
protected HandlerProcessingResult setEjbDescriptorInfo(EjbDescriptor ejbDesc, AnnotationInfo ainfo) throws AnnotationProcessorException {
    EjbSessionDescriptor ejbSingletonDescriptor = (EjbSessionDescriptor) ejbDesc;
    Class ejbClass = (Class) ainfo.getAnnotatedElement();
    Singleton singleton = (Singleton) ainfo.getAnnotation();
    // set session bean type in case it wasn't set in a sparse ejb-jar.xml.
    if (!ejbSingletonDescriptor.isSessionTypeSet()) {
        ejbSingletonDescriptor.setSessionType(EjbSessionDescriptor.SINGLETON);
    }
    doDescriptionProcessing(singleton.description(), ejbDesc);
    doMappedNameProcessing(singleton.mappedName(), ejbDesc);
    doSingletonSpecificProcessing(ejbSingletonDescriptor, ejbClass);
    return setBusinessAndHomeInterfaces(ejbDesc, ainfo);
}
Also used : Singleton(javax.ejb.Singleton) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 53 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class StatefulHandler method createEjbDescriptor.

/**
 * Create a new EjbDescriptor for a given elementName and AnnotationInfo.
 * @param elementName
 * @param ainfo
 * @return a new EjbDescriptor
 */
protected EjbDescriptor createEjbDescriptor(String elementName, AnnotationInfo ainfo) throws AnnotationProcessorException {
    AnnotatedElement ae = ainfo.getAnnotatedElement();
    Class ejbClass = (Class) ae;
    EjbSessionDescriptor newDescriptor = new EjbSessionDescriptor();
    newDescriptor.setName(elementName);
    newDescriptor.setEjbClassName(ejbClass.getName());
    newDescriptor.setSessionType(EjbSessionDescriptor.STATEFUL);
    return newDescriptor;
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 54 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class TransactionAttributeHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    TransactionAttribute taAn = (TransactionAttribute) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = (EjbDescriptor) ejbContext.getDescriptor();
        ContainerTransaction containerTransaction = getContainerTransaction(taAn.value());
        if (ElementType.TYPE.equals(ainfo.getElementType())) {
            ejbContext.addPostProcessInfo(ainfo, this);
        } else {
            Method annMethod = (Method) ainfo.getAnnotatedElement();
            Set txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
            for (Object next : txBusMethods) {
                MethodDescriptor nextDesc = (MethodDescriptor) next;
                Method m = nextDesc.getMethod(ejbDesc);
                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(nextDesc) == null) {
                    // override by xml
                    ejbDesc.setContainerTransactionFor(nextDesc, containerTransaction);
                }
            }
            if (ejbDesc instanceof EjbSessionDescriptor) {
                EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDesc;
                if (sd.isStateful() || sd.isSingleton()) {
                    ClassLoader loader = ejbDesc.getEjbBundleDescriptor().getClassLoader();
                    Set<LifecycleCallbackDescriptor> lcds = ejbDesc.getLifecycleCallbackDescriptors();
                    for (LifecycleCallbackDescriptor lcd : lcds) {
                        if (lcd.getLifecycleCallbackClass().equals(ejbDesc.getEjbClassName()) && lcd.getLifecycleCallbackMethod().equals(annMethod.getName())) {
                            try {
                                Method m = lcd.getLifecycleCallbackMethodObject(loader);
                                MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                                if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
                                    // stateful lifecycle callback txn attr type EJB spec
                                    if (sd.isStateful() && containerTransaction != null) {
                                        String txAttr = containerTransaction.getTransactionAttribute();
                                        if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW) && !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
                                            logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.annotation.handlers.sfsblifecycletxnattrtypewarn", "Stateful session bean {0} lifecycle callback method {1} has transaction " + "attribute {2} with container-managed transaction demarcation. " + "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED", new Object[] { (sd.getName() == null ? "" : sd.getName()), m.getName(), txAttr }));
                                        }
                                    }
                                    // override by xml
                                    ejbDesc.setContainerTransactionFor(md, containerTransaction);
                                    if (logger.isLoggable(Level.FINE)) {
                                        logger.log(Level.FINE, "Found matching callback method {0}<>{1} : {2}", new Object[] { ejbDesc.getEjbClassName(), md, containerTransaction });
                                    }
                                }
                            } catch (Exception e) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, "Transaction attribute for a lifecycle callback annotation processing error", e);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return getDefaultProcessedResult();
}
Also used : Set(java.util.Set) TransactionAttribute(javax.ejb.TransactionAttribute) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) AnnotationProcessorException(org.glassfish.apf.AnnotationProcessorException) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 55 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class HomeInterfaceCreateMethodExceptionRemote method check.

/**
 * Session beans home interface create method throws RemoteException test.
 *
 * The following are the requirements for the enterprise Bean's home interface
 * signature:
 *
 * An Session Bean's home interface defines zero or more create(...) methods.
 *
 * The throws clause must include java.rmi.RemoteException.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbSessionDescriptor) {
        boolean oneFailed = false;
        boolean foundAtLeastOneRemote = false;
        // methods which must throw java.rmi.RemoteException
        if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "No Remote Home Interface for this ejb", new Object[] {}));
            return result;
        }
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
            Method[] methods = c.getDeclaredMethods();
            Class[] methodExceptionTypes;
            boolean throwsRemoteException = false;
            for (int i = 0; i < methods.length; i++) {
                // clear these from last time thru loop
                throwsRemoteException = false;
                if (methods[i].getName().startsWith("create")) {
                    // is failed
                    if (!foundAtLeastOneRemote) {
                        foundAtLeastOneRemote = true;
                    }
                    methodExceptionTypes = methods[i].getExceptionTypes();
                    // methods must also throw java.rmi.RemoteException
                    if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
                        throwsRemoteException = true;
                    }
                    // method
                    if (throwsRemoteException) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The create method which must throw java.rmi.RemoteException was found."));
                    } else if (!throwsRemoteException) {
                        oneFailed = true;
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home Interface [ {0} ] Method [ {1} ]", new Object[] { c.getName(), methods[i].getName() }));
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A create method was found, but did not throw java.rmi.RemoteException."));
                    }
                // end of reporting for this particular 'create' method
                }
            // if the home interface found a "create" method
            }
        // for all the methods within the home interface class, loop
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { descriptor.getHomeClassName(), descriptor.getName() }));
        }
        if (!foundAtLeastOneRemote) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug3", "For Home Interface [ {0} ]", new Object[] { descriptor.getHomeClassName() }));
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "No create method was found in [ {0} ]", new Object[] { descriptor.getHomeClassName() }));
            result.setStatus(result.FAILED);
        } else {
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else {
                result.setStatus(result.PASSED);
            }
        }
        return result;
    } else {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Aggregations

EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)78 Result (com.sun.enterprise.tools.verifier.Result)28 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)28 Method (java.lang.reflect.Method)25 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)23 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)18 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)7 Iterator (java.util.Iterator)6 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)6 Set (java.util.Set)5 EJBException (javax.ejb.EJBException)4 Container (com.sun.ejb.Container)3 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)3 NoSuchEJBException (javax.ejb.NoSuchEJBException)3