Search in sources :

Example 6 with EjbDescriptor

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

the class CmrFields method runIndividualCmrTest.

/**
 * run an individual verifier test of a declated cmr field of the class
 *
 * @param entity the descriptor for the entity bean containing the cmp-field
 * @param info the descriptor for the declared cmr field
 * @param c the class owning the cmp field
 * @parma r the result object to use to put the test results in
 *
 * @return true if the test passed
 */
protected boolean runIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor role, Class c, Result result) {
    boolean foundIt = false;
    CMRFieldInfo info = null;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        info = role.getCMRFieldInfo();
    } catch (Exception e) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: No Local interfaces defined for EJB [ {0} ]", new Object[] { descriptor.getName() }));
        return false;
    }
    if (role.getPartner().getIsMany()) {
        // must be one the collection interface
        if (info.type.getName().equals("java.util.Collection") || info.type.getName().equals("java.util.Set")) {
            foundIt = true;
        }
    } else {
        EjbBundleDescriptorImpl bundle = ((EjbDescriptor) descriptor).getEjbBundleDescriptor();
        if (((EjbDescriptor) descriptor).getLocalClassName() != null && !"".equals(((EjbDescriptor) descriptor).getLocalClassName())) {
            if (isValidInterface(info.type, bundle.getEjbs())) {
                foundIt = true;
            }
        } else {
            if ((role.getRelationshipDescriptor()).getIsBidirectional()) {
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
                return false;
            } else
                foundIt = true;
        }
    }
    if (foundIt) {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
    } else {
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
    }
    return foundIt;
}
Also used : CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 7 with EjbDescriptor

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

the class DependentValueClassModifiers method runIndividualCmpFieldTest.

/**
 * run an individual verifier test of a declated cmp field of the class
 *
 * @param entity the descriptor for the entity bean containing the cmp-field
 * @param f the descriptor for the declared cmp field
 * @param c the class owning the cmp field
 * @parma r the result object to use to put the test results in
 *
 * @return true if the test passed
 */
protected boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class c, Result result) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String fieldName = persistentField.getName();
    String getMethodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
    Method getMethod = getMethod(c, getMethodName, null);
    if (getMethod != null) {
        Class returnType = getMethod.getReturnType();
        // check if this is a reference to a primitive or an array of primitive type
        if (returnType.isArray()) {
            returnType = returnType.getComponentType();
        }
        if (returnType.isPrimitive()) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        if (returnType.isInterface()) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        if (returnType.toString().startsWith("class java.")) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        // it must be a reference to a bean's home or remote interface
        EjbBundleDescriptorImpl bundle = ((EjbDescriptor) entity).getEjbBundleDescriptor();
        if ((isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_REMOTE)) || (isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_LOCAL))) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
            return true;
        }
        // this is a reference to a dependent value class
        int modifiers = returnType.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isAbstract(modifiers) == false && EjbUtils.isValidSerializableType(returnType)) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.passed", "Dependent value class [ {0} ] reference by cmp field [ {1} ] is public, not abstract and serializable", new Object[] { returnType.getName(), fieldName }));
            return true;
        } else {
            result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addWarningDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.failed", "Verifier cannot find out if [ {0} ] is a Dependent value class (reference by cmp field [ {1} ]) ", new Object[] { returnType.getName(), fieldName }));
            return false;
        }
    } else {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.isAccessorDeclared.failed2", "Error : Cannot find accessor [ {0} ] method for [ {1} ] field ", new Object[] { getMethodName, fieldName }));
        return false;
    }
}
Also used : Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 8 with EjbDescriptor

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

the class PrimaryKeyClassFieldsMatchBeanFields method check.

