Search in sources :

Example 51 with EjbEntityDescriptor

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

the class ActiveTxCache method setEJBMetaData.

@Override
protected void setEJBMetaData() throws Exception {
    EjbEntityDescriptor ed = (EjbEntityDescriptor) ejbDescriptor;
    Class primaryKeyClass = loader.loadClass(ed.getPrimaryKeyClassName());
    metadata = new EJBMetaDataImpl(ejbHomeStub, homeIntf, remoteIntf, primaryKeyClass);
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EJBMetaDataImpl(com.sun.ejb.portable.EJBMetaDataImpl)

Example 52 with EjbEntityDescriptor

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

the class ImplementsTimedObjectTest method check.

/**
 * Checks if the EJB class implements the TimedObject interface
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
@Override
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean isEjb30 = descriptor.getEjbBundleDescriptor().getSpecVersion().equalsIgnoreCase("3.0");
    if (descriptor.isTimedObject()) {
        // and 2.1 entity beans.Timers cannot be created for stateful session beans or EJB 3.0 entities.
        if (((descriptor instanceof EjbEntityDescriptor) && isEjb30) || ((descriptor instanceof EjbSessionDescriptor) && ((((EjbSessionDescriptor) descriptor).getSessionType()).equals(EjbSessionDescriptor.STATEFUL)))) {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed1", "[ {0} ] must not implement the TimedObject interface." + "Only 2.1 entity beans or stateless session beans may " + "implement the TimedObject interface", new Object[] { descriptor.getEjbClassName() }));
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly implements the TimedObject interface", new Object[] { descriptor.getEjbClassName() }));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 53 with EjbEntityDescriptor

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

the class EjbFinderMethodNameCmp method check.

/**
 * ejbFind<METHOD>(...) methods not defined for entity bean with container
 *  managed persistence test.
 *
 *   EJB class contains no ejbFind<METHOD>(...) methods declared in the bean
 *   class when the bean is container managed.
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 * @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 {
                // retrieve the home interface methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                // retrieve the EJB Class Methods
                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) {
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            foundAtLeastOne++;
                            if (!oneFailed) {
                                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[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An improperly named [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null));
                if (foundAtLeastOne == 0) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {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 {
                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() + ".notApplicable1", "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 54 with EjbEntityDescriptor

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

the class EjbFinderMethodReturn 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 return type of a finder method must be the enterprise Bean's primary
 *     key type, or an EJB primary key collection
 *
 * @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 returnValueValid = false;
            boolean oneFailed = false;
            boolean oneWarning = 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();
                    String primaryKeyType = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        returnValueValid = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            Class returnByPrimaryKeyValue = ejbFinderMethods[j].getReturnType();
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // (see Section Subsection 9.1.8).
                            if ((returnByPrimaryKeyValue.getName().equals(primaryKeyType)) || (returnByPrimaryKeyValue.getName().equals("java.util.Collection")) || (returnByPrimaryKeyValue.getName().equals("java.util.Enumeration"))) {
                                returnValueValid = true;
                            }
                            if (ejbFindMethodFound && returnValueValid) {
                                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", "An [ {0} ] method was found with valid return type.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && (!returnValueValid)) {
                                if (primaryKeyType.equals("java.lang.Object")) {
                                    oneWarning = true;
                                    result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                    result.addWarningDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                    result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Warning: An [ {0} ] method was found, but [ {1} ] method has [ {2} ] return type.   Deployment descriptor primary key type is [ {3} ]. Definition of the primary key type is deferred to deployment time ?", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName(), ejbFinderMethods[j].getReturnType().getName(), primaryKeyType }));
                                } else {
                                    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 [ {1} ] return type must be the enterprise Bean's primary key type, or an EJB primary key collection .", 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 {
                if (oneWarning) {
                    result.setStatus(result.WARNING);
                } 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 55 with EjbEntityDescriptor

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

the class EjbPostCreateMethodException 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:
 *
 * Compatibility Note: EJB 1.0 allowed the ejbPostCreate 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 ejbPostCreateFound = 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
                    ejbPostCreateFound = false;
                    throwsRemoteException = false;
                    // The method name must be ejbPostCreate.
                    if (methods[i].getName().startsWith("ejbPostCreate")) {
                        foundAtLeastOne++;
                        ejbPostCreateFound = true;
                        // Compatibility Note: EJB 1.0 allowed the ejbPostCreate 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();
                        if (EjbUtils.isValidRemoteException(exceptions)) {
                            throwsRemoteException = true;
                        }
                        // ejbPostCreate method
                        if (ejbPostCreateFound && (!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} ] declares [ {1} ] method which properly does not throw java.rmi.RemoteException.", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                        } else if (ejbPostCreateFound && 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 ejbPostCreate 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++;
                        }
                    }
                }
            } 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 ejbPostCreate(...) 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