// TODO: can this be implemented in a simpler way? is there // any real value to using the map here as opposed to iterating // the relationships live? private EjbRelationshipRole getRoleDescriptor( String ejbName, String cmrFieldName, boolean opposite) { Map rels = (HashMap) relationshipRoleMap.get(ejbName); Iterator iterator = rels.keySet().iterator(); while (iterator.hasNext()) { EjbRelation rel = (EjbRelation) iterator.next(); EjbRelationshipRole role = (EjbRelationshipRole) rels.get(rel); EjbRelationshipRole role1 = rel.getEjbRelationshipRole(); EjbRelationshipRole role2 = rel.getEjbRelationshipRole2(); CmrField candidateCmr = role.getCmrField(); if (ejbName.equals(role.getRelationshipRoleSource().getEjbName()) && (candidateCmr != null) && cmrFieldName.equals(candidateCmr.getCmrFieldName())) { return ((opposite) ? ((role == role1) ? role2 : role1) : role); } else { // check for self ref relationship String ejb1 = role1.getRelationshipRoleSource().getEjbName(); if (ejb1.equals(role2.getRelationshipRoleSource().getEjbName()) && ejbName.equals(ejb1)) { role = ((role == role1) ? role2 : role1); candidateCmr = role.getCmrField(); if ((candidateCmr != null) && cmrFieldName.equals(candidateCmr.getCmrFieldName())) { return ((opposite) ? ((role == role1) ? role2 : role1) : role); } } } } throw new IllegalArgumentException(); }
private void initRelationshipMap() { Relationships relationships = getBundleDescriptor().getSingleRelationships(); if (relationships != null) { EjbRelation[] rels = relationships.getEjbRelation(); int i, count = ((rels != null) ? rels.length : 0); // cache relationship roles by ejb name for (i = 0; i < count; i++) { EjbRelation relationship = rels[i]; addRole(relationship, relationship.getEjbRelationshipRole()); addRole(relationship, relationship.getEjbRelationshipRole2()); } } }