private CmrFieldInfo initRelationshipRole(EjbRelationshipRole role, EjbRelationshipRole relatedRole, Map<String, EnterpriseBeanInfo> infos) throws OpenEJBException {
CmrFieldInfo cmrFieldInfo = new CmrFieldInfo();
// find the entityBeanInfo info for this role
String ejbName = role.getRelationshipRoleSource().getEjbName();
EnterpriseBeanInfo enterpriseBeanInfo = infos.get(ejbName);
if (enterpriseBeanInfo == null) {
throw new OpenEJBException("Relation role source ejb not found " + ejbName);
}
if (!(enterpriseBeanInfo instanceof EntityBeanInfo)) {
throw new OpenEJBException("Relation role source ejb is not an entity bean " + ejbName);
}
EntityBeanInfo entityBeanInfo = (EntityBeanInfo) enterpriseBeanInfo;
cmrFieldInfo.roleSource = entityBeanInfo;
// RoleName: this may be null
cmrFieldInfo.roleName = role.getEjbRelationshipRoleName();
cmrFieldInfo.synthetic = role.getCmrField() == null;
// CmrFieldName: is null for uni-directional relationships
if (role.getCmrField() != null) {
cmrFieldInfo.fieldName = role.getCmrField().getCmrFieldName();
// CollectionType: java.util.Collection or java.util.Set
if (role.getCmrField().getCmrFieldType() != null) {
cmrFieldInfo.fieldType = role.getCmrField().getCmrFieldType().toString();
}
} else {
String relatedEjbName = relatedRole.getRelationshipRoleSource().getEjbName();
EnterpriseBeanInfo relatedEjb = infos.get(relatedEjbName);
if (relatedEjb == null) {
throw new OpenEJBException("Relation role source ejb not found " + relatedEjbName);
}
if (!(relatedEjb instanceof EntityBeanInfo)) {
throw new OpenEJBException("Relation role source ejb is not an entity bean " + relatedEjbName);