Search in sources :

Example 81 with EjbEntityDescriptor

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

the class CmpEjbCreateMethod method check.

/**
 * Entity Bean's with container managed persistence ejbCreate(...) and
 * ejbPostCrete(...) methods must be defined to return the primary key class
 * type. The implementation of the ejbCreate(...) methods should be coded to
 * return a null. The returned value is ignored by the Container.
 *
 * The method signatures must follow these rules:
 *
 * The return type must be defined to return the primary key class type.
 *
 * @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.CONTAINER_PERSISTENCE.equals(persistence)) {
            boolean oneFailed = false;
            int foundAtLeastOne = 0;
            try {
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                Method[] methods1 = c.getDeclaredMethods();
                int loopCounter = 0;
                boolean ejbCreateFound = false;
                boolean returnsPrimaryKeyClassType = false;
                // start do while loop here....
                do {
                    Method[] methods = c.getDeclaredMethods();
                    methods1 = null;
                    methods1 = methods;
                    for (int i = 0; i < methods.length; i++) {
                        // reset flags from last time thru loop
                        ejbCreateFound = false;
                        loopCounter++;
                        returnsPrimaryKeyClassType = false;
                        // The method name must be ejbCreate.
                        if (methods[i].getName().startsWith("ejbCreate")) {
                            foundAtLeastOne++;
                            ejbCreateFound = true;
                            // The return type must be be defined to
                            // return the primary key class type
                            Class rt = methods[i].getReturnType();
                            Class str = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName());
                            do {
                                if (rt.getName().equals(str.getName())) {
                                    returnsPrimaryKeyClassType = true;
                                }
                                str = str.getSuperclass();
                            } while (str != null && returnsPrimaryKeyClassType != true);
                            // method
                            if (ejbCreateFound && returnsPrimaryKeyClassType) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] ejbCreate(...) Method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly returns the primary key class type.", new Object[] { descriptor.getEjbClassName() }));
                            } else if (ejbCreateFound && !returnsPrimaryKeyClassType) {
                                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} ] ejbCreate(...) Method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods1[loopCounter].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An ejbCreate(...) method was found, but did not properly return the primary key class type."));
                            }
                        }
                    }
                } while (((c = c.getSuperclass()) != null) && (!(ejbCreateFound && returnsPrimaryKeyClassType)));
                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 ejbCreate(...) 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: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (BEAN_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.CONTAINER_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 82 with EjbEntityDescriptor

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

the class CmpEjbNoInvalidCreateMethod method check.

/**
 * Entity beans with CMP 1.1 must not define create<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();
    try {
        if (descriptor instanceof EjbCMPEntityDescriptor) {
            String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
            if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence) && ((EjbCMPEntityDescriptor) descriptor).getCMPVersion() == EjbCMPEntityDescriptor.CMP_1_1) {
                try {
                    Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
                    Method[] methods = c.getDeclaredMethods();
                    boolean oneFailed = false;
                    for (int i = 0; i < methods.length; i++) {
                        Method aMethod = methods[i];
                        if (aMethod.getName().startsWith("create")) {
                            if (!aMethod.getName().endsWith("create")) {
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "CMP 1.1 entity beans are not authorized to define [ {0} ] method", new Object[] { aMethod.getName() }));
                                oneFailed = true;
                            }
                        }
                    }
                    if (oneFailed) {
                        result.setStatus(Result.FAILED);
                    } else {
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "No create<METHOD> defined for this CMP 1.1 entity bean [ {0} ] ", new Object[] { descriptor.getName() }));
                    }
                    return result;
                } catch (ClassNotFoundException cnfe) {
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getHomeClassName() }));
                    return result;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] is not a CMP 1.1 Entity Bean.", new Object[] { descriptor.getName() }));
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Method(java.lang.reflect.Method) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 83 with EjbEntityDescriptor

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

the class CMPTest method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
            if (((EjbCMPEntityDescriptor) descriptor).getCMPVersion() < EjbCMPEntityDescriptor.CMP_2_x) {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable3", "Test do not apply to this cmp-version of container managed persistence EJBs"));
                return result;
            }
            return check((EjbCMPEntityDescriptor) descriptor);
        } else {
            // if (BEAN_PERSISTENCE.equals(persistentType))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable2", "Test do not apply to EJB declared with persistence type [ {0} ]", new Object[] { persistentType }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable1", "Test do not apply to non entity EJB "));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 84 with EjbEntityDescriptor

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

the class HomeInterfaceCreateMethodExceptionRemote method check.

/**
 * Entity beans home interface create method throws RemoteException test.
 *
 * The following are the requirements for the enterprise Bean's home interface
 * signature:
 *
 * An Entity 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 EjbEntityDescriptor) {
        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() + ".debug3", "No Remote Home Interface for this ejb", new Object[] {}));
            return result;
        }
        try {
            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 N/A
                    if (!foundAtLeastOneRemote) {
                        foundAtLeastOneRemote = true;
                    }
                    methodExceptionTypes = methods[i].getExceptionTypes();
                    // methods must also throw java.rmi.RemoteException
                    if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
                        throwsRemoteException = true;
                    }
                    // report for this particular create method found in home interface
                    // now display the appropriate results for this particular create
                    // method
                    logger.log(Level.FINE, " Interface " + c.getName() + " method " + methods[i].getName());
                    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(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.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug3", "For Home Interface [ {0} ]", new Object[] { descriptor.getHomeClassName() }));
            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "No create method was found, test not applicable."));
            result.setStatus(result.PASSED);
        } else {
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } 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 : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 85 with EjbEntityDescriptor

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

the class EjbCreateMethodExceptions method check.

/**
 * Entity Bean's ejbCreate(...) methods exceptions test.
 * Each entity Bean class may define zero or more ejbCreate(...) 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:
 *
 * Compatibility Note: EJB 1.0 allowed the ejbCreate method to throw the
 * java.rmi.RemoteException to indicate a non-application exception. This
 * practice is deprecated in EJB 1.1---an EJB 1.1 compliant enterprise bean
 * should throw the javax.ejb.EJBException or another RuntimeException to
 * indicate non-application exceptions to the Container (see Section 12.2.2).
 * Note: Treat as a warning to user in this instance.
 *
 * @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 foundWarning = 0;
        int foundAtLeastOne = 0;
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            boolean ejbCreateFound = false;
            boolean throwsRemoteException = false;
            // start do while loop here....
            do {
                Method[] methods = c.getDeclaredMethods();
                for (int i = 0; i < methods.length; i++) {
                    // reset flags from last time thru loop
                    ejbCreateFound = false;
                    throwsRemoteException = false;
                    // The method name must be ejbCreate.
                    if (methods[i].getName().startsWith("ejbCreate")) {
                        foundAtLeastOne++;
                        ejbCreateFound = true;
                        // Compatibility Note: EJB 1.0 allowed the ejbCreate method to throw
                        // the java.rmi.RemoteException to indicate a non-application
                        // exception. This practice is deprecated in EJB 1.1---an EJB 1.1
                        // compliant enterprise bean should throw the javax.ejb.EJBException
                        // or another RuntimeException to indicate non-application
                        // exceptions to the Container (see Section 12.2.2).
                        // Note: Treat as a warning to user in this instance.
                        Class[] exceptions = methods[i].getExceptionTypes();
                        for (int z = 0; z < exceptions.length; ++z) {
                            if (exceptions[z].getName().equals("java.rmi.RemoteException")) {
                                throwsRemoteException = true;
                                break;
                            }
                        }
                        // method
                        if (ejbCreateFound && (!throwsRemoteException)) {
                            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} ] properly declares [ {1} ] method which does not throw java.rmi.RemoteException.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                        } else if (ejbCreateFound && throwsRemoteException) {
                            result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addWarningDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                            result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Error: Compatibility Note:" + "\n An [ {0} ] method was found, but" + "\n EJB 1.0 allowed the ejbCreate method to throw the " + "\n java.rmi.RemoteException to indicate a non-application" + "\n exception. This practice is deprecated in EJB 1.1" + "\n ---an EJB 1.1 compliant enterprise bean should" + "\n throw the javax.ejb.EJBException or another " + "\n RuntimeException to indicate non-application exceptions" + "\n to the Container. ", new Object[] { methods[i].getName() }));
                            foundWarning++;
                            break;
                        }
                    }
                }
                if (foundWarning > 0)
                    break;
            } while (((c = c.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 ejbCreate(...) 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: [ {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 if (foundWarning > 0) {
            result.setStatus(result.WARNING);
        } 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) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Aggregations

EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)101 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)7 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