Monday, January 08, 2007

BC4J:Get top level master EO in an association.

Here is a code snippet to get the top level parent EO instance in a multi-level association hierarchy.
   /*Recursive function to get the top level entity given a child level entity.
public EntityImpl getTopLevelEntityName(EntityImpl entity) {
AttributeDef[] attrList = entity.getStructureDef().getAttributeDefs();

EntityImpl parentEntity = entity;
for(AttributeDef attr : attrList){
if(AttributeDef.ATTR_ASSOCIATED_ROW == attr.getAttributeKind()){
Object oParentEntity = entity.getAttribute(attr.getName());
if(oParentEntity instanceof EntityImpl){
parentEntity = getTopLevelEntityName((EntityImpl)oParentEntity);
return parentEntity;

No comments: