From 98f0c51b288228b33bb417661495a5b44418e454 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Tue, 10 Apr 2012 13:13:25 +0100 Subject: [PATCH] Update usage of collections of OVF sections --- .../dmtf/ovf/internal/BaseEnvelope.java | 2 +- .../dmtf/ovf/internal/BaseVirtualSystem.java | 10 +- .../v1_5/domain/AbstractVAppType.java | 86 ++++++++---- .../v1_5/domain/CaptureVAppParams.java | 117 +++++++++------- .../v1_5/domain/InstantiationParams.java | 125 +++++++++++++++-- .../director/v1_5/domain/VAppTemplate.java | 87 +++++------- .../v1_5/domain/VAppTemplateChildren.java | 132 ------------------ .../VAppTemplateClientExpectTest.java | 4 + 8 files changed, 286 insertions(+), 277 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplateChildren.java diff --git a/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseEnvelope.java b/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseEnvelope.java index 8303ac6aec..c513c0d293 100644 --- a/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseEnvelope.java +++ b/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseEnvelope.java @@ -137,7 +137,7 @@ public abstract class BaseEnvelope getDiskSections() { + public Set getDiskSections() { return diskSections; } diff --git a/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseVirtualSystem.java b/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseVirtualSystem.java index 74bd231a3c..d499ef423f 100644 --- a/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseVirtualSystem.java +++ b/labs/dmtf/src/main/java/org/jclouds/dmtf/ovf/internal/BaseVirtualSystem.java @@ -74,7 +74,7 @@ public abstract class BaseVirtualSystem extends SectionType { /** * @see BaseVirtualSystem#getProductSections() */ - public B productSections(Iterable productSections) { + public B productSections(Iterable productSections) { this.productSections = Sets.newLinkedHashSet(checkNotNull(productSections, "productSections")); return self(); } @@ -109,9 +109,9 @@ public abstract class BaseVirtualSystem extends SectionType { @XmlElement(name = "Name") private String name; @XmlElement(name = "ProductSection") - private Set productSections; + private Set productSections; @XmlElementRef - private Set additionalSections; + private Set additionalSections; protected BaseVirtualSystem(Builder builder) { super(builder); @@ -137,11 +137,11 @@ public abstract class BaseVirtualSystem extends SectionType { * Specifies product-information for a package, such as product name and version, along with a * set of properties that can be configured */ - public Set getProductSections() { + public Set getProductSections() { return productSections; } - public Set getAdditionalSections() { + public Set getAdditionalSections() { return additionalSections; } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java index a1a062f893..18e7963dcc 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/AbstractVAppType.java @@ -21,19 +21,28 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; +import java.util.Collections; +import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; import javax.xml.bind.annotation.XmlType; -import org.jclouds.dmtf.DMTFConstants; +import org.jclouds.dmtf.ovf.DeploymentOptionSection; +import org.jclouds.dmtf.ovf.DiskSection; +import org.jclouds.dmtf.ovf.NetworkSection; +import org.jclouds.dmtf.ovf.OperatingSystemSection; +import org.jclouds.dmtf.ovf.ProductSection; import org.jclouds.dmtf.ovf.SectionType; +import org.jclouds.dmtf.ovf.StartupSection; +import org.jclouds.dmtf.ovf.VirtualHardwareSection; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; /** * Represents a base type for VAppType and VmType. @@ -63,7 +72,7 @@ public abstract class AbstractVAppType extends ResourceEntityType { private Boolean deployed; private Reference vAppParent; - private List sections = Lists.newArrayList(); + private Set sections = Sets.newLinkedHashSet(); /** * @see AbstractVAppType#isDeployed() @@ -101,7 +110,7 @@ public abstract class AbstractVAppType extends ResourceEntityType { * @see AbstractVAppType#getSections() */ public B sections(Iterable sections) { - this.sections = Lists.newArrayList(checkNotNull(sections, "sections")); + this.sections = Sets.newLinkedHashSet(checkNotNull(sections, "sections")); return self(); } @@ -109,8 +118,6 @@ public abstract class AbstractVAppType extends ResourceEntityType { * @see AbstractVAppType#getSections() */ public B section(SectionType section) { - if (this.sections == null) - this.sections = Lists.newArrayList(); this.sections.add(checkNotNull(section, "section")); return self(); } @@ -122,8 +129,26 @@ public abstract class AbstractVAppType extends ResourceEntityType { @XmlElement(name = "VAppParent") private Reference vAppParent; - @XmlElementRef(namespace = DMTFConstants.OVF_NS) - private List sections = Lists.newArrayList(); + @XmlElementRefs({ + @XmlElementRef(type = VirtualHardwareSection.class), + @XmlElementRef(type = LeaseSettingsSection.class), +// @XmlElementRef(type = EulaSection.class), + @XmlElementRef(type = RuntimeInfoSection.class), +// @XmlElementRef(type = AnnotationSection.class), + @XmlElementRef(type = DeploymentOptionSection.class), + @XmlElementRef(type = StartupSection.class), +// @XmlElementRef(type = ResourceAllocationSection.class), + @XmlElementRef(type = NetworkConnectionSection.class), + @XmlElementRef(type = CustomizationSection.class), + @XmlElementRef(type = ProductSection.class), + @XmlElementRef(type = GuestCustomizationSection.class), + @XmlElementRef(type = OperatingSystemSection.class), + @XmlElementRef(type = NetworkConfigSection.class), + @XmlElementRef(type = NetworkSection.class), +// @XmlElementRef(type = InstallSection.class), + @XmlElementRef(type = DiskSection.class) + }) + private Set sections = Sets.newLinkedHashSet(); @XmlAttribute private Boolean deployed; @@ -134,7 +159,7 @@ public abstract class AbstractVAppType extends ResourceEntityType { protected AbstractVAppType(Builder builder) { super(builder); this.vAppParent = builder.vAppParent; - this.sections = builder.sections; + this.sections = builder.sections.isEmpty() ? null : ImmutableSet.copyOf(builder.sections); this.deployed = builder.deployed; } @@ -146,32 +171,31 @@ public abstract class AbstractVAppType extends ResourceEntityType { } /** - * Specific ovf:Section with additional information for the vApp. + * Specific {@code ovf:Section} with additional information for the vApp. * * Objects of the following type(s) are allowed in the list: *
    - *
  • SectionType - *
  • VirtualHardwareSectionType - *
  • LeaseSettingsSectionType - *
  • EulaSectionType - *
  • RuntimeInfoSectionType - *
  • AnnotationSectionType - *
  • DeploymentOptionSectionType - *
  • StartupSectionType - *
  • ResourceAllocationSectionType - *
  • NetworkConnectionSectionType - *
  • CustomizationSectionType - *
  • ProductSectionType - *
  • GuestCustomizationSectionType - *
  • OperatingSystemSectionType - *
  • NetworkConfigSectionType - *
  • NetworkSectionType - *
  • DiskSectionType - *
  • InstallSectionType + *
  • {@link VirtualHardwareSectionType} + *
  • {@link LeaseSettingsSectionType} + *
  • {@link EulaSectionType} + *
  • {@link RuntimeInfoSectionType} + *
  • {@link AnnotationSectionType} + *
  • {@link DeploymentOptionSectionType} + *
  • {@link StartupSectionType} + *
  • {@link ResourceAllocationSectionType} + *
  • {@link NetworkConnectionSectionType} + *
  • {@link CustomizationSectionType} + *
  • {@link ProductSectionType} + *
  • {@link GuestCustomizationSectionType} + *
  • {@link OperatingSystemSectionType} + *
  • {@link NetworkConfigSectionType} + *
  • {@link NetworkSectionType} + *
  • {@link DiskSectionType} + *
  • {@link InstallSectionType} *
*/ - public List getSections() { - return this.sections; + public Set getSections() { + return sections != null ? ImmutableSet.copyOf(sections) : Collections.emptySet(); } /** diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CaptureVAppParams.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CaptureVAppParams.java index 071da5176c..8a0093365c 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CaptureVAppParams.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/CaptureVAppParams.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; @@ -28,24 +27,26 @@ import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.jclouds.dmtf.ovf.DeploymentOptionSection; +import org.jclouds.dmtf.ovf.DiskSection; +import org.jclouds.dmtf.ovf.NetworkSection; +import org.jclouds.dmtf.ovf.OperatingSystemSection; +import org.jclouds.dmtf.ovf.ProductSection; import org.jclouds.dmtf.ovf.SectionType; +import org.jclouds.dmtf.ovf.StartupSection; +import org.jclouds.dmtf.ovf.VirtualHardwareSection; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; - /** * Represents the parameters for capturing a vApp to a vApp template. - *

- *

- *

Java class for CaptureVAppParams complex type. - *

- *

The following schema fragment specifies the expected content contained within this class. - *

+ * *

  * <complexType name="CaptureVAppParams">
  *   <complexContent>
@@ -78,11 +79,11 @@ public class CaptureVAppParams extends ParamsType {
 
    private static class ConcreteBuilder extends Builder {
    }
-   
+
    public static abstract class Builder> extends ParamsType.Builder {
 
       private Reference source;
-      private Set sections = Sets.newLinkedHashSet();
+      private Set sections = Sets.newLinkedHashSet();
 
       /**
        * @see CaptureVAppParams#getSource()
@@ -94,19 +95,27 @@ public class CaptureVAppParams extends ParamsType {
 
       /**
        * Sets source to a new Reference that uses this URI as the href.
-       * 
+       *
        * @see CaptureVAppParams#getSource()
        */
       public B source(URI source) {
          this.source = Reference.builder().href(source).build();
          return self();
       }
-      
+
       /**
        * @see CaptureVAppParams#getSections()
        */
-      public B sections(Set sections) {
-         this.sections = checkNotNull(sections, "sections");
+      public B section(SectionType section) {
+         this.sections.add(checkNotNull(section, "section"));
+         return self();
+      }
+
+      /**
+       * @see CaptureVAppParams#getSections()
+       */
+      public B sections(Iterable sections) {
+         this.sections = Sets.newLinkedHashSet(checkNotNull(sections, "sections"));
          return self();
       }
 
@@ -125,7 +134,7 @@ public class CaptureVAppParams extends ParamsType {
    private CaptureVAppParams(Builder builder) {
       super(builder);
       this.source = builder.source;
-      this.sections = builder.sections;
+      this.sections = builder.sections.isEmpty() ? null : ImmutableSet.copyOf(builder.sections);
    }
 
    private CaptureVAppParams() {
@@ -138,46 +147,60 @@ public class CaptureVAppParams extends ParamsType {
 
    @XmlElement(name = "Source", required = true)
    protected Reference source;
-   @XmlElementRef
-   protected Set sections = Sets.newLinkedHashSet();
+   @XmlElementRefs({
+      @XmlElementRef(type = VirtualHardwareSection.class),
+      @XmlElementRef(type = LeaseSettingsSection.class),
+//      @XmlElementRef(type = EulaSection.class),
+      @XmlElementRef(type = RuntimeInfoSection.class),
+//      @XmlElementRef(type = AnnotationSection.class),
+      @XmlElementRef(type = DeploymentOptionSection.class),
+      @XmlElementRef(type = StartupSection.class),
+//      @XmlElementRef(type = ResourceAllocationSection.class),
+      @XmlElementRef(type = NetworkConnectionSection.class),
+      @XmlElementRef(type = CustomizationSection.class),
+      @XmlElementRef(type = ProductSection.class),
+      @XmlElementRef(type = GuestCustomizationSection.class),
+      @XmlElementRef(type = OperatingSystemSection.class),
+      @XmlElementRef(type = NetworkConfigSection.class),
+      @XmlElementRef(type = NetworkSection.class),
+//      @XmlElementRef(type = InstallSection.class),
+      @XmlElementRef(type = DiskSection.class)
+   })
+   protected Set sections = Sets.newLinkedHashSet();
 
    /**
     * Gets the value of the source property.
-    *
-    * @return possible object is
-    *         {@link Reference }
     */
    public Reference getSource() {
       return source;
    }
 
    /**
-    * An ovf:Section to configure the captured vAppTemplate.
+    * An {@code ovf:Section} to configure the captured vAppTemplate.
     *
-    *  Gets the value of the section property.
-    *    
-    * Objects of the following type(s) are allowed in the list
-    * {@link SectionType }
-    * {@link VirtualHardwareSection }
-    * {@link LeaseSettingsSection }
-    * {@link EulaSection }
-    * {@link RuntimeInfoSection }
-    * {@link AnnotationSection }
-    * {@link DeploymentOptionSection }
-    * {@link StartupSection }
-    * {@link ResourceAllocationSection }
-    * {@link NetworkConnectionSection }
-    * {@link CustomizationSection }
-    * {@link ProductSection }
-    * {@link GuestCustomizationSection }
-    * {@link OperatingSystemSection }
-    * {@link NetworkConfigSection }
-    * {@link NetworkSection }
-    * {@link DiskSection }
-    * {@link InstallSection }
+    * Objects of the following type(s) are allowed in the list:
+    * 
    + *
  • {@link VirtualHardwareSectionType} + *
  • {@link LeaseSettingsSectionType} + *
  • {@link EulaSectionType} + *
  • {@link RuntimeInfoSectionType} + *
  • {@link AnnotationSectionType} + *
  • {@link DeploymentOptionSectionType} + *
  • {@link StartupSectionType} + *
  • {@link ResourceAllocationSectionType} + *
  • {@link NetworkConnectionSectionType} + *
  • {@link CustomizationSectionType} + *
  • {@link ProductSectionType} + *
  • {@link GuestCustomizationSectionType} + *
  • {@link OperatingSystemSectionType} + *
  • {@link NetworkConfigSectionType} + *
  • {@link NetworkSectionType} + *
  • {@link DiskSectionType} + *
  • {@link InstallSectionType} + *
*/ - public Set getSections() { - return Collections.unmodifiableSet(this.sections); + public Set getSections() { + return sections != null ? ImmutableSet.copyOf(sections) : Collections.emptySet(); } @Override @@ -187,8 +210,8 @@ public class CaptureVAppParams extends ParamsType { if (o == null || getClass() != o.getClass()) return false; CaptureVAppParams that = CaptureVAppParams.class.cast(o); - return equal(source, that.source) && - equal(sections, that.sections); + return equal(source, that.source) + && equal(sections, that.sections); } @Override diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/InstantiationParams.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/InstantiationParams.java index 43073147f2..c07dd5fc47 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/InstantiationParams.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/InstantiationParams.java @@ -21,21 +21,32 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; import java.util.Set; import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import org.jclouds.dmtf.ovf.DeploymentOptionSection; +import org.jclouds.dmtf.ovf.DiskSection; +import org.jclouds.dmtf.ovf.NetworkSection; +import org.jclouds.dmtf.ovf.OperatingSystemSection; +import org.jclouds.dmtf.ovf.ProductSection; import org.jclouds.dmtf.ovf.SectionType; +import org.jclouds.dmtf.ovf.StartupSection; +import org.jclouds.dmtf.ovf.VirtualHardwareSection; import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; /** - * Represents a list of ovf:Section to configure for instantiating a VApp. - * + * Represents a list of {@code ovf:Section} to configure for instantiating a VApp. + * * @author grkvlt@apache.org * @see * vCloud REST API - InstantiationParamsType @@ -43,7 +54,7 @@ import com.google.common.collect.Sets; */ @XmlRootElement(name = "InstantiationParams") @XmlType(name = "InstantiationParamsType") -public class InstantiationParams { +public class InstantiationParams implements Set { public static Builder builder() { return new Builder(); @@ -87,18 +98,35 @@ public class InstantiationParams { } private InstantiationParams(Set sections) { - this.sections = ImmutableSet.copyOf(sections); + this.sections = sections.isEmpty() ? null : ImmutableSet.copyOf(sections); } - @XmlElementRef - protected Set sections = Sets.newLinkedHashSet(); + @XmlElementRefs({ + @XmlElementRef(type = VirtualHardwareSection.class), + @XmlElementRef(type = LeaseSettingsSection.class), +// @XmlElementRef(type = EulaSection.class), + @XmlElementRef(type = RuntimeInfoSection.class), +// @XmlElementRef(type = AnnotationSection.class), + @XmlElementRef(type = DeploymentOptionSection.class), + @XmlElementRef(type = StartupSection.class), +// @XmlElementRef(type = ResourceAllocationSection.class), + @XmlElementRef(type = NetworkConnectionSection.class), + @XmlElementRef(type = CustomizationSection.class), + @XmlElementRef(type = ProductSection.class), + @XmlElementRef(type = GuestCustomizationSection.class), + @XmlElementRef(type = OperatingSystemSection.class), + @XmlElementRef(type = NetworkConfigSection.class), + @XmlElementRef(type = NetworkSection.class), +// @XmlElementRef(type = InstallSection.class), + @XmlElementRef(type = DiskSection.class) + }) + protected Set sections = Sets.newLinkedHashSet(); /** * An {@code ovf:Section} to configure for instantiation. * - * Objects of the following type(s) are allowed in the list + * Objects of the following type(s) are allowed in the list: *
    - *
  • {@link SectionType} *
  • {@link VirtualHardwareSection} *
  • {@link LeaseSettingsSection} *
  • {@link EulaSection} @@ -118,8 +146,8 @@ public class InstantiationParams { *
  • {@link InstallSection} *
*/ - public Set getSections() { - return sections; + public Set getSections() { + return sections != null ? ImmutableSet.copyOf(sections) : Collections.emptySet(); } @Override @@ -141,4 +169,81 @@ public class InstantiationParams { public String toString() { return Objects.toStringHelper("").add("sections", sections).toString(); } + + /** + * The delegate always returns a {@link Set} even if {@link #sections} is {@literal null}. + * + * The delegated {@link Set} is used by the methods implementing its interface. + *

+ * NOTE Annoying lack of multiple inheritance for using ForwardingList! + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private Set delegate() { + return (Set) getSections(); + } + + @Override + public boolean add(SectionType arg0) { + return delegate().add(arg0); + } + + @Override + public boolean addAll(Collection arg0) { + return delegate().addAll(arg0); + } + + @Override + public void clear() { + delegate().clear(); + } + + @Override + public boolean contains(Object arg0) { + return delegate().contains(arg0); + } + + @Override + public boolean containsAll(Collection arg0) { + return delegate().containsAll(arg0); + } + + @Override + public boolean isEmpty() { + return delegate().isEmpty(); + } + + @Override + public Iterator iterator() { + return delegate().iterator(); + } + + @Override + public boolean remove(Object arg0) { + return delegate().remove(arg0); + } + + @Override + public boolean removeAll(Collection arg0) { + return delegate().removeAll(arg0); + } + + @Override + public boolean retainAll(Collection arg0) { + return delegate().retainAll(arg0); + } + + @Override + public int size() { + return delegate().size(); + } + + @Override + public Object[] toArray() { + return delegate().toArray(); + } + + @Override + public T[] toArray(T[] arg0) { + return delegate().toArray(arg0); + } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplate.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplate.java index 751ead8e36..8b24e38410 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplate.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplate.java @@ -28,8 +28,8 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSeeAlso; import org.jclouds.dmtf.ovf.DeploymentOptionSection; import org.jclouds.dmtf.ovf.DiskSection; @@ -69,7 +69,7 @@ public class VAppTemplate extends ResourceEntityType { public static abstract class Builder> extends ResourceEntityType.Builder { private Owner owner; private Set children = Sets.newLinkedHashSet(); - private Set sections = Sets.newLinkedHashSet(); + private Set sections = Sets.newLinkedHashSet(); private String vAppScopedLocalId; private Boolean ovfDescriptorUploaded; private Boolean goldMaster; @@ -85,16 +85,16 @@ public class VAppTemplate extends ResourceEntityType { /** * @see VAppTemplate#getChildren() */ - public B children(Set children) { - this.children = checkNotNull(children, "children"); + public B children(Iterable children) { + this.children = Sets.newLinkedHashSet(checkNotNull(children, "children")); return self(); } /** * @see VAppTemplate#getSections() */ - public B sections(Set sections) { - this.sections = checkNotNull(sections, "sections"); + public B sections(Iterable sections) { + this.sections = Sets.newLinkedHashSet(checkNotNull(sections, "sections")); return self(); } @@ -140,10 +140,10 @@ public class VAppTemplate extends ResourceEntityType { @XmlElement(name = "Owner") private Owner owner; - @XmlElement(name = "Children") - private VAppTemplateChildren children = VAppTemplateChildren.builder().build(); + @XmlElementWrapper(name = "Children") + @XmlElement(name = "Vm") + private Set children = Sets.newLinkedHashSet(); @XmlElementRefs({ - @XmlElementRef(type = SectionType.class), @XmlElementRef(type = VirtualHardwareSection.class), @XmlElementRef(type = LeaseSettingsSection.class), // @XmlElementRef(type = EulaSection.class), @@ -162,7 +162,7 @@ public class VAppTemplate extends ResourceEntityType { // @XmlElementRef(type = InstallSection.class), @XmlElementRef(type = DiskSection.class) }) - private Set sections = Sets.newLinkedHashSet(); + private Set sections = Sets.newLinkedHashSet(); @XmlElement(name = "VAppScopedLocalId") private String vAppScopedLocalId; @XmlAttribute @@ -173,8 +173,8 @@ public class VAppTemplate extends ResourceEntityType { protected VAppTemplate(Builder builder) { super(builder); this.owner = builder.owner; - this.children = VAppTemplateChildren.builder().vms(builder.children).build(); - this.sections = ImmutableSet.copyOf(builder.sections); + this.children = builder.children.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(builder.children); + this.sections = builder.sections.isEmpty() ? null : ImmutableSet.copyOf(builder.sections); this.vAppScopedLocalId = builder.vAppScopedLocalId; this.ovfDescriptorUploaded = builder.ovfDescriptorUploaded; this.goldMaster = builder.goldMaster; @@ -186,9 +186,6 @@ public class VAppTemplate extends ResourceEntityType { /** * Gets the value of the owner property. - * - * @return possible object is - * {@link Owner } */ public Owner getOwner() { return owner; @@ -196,47 +193,41 @@ public class VAppTemplate extends ResourceEntityType { /** * Gets the value of the children property. - * - * @return possible object is - * {@link VAppTemplateChildren } */ public Set getChildren() { - return children.getVms(); + return children; } /** * Contains ovf sections for vApp template. - * Gets the value of the section property. - *

- * Objects of the following type(s) are allowed in the list - * {@link SectionType } - * {@link VirtualHardwareSection } - * {@link LeaseSettingsSection } - * {@link EulaSection } - * {@link RuntimeInfoSection } - * {@link AnnotationSection } - * {@link DeploymentOptionSection } - * {@link StartupSection } - * {@link ResourceAllocationSection } - * {@link NetworkConnectionSection } - * {@link CustomizationSection } - * {@link ProductSection } - * {@link GuestCustomizationSection } - * {@link OperatingSystemSection } - * {@link NetworkConfigSection } - * {@link NetworkSection } - * {@link DiskSection } - * {@link InstallSection } + * + * Objects of the following type(s) are allowed in the list: + *

    + *
  • {@link VirtualHardwareSectionType} + *
  • {@link LeaseSettingsSectionType} + *
  • {@link EulaSectionType} + *
  • {@link RuntimeInfoSectionType} + *
  • {@link AnnotationSectionType} + *
  • {@link DeploymentOptionSectionType} + *
  • {@link StartupSectionType} + *
  • {@link ResourceAllocationSectionType} + *
  • {@link NetworkConnectionSectionType} + *
  • {@link CustomizationSectionType} + *
  • {@link ProductSectionType} + *
  • {@link GuestCustomizationSectionType} + *
  • {@link OperatingSystemSectionType} + *
  • {@link NetworkConfigSectionType} + *
  • {@link NetworkSectionType} + *
  • {@link DiskSectionType} + *
  • {@link InstallSectionType} + *
*/ - public Set getSections() { - return Collections.unmodifiableSet(this.sections); + public Set getSections() { + return sections != null ? ImmutableSet.copyOf(sections) : Collections.emptySet(); } /** * Gets the value of the vAppScopedLocalId property. - * - * @return possible object is - * {@link String } */ public String getVAppScopedLocalId() { return vAppScopedLocalId; @@ -244,9 +235,6 @@ public class VAppTemplate extends ResourceEntityType { /** * Gets the value of the ovfDescriptorUploaded property. - * - * @return possible object is - * {@link Boolean } */ public Boolean isOvfDescriptorUploaded() { return ovfDescriptorUploaded; @@ -254,9 +242,6 @@ public class VAppTemplate extends ResourceEntityType { /** * Gets the value of the goldMaster property. - * - * @return possible object is - * {@link Boolean } */ public boolean isGoldMaster() { if (goldMaster == null) { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplateChildren.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplateChildren.java deleted file mode 100644 index c81c8b51c1..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/VAppTemplateChildren.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.jclouds.vcloud.director.v1_5.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Collections; -import java.util.Set; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - - -/** - * Represents vApp template children. - *

- *

- *

Java class for VAppTemplateChildren complex type. - *

- *

The following schema fragment specifies the expected content contained within this class. - *

- *

- * <complexType name="VAppTemplateChildren">
- *   <complexContent>
- *     <extension base="{http://www.vmware.com/vcloud/v1.5}VCloudExtensibleType">
- *       <sequence>
- *         <element name="Vm" type="{http://www.vmware.com/vcloud/v1.5}VAppTemplateType" maxOccurs="unbounded" minOccurs="0"/>
- *       </sequence>
- *       <anyAttribute processContents='lax' namespace='##other'/>
- *     </extension>
- *   </complexContent>
- * </complexType>
- * 
- */ -@XmlRootElement(name = "Children") -@XmlType(propOrder = { - "vms" -}) -public class VAppTemplateChildren { - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromVAppTemplateChildren(this); - } - - public static class Builder { - private Set vms = Sets.newLinkedHashSet(); - - /** - * @see VAppTemplateChildren#getVms() - */ - public Builder vms(Set vms) { - this.vms = checkNotNull(vms, "vms"); - return this; - } - - - public VAppTemplateChildren build() { - return new VAppTemplateChildren(vms); - } - - - public Builder fromVAppTemplateChildren(VAppTemplateChildren in) { - return vms(in.getVms()); - } - } - - private VAppTemplateChildren(Set vm) { - this.vms = ImmutableSet.copyOf(vm); - } - - private VAppTemplateChildren() { - // For JAXB - } - - @XmlElement(name = "Vm") - protected Set vms = Sets.newLinkedHashSet(); - - /** - * Gets the value of the vm property. - */ - public Set getVms() { - return Collections.unmodifiableSet(this.vms); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - VAppTemplateChildren that = VAppTemplateChildren.class.cast(o); - return equal(vms, that.vms); - } - - @Override - public int hashCode() { - return Objects.hashCode(vms); - } - - @Override - public String toString() { - return Objects.toStringHelper("") - .add("vms", vms).toString(); - } - -} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java index 21a63f50d6..c2213b08c9 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/features/VAppTemplateClientExpectTest.java @@ -33,6 +33,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; +import java.io.IOException; import java.net.URI; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -68,8 +69,11 @@ import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.VAppNetworkConfiguration; import org.jclouds.vcloud.director.v1_5.domain.VAppTemplate; import org.jclouds.vcloud.director.v1_5.internal.VCloudDirectorAdminClientExpectTest; +import org.jclouds.xml.internal.JAXBParser; import org.testng.annotations.Test; +import com.google.common.base.Strings; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; /**