/**
  * Add multiple exceptions to exception collection. This method should only be called before
  * returning the response to the client.
  */
 public void addException(Collection bException) {
   if (bException != null && bException.size() > 0) {
     setStatus(STATUS_FAILURE);
     initExceptions();
     Iterator iter = bException.iterator();
     while (iter.hasNext()) {
       exceptions.add(iter.next());
     }
   }
 }
 /**
  * Helper method for adding to the response's already existing collection. This method should only
  * be called before returning the response to the client.
  */
 public void addCollection(Collection bCollection) {
   if (bCollection != null) {
     Iterator iter = bCollection.iterator();
     while (iter.hasNext()) {
       collection.add(iter.next());
     }
   }
 }
 /**
  * Add multiple exceptions to exception collection. This method should only be called before
  * returning the response to the client.
  */
 public void setExceptions(Collection bException) {
   if (bException != null && bException.size() > 0) {
     setStatus(STATUS_FAILURE);
     initExceptions();
     exceptions = null;
     exceptions = new ArrayList(bException);
   }
 }
  /**
   * Utility method for combining the contents of many bulk responses into one. This is useful for
   * JAXR calls that will include multiple calls to the registry for information.
   *
   * <p>If any of the given responses have isPartial set to true, then the returned response will
   * have isPartial set to true as well.
   *
   * <p>This method does not set requestId on the returned bulk response.
   *
   * <p>Status for the returned response is determined after the information has been filled in as
   * follows: 1. default = STATUS_SUCCESS 2. if partial, STATUS_WARNING 3. if exceptions.size() > 0,
   * STATUS_FAILURE
   *
   * @param responses A Collection of BulkResponses
   * @return A BulkResponse containing all the included information
   */
  public static BulkResponse combineBulkResponses(Collection responses) {
    BulkResponseImpl combinedResponse = new BulkResponseImpl();
    combinedResponse.setStatus(JAXRResponse.STATUS_SUCCESS);
    try {
      BulkResponseImpl response = null;
      Collection information = new ArrayList();
      Collection exceptions = new ArrayList();
      boolean isPartial = false;
      Iterator iter = responses.iterator();

      while (iter.hasNext()) {
        response = (BulkResponseImpl) iter.next();
        information.addAll(response.getCollection());
        if (response.getExceptions() != null) {
          exceptions.addAll(response.getExceptions());
        }
        if (response.isPartialResponse() == true) {
          isPartial = true;
        }
      }

      // set partial status before collection
      combinedResponse.setPartialResponse(isPartial);
      if (isPartial == true) {
        combinedResponse.setStatus(JAXRResponse.STATUS_WARNING);
      }
      combinedResponse.setCollection(information);
      if (exceptions.size() > 0) {
        combinedResponse.setExceptions(exceptions);
        combinedResponse.setStatus(JAXRResponse.STATUS_FAILURE);
      }
    } catch (JAXRException e) {
      logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return combinedResponse;
  }