/**
 * Enterprise Java Bean primary key maps to multiple fields in the Entity bean
 * class test.
 *
 * The primkey-field element is not used if the primary key maps to multiple
 * container-managed fields (i.e. the key is a compound key). In this case, the
 * fields of the primary key class must be public, and their names must
 * correspond to the field names of the entity bean class that comprise the key.
 *
 * @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();
    // field names of the entity bean class that comprise the key.
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
            // field in entity bean class and this test in notApplicable
            try {
                FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
                if (fd != null) {
                    String pkf = fd.getName();
                    if (pkf.length() > 0) {
                        // N/A case
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
                    }
                } else {
                    try {
                        VerifierTestContext context = getVerifierContext();
                        ClassLoader jcl = context.getClassLoader();
                        Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
                        Field[] fields = c.getDeclaredFields();
                        Vector beanFields = ((EjbDescriptor) descriptor).getFieldDescriptors();
                        boolean oneFailed = false;
                        boolean badField = false;
                        for (int i = 0; i < fields.length; i++) {
                            badField = false;
                            if (EjbUtils.isPKFieldMatchingBeanFields(fields[i], beanFields)) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "Valid: Field [ {0} ] defined within primary key class [ {1} ] does correspond to the field names of the entity bean class [ {2} ] that comprise the key.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getEjbClassName() }));
                                continue;
                            } else {
                                if (!oneFailed) {
                                    oneFailed = true;
                                }
                                badField = true;
                            }
                            if (badField == true) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within primary key class [ {1} ] does not correspond to the field names of the entity bean class [ {2} ] that comprise the key.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getEjbClassName() }));
                            }
                        }
                        if (!oneFailed) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "This primary key class [ {0} ] has defined all fields which correspond to the field names of the entity bean class [ {1} ] that comprise the key.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), 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 or [ {1} ] class not found.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), ((EjbEntityDescriptor) descriptor).getEjbClassName() }));
                    } catch (Throwable t) {
                        result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.warning(smh.getLocalString(getClass().getName() + ".warningException", "Warning: [ {0} ] class encountered [ {1} ]. Cannot access fields of class [ {2} ] which is external to [ {3} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
                    }
                }
            } catch (NullPointerException e) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
            }
            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.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}.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Field(java.lang.reflect.Field) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) Vector(java.util.Vector) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 9 with EjbDescriptor

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

the class ASEjbName method check.

/**
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    boolean oneFailed = false;
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        String ejbName = descriptor.getName();
        if (ejbName.length() == 0) {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "failed [AS-EJB ejb] : ejb-name cannot not be empty. It should be a valid ejb-name as defined in ejb-jar.xml"));
        } else {
            EjbDescriptor testDesc = descriptor.getEjbBundleDescriptor().getEjbByName(ejbName);
            if (testDesc != null && testDesc.getName().equals(ejbName)) {
                addGoodDetails(result, compName);
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] :  ejb-name is {0} and verified with ejb-jar.xml", new Object[] { ejbName }));
            } else {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb] :  ejb-name {0} is not found in ejb-jar.xml. It should exist in ejb-jar.xml also.", new Object[] { ejbName }));
            }
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create descriptor object"));
    }
    return result;
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 10 with EjbDescriptor

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

the class EjbNameUnique method check.

/**
 * The ejb-name must be unique amoung the names of the enterprise beans within
 * the same ejb-jar file.
 *
 * @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();
    String ejbName = descriptor.getName();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // initialize needed by ejb loop
    int found = 0;
    // no duplicates.
    for (Iterator itr = descriptor.getEjbBundleDescriptor().getEjbs().iterator(); itr.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
        if (ejbDescriptor.getName().equals(ejbName)) {
            found++;
            if (found > 1) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] has found [ {1} ] duplicate ejb name(s) within the same jar.", new Object[] { ejbName, new Integer((found - 1)) }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: [ {0} ] was found once within jar, ejb-name is unique.", new Object[] { ejbName }));
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)48 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)19 Iterator (java.util.Iterator)18 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)16 Result (com.sun.enterprise.tools.verifier.Result)14 Method (java.lang.reflect.Method)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 Set (java.util.Set)8 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)6 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)5 Container (com.sun.ejb.Container)4 Field (java.lang.reflect.Field)4 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)4 DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)4 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)3 Constructor (java.lang.reflect.Constructor)3 Descriptor (org.glassfish.deployment.common.Descriptor)3 InterceptorBindingDescriptor (org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)3