public void batchRelate(
      ModelRoot modelRoot, boolean relateProxies, boolean notifyChanges, boolean searchAllRoots) {
    InstanceList instances = null;
    ModelRoot baseRoot = modelRoot;

    if (ModelClass == null) {
      // R518
      ModelClass_c relInst39205 =
          (ModelClass_c) baseRoot.getInstanceList(ModelClass_c.class).get(new Object[] {m_obj_id});
      // if there was no local element, check for any global elements
      // failing that proceed to check other model roots
      if (relInst39205 == null) {
        relInst39205 =
            (ModelClass_c)
                Ooaofooa.getDefaultInstance()
                    .getInstanceList(ModelClass_c.class)
                    .get(new Object[] {m_obj_id});
      }
      if (relInst39205 == null && searchAllRoots && !baseRoot.isCompareRoot()) {
        Ooaofooa[] roots = Ooaofooa.getInstances();
        for (int i = 0; i < roots.length; i++) {
          if (roots[i].isCompareRoot()) {
            // never use elements from any compare root
            continue;
          }
          relInst39205 =
              (ModelClass_c)
                  roots[i].getInstanceList(ModelClass_c.class).get(new Object[] {m_obj_id});
          if (relInst39205 != null) break;
        }
      }
      // synchronized
      if (relInst39205 != null) {
        if (relateProxies || !isProxy() || (inSameComponent(this, relInst39205) && !isProxy())) {
          relInst39205.relateAcrossR518To(this, notifyChanges);
        }
      }
    }

    // R517
    StateMachine_c relInst39206 =
        (StateMachine_c) baseRoot.getInstanceList(StateMachine_c.class).get(new Object[] {m_sm_id});
    // if there was no local element, check for any global elements
    // failing that proceed to check other model roots
    if (relInst39206 == null) {
      relInst39206 =
          (StateMachine_c)
              Ooaofooa.getDefaultInstance()
                  .getInstanceList(StateMachine_c.class)
                  .get(new Object[] {m_sm_id});
    }
    if (relInst39206 == null && searchAllRoots && !baseRoot.isCompareRoot()) {
      Ooaofooa[] roots = Ooaofooa.getInstances();
      for (int i = 0; i < roots.length; i++) {
        if (roots[i].isCompareRoot()) {
          // never use elements from any compare root
          continue;
        }
        relInst39206 =
            (StateMachine_c)
                roots[i].getInstanceList(StateMachine_c.class).get(new Object[] {m_sm_id});
        if (relInst39206 != null) break;
      }
    }
    // synchronized
    if (relInst39206 != null) {
      if (relateProxies || !isProxy() || (inSameComponent(this, relInst39206) && !isProxy())) {
        relInst39206.relateAcrossR517To(this, notifyChanges);
      }
    }
  }