job:  #4  Changed the way V_PARs are processed to quit using an added Order attribute.  Now, the Order of TE_PAR is used.  And the code is a bit more efficient to boot.

.//====================================================================
.//
.// $RCSfile: q.utils.arc,v $
.//
.// (c) Copyright 1998-2013 Mentor Graphics Corporation  All rights reserved.
.//
.//====================================================================
.//
.function gen_parameter_list .// string
  .param inst_ref_set v_pars
  .param boolean prefix_param_delimiter
  .param string invocation_flavor
  .//
  .assign result = ""
  .if ( not_empty v_pars )
    .select any te_string from instances of TE_STRING
    .assign item_count = 0
    .select many te_pars related by v_pars->TE_PAR[R2063]
    .for each te_par in te_pars
      .select one te_parm related by te_par->TE_PARM[R2091]
      .assign te_par.Order = te_parm.Order
      .assign item_count = item_count + 1
    .end for
    .assign item_number = 0
    .assign param_delimiter = ""
    .if ( prefix_param_delimiter )
      .assign param_delimiter = ","
    .end if
    .while ( item_number < item_count )
          .select any te_par related by v_pars->TE_PAR[R2063] where ( selected.Order == item_number )
          .select one v_par related by te_par->V_PAR[R2063]
          .select one v_val related by v_par->V_VAL[R800]
          .select one te_val related by v_val->TE_VAL[R2040]
          .assign result = ( result + param_delimiter ) + te_val.OAL
          .if ( "" == te_val.buffer )
            .invoke gen_value( v_val )
          .end if
${param_delimiter}\
          .//
          .// Determine if the parameter is of type string.
          .// If string, check to see if this parameter is actually a function.
          .// If so, declare a variable in this scope to hold the return string.
          .// Do so by traversing to the te_blk instance to add the declaration.
          .assign stringbody = false
          .if ( 0 == te_par.By_Ref )
            .select one te_dt related by v_val->S_DT[R820]->TE_DT[R2021]
            .if ( 4 == te_dt.Core_Typ )
              .// Check the four types of returnable action bodies for string.
              .select one v_trv related by v_val->V_TRV[R801]
              .if ( not_empty v_trv )
                .assign stringbody = true
              .else
              .select one v_msv related by v_val->V_MSV[R801]
              .if ( not_empty v_msv )
                .assign stringbody = true
              .else
              .select one v_brv related by v_val->V_BRV[R801]
              .if ( not_empty v_brv )
                .assign stringbody = true
              .else
              .select one v_fnv related by v_val->V_FNV[R801]
              .if ( not_empty v_fnv )
                .assign stringbody = true
              .end if
              .end if
              .end if
              .end if
              .if ( stringbody )
                .assign te_par.buffer = "v_sretval" + "${info.unique_num}"
                .select one te_blk related by v_val->ACT_BLK[R826]->TE_BLK[R2016]
                .assign te_blk.declaration = ( ( ( te_blk.declaration + te_dt.ExtName ) + ( " " + te_par.buffer ) ) + ( "[" + te_string.max_string_length ) ) + "];"
${te_string.strcpy}( ${te_par.buffer}, \
              .end if
            .end if
            .//
            .//
${te_val.buffer}\
            .if ( stringbody )
)\
            .end if
          .else
&(${te_val.buffer})\
          .end if
          .assign param_delimiter = ", "
      .assign item_number = item_number + 1
    .end while
  .end if
  .assign attr_result = result
.end function
.//
.//====================================================================
.//
.function is_reflexive .// boolean
  .param inst_ref r_rel
  .//
  .assign result = false
  .select one r_simp related by r_rel->R_SIMP[R206]
  .if ( not_empty r_simp )
    .select many r_parts related by r_simp->R_PART[R207]
    .if ( (cardinality r_parts) > 1 )
      .select any first_r_part related by r_simp->R_PART[R207]
      .select any second_r_part related by r_simp->R_PART[R207] where (selected.OIR_ID != first_r_part.OIR_ID)
      .if ( first_r_part.Obj_ID == second_r_part.Obj_ID )
        .assign result = true
      .end if
    .else
      .select any r_part related by r_simp->R_PART[R207]
      .select one r_form related by r_simp->R_FORM[R208]
      .if ( not_empty r_form )
        .if ( r_part.Obj_ID == r_form.Obj_ID )
          .assign result = true
        .end if
      .end if
    .end if
  .else
    .select one r_assoc related by r_rel->R_ASSOC[R206]
    .if ( not_empty r_assoc )
      .select one r_aone related by r_assoc->R_AONE[R209]
      .select one r_aoth related by r_assoc->R_AOTH[R210]
      .if ( r_aone.Obj_ID == r_aoth.Obj_ID )
        .assign result = true
      .end if
    .end if
  .end if
  .assign attr_result = result
.end function
.//
.//============================================================================
.//   Sort the instances in the instance set <item_set> in ascending numeric
.// order, based on the value of the Numb (integer) attribute value of
.// each instance. The Order (integer) attribute value of each instance will
.// be set to contain a value relative to Numb, indicating the position
.// the instance has in the ordered set.
.//   This function is definately *slow*, but will work with any objects
.// which contain integer attributes <Numb> and <Order>.
.//============================================================================
.function SortSetAscendingByAttr_Numb
  .param inst_ref_set item_set
  .//
  .// Clear the Order attribute of all set members.
  .for each item in item_set
    .assign item.Order = 0
  .end for
  .// simple pseudo bubble sort
  .assign item_set_copy = item_set
  .for each item in item_set
    .for each item_copy in item_set_copy
      .if ( item_copy.Numb > item.Numb )
        .assign item_copy.Order = item_copy.Order + 1
      .end if
    .end for
  .end for
.end function
.//
.//============================================================================
.// Given a set of instances, sets the attribute Order to
.// a value corresponding to the alphabetical order its Name attribute
.// is in the set
.//
.// <item_set> - from instances of anything with Name and Order attributes
.//============================================================================
.function SortSetAlphabeticallyByNameAttr
  .param inst_ref_set item_set
  .//
  .// Clear the Order attribute of all set members.
  .for each item in item_set
    .assign item.Order = 0
  .end for
  .//
  .assign item_set_copy = item_set
  .for each item in item_set
    .for each item_copy in item_set_copy
      .if ( item_copy.Name > item.Name )
        .assign item_copy.Order = item_copy.Order + 1
      .end if
    .end for
  .end for
.end function
.//

.//====================================================================
.//
.// $RCSfile: q.utils.arc,v $
.//
.// (c) Copyright 1998-2013 Mentor Graphics Corporation  All rights reserved.
.//
.//====================================================================
.//
.function gen_parameter_list
  .param inst_ref_set v_pars
  .param boolean prefix_param_delimiter
  .param string invocation_flavor
  .//
  .assign result = ""
  .if ( not_empty v_pars )
    .select any te_string from instances of TE_STRING
    .for each v_par in v_pars
      .select one te_par related by v_par->TE_PAR[R2063]
      .select one te_parm related by te_par->TE_PARM[R2091]
      .assign te_par.Order = te_parm.Order
      .assign v_par.Order = te_par.Order
    .end for
    .assign item_count = cardinality v_pars
    .assign item_number = 0
    .assign param_delimiter = ""
    .if ( prefix_param_delimiter )
      .assign param_delimiter = ","
    .end if
    .while ( item_number < item_count )
      .for each v_par in v_pars
        .if ( v_par.Order == item_number )
          .select one v_val related by v_par->V_VAL[R800]
          .select one te_val related by v_val->TE_VAL[R2040]
          .assign result = ( result + param_delimiter ) + te_val.OAL
          .if ( "" == te_val.buffer )
            .invoke gen_value( v_val )
          .end if
${param_delimiter}\
          .//
          .// Determine if the parameter is of type string.
          .// If string, check to see if this parameter is actually a function.
          .// If so, declare a variable in this scope to hold the return string.
          .// Do so by traversing to the te_blk instance to add the declaration.
          .assign stringbody = false
          .select one te_par related by v_par->TE_PAR[R2063]
          .if ( 0 == te_par.By_Ref )
            .select one te_dt related by v_val->S_DT[R820]->TE_DT[R2021]
            .if ( 4 == te_dt.Core_Typ )
              .// Check the four types of returnable action bodies for string.
              .select one v_trv related by v_val->V_TRV[R801]
              .if ( not_empty v_trv )
                .assign stringbody = true
              .else
              .select one v_msv related by v_val->V_MSV[R801]
              .if ( not_empty v_msv )
                .assign stringbody = true
              .else
              .select one v_brv related by v_val->V_BRV[R801]
              .if ( not_empty v_brv )
                .assign stringbody = true
              .else
              .select one v_fnv related by v_val->V_FNV[R801]
              .if ( not_empty v_fnv )
                .assign stringbody = true
              .end if
              .end if
              .end if
              .end if
              .if ( stringbody )
                .assign te_par.buffer = "v_sretval" + "${info.unique_num}"
                .select one te_blk related by v_val->ACT_BLK[R826]->TE_BLK[R2016]
                .assign te_blk.declaration = ( ( ( te_blk.declaration + te_dt.ExtName ) + ( " " + te_par.buffer ) ) + ( "[" + te_string.max_string_length ) ) + "];"
${te_string.strcpy}( ${te_par.buffer}, \
              .end if
            .end if
            .//
            .//
${te_val.buffer}\
            .if ( stringbody )
)\
            .end if
          .else
&(${te_val.buffer})\
          .end if
          .assign param_delimiter = ", "
          .break for
        .end if
      .end for
      .assign item_number = item_number + 1
    .end while
  .end if
  .assign attr_result = result
.end function
.//
.//====================================================================
.//
.function is_reflexive
  .param inst_ref r_rel
  .//
  .assign result = false
  .select one srel related by r_rel->R_SIMP[R206]
  .if ( not_empty srel )
    .select many part_set related by srel->R_PART[R207]
    .if ( (cardinality part_set) > 1 )
      .select any part1 related by srel->R_PART[R207]
      .select any part2 related by srel->R_PART[R207] where (selected.OIR_ID != part1.OIR_ID)
      .if ( part1.Obj_ID == part2.Obj_ID )
        .assign result = true
      .end if
    .else
      .select any part related by srel->R_PART[R207]
      .select one form related by srel->R_FORM[R208]
      .if ( not_empty form )
        .if ( part.Obj_ID == form.Obj_ID )
          .assign result = true
        .end if
      .end if
    .end if
  .else
    .select one arel related by r_rel->R_ASSOC[R206]
    .if ( not_empty arel )
      .select one aone related by arel->R_AONE[R209]
      .select one aoth related by arel->R_AOTH[R210]
      .if ( aone.Obj_ID == aoth.Obj_ID )
        .assign result = true
      .end if
    .end if
  .end if
  .assign attr_result = result
.end function
.//
.//============================================================================
.//   Sort the instances in the instance set <item_set> in ascending numeric
.// order, based on the value of the Numb (integer) attribute value of
.// each instance. The Order (integer) attribute value of each instance will
.// be set to contain a value relative to Numb, indicating the position
.// the instance has in the ordered set.
.//   This function is definately *slow*, but will work with any objects
.// which contain integer attributes <Numb> and <Order>.
.//============================================================================
.function SortSetAscendingByAttr_Numb
  .param inst_ref_set item_set
  .//
  .// Clear the Order attribute of all set members.
  .for each item in item_set
    .assign item.Order = 0
  .end for
  .// simple pseudo bubble sort
  .assign item_set_copy = item_set
  .for each item in item_set
    .for each item_copy in item_set_copy
      .if ( item_copy.Numb > item.Numb )
        .assign item_copy.Order = item_copy.Order + 1
      .end if
    .end for
  .end for
.end function
.//
.//============================================================================
.// Given a set of instances, sets the attribute Order to
.// a value corresponding to the alphabetical order its Name attribute
.// is in the set
.//
.// <item_set> - from instances of anything with Name and Order attributes
.//============================================================================
.function SortSetAlphabeticallyByNameAttr
  .param inst_ref_set item_set
  .//
  .// Clear the Order attribute of all set members.
  .for each item in item_set
    .assign item.Order = 0
  .end for
  .//
  .assign item_set_copy = item_set
  .for each item in item_set
    .for each item_copy in item_set_copy
      .if ( item_copy.Name > item.Name )
        .assign item_copy.Order = item_copy.Order + 1
      .end if
    .end for
  .end for
.end function
.//


job #8633 - Add back newline that is currently in the master version.

.//====================================================================
.//
.// File:      create_external_link_evaluator.arc
.//
.//====================================================================
.invoke arc_env = GET_ENV_VAR( "PTC_MC_ARC_DIR" )
.assign mc_archetypes = arc_env.result
.if ( mc_archetypes == "" )
  .print "\nERROR: Environment variable PTC_MC_ARC_DIR not set."
  .exit 100
.end if
.invoke arc_env1 = GET_ENV_VAR( "IO_CORE_ARC_DIR" )
.assign io_core_archetypes = arc_env1.result
.if ( io_core_archetypes == "" )
  .print "\nERROR: Environment variable IO_CORE_ARC_DIR not set."
  .exit 100
.end if
.//
.include "${mc_archetypes}/arch_utils.inc"
.include "${io_core_archetypes}/generate_configurable_components.inc"
.//
.//====================================================================
.//
.function is_legacy_containment_assoc
  .param inst_ref rel   .// R_REL
  .assign attr_result = false
  .if ( rel.Numb == 1 )
    .assign attr_result = true
  .elif ( rel.Numb == 8 )
    .assign attr_result = true
  .elif ( rel.Numb == 14 )
    .assign attr_result = true
  .elif ( rel.Numb == 23 )
    .assign attr_result = true
  .end if
.end function
.//
.//====================================================================
.//
.assign class_name = "ExternalLinkEvaluator"
//========================================================================
//
// File: ${class_name}.java
//
// WARNING:      Do not edit this generated file
// Generated by: ${info.arch_file_name}
//
//========================================================================
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License.  You may obtain a copy
// of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the
// License for the specific language governing permissions and limitations under
// the License.
//========================================================================
//

package org.xtuml.bp.io.mdl;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Vector;

import org.xtuml.bp.core.*;
import org.xtuml.bp.ui.canvas.*;
import org.xtuml.bp.core.common.IPersistenceHierarchyMetaData;
import org.xtuml.bp.core.common.NonRootModelElement;
import org.xtuml.bp.core.common.PersistableModelComponent;
import org.xtuml.bp.core.common.PersistenceManager;

.// exclude diagrams and repeated EOs
.select many eos from instances of EO
.assign non_graphics_eos = eos - eos
.for each eo in eos
    .invoke result =  firstOccurrence(eo)
    .assign is_first = result.firstOccurrence
    .select one table related by eo->EI[R3]->T[R4]
    .if (not_empty table)
        .if ((table.DomainName != "ooaofgraphics") AND (is_first == true))
            .assign non_graphics_eos = non_graphics_eos | eo
        .end if
    .end if
.end for

public class ${class_name} {

	static IPersistenceHierarchyMetaData metaData = PersistenceManager.getHierarchyMetaData();
	static public Map evaluators = new Hashtable();
	static {
.for each eo in non_graphics_eos
    .invoke eo_class_name = get_class_name(eo)
		evaluators.put(${eo_class_name.body}.class, new ${eo_class_name.body}Evaluator());
.end for
	}

	public static HashMap<String, List<NonRootModelElement>> getAssociationMapOfExternalRGOs(
			NonRootModelElement element) {
        IPersistenceHierarchyMetaData metaData = PersistenceManager.getHierarchyMetaData();
        if (element != null) {
            IMEExternalLinkEvaluator evaluator = (IMEExternalLinkEvaluator) evaluators.get(element.getClass());
            if (evaluator != null) {
                return evaluator.getAssociationMapOfExternalRGOs(element);
            }
        }
        return new HashMap<String, List<NonRootModelElement>>();
	}

