Search in sources :

Example 21 with EjbEntityDescriptor

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

the class EjbFinderMethodFinal method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     The method must not be declared as final.
 *
 * @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 EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isFinal = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isFinal = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            foundAtLeastOne++;
                            ejbFindMethodFound = true;
                            // The method must not be declared as final.
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isFinal(findMethodModifiers)) {
                                isFinal = true;
                            }
                            if (ejbFindMethodFound && !isFinal) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A non-final [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && isFinal) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
            } 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: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(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(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 22 with EjbEntityDescriptor

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

the class EjbFinderMethodPublic method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     A finder method must be declared as public.
 *
 * @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 EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isPublic = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isPublic = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // A finder method must be declared as public. check the modifier
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isPublic(findMethodModifiers)) {
                                isPublic = true;
                            }
                            if (ejbFindMethodFound && isPublic) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A public [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && !isPublic) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but was not public.", new Object[] { ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "No ejbFind<METHOD> method was found in [ {0} ] class.", new Object[] { descriptor.getEjbClassName() }));
                }
            } 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: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(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(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 23 with EjbEntityDescriptor

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

the class EjbFinderMethodStatic method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     The method must not be declared as static.
 *
 * @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 EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isStatic = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isStatic = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // The method must not be declared as static.
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isStatic(findMethodModifiers)) {
                                isStatic = true;
                            }
                            if (ejbFindMethodFound && !isStatic) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A non-static [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && isStatic) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
            } 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: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(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(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 24 with EjbEntityDescriptor

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

the class EjbPostCreateMethodArgs method check.

/**
 * Entity Bean's ejbPostCreate(...) methods test.
 * Each entity Bean class may define zero or more ejbPostCreate(...) methods.
 * The number and signatures of a entity Bean's create methods are specific
 * to each EJB class. The method signatures must follow these rules:
 *
 * The method name must be ejbPostCreate.
 *
 * The methods arguments must be the same as the arguments of the
 * matching ejbCreate(...) method.
 *
 * @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 EjbEntityDescriptor) {
        boolean oneFailed = false;
        int foundAtLeastOne = 0;
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            Class[] ejbPostCreateMethodParameterTypes;
            Class[] ejbCreateMethodParameterTypes;
            boolean signaturesMatch = false;
            boolean ejbCreateExists = false;
            Method[] methods = c.getDeclaredMethods();
            Vector<Method> createMethodSuffix = new Vector<Method>();
            for (int i = 0; i < methods.length; i++) {
                // The method name must start with create.
                if (methods[i].getName().startsWith("ejbCreate")) {
                    createMethodSuffix.addElement((Method) methods[i]);
                    ejbCreateExists = true;
                }
            }
            // start do while loop here....
            do {
                for (int i = 0; i < methods.length; i++) {
                    // reset flags from last time thru loop
                    signaturesMatch = false;
                    // The method name must be ejbPostCreate.
                    if (methods[i].getName().startsWith("ejbPostCreate")) {
                        foundAtLeastOne++;
                        String matchSuffix = methods[i].getName().substring(13);
                        for (int k = 0; k < createMethodSuffix.size(); k++) {
                            if (matchSuffix.equals(((Method) createMethodSuffix.elementAt(k)).getName().substring(9))) {
                                ejbCreateMethodParameterTypes = ((Method) createMethodSuffix.elementAt(k)).getParameterTypes();
                                ejbPostCreateMethodParameterTypes = methods[i].getParameterTypes();
                                if (Arrays.equals(ejbCreateMethodParameterTypes, ejbPostCreateMethodParameterTypes)) {
                                    signaturesMatch = true;
                                    break;
                                }
                            }
                        }
                        if (signaturesMatch) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] declares [ {1} ] method with parameters that match corresponding [ {2} ] method.", new Object[] { descriptor.getEjbClassName(), methods[i].getName(), "ejbCreate<method>" }));
                        } else if (!signaturesMatch) {
                            oneFailed = true;
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but [ {1} ] method parameters did not match any corresponding [ {2} ] method parameters.", new Object[] { methods[i].getName(), methods[i].getName(), "ejbCreate<method>" }));
                            break;
                        }
                    }
                }
                if (oneFailed == true)
                    break;
            } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
            if (ejbCreateExists == false) {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbPostCreate(...) methods.", new Object[] { descriptor.getEjbClassName() }));
            }
            if (foundAtLeastOne == 0 && ejbCreateExists == true) {
                oneFailed = true;
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!", new Object[] {}));
            }
        } 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: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
            oneFailed = true;
        }
        if (oneFailed) {
            result.setStatus(result.FAILED);
        } else if (foundAtLeastOne == 0) {
            result.setStatus(result.NOT_APPLICABLE);
        } else {
            result.setStatus(result.PASSED);
        }
        return result;
    } else {
        result.addNaDetails(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(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Vector(java.util.Vector) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 25 with EjbEntityDescriptor

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

the class HomeInterfaceFindByPrimaryKeyArg 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.
 * @return boolean the results for this assertion i.e if a test has failed or not
 */
private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor) {
    Class[] ejbFinderMethodParameterTypes;
    boolean findByPrimaryKeyMethodFound = false;
    boolean foundOne = false;
    boolean oneFailed = false;
    boolean paramValid = false;
    boolean onlyOneParam = false;
    try {
        // retrieve the home interface methods
        VerifierTestContext context = getVerifierContext();
        ClassLoader jcl = context.getClassLoader();
        Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader());
        Method[] ejbFinderMethods = homeInterfaceClass.getDeclaredMethods();
        String primaryKeyType = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
        for (int j = 0; j < ejbFinderMethods.length; ++j) {
            // reset all booleans for next method within the loop
            paramValid = false;
            onlyOneParam = false;
            findByPrimaryKeyMethodFound = false;
            if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
                // Every entity enterprise Bean class must define the
                // findByPrimaryKey method. The result type for this method must
                // be the primary key type (i.e. the findByPrimaryKey method
                // must be a single-object finder).
                findByPrimaryKeyMethodFound = true;
                ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes();
                if (ejbFinderMethodParameterTypes.length == 1) {
                    onlyOneParam = true;
                    for (int k = 0; k < ejbFinderMethodParameterTypes.length; ++k) {
                        if (ejbFinderMethodParameterTypes[k].getName().equals(primaryKeyType)) {
                            paramValid = true;
                            break;
                        }
                    }
                } else {
                    // should already be set...
                    onlyOneParam = false;
                    paramValid = false;
                }
                // report for this particular findByPrimaryKey(...)
                if (findByPrimaryKeyMethodFound && paramValid) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For Home interface [ {0} ] Finder Method [ {1} ]", new Object[] { homeInterfaceClass.getName(), ejbFinderMethods[j].getName() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A findByPrimaryKey method with valid parameter type was found."));
                    foundOne = true;
                    break;
                } else if (findByPrimaryKeyMethodFound && onlyOneParam && !paramValid) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addNaDetails(smh.getLocalString(getClass().getName() + ".debug1", "For home interface [ {0} ] Finder Method [ {1} ]", new Object[] { homeInterfaceClass.getName(), ejbFinderMethods[j].getName() }));
                    result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable2", "A findByPrimaryKey method was found, but with non-PrimaryKeyClass arg parameter type."));
                } else if (findByPrimaryKeyMethodFound && !onlyOneParam) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addNaDetails(smh.getLocalString(getClass().getName() + ".debug1", "For home interface [ {0} ] Finder Method [ {1} ]", new Object[] { homeInterfaceClass.getName(), ejbFinderMethods[j].getName() }));
                    result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "A findByPrimaryKey method was found, but with non-single arg parameters."));
                }
            }
        }
        if (!foundOne) {
            oneFailed = true;
            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[] { homeInterfaceClass.getName() }));
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No single arg findByPrimaryKey(PrimaryKeyClass) method was found in home interface class [ {0} ].", new Object[] { homeInterfaceClass.getName() }));
        }
        return oneFailed;
    } 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.", new Object[] { home }));
        return oneFailed;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method)

Aggregations

EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)100 Result (com.sun.enterprise.tools.verifier.Result)88 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)87 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)49 Method (java.lang.reflect.Method)42 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)18 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)12 Iterator (java.util.Iterator)12 Field (java.lang.reflect.Field)10 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 Set (java.util.Set)8 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)7 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)6 Vector (java.util.Vector)5 Descriptor (org.glassfish.deployment.common.Descriptor)3 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 IASEjbExtraDescriptors (org.glassfish.ejb.deployment.descriptor.runtime.IASEjbExtraDescriptors)3 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)2