/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of
   *     ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding objects.
   */
  public static ims.coe.vo.CommunicationUnderstandingCollection
      createCommunicationUnderstandingCollectionFromCommunicationSpeechAndLanguageUnderstanding(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.coe.vo.CommunicationUnderstandingCollection voList =
        new ims.coe.vo.CommunicationUnderstandingCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding domainObject =
          (ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding)
              iterator.next();
      ims.coe.vo.CommunicationUnderstanding vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of
   *     ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding objects.
   */
  public static ims.coe.vo.CommunicationUnderstandingCollection
      createCommunicationUnderstandingCollectionFromCommunicationSpeechAndLanguageUnderstanding(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.coe.vo.CommunicationUnderstandingCollection voList =
        new ims.coe.vo.CommunicationUnderstandingCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding domainObject =
          (ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding)
              domainObjectList.get(i);
      ims.coe.vo.CommunicationUnderstanding vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject from the
   * ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.coe.vo.CommunicationUnderstanding create(
      DomainObjectMap map,
      ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.coe.vo.CommunicationUnderstanding valueObject =
        (ims.coe.vo.CommunicationUnderstanding)
            map.getValueObject(domainObject, ims.coe.vo.CommunicationUnderstanding.class);
    if (null == valueObject) {
      valueObject =
          new ims.coe.vo.CommunicationUnderstanding(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding
      extractCommunicationSpeechAndLanguageUnderstanding(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.coe.vo.CommunicationUnderstanding valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_CommunicationSpeechAndLanguageUnderstanding();
    ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding domainObject =
        null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding)
            domMap.get(valueObject);
      }
      // ims.coe.vo.CommunicationUnderstanding ID_CommunicationSpeechAndLanguageUnderstanding field
      // is unknown
      domainObject =
          new ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName()
              + "__"
              + valueObject.getID_CommunicationSpeechAndLanguageUnderstanding());
      if (domMap.get(key) != null) {
        return (ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding)
            domMap.get(key);
      }
      domainObject =
          (ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding)
              domainFactory.getDomainObject(
                  ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding
                      .class,
                  id);

      // TODO: Not sure how this should be handled. Effectively it must be a staleobject exception,
      // but maybe should be handled as that further up.
      if (domainObject == null) return null;

      domMap.put(key, domainObject);
    }
    domainObject.setVersion(valueObject.getVersion_CommunicationSpeechAndLanguageUnderstanding());

    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value1 = null;
    if (null != valueObject.getSpeechAndLanguageUnderstanding()) {
      value1 =
          domainFactory.getLookupInstance(valueObject.getSpeechAndLanguageUnderstanding().getID());
    }
    domainObject.setSpeechAndLanguageUnderstanding(value1);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value2 = null;
    if (null != valueObject.getStatus()) {
      value2 = domainFactory.getLookupInstance(valueObject.getStatus().getID());
    }
    domainObject.setStatus(value2);

    return domainObject;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject
   *     ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding
   */
  public static ims.coe.vo.CommunicationUnderstanding insert(
      DomainObjectMap map,
      ims.coe.vo.CommunicationUnderstanding valueObject,
      ims.coe.assessment.domain.objects.CommunicationSpeechAndLanguageUnderstanding domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_CommunicationSpeechAndLanguageUnderstanding(domainObject.getId());
    valueObject.setIsRIE(domainObject.getIsRIE());

    // If this is a recordedInError record, and the domainObject
    // value isIncludeRecord has not been set, then we return null and
    // not the value object
    if (valueObject.getIsRIE() != null
        && valueObject.getIsRIE().booleanValue() == true
        && !domainObject.isIncludeRecord()) return null;

    // If this is not a recordedInError record, and the domainObject
    // value isIncludeRecord has been set, then we return null and
    // not the value object
    if ((valueObject.getIsRIE() == null || valueObject.getIsRIE().booleanValue() == false)
        && domainObject.isIncludeRecord()) return null;

    // SpeechAndLanguageUnderstanding
    ims.domain.lookups.LookupInstance instance1 = domainObject.getSpeechAndLanguageUnderstanding();
    if (null != instance1) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance1.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance1.getImage().getImageId(), instance1.getImage().getImagePath());
      }
      color = instance1.getColor();
      if (color != null) color.getValue();

      ims.coe.vo.lookups.SpeechAndLanguageUnderstanding voLookup1 =
          new ims.coe.vo.lookups.SpeechAndLanguageUnderstanding(
              instance1.getId(), instance1.getText(), instance1.isActive(), null, img, color);
      ims.coe.vo.lookups.SpeechAndLanguageUnderstanding parentVoLookup1 = voLookup1;
      ims.domain.lookups.LookupInstance parent1 = instance1.getParent();
      while (parent1 != null) {
        if (parent1.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent1.getImage().getImageId(), parent1.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent1.getColor();
        if (color != null) color.getValue();
        parentVoLookup1.setParent(
            new ims.coe.vo.lookups.SpeechAndLanguageUnderstanding(
                parent1.getId(), parent1.getText(), parent1.isActive(), null, img, color));
        parentVoLookup1 = parentVoLookup1.getParent();
        parent1 = parent1.getParent();
      }
      valueObject.setSpeechAndLanguageUnderstanding(voLookup1);
    }
    // Status
    ims.domain.lookups.LookupInstance instance2 = domainObject.getStatus();
    if (null != instance2) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance2.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance2.getImage().getImageId(), instance2.getImage().getImagePath());
      }
      color = instance2.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.YesNoUnknown voLookup2 =
          new ims.core.vo.lookups.YesNoUnknown(
              instance2.getId(), instance2.getText(), instance2.isActive(), null, img, color);
      ims.core.vo.lookups.YesNoUnknown parentVoLookup2 = voLookup2;
      ims.domain.lookups.LookupInstance parent2 = instance2.getParent();
      while (parent2 != null) {
        if (parent2.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent2.getImage().getImageId(), parent2.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent2.getColor();
        if (color != null) color.getValue();
        parentVoLookup2.setParent(
            new ims.core.vo.lookups.YesNoUnknown(
                parent2.getId(), parent2.getText(), parent2.isActive(), null, img, color));
        parentVoLookup2 = parentVoLookup2.getParent();
        parent2 = parent2.getParent();
      }
      valueObject.setStatus(voLookup2);
    }
    return valueObject;
  }