コード例 #1
0
ファイル: AxiomXpathParser.java プロジェクト: jjtyro/stratos
  private void loadHostName(final List<OMNode> nodes, final ServiceContext serviceCtxt) {

    if (nodes == null || nodes.isEmpty()) {
      return;
    }

    // read host element
    if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {

      OMElement node = (OMElement) nodes.get(0);

      if (node.getText() != null) {
        serviceCtxt.setHostName(node.getText());
      }
    }
  }
コード例 #2
0
ファイル: AxiomXpathParser.java プロジェクト: jjtyro/stratos
  private void loadPayload(final List<OMNode> nodes, final ServiceContext serviceCtxt) {

    if (nodes == null || nodes.isEmpty()) {
      return;
    }

    // read payload element
    if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {

      OMElement node = (OMElement) nodes.get(0);

      if (node.getText() != null) {
        byte[] payload = CloudControllerUtil.getBytesFromFile(node.getText());
        serviceCtxt.setPayload(payload);
      }
    }
  }
コード例 #3
0
ファイル: AxiomXpathParser.java プロジェクト: jjtyro/stratos
  public List<ServiceContext> getServiceContexts() {

    List<ServiceContext> serviceContextList = new ArrayList<ServiceContext>();

    // services can be found from this XPATH
    String xpath = CloudControllerConstants.SERVICES_ELEMENT_XPATH;
    List<?> serviceNodes = getMatchingNodes(xpath, documentElement);

    if (serviceNodes == null || serviceNodes.isEmpty()) {
      // or from this XPATH
      xpath = CloudControllerConstants.SERVICE_ELEMENT_XPATH;
      serviceNodes = getMatchingNodes(xpath, documentElement);
    }

    if (serviceNodes == null || serviceNodes.isEmpty()) {
      log.warn("No service found in this configuration file : " + xmlSource.getPath());
      return serviceContextList;
    }

    for (Object obj : serviceNodes) {
      ServiceContext serviceCtxt = new ServiceContext();

      // set the definition file
      serviceCtxt.setFile(xmlSource);

      if (obj instanceof OMNode) {
        OMNode serviceNode = (OMNode) obj;

        if (serviceNode.getType() == OMNode.ELEMENT_NODE) {

          OMElement node = (OMElement) serviceNode;

          if (node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR)) == null) {
            String msg =
                "Essential '"
                    + CloudControllerConstants.SERVICE_DOMAIN_ATTR
                    + "' "
                    + "attribute of '"
                    + CloudControllerConstants.SERVICE_ELEMENT
                    + "' element cannot be found in "
                    + xmlSource;

            handleException(msg);
          }

          // set domain name
          serviceCtxt.setDomainName(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR))
                  .getAttributeValue());

          // set sub domain
          serviceCtxt.setSubDomainName(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_SUB_DOMAIN_ATTR))
                  .getAttributeValue());

          // set tenant range
          serviceCtxt.setTenantRange(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_TENANT_RANGE_ATTR))
                  .getAttributeValue());

          OMNode cartridgeNode =
              getFirstMatchingNode(xpath + CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH, node);

          if (cartridgeNode != null && cartridgeNode.getType() == OMNode.ELEMENT_NODE) {

            OMElement cartridgeElt = (OMElement) cartridgeNode;

            String type =
                cartridgeElt
                    .getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
                    .getAttributeValue();

            if ("".equals(type)) {
              String msg =
                  "Essential '"
                      + CloudControllerConstants.TYPE_ATTR
                      + "' "
                      + " attribute of '"
                      + CloudControllerConstants.CARTRIDGE_ELEMENT
                      + "' of '"
                      + CloudControllerConstants.SERVICE_ELEMENT
                      + "' element cannot be found in "
                      + xmlSource;

              handleException(msg);
            }

            // set Cartridge type
            serviceCtxt.setCartridgeType(type);
          }
          if (serviceCtxt.getCartridgeType() == null) {
            String msg =
                "Essential '"
                    + CloudControllerConstants.CARTRIDGE_ELEMENT
                    + "' element"
                    + " has not specified in "
                    + xmlSource;
            handleException(msg);
          }

          // load payload
          loadPayload(
              getMatchingNodes(xpath + CloudControllerConstants.PAYLOAD_ELEMENT_XPATH, node),
              serviceCtxt);

          // load host name
          loadHostName(
              getMatchingNodes(xpath + CloudControllerConstants.HOST_ELEMENT_XPATH, node),
              serviceCtxt);

          // load properties
          loadProperties(node, serviceCtxt.getProperties());
        }
      }

      FasterLookUpDataHolder.getInstance().addServiceContext(serviceCtxt);
      // add each domain specific template to list
      serviceContextList.add(serviceCtxt);
    }

    return serviceContextList;
  }