Package com.jamesmurty.utils

Examples of com.jamesmurty.utils.XMLBuilder


   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
      DeploymentParams params = DeploymentParams.class.cast(input);
      try {
       
        XMLBuilder builder = XMLBuilder.create("Deployment").a("xmlns", "http://schemas.microsoft.com/windowsazure")
                  .e("Name").t(params.getName()).up()
                  .e("DeploymentSlot").t("Production").up()
                  .e("Label").t(params.getName()).up()
                  .e("RoleList")
                  .e("Role")
                  .e("RoleName").t(params.getName()).up()
                  .e("RoleType").t("PersistentVMRole").up()
                  .e("ConfigurationSets");
                 
        if (params.getOsType() == OSType.WINDOWS){
          XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Windows
          configBuilder.e("ConfigurationSetType").t("WindowsProvisioningConfiguration").up()
              .e("ComputerName").t(params.getUsername()).up()
              .e("AdminPassword").t(params.getPassword()).up()
              .e("ResetPasswordOnFirstLogon").t("false").up()
              .e("EnableAutomaticUpdate").t("false").up()
              .e("DomainJoin")
              .e("Credentials")
                  .e("Domain").t(params.getName()).up()
                  .e("Username").t(params.getUsername()).up()
                  .e("Password").t(params.getPassword()).up()
              .up()//Credentials
              .e("JoinDomain").t(params.getName()).up()
              .up()// Domain Join
              .e("StoredCertificateSettings").up()
              .up();//Windows ConfigurationSet
        }else if (params.getOsType() == OSType.LINUX){
          XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Linux
          configBuilder.e("ConfigurationSetType").t("LinuxProvisioningConfiguration").up()
              .e("HostName").t(params.getName()).up()
              .e("UserName").t(params.getUsername()).up()
              .e("UserPassword").t(params.getPassword()).up()
              .e("DisableSshPasswordAuthentication").t("false").up()
              .e("SSH").up()
              .up();//Linux ConfigurationSet 
        }
       
        XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Network
      configBuilder.e("ConfigurationSetType").t("NetworkConfiguration").up();
     
      XMLBuilder inputEndpoints = configBuilder.e("InputEndpoints");
      for (InputEndpoint endpoint : params.getEndpoints()){
        XMLBuilder inputBuilder = inputEndpoints.e("InputEndpoint");
              inputBuilder.e("LocalPort").t(endpoint.getLocalPort().toString()).up()
              .e("Name").t(endpoint.getName()).up()
              .e("Port").t(endpoint.getExternalPort().toString()).up()
              .e("Protocol").t(endpoint.getProtocol().name()).up()
              .up();//InputEndpoint 
          }
View Full Code Here


   }

   protected String generateXml(String name, String template, SortedMap<ResourceType, String> virtualHardwareQuantity,
         String networkName, @Nullable String fenceMode, URI network) throws ParserConfigurationException,
         FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(name);

      rootBuilder.e("VAppTemplate").a("href", template);

      XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
      addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
      addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
View Full Code Here

      return rootBuilder.asString(outputProperties);
   }

   protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, @Nullable String fenceMode,
         URI network) {
      XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig")
            .a("name", name);
      if (fenceMode != null) {
         XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
         featuresBuilder.e("FenceMode").t(fenceMode);
      }
      networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
   }
View Full Code Here

      }
      networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
   }

   protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
      XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns)
            .a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema)
            .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
      return rootBuilder;
   }
View Full Code Here

      return options;
   }

   protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
         SortedMap<ResourceType, String> virtualHardwareQuantity) {
      XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns)
            .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
      if (propLocal.get() != null) {
         for (Entry<String, String> entry : propLocal.get().entrySet()) {
            productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1")
                  .a("ovf:key", entry.getKey()).a("ovf:value", entry.getValue());
         }
         propLocal.set(null);
      }
      if (virtualHardwareQuantity.size() > 0) {
         XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e("VirtualHardwareSection").a(
               "xmlns:q1", ns);
         for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
            XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
                  "http://schemas.dmtf.org/ovf/envelope/1");
            itemBuilder.e("InstanceID")
                  .a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
                  .t(virtualHardwareToInstanceId.get(entry.getKey()));
            itemBuilder.e("ResourceType")
                  .a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
                  .t(entry.getKey().value());
            itemBuilder.e("VirtualQuantity")
                  .a("xmlns", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
                  .t(entry.getValue());
         }
      }
   }
View Full Code Here

      this.stringBinder = stringBinder;
   }

   protected String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
         FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi",
            "http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
      rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name").toString());
      rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled").toString());
      if (postParams.containsKey("description") && postParams.get("description") != null)
         rootBuilder.e("Description").t((String) postParams.get("description"));
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }
View Full Code Here

   protected String generateXml(VApp vApp, VAppConfiguration configuration)
            throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
      String name = configuration.getName() != null ? configuration.getName() : vApp.getName();

      XMLBuilder rootBuilder = buildRoot(vApp, name);

      XMLBuilder sectionBuilder = rootBuilder.e("Section").a("xsi:type", "VirtualHardwareSection_Type").a("xmlns",
               "http://schemas.dmtf.org/ovf/envelope/1").a("xmlns:q2", "http://www.vmware.com/vcloud/v1");
      sectionBuilder.e("Info").t("Virtual Hardware");

      addProcessorItem(sectionBuilder, vApp, configuration);
      addMemoryItem(sectionBuilder, vApp, configuration);
      addDiskItems(sectionBuilder, vApp, configuration);
View Full Code Here

      }
   }

   private XMLBuilder addResourceWithQuantity(XMLBuilder sectionBuilder, ResourceAllocationSettingData resource,
            long quantity) {
      XMLBuilder itemBuilder = sectionBuilder.e("Item");
      addCommonElements(itemBuilder, resource, quantity);
      return itemBuilder;
   }
View Full Code Here

      itemBuilder.e("ResourceType").a("xmlns", RESOURCE_ALLOCATION_NS).t(resource.getResourceType().value());
      itemBuilder.e("VirtualQuantity").a("xmlns", RESOURCE_ALLOCATION_NS).t(quantity + "");
   }

   private XMLBuilder addDiskWithQuantity(XMLBuilder sectionBuilder, ResourceAllocationSettingData disk) {
      XMLBuilder itemBuilder = sectionBuilder.e("Item");
      itemBuilder.e("AddressOnParent").a("xmlns", RESOURCE_ALLOCATION_NS).t(disk.getAddressOnParent() + "");
      for (String hostResource : disk.getHostResources())
         itemBuilder.e("HostResource").a("xmlns", RESOURCE_ALLOCATION_NS).t(hostResource);
      addCommonElements(itemBuilder, disk, disk.getVirtualQuantity());
      return itemBuilder;
   }
View Full Code Here

   protected XMLBuilder buildRoot(VApp vApp, String name) throws ParserConfigurationException,
            FactoryConfigurationError {
      String status = vApp.getStatus().value();
      if (apiVersion.indexOf("0.8") != -1 && "8".equals(status))
         status = "2";
      XMLBuilder rootBuilder = XMLBuilder.create("VApp").a("type", vApp.getType()).a("name", name).a("status", status)
               .a("size", vApp.getSize() + "").a("xmlns", ns).a("xmlns:xsi",
                        "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
      return rootBuilder;
   }
View Full Code Here

TOP

Related Classes of com.jamesmurty.utils.XMLBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.