/**
  * Copy one ValueObject to another
  *
  * @param valueObjectDest to be updated
  * @param valueObjectSrc to copy values from
  */
 public static ims.core.vo.CareContextSmallVo copy(
     ims.core.vo.CareContextSmallVo valueObjectDest,
     ims.core.vo.CareContextSmallVo valueObjectSrc) {
   if (null == valueObjectSrc) {
     return valueObjectSrc;
   }
   valueObjectDest.setID_CareContext(valueObjectSrc.getID_CareContext());
   valueObjectDest.setIsRIE(valueObjectSrc.getIsRIE());
   // Context
   valueObjectDest.setContext(valueObjectSrc.getContext());
   // StartDateTime
   valueObjectDest.setStartDateTime(valueObjectSrc.getStartDateTime());
   // EndDateTime
   valueObjectDest.setEndDateTime(valueObjectSrc.getEndDateTime());
   // CareContextHistory
   valueObjectDest.setCareContextHistory(valueObjectSrc.getCareContextHistory());
   return valueObjectDest;
 }
  public static ims.core.admin.domain.objects.CareContext extractCareContext(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.core.vo.CareContextSmallVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_CareContext();
    ims.core.admin.domain.objects.CareContext domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject);
      }
      // ims.core.vo.CareContextSmallVo ID_CareContext field is unknown
      domainObject = new ims.core.admin.domain.objects.CareContext();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_CareContext());
      if (domMap.get(key) != null) {
        return (ims.core.admin.domain.objects.CareContext) domMap.get(key);
      }
      domainObject =
          (ims.core.admin.domain.objects.CareContext)
              domainFactory.getDomainObject(ims.core.admin.domain.objects.CareContext.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_CareContext());

    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value1 = null;
    if (null != valueObject.getContext()) {
      value1 = domainFactory.getLookupInstance(valueObject.getContext().getID());
    }
    domainObject.setContext(value1);
    ims.framework.utils.DateTime dateTime2 = valueObject.getStartDateTime();
    java.util.Date value2 = null;
    if (dateTime2 != null) {
      value2 = dateTime2.getJavaDate();
    }
    domainObject.setStartDateTime(value2);
    ims.framework.utils.DateTime dateTime3 = valueObject.getEndDateTime();
    java.util.Date value3 = null;
    if (dateTime3 != null) {
      value3 = dateTime3.getJavaDate();
    }
    domainObject.setEndDateTime(value3);

    // SaveAsRefVO treated as RefValueObject
    ims.core.admin.vo.CareContextHistoryRefVoCollection refCollection4 =
        new ims.core.admin.vo.CareContextHistoryRefVoCollection();
    if (valueObject.getCareContextHistory() != null) {
      for (int i4 = 0; i4 < valueObject.getCareContextHistory().size(); i4++) {
        ims.core.admin.vo.CareContextHistoryRefVo ref4 =
            (ims.core.admin.vo.CareContextHistoryRefVo) valueObject.getCareContextHistory().get(i4);
        refCollection4.add(ref4);
      }
    }
    int size4 = (null == refCollection4) ? 0 : refCollection4.size();
    java.util.Set domainCareContextHistory4 = domainObject.getCareContextHistory();
    if (domainCareContextHistory4 == null) {
      domainCareContextHistory4 = new java.util.HashSet();
    }
    java.util.Set newSet4 = new java.util.HashSet();
    for (int i = 0; i < size4; i++) {
      ims.core.admin.vo.CareContextHistoryRefVo vo = refCollection4.get(i);
      ims.core.admin.domain.objects.CareContextHistory dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom = (ims.core.admin.domain.objects.CareContextHistory) domMap.get(vo);
          }
        } else {
          dom =
              (ims.core.admin.domain.objects.CareContextHistory)
                  domainFactory.getDomainObject(
                      ims.core.admin.domain.objects.CareContextHistory.class, vo.getBoId());
        }
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainCareContextHistory4.contains(dom)) {
        domainCareContextHistory4.add(dom);
      }
      newSet4.add(dom);
    }
    java.util.Set removedSet4 = new java.util.HashSet();
    java.util.Iterator iter4 = domainCareContextHistory4.iterator();
    // Find out which objects need to be removed
    while (iter4.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter4.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet4.contains(o)) {
        removedSet4.add(o);
      }
    }
    iter4 = removedSet4.iterator();
    // Remove the unwanted objects
    while (iter4.hasNext()) {
      domainCareContextHistory4.remove(iter4.next());
    }

    domainObject.setCareContextHistory(domainCareContextHistory4);

    return domainObject;
  }