From 693af6dc2513eae10f061761d4990aa2898e9b14 Mon Sep 17 00:00:00 2001 From: danikov Date: Tue, 7 Feb 2012 15:15:45 +0000 Subject: [PATCH] rebase metadata/entry on new base classes --- .../vcloud/director/v1_5/domain/Metadata.java | 83 ++++++++++++----- .../director/v1_5/domain/MetadataEntry.java | 90 +++++++++---------- 2 files changed, 107 insertions(+), 66 deletions(-) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java index cc22cc5dcb..316f83461a 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Metadata.java @@ -4,18 +4,21 @@ import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS; +import java.net.URI; import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -@XmlRootElement(namespace = NS, name = "MetaDataList") -public class Metadata { +@XmlRootElement(namespace = NS, name = "Metadata") +public class Metadata extends ResourceType{ + @SuppressWarnings("unchecked") public static Builder builder() { return new Builder(); } @@ -24,28 +27,67 @@ public class Metadata { return new Builder().fromMetadataList(this); } - public static class Builder { + public static class Builder extends ResourceType.Builder { - private Set metadata = Sets.newLinkedHashSet(); + private Set metadataEntries = Sets.newLinkedHashSet(); /** - * @see OrgList#getOrgs + * @see Metadata#getMetadata() */ - public Builder metadata(Set orgs) { - this.metadata = Sets.newLinkedHashSet(checkNotNull(orgs, "metadata")); + public Builder metadata(Set metadataEntries) { + this.metadataEntries = Sets.newLinkedHashSet(checkNotNull(metadataEntries, "metadataEntries")); return this; } /** - * @see OrgList#getOrgs + * @see Metadata#getMetadata() */ - public Builder addMetadata(MetadataEntry org) { - metadata.add(checkNotNull(org, "metadatum")); + public Builder entry(MetadataEntry metadataEntry) { + metadataEntries.add(checkNotNull(metadataEntry, "metadataEntry")); return this; } public Metadata build() { - return new Metadata(metadata); + Metadata metadata = new Metadata(href, metadataEntries); + metadata.setType(type); + metadata.setLinks(links); + return metadata; + } + + /** + * @see ResourceType#getHref() + */ + @Override + public Builder href(URI href) { + super.href(href); + return this; + } + + /** + * @see ResourceType#getType() + */ + @Override + public Builder type(String type) { + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; } public Builder fromMetadataList(Metadata in) { @@ -57,11 +99,12 @@ public class Metadata { // For JAXB and builder use } - private Metadata(Set orgs) { - this.metadata = ImmutableSet.copyOf(orgs); + private Metadata(URI href, Set metadataEntries) { + super(href); + this.metadata = ImmutableSet.copyOf(metadataEntries); } - @XmlElement(namespace = NS, name = "MetaData") + @XmlElement(namespace = NS, name = "MetadataEntry") private Set metadata = Sets.newLinkedHashSet(); public Set getMetadata() { @@ -70,22 +113,20 @@ public class Metadata { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) + if (!super.equals(o)) return false; Metadata that = Metadata.class.cast(o); - return equal(metadata, that.metadata); + return super.equals(that) && equal(metadata, that.metadata); } @Override public int hashCode() { - return Objects.hashCode(metadata); + return super.hashCode() + Objects.hashCode(metadata); } @Override - public String toString() { - return Objects.toStringHelper("").add("metadata", metadata).toString(); + public ToStringHelper string() { + return super.string().add("metadata", metadata); } } diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java index d48fb31cad..e28cea3976 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/MetadataEntry.java @@ -13,11 +13,10 @@ import javax.xml.bind.annotation.XmlRootElement; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @XmlRootElement(namespace = NS, name = "org/metadata") -public class MetadataEntry extends BaseResource { +public class MetadataEntry extends ResourceType { @SuppressWarnings("unchecked") public static Builder builder() { @@ -25,14 +24,12 @@ public class MetadataEntry extends BaseResource { } public Builder toBuilder() { - return new Builder().fromMetadatum(this); + return new Builder().fromMetadata(this); } - public static class Builder extends BaseResource.Builder { - + public static class Builder extends ResourceType.Builder { private String key; private String value; - private Set links = Sets.newLinkedHashSet(); /** * @see MetadataEntry#getKey @@ -50,38 +47,51 @@ public class MetadataEntry extends BaseResource { return this; } - /** - * @see MetadataEntry#? - */ - public Builder links(Set links) { - this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); - return this; - } - - /** - * @see MetadataEntry#? - */ - public Builder addLink(Link org) { - links.add(checkNotNull(org, "org")); - return this; - } - public MetadataEntry build() { - return new MetadataEntry(href, type, key, value, links); + MetadataEntry metadataEntry = new MetadataEntry(href, key, value); + metadataEntry.setType(type); + metadataEntry.setLinks(links); + return metadataEntry; } - - public Builder fromMetadatum(MetadataEntry in) { - return key(in.getKey()).value(in.getValue()); - } - + + /** + * @see ResourceType#getHref() + */ @Override public Builder href(URI href) { - return Builder.class.cast(super.href(href)); + super.href(href); + return this; } + /** + * @see ResourceType#getType() + */ @Override public Builder type(String type) { - return Builder.class.cast(super.type(type)); + super.type(type); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder links(Set links) { + super.links(Sets.newLinkedHashSet(checkNotNull(links, "links"))); + return this; + } + + /** + * @see ResourceType#getLinks() + */ + @Override + public Builder link(Link link) { + super.link(link); + return this; + } + + public Builder fromMetadata(MetadataEntry in) { + return key(in.getKey()).value(in.getValue()); } } @@ -90,19 +100,16 @@ public class MetadataEntry extends BaseResource { // For JAXB and builder use } - private MetadataEntry(URI href, String type, String key, String value, Set links) { - super(href, type); - this.key = key; - this.value = value; - this.links = ImmutableSet.copyOf(links); + private MetadataEntry(URI href, String key, String value) { + super(href); + this.key = checkNotNull(key, "key"); + this.value = checkNotNull(value, "value"); } @XmlAttribute private String key; @XmlElement(namespace = NS, name = "Value") private String value; - @XmlElement(namespace = NS, name = "Link") - private Set links = Sets.newLinkedHashSet(); /** * @@ -120,20 +127,13 @@ public class MetadataEntry extends BaseResource { return value; } - /** - * TODO - */ - public Set getLinks() { - return ImmutableSet.copyOf(links); - } - @Override public boolean equals(Object o) { if (!super.equals(o)) return false; MetadataEntry that = MetadataEntry.class.cast(o); - return equal(key, that.key); + return super.equals(that) && equal(key, that.key); } @Override