private XmlObject[] getServiceManifestXmlObject(AgreementOffer offerType) {
    XmlObject[] serviceXML =
        offerType
            .getTerms()
            .getAll()
            .getServiceDescriptionTermArray(0)
            .selectChildren(XmlBeanServiceManifestDocument.type.getDocumentElementName());

    if (serviceXML.length == 0) {
      fail("there is no service manifest doc in service description terms.");
    }
    return serviceXML;
  }
  private String allocateServices(AgreementOffer offer) throws AgreementFactoryException {

    String ac_url =
        ComponentConfigurationProvider.getString("VMServiceInstantiation.url.ac"); // $NON-NLS-1$
    String co_url =
        ComponentConfigurationProvider.getString("VMServiceInstantiation.url.co"); // $NON-NLS-1$

    ServiceManifestDocument manifest = Tools.offerToServiceManifest(offer.getXMLObject());

    log.debug(
        "allocate service for manifest:\n"
            + manifest.xmlText(new XmlOptions().setSavePrettyPrint()));

    String allocationOffer = "";

    boolean skipACtest =
        ComponentConfigurationProvider.getBoolean(
            "VMServiceInstantiation.skipACtest", false); // $NON-NLS-1$

    if (!skipACtest) {
      try {
        log.info(MessageFormat.format("calling admission control at {0}", new Object[] {ac_url}));

        ACModelApi ac = JAXRSClientFactory.create(ac_url, ACModelApi.class);
        allocationOffer = ac.performACTest(manifest.xmlText());

        // allocationOffer = ac.admissionControl("allocate", manifest.xmlText());
        log.info("calling admission control done...");

        log.info(MessageFormat.format("processing admission control response", new Object[] {}));
        log.debug("admission control plain response: \n" + allocationOffer);

        XmlOptions opt = new XmlOptions();
        opt.setLoadReplaceDocumentElement(AllocationOfferDocument.type.getDocumentElementName());
        AllocationOfferDocument ao = AllocationOfferDocument.Factory.parse(allocationOffer, opt);

        log.debug("admission control parsed response:");
        log.debug(ao.xmlText(new XmlOptions().setSavePrettyPrint()));

        if (ao.getAllocationOffer().getAdmissionControlDecision() == 0) {
          throw new AgreementFactoryException("service it is not admidded by admission control.");
        }

      } catch (Exception e) {
        if (e instanceof AgreementFactoryException) {
          throw (AgreementFactoryException) e;
        }

        throw new AgreementFactoryException("Error calling admission control.", e);
      }
    } else {
      log.info("admission control test is skipped");
    }

    try {
      log.info(MessageFormat.format("calling cloud optimizer at {0}", new Object[] {co_url}));

      CloudOptimizerREST co = JAXRSClientFactory.create(co_url, CloudOptimizerREST.class);
      WebClient.client(co).type(MediaType.APPLICATION_XML);

      String response = co.deploy(manifest.xmlText());

      log.info("calling cloud optimizer done...");
      log.debug("cloud optimizer response: '" + response + "'");

      if ((response == null) || ("".equals(response))) {
        throw new AgreementFactoryException("Service could not be deployed by cloud optimizer.");
      }

    } catch (Exception e) {
      if (e instanceof AgreementFactoryException) {
        throw (AgreementFactoryException) e;
      }

      throw new AgreementFactoryException("Error calling cloud optimizer.", e);
    }

    return manifest.getServiceManifest().getServiceDescriptionSection().getServiceId();
  }