Search in sources :

Example 16 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class CmpFieldsTransient method check.

/**
 * The Bean Provider is responsible for using the cmp-field elements of the
 * deployment descriptor to declare the instance's fields that the Container
 * must load and store at the defined times.
 *
 *  The fields must not be defined in the entity bean class as transient.
 *
 * @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)) {
            // this test apply only to 1.x cmp beans. in cmp 2.x, fields are virtual fields only
            if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
                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;
            }
            boolean oneFailed = false;
            boolean badField = false;
            for (Iterator itr = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields().iterator(); itr.hasNext(); ) {
                FieldDescriptor nextPersistentField = (FieldDescriptor) itr.next();
                badField = false;
                boolean foundField = false;
                // fields must not be defined in the entity bean class as transient.
                Class c1 = null;
                try {
                    Class c = Class.forName(((EjbEntityDescriptor) descriptor).getEjbClassName(), false, getVerifierContext().getClassLoader());
                    // start do while loop here....
                    do {
                        try {
                            c1 = c;
                            Field f = c.getDeclaredField(nextPersistentField.getName());
                            foundField = true;
                            int modifiers = f.getModifiers();
                            if (!Modifier.isTransient(modifiers)) {
                                continue;
                            } else {
                                if (!oneFailed) {
                                    oneFailed = true;
                                }
                                badField = true;
                            }
                            if (badField) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within entity bean class [ {1} ] is defined as transient.  Container managed field must not be defined in the entity bean class as transient.", new Object[] { nextPersistentField.getName(), c.getName() }));
                            }
                        } catch (NoSuchFieldException e) {
                            foundField = false;
                        }
                    } while (((c = c.getSuperclass()) != null) && (!foundField));
                    if (!foundField) {
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: [ {0} ] field not found within class [ {1} ]", new Object[] { nextPersistentField.getName(), ((EjbEntityDescriptor) descriptor).getEjbClassName() }));
                    }
                } catch (ClassNotFoundException e) {
                    Verifier.debug(e);
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    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[] { ((EjbEntityDescriptor) descriptor).getEjbClassName() }));
                }
                if (!oneFailed) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "This entity bean class [ {0} ] has defined [ {1} ] container managed field as non-transient field.", new Object[] { c1.getName(), nextPersistentField.getName() }));
                }
            }
            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.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 : 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) Iterator(java.util.Iterator) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 17 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class CascadeDeleteNotSupportedForManyMany 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 isMany = false;
    boolean isPartnerMany = false;
    boolean cascadeDelete = false;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    isMany = role.getIsMany();
    isPartnerMany = (role.getPartner()).getIsMany();
    cascadeDelete = role.getCascadeDelete();
    if (isMany && isPartnerMany && cascadeDelete) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: cascade-delete should not be supported for many-many relationships. Please check Relationship Role [{0}]", new Object[] { role.getName() }));
        return false;
    } else {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "cascade-delete is not supported for many-many relationships. Test passed.", new Object[] {}));
        return true;
    }
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 18 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor 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 19 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class CmrUseCorrectCollectionInterface 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 rrd, Class c, Result result) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (rrd.getPartner().getIsMany()) {
        // must be one the collection interface
        if (rrd.getCMRFieldType() == null) {
            addErrorDetails(result, compName);
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "Error : CMR field [ {0} ]  cmr-field-type must be defined for one-to-many or many-to-many relationships and the value of the cmr-field-type element must be either: java.util.Collection or java.util.Set", new Object[] { rrd.getCMRField() }));
            return false;
        } else {
            CMRFieldInfo info = rrd.getCMRFieldInfo();
            if (rrd.getCMRFieldType().equals(info.type.getName())) {
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "CMR field [ {0} ] is the same type as declared in the deployment descriptors [ {1} ]", new Object[] { info.name, info.role.getCMRFieldType() }));
                return true;
            } else {
                addErrorDetails(result, compName);
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : CMR field [ {0} ] is not the same type as declared in the deployment descriptors [ {1} ]", new Object[] { info.name, info.role.getCMRFieldType() }));
                return false;
            }
        }
    }
    return true;
}
Also used : CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 20 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor 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)

Aggregations

ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)237 Result (com.sun.enterprise.tools.verifier.Result)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)87 Method (java.lang.reflect.Method)70 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Iterator (java.util.Iterator)40 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)19 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)16 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 Field (java.lang.reflect.Field)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)12 Enumeration (java.util.Enumeration)11 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)11 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)6 Vector (java.util.Vector)6