Search in sources :

Example 86 with MethodDescriptor

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

the class TransactionDemarcationHomeInterface method commonToBothInterfaces.

/**
 * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @param home for the Home interface of the Ejb.
 * @param methodIntf is the interface type
 * @return boolean the results for this assertion i.e if a test has failed or not
 */
private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor, String methodIntf) {
    boolean oneFailed = false;
    try {
        Arrays.sort(EJBObjectMethods);
        Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
        Method[] methods = c.getDeclaredMethods();
        boolean lookForIt = false;
        for (int i = 0; i < methods.length; i++) {
            if (Arrays.binarySearch(EJBObjectMethods, methods[i].getName()) < 0) {
                try {
                    ContainerTransaction containerTransaction = null;
                    boolean resolved = false;
                    if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                        for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                            lookForIt = false;
                            MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                            // style 1)
                            if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
                                // if Home - PASS
                                if (methodDescriptor.getEjbClassSymbol() == null) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) {
                                    lookForIt = true;
                                // if empty String PASS
                                } else if (methodDescriptor.getEjbClassSymbol().equals("")) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) {
                                    lookForIt = false;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) {
                                    lookForIt = false;
                                // else (Bogus)
                                } else {
                                    // carry on & don't look for
                                    // container transaction
                                    lookForIt = false;
                                }
                            } else if (methodDescriptor.getParameterClassNames() == null) {
                                // if (getEjbClassSybol() is Home or is the empty String AND if methods[i].getName().equals(methodDescriptor.getName())
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // carry on
                                    lookForIt = false;
                                }
                            } else {
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName())) && (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(methods[i], methodIntf)).getParameterClassNames()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // CARRY ON
                                    lookForIt = false;
                                }
                            }
                            if (lookForIt) {
                                containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                                if (containerTransaction != null) {
                                    String transactionAttribute = containerTransaction.getTransactionAttribute();
                                    // don't need this check here
                                    if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is valid.   Transaction attributes must be specified for all methods except getEJBMetaData and getHomeHandle methods of home interface [ {3} ]", new Object[] { methods[i].getName(), transactionAttribute, methodDescriptor.getName(), home }));
                                        resolved = true;
                                    } else {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] " + "is not valid.   Transaction attributes must be specified for " + "all methods except getEJBMetaData and getHomeHandle methods of " + "home interface [ {3} ]", new Object[] { methods[i].getName(), transactionAttribute, methodDescriptor.getName(), home }));
                                    }
                                } else {
                                    oneFailed = true;
                                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException", "Error: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
                                }
                            }
                        }
                        // did you resolve the last one okay?
                        if (!resolved) {
                            /*
                                // This if-stmt code is a workaround introduced by Harminder
                                // because currently methodDescriptor.getEjbClassSymbol() is
                                // returning NULL
                                //if (allMethods){
                                if (!wildCardWasPresent) {
*/
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Transaction attributes must be specified for the methods defined in the home interface [ {0} ].  Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", new Object[] { home, methods[i].getName(), descriptor.getName() }));
                        }
                    /*
                             else {
                                      result.addGoodDetails(smh.getLocalString
                                                                   ("tests.componentNameConstructor",
                                                                    "For [ {0} ]",
                                                                    new Object[] {compName.toString()}));
				      result.addGoodDetails(smh.getLocalString
						(getClass().getName() + ".passed",
					         "Valid: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is valid.   Transaction attributes must be specified for all methods except getEJBMetaData and getHomeHandle methods of home interface [ {3} ]",
						 new Object[] {methods[i].getName(),"*","*", home}));
//                              }
                              // End of workaround code. Note : this else also has to be removed once
                              // the original bug of methodDesc.getEjbClassSymbol() is fixed

                          }
*/
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "Error: There are no method container transactions within this bean [ {0} ].   Transaction attributes must be specified for the methods defined in the home interface [ {1} ].  Method [ {2} ] has no transaction attribute defined.", new Object[] { descriptor.getName(), home, methods[i].getName() }));
                    }
                    if (oneFailed == true && i == methods.length - 1)
                        return oneFailed;
                    else
                        continue;
                } catch (Exception e) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Home interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { home, e.getMessage(), descriptor.getName() }));
                    oneFailed = true;
                    return oneFailed;
                }
            } else // if found relevant Home interface method
            {
                oneFailed = true;
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failedExcep", "Error: Method [ {0} ] should not be assigned a transaction attribute.", new Object[] { methods[i].getName() }));
            }
        }
        // for all the methods within the home interface class, loop
        return oneFailed;
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { home, descriptor.getName() }));
        oneFailed = true;
        return oneFailed;
    }
}
Also used : Enumeration(java.util.Enumeration) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 87 with MethodDescriptor

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

the class TransactionDemarcationBeanManaged method check.

/**
 * Session/Entity Bean bean-managed transaction demarcation type test.
 * The Application Assembler must not define transaction attributes for an
 * enterprise bean with bean-managed transaction demarcation.
 *
 * @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 {
        // enterprise bean with bean-managed transaction demarcation.
        if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
            String transactionType = descriptor.getTransactionType();
            if (EjbDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
                ContainerTransaction containerTransaction = null;
                if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                    for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                        MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                        containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                        try {
                            String transactionAttribute = containerTransaction.getTransactionAttribute();
                            // don't need this check here
                            if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.   The Application Assembler must not define transaction attributes for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
                            } else {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
                            }
                        } catch (NullPointerException e) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Valid: TransactionAttribute is null for method [ {0} ] in bean [ {1} ]", new Object[] { methodDescriptor.getName(), descriptor.getName() }));
                            return result;
                        }
                    }
                } else {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed2", "Valid: There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
                }
                return result;
            } else {
                // not container managed, but is a session/entity bean
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.BEAN_TRANSACTION_TYPE, transactionType }));
            }
            return result;
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
            return result;
        }
    } catch (Throwable t) {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Enumeration(java.util.Enumeration) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 88 with MethodDescriptor

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

the class ContainerTransactionMethodExists method check.

/**
 * @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)) {
        Map<MethodDescriptor, ContainerTransaction> transactionalMethods = descriptor.getMethodContainerTransactions();
        if (transactionalMethods != null) {
            for (MethodDescriptor methodDescriptor : transactionalMethods.keySet()) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid container transaction method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 89 with MethodDescriptor

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

the class ExcludeListMethodsExist method check.

/**
 * Methods used in exclude-list element of the deployment descriptor
 * must be methods defined in the enterprise bean's remote 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.getExcludedMethodDescriptors();
        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 exclude list 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 90 with MethodDescriptor

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

the class MethodPermissionMethodExists method check.

/**
 * Methods used in method permission element of the deployment descriptor
 * must be methods defined in the enterprise bean's remote 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)) {
        Map<MethodPermission, Collection<MethodDescriptor>> permissionedMethods = descriptor.getMethodPermissionsFromDD();
        if (permissionedMethods != null) {
            for (MethodPermission methodPermission : permissionedMethods.keySet()) for (MethodDescriptor methodDescriptor : permissionedMethods.get(methodPermission)) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid method permission method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Collection(java.util.Collection) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

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