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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations