/**
   * @param adr
   * @param addressMap
   * @param exclude - Set of Delivery addresses already seen to avoid loops
   * @param msg - The Message wrapper for context dependent addressing
   */
  public void simpleResolveAddress(
      DeliveryAddress adr, List<PhysicalAddress> addressList, Set<DeliveryAddress> exclude) {
    if (exclude == null) {
      exclude = new HashSet<DeliveryAddress>();
    }

    if (!exclude.contains(adr)) {
      exclude.add(adr);

      AddressType type = adr.getAddressType();

      switch (type) {
        case Physical:
          {
            PhysicalAddress a = adr.getPhysicalAddress();
            addressList.add(a);
            break;
          }
        case Group:
          {
            DeliveryGroup grp = groupMgr.findGroup(adr.getGroupAddress().getName());
            if (grp != null) {
              // Loop the group
              LinkedList<DeliveryAddress> grpList = grp.getGroup();
              Iterator<DeliveryAddress> itr = grpList.iterator();
              while (itr.hasNext()) {
                simpleResolveAddress(itr.next(), addressList, exclude);
              }
            }
            break;
          }
        case Party:
          {
            UserContactInfo userInfo = userMgr.findUser(adr.getPartyAddress().getName());
            if (userInfo != null) {

              // TODO Extend for context and better address selection - ay need more context for the
              // operation.
              // TODO Extend for presence

              // Resolve the user preferred address
              PhysicalAddress a = userInfo.getPreferredAddress();
              addressList.add(a);
            }
            break;
          }
      }
    }
  }
  /**
   * @param adr
   * @param addressMap
   * @param exclude - Set of Delivery addresses already seen to avoid loops
   * @param msg - The Message wrapper for context dependent addressing
   */
  public <T extends Message> void resolveAddress(
      DeliveryAddress adr,
      HashMap<String, List<PhysicalAddress>> addressMap,
      Set<DeliveryAddress> exclude,
      MessageWrapper<T> msg,
      Recipient r) {
    if (!exclude.contains(adr)) {
      exclude.add(adr);

      AddressType type = adr.getAddressType();

      if (type == null) {
        eventLogger.logSummaryEvent(
            LogEntryType.User_SendMessage,
            EventLevel.warn,
            "resolveAddress",
            "RecipientAddress Type Unknown",
            "Recipient passed with unknown/type");
        return;
      }

      switch (adr.getAddressType()) {
        case Physical:
          {
            PhysicalAddress a = adr.getPhysicalAddress();
            List<PhysicalAddress> list = addressMap.get(a.getServiceId());
            if (list == null) {
              list = new LinkedList<PhysicalAddress>();
              addressMap.put(a.getServiceId(), list);
            }
            list.add(a);

            break;
          }
        case Group:
          {
            DeliveryGroup grp = groupMgr.findGroup(adr.getGroupAddress().getName());
            if (grp != null) {
              // Loop the group
              LinkedList<DeliveryAddress> grpList = grp.getGroup();
              Iterator<DeliveryAddress> itr = grpList.iterator();
              while (itr.hasNext()) {
                resolveAddress(itr.next(), addressMap, exclude, msg, r);
              }
            }
            break;
          }
        case Party:
          {
            UserContactInfo userInfo = userMgr.findUser(adr.getPartyAddress().getName());
            if (userInfo != null) {

              // TODO Extend for context and better address selection - ay need more context for the
              // operation.
              // TODO Extend for presence

              // Resolve the user preferred address
              PhysicalAddress a = userInfo.getPreferredAddress();

              List<PhysicalAddress> list = addressMap.get(a.getServiceId());
              if (list == null) {
                list = new LinkedList<PhysicalAddress>();
                addressMap.put(a.getServiceId(), list);
              }
              list.add(a);
            }
            break;
          }
      }
    }
  }