    public static List findExternalRGOs(
            NonRootModelElement modelElement, boolean loadComponent, boolean rgoToComponent, boolean checkSameComponent) {
            List externalLinks = new Vector(){
                public boolean add(Object element){
                    if(!contains(element)){
                        return super.add(element);
                    }
                    return false;
                }
            };
            gatherRGOsExternalTo(modelElement, externalLinks, loadComponent, rgoToComponent, checkSameComponent);
            return externalLinks;
    }

    private static void gatherRGOsExternalTo(NonRootModelElement modelElement, List rgos, boolean loadComponent, boolean rgoToComponent, boolean checkSameComponent){
        IPersistenceHierarchyMetaData metaData = PersistenceManager.getHierarchyMetaData();
        if (modelElement != null) {
            IMEExternalLinkEvaluator evaluator = (IMEExternalLinkEvaluator) evaluators.get(modelElement.getClass());
            if (evaluator != null) {
                evaluator.findExternalRGOs(modelElement, rgos, loadComponent, checkSameComponent);
            }
        }
        if(rgoToComponent){
        List children = metaData.getChildren(modelElement, loadComponent);
        for (Iterator iterator = children.iterator(); iterator.hasNext();) {
            NonRootModelElement child = (NonRootModelElement) iterator.next();
            gatherRGOsExternalTo(child, rgos, loadComponent,rgoToComponent, checkSameComponent);
        }
       }
    }
	public static boolean hasExternalRGO(NonRootModelElement modelElement, boolean loadComponent){
		if (modelElement != null) {
			IMEExternalLinkEvaluator evaluator = (IMEExternalLinkEvaluator) evaluators
					..get(modelElement.getClass());
			if (evaluator != null) {
				return evaluator.hasExternalRGO(modelElement, loadComponent);
			}
		}
		return false;
	}
	private final static boolean isComponentSame(
		NonRootModelElement modelElement,
		NonRootModelElement other) {
		return (PersistenceManager.getComponent(modelElement) == PersistenceManager.getComponent(other));
	}

	interface IMEExternalLinkEvaluator {
		public void findExternalRGOs(NonRootModelElement modelElement, List externalMEs, boolean loadComponent, boolean checkSameComponent);
		public boolean hasExternalRGO(NonRootModelElement modelElement, boolean loadComponent);
		public HashMap<String, List<NonRootModelElement>> getAssociationMapOfExternalRGOs(NonRootModelElement element);
	}

.for each eo in non_graphics_eos
    .assign root_eo = eo
    .if (eo.componentRoot != true)
        .invoke result = get_parent_component_of_eo (eo)
        .assign root_eo = result.parent_component_of_eo
    .end if

    .invoke result = children_of_component(root_eo)
    .assign component_elements = result.children_list
    .invoke eo_class_name = get_class_name(eo)

    .print "generating class {${eo_class_name.body}Evaluator} with parent {${root_eo.Name}}"

