Search in sources :

Example 1 with CMRFieldInfo

use of org.glassfish.ejb.deployment.descriptor.CMRFieldInfo 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 2 with CMRFieldInfo

use of org.glassfish.ejb.deployment.descriptor.CMRFieldInfo 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 3 with CMRFieldInfo

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

the class NameMapper method getRelatedEjbDescriptor.

private EjbCMPEntityDescriptor getRelatedEjbDescriptor(String ejbName, String ejbFieldName) {
    EjbCMPEntityDescriptor descriptor = ((ejbName != null) ? getDescriptorForEjbName(ejbName) : null);
    if (descriptor != null) {
        PersistenceDescriptor persistenceDescriptor = descriptor.getPersistenceDescriptor();
        CMRFieldInfo cmrf = persistenceDescriptor.getCMRFieldInfoByName(ejbFieldName);
        return cmrf.role.getPartner().getOwner();
    }
    return null;
}
Also used : PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Example 4 with CMRFieldInfo

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

the class CmrFieldAccessor 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 rrd the descriptor for the declared cmr field
 * @param c the class owning the cmp field
 * @param result the result object to use to put the test results in
 *
 * @return true if the test passed
 */
protected boolean runIndividualCmrTest(Descriptor entity, RelationRoleDescriptor rrd, Class c, Result result) {
    boolean oneFailed = false;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    CMRFieldInfo info = rrd.getCMRFieldInfo();
    if (info == null) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.isAccessorDeclared.failed1", "Error : no CMR Field  declared ", new Object[] {}));
        return false;
    }
    oneFailed = isAccessorDeclared(info.name, info.type, c, result);
    if (oneFailed == false) {
    // do nothing, appropriate message has been added in
    // isAccessorDeclared().
    } else {
        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.isAccessorDeclared.passed", "CMR Field is properly declared ", new Object[] {}));
    }
    return oneFailed;
}
Also used : CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 5 with CMRFieldInfo

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

the class CmrFieldsAccessorExposition 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) {
    // check first if this is one-to-one or many-to-one relationship ...previous version of ejb specs
    // if ((!rrd.getIsMany() && !rrd.getPartner().getIsMany()) ||
    // (rrd.getIsMany() && !rrd.getPartner().getIsMany())) {
    // }
    // everyone falls back and should be checked
    boolean pass = true;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // should not have accessor methods exposed.
    if (((EjbDescriptor) descriptor).getRemoteClassName() != null && !((((EjbDescriptor) descriptor).getRemoteClassName()).equals(""))) {
        String interfaceType = ((EjbDescriptor) descriptor).getRemoteClassName();
        try {
            CMRFieldInfo info = rrd.getCMRFieldInfo();
            Class remoteInterface = Class.forName(interfaceType, false, getVerifierContext().getClassLoader());
            String getMethodName = "get" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);
            String setMethodName = "set" + Character.toUpperCase(info.name.charAt(0)) + info.name.substring(1);
            Method getMethod = getMethod(remoteInterface, getMethodName, null);
            if (getMethod != null) {
                addErrorDetails(result, compName);
                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failed", "Error : CMR field {0} accessor method [ {1} ] is exposed through the component interface [ {2} ]", new Object[] { "get", info.name, interfaceType }));
                pass = false;
            } else {
                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.CmrFieldsAccessorExposition.passed", "CMR field {0} accessor method [ {1} ] is not exposed through the component interface [ {2} ]", new Object[] { "get", info.name, interfaceType }));
                pass = true;
            }
            Class[] parms = { info.type };
            Method setMethod = getMethod(remoteInterface, setMethodName, parms);
            if (setMethod != null) {
                addErrorDetails(result, compName);
                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failed", "Error : CMR field {0} accessor method [ {1} ] is exposed through the component interface [ {2} ]", new Object[] { "set", info.name, interfaceType }));
                pass = false;
            } else {
                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.CmrFieldsAccessorExposition.passed", "CMR field [{0}] accessor method [ {1} ] is not exposed through the component interface [ {2} ]", new Object[] { "set", info.name, interfaceType }));
            }
        } catch (Exception e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CmrFieldsAccessorExposition.failedException", "Error:  [{0}] class not found or local interface not defined", new Object[] { interfaceType }));
            pass = false;
        }
    }
    return pass;
}
Also used : CMRFieldInfo(org.glassfish.ejb.deployment.descriptor.CMRFieldInfo) Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

CMRFieldInfo (org.glassfish.ejb.deployment.descriptor.CMRFieldInfo)5 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 Method (java.lang.reflect.Method)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)1 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)1 IASEjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor)1 PersistenceDescriptor (org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor)1