Updated Metadata and associated domain objects

This commit is contained in:
Andrew Donald Kennedy 2012-02-09 15:07:04 +00:00
parent d983eb3826
commit 86e15398aa
4 changed files with 219 additions and 22 deletions

View File

@ -38,7 +38,9 @@ public class VCloudDirectorMediaType {
public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml"; public static final String METADATA = "application/vnd.vmware.vcloud.metadata+xml";
public static final String METADATA_ENTRY = "*/*"; // TODO public static final String METADATA_ENTRY = "*/*"; // No media type (?)
public static final String METADATA_VALUE = "application/vnd.vmware.vcloud.metadata.value+xml";;
public static final String ORG = "application/vnd.vmware.vcloud.org+xml"; public static final String ORG = "application/vnd.vmware.vcloud.org+xml";

View File

@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry.Builder;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
@ -56,7 +57,7 @@ public class Metadata extends ResourceType<Metadata> {
@Override @Override
public Builder toBuilder() { public Builder toBuilder() {
return new Builder().fromMetadataList(this); return new Builder().fromMetadata(this);
} }
public static class Builder extends ResourceType.Builder<Metadata> { public static class Builder extends ResourceType.Builder<Metadata> {
@ -123,8 +124,16 @@ public class Metadata extends ResourceType<Metadata> {
return this; return this;
} }
public Builder fromMetadataList(Metadata in) { public Builder fromMetadata(Metadata in) {
return metadata(in.getMetadata()); return fromResourceType(in).metadata(in.getMetadata());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResourceType(ResourceType<Metadata> in) {
return Builder.class.cast(super.fromResourceType(in));
} }
} }
@ -134,14 +143,14 @@ public class Metadata extends ResourceType<Metadata> {
private Metadata(URI href, Set<MetadataEntry> metadataEntries) { private Metadata(URI href, Set<MetadataEntry> metadataEntries) {
super(href); super(href);
this.metadata = ImmutableSet.copyOf(metadataEntries); this.metadataEntries = ImmutableSet.copyOf(metadataEntries);
} }
@XmlElement(namespace = VCLOUD_1_5_NS, name = "MetadataEntry") @XmlElement(namespace = VCLOUD_1_5_NS, name = "MetadataEntry")
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet(); private Set<MetadataEntry> metadataEntries = Sets.newLinkedHashSet();
public Set<MetadataEntry> getMetadata() { public Set<MetadataEntry> getMetadata() {
return ImmutableSet.copyOf(metadata); return ImmutableSet.copyOf(metadataEntries);
} }
@Override @Override
@ -151,17 +160,17 @@ public class Metadata extends ResourceType<Metadata> {
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
Metadata that = Metadata.class.cast(o); Metadata that = Metadata.class.cast(o);
return super.equals(that) && equal(metadata, that.metadata); return super.equals(that) && equal(this.metadataEntries, that.metadataEntries);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() + Objects.hashCode(metadata); return super.hashCode() + Objects.hashCode(metadataEntries);
} }
@Override @Override
public ToStringHelper string() { public ToStringHelper string() {
return super.string().add("metadata", metadata); return super.string().add("metadataEntries", metadataEntries);
} }
} }

View File

@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Link.Builder;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
@ -55,15 +56,15 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
@Override @Override
public Builder toBuilder() { public Builder toBuilder() {
return new Builder().fromMetadata(this); return new Builder().fromMetadataEntry(this);
} }
public static class Builder extends ResourceType.Builder<MetadataEntry> { public static class Builder extends ResourceType.Builder<MetadataEntry> {
private String key; private String key;
private String value; private MetadataValue value;
/** /**
* @see MetadataEntry#getKey * @see MetadataEntry#getKey()
*/ */
public Builder key(String key) { public Builder key(String key) {
this.key = key; this.key = key;
@ -71,9 +72,19 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
} }
/** /**
* @see MetadataEntry#getValue * @see MetadataEntry#getValue()
*/ */
public Builder value(String value) { public Builder value(MetadataValue value) {
this.value = value;
return this;
}
/**
* @see MetadataEntry#getKey()
* @see MetadataEntry#getValue()
*/
public Builder entry(String key, MetadataValue value) {
this.key = key;
this.value = value; this.value = value;
return this; return this;
} }
@ -122,17 +133,24 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
return this; return this;
} }
public Builder fromMetadata(MetadataEntry in) { public Builder fromMetadataEntry(MetadataEntry in) {
return key(in.getKey()).value(in.getValue()); return fromResourceType(in).entry(key, value);
} }
/**
* {@inheritDoc}
*/
@Override
public Builder fromResourceType(ResourceType<MetadataEntry> in) {
return Builder.class.cast(super.fromResourceType(in));
}
} }
private MetadataEntry() { private MetadataEntry() {
// For JAXB and builder use // For JAXB and builder use
} }
private MetadataEntry(URI href, String key, String value) { private MetadataEntry(URI href, String key, MetadataValue value) {
super(href); super(href);
this.key = checkNotNull(key, "key"); this.key = checkNotNull(key, "key");
this.value = checkNotNull(value, "value"); this.value = checkNotNull(value, "value");
@ -141,7 +159,7 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Key") @XmlElement(namespace = VCLOUD_1_5_NS, name = "Key")
private String key; private String key;
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Value") @XmlElement(namespace = VCLOUD_1_5_NS, name = "Value")
private String value; private MetadataValue value;
/** /**
* @return key of the entry * @return key of the entry
@ -153,7 +171,7 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
/** /**
* @return value of the entry * @return value of the entry
*/ */
public String getValue() { public MetadataValue getValue() {
return value; return value;
} }
@ -164,12 +182,12 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
MetadataEntry that = MetadataEntry.class.cast(o); MetadataEntry that = MetadataEntry.class.cast(o);
return super.equals(that) && equal(key, that.key); return super.equals(that) && equal(key, that.key) && equal(this.value, that.value);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return super.hashCode() + Objects.hashCode(key); return super.hashCode() + Objects.hashCode(key, value);
} }
@Override @Override

View File

@ -0,0 +1,168 @@
/**
* 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.*;
import static com.google.common.base.Preconditions.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue.Builder;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Sets;
/**
* Represents a metadata entry
*
* <pre>
* &lt;xs:complexType name="MetadataType"&gt;
* </pre>
*
* @author danikov
*/
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "MetadataValue")
public class MetadataValue extends ResourceType<MetadataValue> {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY;
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return new Builder().fromMetadataValue(this);
}
public static class Builder extends ResourceType.Builder<MetadataValue> {
private String value;
/**
* @see MetadataValue#getValue
*/
public Builder value(String value) {
this.value = value;
return this;
}
@Override
public MetadataValue build() {
MetadataValue metadataValue = new MetadataValue(href, value);
metadataValue.setType(type);
metadataValue.setLinks(links);
return metadataValue;
}
/**
* @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<Link> 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 fromMetadataValue(MetadataValue in) {
return fromResourceType(in).value(value);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResourceType(ResourceType<MetadataValue> in) {
return Builder.class.cast(super.fromResourceType(in));
}
}
private MetadataValue() {
// For JAXB and builder use
}
private MetadataValue(URI href, String value) {
super(href);
this.value = checkNotNull(value, "value");
}
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Value", required = true)
private String value;
/**
* The value.
*/
public String getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MetadataValue that = MetadataValue.class.cast(o);
return super.equals(that) && equal(this.value, that.value);
}
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(value);
}
@Override
public ToStringHelper string() {
return super.string().add("value", value);
}
}