	static class ${eo_class_name.body}Evaluator implements IMEExternalLinkEvaluator{
		public HashMap<String, List<NonRootModelElement>> getAssociationMapOfExternalRGOs(NonRootModelElement element) {
			HashMap<String, List<NonRootModelElement>> map = new HashMap<String, List<NonRootModelElement>>();
			NonRootModelElement[] externalMEs = new NonRootModelElement[0];
    .assign rgoCntr = 0;
    .select any model_class from instances of O_OBJ where (selected.Name == eo.Name)
    .select many rto_set related by model_class->R_OIR[R201]->R_RTO[R203]
    .for each rto in rto_set
        .select one relation related by rto->R_OIR[R203]->R_REL[R201]
          .select many rgo_set related by relation->R_OIR[R201]->R_RGO[R203]
          .for each rgo in rgo_set
              .select one related_class related by rgo->R_OIR[R203]->O_OBJ[R201]
              .invoke result = is_member_of_component(related_class, component_elements)
              .assign member_of_same_component = result.is_member
              .assign card = -1
              .assign relation_type = "other"
              .assign phrase = ""
              .invoke is_reflexive = is_reflexive(relation)
              .select any form related by rgo->R_FORM[R205]
              .if(not_empty form)
                  .assign card = form.Mult
                  .if (is_reflexive.result)
                    .assign phrase = "$cr{form.Txt_phrs}"
                  .end if
                  .assign relation_type = "formalizer"
              .else
	              .select any assr related by rgo->R_ASSR[R205]
	              .if(not_empty assr)
	                .assign card = 1
	                .assign relation_type = "class_as_link"
	                .if (is_reflexive.result)
	                  .select any aone related by rto->R_AONE[R204]
	                  .if (empty aone)
	                    .select any aoth related by rto->R_AOTH[R204]
	                    .assign phrase = "$cr{aoth.Txt_phrs}"
	                  .else
	                    .assign phrase = "$cr{aone.Txt_phrs}"
	                  .end if
                    .end if
	              .else
		            .select any sub related by rgo->R_SUB[R205]
		            .if(not_empty sub)
		                .assign card = 0
		                .assign relation_type = "class_as_subtype"
		            .end if
                  .end if
              .end if
              .invoke related_class_name = get_class_name(related_class)
              .if (card == 0)
                .invoke nav = get_nav_func_name(related_class, relation, "one")
                .assign varName = "inst$Cr{related_class.Name}${rgoCntr}"
                .assign listvar = "R${relation.Numb}List"
            ${related_class_name.body} ${varName} = ${related_class_name.body}.${nav.body}${phrase}((${eo_class_name.body})element, true);
                .assign condition = "${varName} != null"
            if(${condition}){
            	List<NonRootModelElement> ${listvar} = new ArrayList<NonRootModelElement>();
            	${listvar}.add(${varName});
                map.put("R${relation.Numb}", ${listvar});
            }
                .assign rgoCntr = rgoCntr + 1
              .else
                .invoke nav = get_nav_func_name(related_class, relation, "many")
                .assign listvar = "R${relation.Numb}List${phrase}"
            List<NonRootModelElement> ${listvar} = new ArrayList<NonRootModelElement>();
            externalMEs = ${related_class_name.body}.${nav.body}${phrase}((${eo_class_name.body})element, true);
            for(int i=0; i<externalMEs.length; i++){
                ${listvar}.add(externalMEs[i]);
            }
            map.put("R${relation.Numb}", ${listvar});
              .end if
          .end for
    .end for
    		return map;
		}
		public void findExternalRGOs(NonRootModelElement modelElement, List externalMEList, boolean loadComponent, boolean checkSameComponent){
    NonRootModelElement[] externalMEs;

    .assign rgoCntr = 0;
    .select any model_class from instances of O_OBJ where (selected.Name == eo.Name)
    .select many rto_set related by model_class->R_OIR[R201]->R_RTO[R203]
    .for each rto in rto_set
        .select one relation related by rto->R_OIR[R203]->R_REL[R201]

          .select many rgo_set related by relation->R_OIR[R201]->R_RGO[R203]
          .for each rgo in rgo_set
              .select one related_class related by rgo->R_OIR[R203]->O_OBJ[R201]
              .invoke result = is_member_of_component(related_class, component_elements)
              .assign member_of_same_component = result.is_member
              .assign card = -1
              .assign relation_type = "other"
              .assign phrase = ""
              .invoke is_reflexive = is_reflexive(relation)
              .select any form related by rgo->R_FORM[R205]
              .if(not_empty form)
                  .assign card = form.Mult
                  .if (is_reflexive.result)
                    .assign phrase = "$cr{form.Txt_phrs}"
                  .end if
                  .assign relation_type = "formalizer"
              .else
	              .select any assr related by rgo->R_ASSR[R205]
	              .if(not_empty assr)
	                .assign card = 1
	                .assign relation_type = "class_as_link"
                    .if (is_reflexive.result)
                      .select any aone related by rto->R_AONE[R204]
                      .if (empty aone)
                        .select any aoth related by rto->R_AOTH[R204]
                        .assign phrase = "$cr{aoth.Txt_phrs}"
                      .else
                        .assign phrase = "$cr{aone.Txt_phrs}"
                      .end if
                    .end if
	              .else
		            .select any sub related by rgo->R_SUB[R205]
		            .if(not_empty sub)
		                .assign card = 0
		                .assign relation_type = "class_as_subtype"
		            .end if
                  .end if
              .end if
              .invoke related_class_name = get_class_name(related_class)
              .if (card == 0)
                .invoke nav = get_nav_func_name(related_class, relation, "one")
                .assign varName = "inst$Cr{related_class.Name}${rgoCntr}"
            ${related_class_name.body} ${varName} = ${related_class_name.body}.${nav.body}${phrase}((${eo_class_name.body})modelElement, loadComponent);
                .assign condition = "${varName} != null"
              .if(member_of_same_component)
                .assign condition = "${condition} && (!checkSameComponent || !isComponentSame(modelElement, ${varName}))"
              .end if
            if(${condition}){
                externalMEList.add(${varName});
            }
                .assign rgoCntr = rgoCntr + 1
              .else
                .invoke nav = get_nav_func_name(related_class, relation, "many")
            externalMEs = ${related_class_name.body}.${nav.body}${phrase}((${eo_class_name.body})modelElement, loadComponent);
            for(int i=0; i<externalMEs.length; i++){
                  .if(member_of_same_component)
                if(!checkSameComponent || !isComponentSame(modelElement, externalMEs[i])){
                  .end if
                externalMEList.add(externalMEs[i]);
                  .if(member_of_same_component)
                }
                  .end if
            }
              .end if
          .end for
    .end for
    .//
    .select many relations related by model_class->R_OIR[R201]->R_REL[R201]
    .for each relation in relations
            // ${model_class.Name} ->R${relation.Numb}
        .select many related_classes related by relation->R_OIR[R201]->O_OBJ[R201] where (selected.Obj_ID != model_class.Obj_ID)
        .for each related_class in related_classes
          .invoke ilc = is_legacy_containment_assoc(relation)
          .if (ilc.result)
           //                      ->R${relation.Numb} -- ${related_class.Name} <<Legacy Containment>>
          .else
            .invoke result = is_member_of_component(related_class, component_elements)
            .if (not result.is_member)
           //                      ->R${relation.Numb} -- ${related_class.Name} <<DEFINITE EXTERNAL LINK>>
            .else
           //                      ->R${relation.Numb} -- ${related_class.Name}
            .end if
          .end if
        .end for
    .end for
		}
		public boolean hasExternalRGO(NonRootModelElement modelElement, boolean loadComponent){
			NonRootModelElement  inst=null;
    .for each rto in rto_set
        .select one relation related by rto->R_OIR[R203]->R_REL[R201]
          .select many rgo_set related by relation->R_OIR[R201]->R_RGO[R203]
          .for each rgo in rgo_set
              .select one related_class related by rgo->R_OIR[R203]->O_OBJ[R201]
              .invoke result = is_member_of_component(related_class, component_elements)
              .assign member_of_same_component = result.is_member
              .assign phrase = ""
              .invoke is_reflexive = is_reflexive(relation)
              .if (is_reflexive.result)
                .select any form related by rgo->R_FORM[R205]
                .if (not_empty form)
                  .assign phrase = "$cr{form.Txt_phrs}"
                .else
                  .select any aone related by rto->R_AONE[R204]
                  .if (empty aone)
                    .select any aoth related by rto->R_AOTH[R204]
                    .assign phrase = "$cr{aoth.Txt_phrs}"
                  .else
                    .assign phrase = "$cr{aone.Txt_phrs}"
                  .end if
                .end if
              .end if
              .invoke related_class_name = get_class_name(related_class)
              .invoke nav = get_nav_func_name(related_class, relation, "one")
				inst = ${related_class_name.body}.${nav.body}${phrase}((${eo_class_name.body})modelElement, loadComponent);
              .assign condition = "inst != null"
              .if(member_of_same_component)
              .assign condition = "${condition} && !isComponentSame(modelElement, inst)"
              .end if
            if(${condition}){
                return true;
            }
          .end for
    .end for
	    return false;
	}
 }
.end for
}
.//
.emit to file "src/org/xtuml/bp/io/mdl/${class_name}.java"