public OMElement registryStoredQuery(QueryBuilder builder, NonBlockCallBack callback) {
   if (builder == null) return null;
   if (callback == null) callback = new NonBlockCallBack();
   String stirng = registryStoredQuery.transaction(builder, callback);
   AxiomUtil axiom = AxiomUtil.getInstance();
   return axiom.fromString(stirng);
 }
 public OMElement retrieveDocumentSet(RetrieveBuilder builder, NonBlockCallBack callback) {
   if (builder == null) return null;
   if (callback == null) callback = new NonBlockCallBack();
   String stirng = retrieveDocumentSet.transaction(builder, callback);
   AxiomUtil axiom = AxiomUtil.getInstance();
   return axiom.fromString(stirng);
 }
  public List<DocumentResponseType> registryStoredQueryAndRetrieveDocumentSet(
      QueryBuilder builder, NonBlockCallBack callback) {
    List<DocumentResponseType> documents = Lists.newArrayList();

    OMElement response = registryStoredQuery(builder, callback);
    AxiomUtil axiom = AxiomUtil.getInstance();
    AdhocQueryResponseType adhocQueryResponse =
        axiom.fromXML(response, AdhocQueryResponseType.class);
    String status = adhocQueryResponse.getStatus();
    if (status.equals(Namespace.SUCCESS.getNamespace())) {
      Map<String, List<String>> map = Maps.newHashMap();
      RegistryObjectListType objectList = adhocQueryResponse.getRegistryObjectList();
      List<ExtrinsicObjectType> docEntries = objectList.getExtrinsicObjects();
      SlotFinder finder = new SlotFinder();
      for (ExtrinsicObjectType docEntry : docEntries) {
        String docId = docEntry.getId();
        String repositoryUniqueId =
            finder.findByDocumentEntryRepositoryUniqueId(docEntry.getSlots());
        if (map.containsKey(repositoryUniqueId)) {
          List<String> list = map.get(repositoryUniqueId);
          list.add(docId);
          map.put(repositoryUniqueId, list);
        } else {
          map.put(repositoryUniqueId, Lists.newArrayList(docId));
        }
      }

      Set<String> repositoryUniqueIds = map.keySet();
      for (String repositoryUniqueId : repositoryUniqueIds) {
        RetrieveBuilder retrieveBuilder = new RetrieveBuilder();
        retrieveBuilder.setRepositoryUniqueId(repositoryUniqueId);
        List<String> docIds = map.get(repositoryUniqueId);
        retrieveBuilder.setDocumentIds(Sets.newTreeSet(docIds));
        // TODO query repository endpoint
        retrieveBuilder.setEndpoint("");
        OMElement _response = retrieveDocumentSet(retrieveBuilder, callback);
        RetrieveDocumentSetResponseType retrieveDocumentSetResponse =
            axiom.fromXML(_response, RetrieveDocumentSetResponseType.class);
        List<DocumentResponseType> docs = retrieveDocumentSetResponse.getDocumentResponses();
        documents.addAll(docs);
      }
    }
    return documents;
  }
  @Override
  public OMElement getMessageFromXML() {
    if (!validate()) {
      return null;
    }
    AxiomUtil axiom = AxiomUtil.getInstance();

    OMElement root = axiom.createOMElement(EbXML.Association, Namespace.RIM3);
    root.addAttribute("id", this.getId(), null);
    root.addAttribute("objectType", ProvideAndRegistryDocumentSet_B_UUIDs.ASSOCIATION, null);

    root.addAttribute("sourceObject", association.getSourceObject(), null);
    root.addAttribute("targetObject", association.getTargetObject(), null);
    root.addAttribute("associationType", association.getAssociation(), null);

    if (association.getNote() != null) {
      OMElement slot = generateSlot("SubmissionSetStatus", new String[] {association.getNote()});
      root.addChild(slot);
    }
    return root;
  }