Package com.jamesmurty.utils

Examples of com.jamesmurty.utils.XMLBuilder


   }

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


      return rootBuilder;
   }

   protected String generateXml(String newName, String vApp, CloneVAppOptions options)
         throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
      XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
      if (options.getDescription() != null)
         rootBuilder.e("Description").text(options.getDescription());
      rootBuilder.e("VApp").a("xmlns", ns).a("href", vApp).a("type", TerremarkVCloudMediaType.VAPP_XML);
      Properties outputProperties = new Properties();
      outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
      return rootBuilder.asString(outputProperties);
   }
View Full Code Here

      Optional<String> location = Optional.fromNullable((String) postParams.get("location"));
      Optional<String> affinityGroup = Optional.fromNullable((String) postParams.get("affinityGroup"));
      CreateHostedServiceOptions options = Optional
               .fromNullable((CreateHostedServiceOptions) postParams.get("options")).or(NO_OPTIONS);
      try {
         XMLBuilder createHostedService = XMLBuilder.create("CreateHostedService")
                  .a("xmlns", "http://schemas.microsoft.com/windowsazure").e("ServiceName").t(serviceName).up()
                  .e("Label").t(label).up();

         if (options.getDescription().isPresent())
            createHostedService.e("Description").t(options.getDescription().get()).up();

         if (location.isPresent())
            createHostedService.e("Location").t(location.get()).up();
         else if (affinityGroup.isPresent())
            createHostedService.e("AffinityGroup").t(affinityGroup.get()).up();
         else
            throw new IllegalArgumentException("you must specify either Location or AffinityGroup!");

         if (options.getExtendedProperties().isPresent() && options.getExtendedProperties().get().size() > 0) {
            XMLBuilder extendedProperties = createHostedService.e("ExtendedProperties");
            for (Entry<String, String> entry : options.getExtendedProperties().get().entrySet())
               extendedProperties.e("ExtendedProperty").e("Name").t(entry.getKey()).up().e("Value").t(entry.getValue());
         }
         return (R) request.toBuilder().payload(createHostedService.asString()).build();
      } catch (Exception e) {
         throw Throwables.propagate(e);
      }
View Full Code Here

   @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

   public String generateXml(FirewallRule firewallRule) {
      checkNotNull(firewallRule, "FirewallRule");

      try {
         XMLBuilder rootBuilder = buildRoot();
         addFirewallRuleSection(rootBuilder, firewallRule);
         Properties outputProperties = new Properties();
         outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
         return rootBuilder.asString(outputProperties);
      } catch (Exception e) {
         return null;
      }
   }
View Full Code Here

         return null;
      }
   }

   void addFirewallRuleSection(XMLBuilder rootBuilder, FirewallRule firewallRule) {
      XMLBuilder firewallRuleBuilder = rootBuilder.e("svvs:FirewallRule");
      firewallRuleBuilder.e("svvs:IsEnabled").t(firewallRule.isEnabled() ? "true" : "false");
      firewallRuleBuilder.e("svvs:Description").t("Server Tier Firewall Rule");
      firewallRuleBuilder.e("svvs:Type").t(firewallRule.getFirewallType());
      firewallRuleBuilder.e("svvs:Log").t(firewallRule.isLogged() ? "yes" : "no");
      firewallRuleBuilder.e("svvs:Policy").t(firewallRule.getPolicy());
      firewallRuleBuilder.e("svvs:Protocols").e("svvs:"+firewallRule.getProtocol()).t("true").up().up();
      firewallRuleBuilder.e("svvs:Port").t(firewallRule.getPort());
      firewallRuleBuilder.e("svvs:Destination").t(firewallRule.getDestination());
      firewallRuleBuilder.e("svvs:Source").t(firewallRule.getSource());
   }
View Full Code Here

      firewallRuleBuilder.e("svvs:Destination").t(firewallRule.getDestination());
      firewallRuleBuilder.e("svvs:Source").t(firewallRule.getSource());
   }

   protected XMLBuilder buildRoot() throws ParserConfigurationException, FactoryConfigurationError {
      XMLBuilder rootBuilder = XMLBuilder.create("svvs:FirewallService")
            .a("xmlns:common", "http://schemas.dmtf.org/wbem/wscim/1/common")
            .a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8")
            .a("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
            .a("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData")
            .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1")
View Full Code Here

      return request;
   }

   public String generateXml(T spec) {
      try {
         XMLBuilder rootBuilder = buildRoot();
         bindSpec(spec, rootBuilder);
         Properties outputProperties = new Properties();
         outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
         return rootBuilder.asString(outputProperties);
      } catch (Exception e) {
         throw Throwables.propagate(e);
      }
   }
View Full Code Here

      // fix this once savvis api starts returning correctly
      addVirtualHardwareSection(vAppBuilder, spec.getName(), spec.getNetworkTierName().replace("-", " "), spec);
   }

   void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) {
      XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection");
      virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware");
      addSystem(virtualHardwareSectionBuilder, name);
      addItems(virtualHardwareSectionBuilder, spec, networkName);
   }
View Full Code Here

      addNetwork(virtualHardwareSectionBuilder, networkName);
      addDisks(virtualHardwareSectionBuilder, spec);
   }

   private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) {
      XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System");
      systemBuilder.e("vssd:Description").t("Virtual Hardware Family");
      systemBuilder.e("vssd:ElementName").t(name);
      systemBuilder.e("vssd:InstanceID").t("1");
      systemBuilder.e("vssd:VirtualSystemIdentifier").t(name);
   }
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.