Search in sources :

Example 91 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class UncheckedMethodsExist method check.

/**
 * Methods used in unchecked element of the deployment descriptor
 * must be methods defined in the enterprise bean's component and/or home
 * interface.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        Set<MethodDescriptor> permissionedMethods = descriptor.getUncheckedMethodDescriptors();
        if (permissionedMethods != null && permissionedMethods.size() > 0) {
            for (MethodDescriptor methodDescriptor : permissionedMethods) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid unchecked method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 92 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class ContainerTransactionStyle3 method commonToAllInterfaces.

/**
 * Iterate over all the bean methods and check if they are present in any
 * of the bean's interfaces.
 */
private void commonToAllInterfaces() {
    boolean isTimedObject = false;
    try {
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class beanClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
        isTimedObject = javax.ejb.TimedObject.class.isAssignableFrom(beanClass);
    }// continue
     catch (ClassNotFoundException e) {
    }
    initializeMethods();
    for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
        MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
        if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS) || // style 1 and 2
        methodDescriptor.getParameterClassNames() == null)
            continue;
        if (isTimedObject && MethodDescriptor.EJB_BEAN.equals(methodDescriptor.getEjbClassSymbol()) && methodDescriptor.getName().equals("ejbTimeout")) {
            String[] params = methodDescriptor.getJavaParameterClassNames();
            if (params.length == 1 && params[0].trim().equals("javax.ejb.Timer"))
                // found a match
                continue;
        }
        // if implements timer
        Set<Method> methods = getAllInterfaceMethods(methodDescriptor);
        if (!isMethodContained(methods, methodDescriptor)) {
            // report failure
            String ejbClassSymbol = methodDescriptor.getEjbClassSymbol();
            String intf = ejbClassSymbol;
            if (ejbClassSymbol == null) {
                intf = smh.getLocalString(getClass().getName() + ".msg", "any of bean");
            } else if (ejbClassSymbol.equals(MethodDescriptor.EJB_REMOTE)) {
                intf = "Remote or RemoteBusiness";
            } else if (ejbClassSymbol.equals(MethodDescriptor.EJB_LOCAL)) {
                intf = "Local or LocalBusiness";
            }
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Container Transaction method name [ {0} ] not " + "defined in [ {1} ] interface(s).", new Object[] { methodDescriptor.getName(), intf }));
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 93 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class ContainerTransactionStyle2 method check.

/**
 * Each container transaction element consists of a list of one or more
 * method elements, and the trans-attribute element. The container transaction
 * element specifies that all the listed methods are assigned the specified
 * transaction attribute value.
 *
 * Style 2:
 *    <method>
 *      <ejb-name> EJBNAME</ejb-name>
 *      <method-name>METHOD</method-name>
 *    </method>
 * This style is used for referring to a specified method of the remote or home
 * interface of the specified enterprise bean. If there are multiple methods
 * with the same overloaded name, this style refers to all the methods with the
 * same name. There must be at most one container transaction element that uses
 * the Style 2 method element for a given method name.  If there is also a
 * container transaction element that uses Style 1 element for the same bean,
 * the value specified by the Style 2 element takes precedence.
 *
 * @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();
    // <ejb-class>verifier.ejb.hello.BogusEJB...
    try {
        boolean oneFailed = false;
        if (!descriptor.getMethodContainerTransactions().isEmpty()) {
            int na = 0;
            for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                // see if it's a style 2
                if (methodDescriptor.getParameterClassNames() == null) {
                    int foundIt = 0;
                    // for given method name
                    for (Enumeration eee = descriptor.getMethodContainerTransactions().keys(); eee.hasMoreElements(); ) {
                        MethodDescriptor matchingMethodDescriptor = (MethodDescriptor) eee.nextElement();
                        // see if this md is style 2 ?
                        if (matchingMethodDescriptor.getParameterClassNames() == null) {
                            // encountered method name
                            if (methodDescriptor.getName().equals(matchingMethodDescriptor.getName())) {
                                foundIt++;
                            }
                        }
                    }
                    // DOL only saves one container tx with "*", so can't fail...
                    if (foundIt == 1) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Container Transaction method name [ {0} ] defined only once in [ {1} ] bean.", new Object[] { methodDescriptor.getName(), descriptor.getName() }));
                    } else if (foundIt > 1) {
                        if (!oneFailed) {
                            oneFailed = false;
                        }
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Container Transaction method name [ {0} ] is defined [ {1} ] times in [ {2} ] bean.  Method name container transaction style{3} is allowed only once per bean.", new Object[] { methodDescriptor.getName(), new Integer(foundIt), descriptor.getName(), new Integer(2) }));
                    } else {
                        na++;
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Container Transaction method name [ {0} ] not defined in [ {1} ] bean.", new Object[] { methodDescriptor.getName(), descriptor.getName() }));
                    }
                } else {
                    // not a style 2
                    na++;
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Container Transaction method name [ {0} ] not defined as style{1} container transaction within [ {2} ].", new Object[] { methodDescriptor.getName(), new Integer(2), descriptor.getName() }));
                }
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (na == descriptor.getMethodContainerTransactions().size()) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if !descriptor.getMethodContainerTransactions().isEmpty
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no container transactions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
            return result;
        }
    } catch (Throwable t) {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : Enumeration(java.util.Enumeration) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 94 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class BeanMethodCalculatorImpl method transformAndAdd.

/**
 * utiliy method to transform our collection of Method objects into
 * MethodDescriptor objects and add them to our global list of
 * elligible methods
 * @param the collection of acceptable method objects
 * @param the method-intf identifier for those methods
 * @param the global list of MethodDescriptors objects
 */
private void transformAndAdd(Collection methods, String methodIntf, Vector globalList) {
    for (Iterator itr = methods.iterator(); itr.hasNext(); ) {
        Method m = (Method) itr.next();
        MethodDescriptor md = new MethodDescriptor(m, methodIntf);
        globalList.add(md);
    }
}
Also used : Iterator(java.util.Iterator) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 95 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class BeanMethodCalculatorImpl method getTransactionalMethodsFor.

/**
 * @return a collection of MethodDescriptor for all the methods of my
 * ejb which are elligible to have a particular transaction setting.
 */
public Collection getTransactionalMethodsFor(com.sun.enterprise.deployment.EjbDescriptor desc, ClassLoader loader) throws ClassNotFoundException, NoSuchMethodException {
    EjbDescriptor ejbDescriptor = (EjbDescriptor) desc;
    // only set if desc is a stateful session bean.  NOTE that
    // !statefulSessionBean does not imply stateless session bean
    boolean statefulSessionBean = false;
    Vector methods = new Vector();
    if (ejbDescriptor instanceof EjbSessionDescriptor) {
        statefulSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isStateful();
        boolean singletonSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isSingleton();
        // Session Beans
        if (ejbDescriptor.isRemoteInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBObject.class, sessionBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getRemoteClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        if (ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getRemoteBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_REMOTE));
                }
            }
        }
        if (ejbDescriptor.isLocalInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBLocalObject.class, sessionLocalBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getLocalClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
        if (ejbDescriptor.isLocalBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getLocalBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
                }
            }
        }
        if (ejbDescriptor.isLocalBean()) {
            String intfName = ejbDescriptor.getEjbClassName();
            Class businessIntf = loader.loadClass(intfName);
            Method[] busIntfMethods = businessIntf.getMethods();
            for (Method next : busIntfMethods) {
                methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
            }
        }
        if (ejbDescriptor.hasWebServiceEndpointInterface()) {
            Class webServiceClass = loader.loadClass(ejbDescriptor.getWebServiceEndpointInterfaceName());
            Method[] webMethods = webServiceClass.getMethods();
            for (int i = 0; i < webMethods.length; i++) {
                methods.add(new MethodDescriptor(webMethods[i], MethodDescriptor.EJB_WEB_SERVICE));
            }
        }
        // SFSB and Singleton can have lifecycle callbacks transactional
        if (statefulSessionBean || singletonSessionBean) {
            Set<LifecycleCallbackDescriptor> lcds = ejbDescriptor.getLifecycleCallbackDescriptors();
            for (LifecycleCallbackDescriptor lcd : lcds) {
                try {
                    Method m = lcd.getLifecycleCallbackMethodObject(loader);
                    MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                    methods.add(md);
                } catch (Exception e) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Lifecycle callback processing error", e);
                    }
                }
            }
        }
    } else {
        // entity beans local interfaces
        String homeIntf = ejbDescriptor.getHomeClassName();
        if (homeIntf != null) {
            Class home = loader.loadClass(homeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_HOME, methods);
            String remoteIntf = ejbDescriptor.getRemoteClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        // enity beans remote interfaces
        String localHomeIntf = ejbDescriptor.getLocalHomeClassName();
        if (localHomeIntf != null) {
            Class home = loader.loadClass(localHomeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBLocalHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCALHOME, methods);
            String remoteIntf = ejbDescriptor.getLocalClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBLocalObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
    }
    if (!statefulSessionBean) {
        if (ejbDescriptor.isTimedObject()) {
            if (ejbDescriptor.getEjbTimeoutMethod() != null) {
                methods.add(ejbDescriptor.getEjbTimeoutMethod());
            }
            for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
                methods.add(schd.getTimeoutMethod());
            }
        }
    }
    return methods;
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Collection(java.util.Collection) Vector(java.util.Vector) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Aggregations

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)97 Method (java.lang.reflect.Method)37 Iterator (java.util.Iterator)25 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)23 Set (java.util.Set)18 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)16 ArrayList (java.util.ArrayList)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 MethodPermission (com.sun.enterprise.deployment.MethodPermission)10 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)9 HashSet (java.util.HashSet)9 Vector (java.util.Vector)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 MethodNode (com.sun.enterprise.deployment.node.MethodNode)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6