Tidy up domain objects, using media type enum

This commit is contained in:
Andrew Donald Kennedy 2012-02-08 18:50:59 +00:00
parent 69c4bd62e6
commit aab725d9eb
17 changed files with 154 additions and 98 deletions

View File

@ -0,0 +1,31 @@
/**
* 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;
/**
* Constants used by VCloudDirector clients
*
* @author grkvlt@apache.org
*/
public class VCloudDirectorConstants {
/** The XML namespace used by the clients. */
public static final String XMLNS = "http://www.vmware.com/vcloud/v1.5";
}

View File

@ -26,27 +26,24 @@ package org.jclouds.vcloud.director.v1_5;
*
* @see javax.ws.rs.core.MediaType;
*/
public interface VCloudDirectorMediaType {
public final static String NS = "http://www.vmware.com/vcloud/v1.5";
public enum VCloudDirectorMediaType {
ANY("*/*"),
SESSION("application/vnd.vmware.vcloud.session+xml"),
ERROR("application/vnd.vmware.vcloud.error+xml"),
ORG_LIST("application/vnd.vmware.vcloud.orgList+xml"),
METADATA("application/vnd.vmware.vcloud.metadata+xml"),
METADATA_ENTRY("*/*"), // TODO
ORG("application/vnd.vmware.vcloud.org+xml"),
TASKS_LIST("application/vnd.vmware.vcloud.tasksList+xml"),
TASK("application/vnd.vmware.vcloud.task+xml");
public final static String ANY = "*/*";
public final static String SESSION_XML = "application/vnd.vmware.vcloud.session+xml";
public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
public final static String METADATA_XML = "application/vnd.vmware.vcloud.metadata+xml";
public static final String METADATAENTRY_XML = "TODO"; // TODO
public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
public static final String ORG_NETWORK_XML = "application/vnd.vmware.vcloud.orgNetwork+xml";
public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
private final String mediaType;
private VCloudDirectorMediaType(String mediaType) {
this.mediaType = mediaType;
}
public String getMediaType() {
return mediaType;
}
}

View File

@ -18,9 +18,9 @@
*/
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
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;
@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlElement;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
@ -143,7 +145,6 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Builder<T> fromResourceType(ResourceType<T> in) {
return Builder.class.cast(super.fromResourceType(in));
@ -156,9 +157,9 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
}
}
@XmlElement(namespace = NS, name = "Description")
@XmlElement(namespace = XMLNS, name = "Description")
private String description;
@XmlElement(namespace = NS, name = "TasksInProgress")
@XmlElement(namespace = XMLNS, name = "TasksInProgress")
private TasksInProgress tasksInProgress;
@XmlAttribute
private String id;
@ -210,13 +211,21 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
this.id = id;
}
/**
* Returns the unique UUID string for this entity.
*
* Once we have an entity, the {@link #getId()} field is better suited to retrieving the
* id than {@link #getHref()}.
*
* @see ReferenceType#getUuid()
*/
@Override
public String getUuid() {
return Iterables.getLast(Splitter.on(":").split(id));
}
/**
* Contains the name of the the entity.
*
* The object type, specified as a MIME content type, of the object that the link references.
* This attribute is present only for links to objects. It is not present for links to actions.
*
* @return type definition, type, expressed as an HTTP Content-Type
*/
public String getName() {
return name;
@ -231,7 +240,7 @@ public class EntityType<T extends EntityType<T>> extends ResourceType<T> {
EntityType<?> that = EntityType.class.cast(o);
return super.equals(that) &&
equal(this.id, that.id) && equal(this.description, that.description) &&
equal(this.tasksInProgress, that.tasksInProgress);
equal(this.tasksInProgress, that.tasksInProgress) && equal(this.name, that.name);
}
@Override

View File

@ -20,12 +20,7 @@ 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.VCloudDirectorMediaType.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -43,7 +38,7 @@ import com.google.common.base.Objects;
*
* @author grkvlt@apache.org
*/
@XmlRootElement(namespace = NS, name = "Error")
@XmlRootElement(namespace = XMLNS, name = "Error")
@XmlAccessorType(XmlAccessType.FIELD)
public class Error {

View File

@ -18,8 +18,8 @@
*/
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 static com.google.common.base.Objects.*;
import static com.google.common.base.Preconditions.*;
import java.net.URI;
import java.util.Map;

View File

@ -18,9 +18,9 @@
*/
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
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;
@ -42,7 +42,7 @@ import com.google.common.collect.Sets;
*
* @author danikov
*/
@XmlRootElement(namespace = NS, name = "Metadata")
@XmlRootElement(namespace = XMLNS, name = "Metadata")
public class Metadata extends ResourceType<Metadata>{
@SuppressWarnings("unchecked")
@ -133,7 +133,7 @@ public class Metadata extends ResourceType<Metadata>{
this.metadata = ImmutableSet.copyOf(metadataEntries);
}
@XmlElement(namespace = NS, name = "MetadataEntry")
@XmlElement(namespace = XMLNS, name = "MetadataEntry")
private Set<MetadataEntry> metadata = Sets.newLinkedHashSet();
public Set<MetadataEntry> getMetadata() {

View File

@ -18,9 +18,9 @@
*/
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
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;
@ -41,7 +41,7 @@ import com.google.common.collect.Sets;
*
* @author danikov
*/
@XmlRootElement(namespace = NS, name = "TODO")
@XmlRootElement(namespace = XMLNS, name = "MetadataEntry")
public class MetadataEntry extends ResourceType<MetadataEntry> {
@SuppressWarnings("unchecked")
@ -134,9 +134,9 @@ public class MetadataEntry extends ResourceType<MetadataEntry> {
this.value = checkNotNull(value, "value");
}
@XmlElement(namespace = NS, name = "Key")
@XmlElement(namespace = XMLNS, name = "Key")
private String key;
@XmlElement(namespace = NS, name = "Value")
@XmlElement(namespace = XMLNS, name = "Value")
private String value;
/**

View File

@ -20,7 +20,7 @@ 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.VCloudDirectorMediaType.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Set;
@ -43,7 +43,7 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "Org")
@XmlRootElement(namespace = XMLNS, name = "Org")
public class Org extends EntityType<Org> {
@SuppressWarnings("unchecked")
@ -170,7 +170,7 @@ public class Org extends EntityType<Org> {
this.fullName = fullName;
}
@XmlElement(namespace = NS, name = "FullName")
@XmlElement(namespace = XMLNS, name = "FullName")
private String fullName;
/**

View File

@ -18,9 +18,9 @@
*/
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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
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.util.Set;
@ -36,7 +36,7 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "OrgList")
@XmlRootElement(namespace = XMLNS, name = "OrgList")
public class OrgList {
public static Builder builder() {
@ -84,7 +84,7 @@ public class OrgList {
this.orgs = ImmutableSet.copyOf(orgs);
}
@XmlElement(namespace = NS, name = "Org")
@XmlElement(namespace = XMLNS, name = "Org")
private Set<Reference> orgs = Sets.newLinkedHashSet();
public Set<Reference> getOrgs() {

View File

@ -28,7 +28,9 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
/**
* A reference to a resource.
@ -42,7 +44,7 @@ import com.google.common.base.Objects.ToStringHelper;
* @author grkvlt@apache.org
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceType<T extends ReferenceType<T>> {
public class ReferenceType<T extends ReferenceType<T>> implements URISupplier {
public static <T extends ReferenceType<T>> Builder<T> builder() {
return new Builder<T>();
@ -156,6 +158,15 @@ public class ReferenceType<T extends ReferenceType<T>> {
this.id = id;
}
/**
* Returns the unique UUID string for this reference.
*
* @see ResourceType#getUuid()
*/
public String getUuid() {
return Iterables.getLast(Splitter.on("/").split(href.getPath()));
}
/**
* Contains the name of the the entity.
*
@ -189,8 +200,9 @@ public class ReferenceType<T extends ReferenceType<T>> {
}
/**
* @see #getHref()
* @see URISupplier#getURI()
*/
@Override
public URI getURI() {
return getHref();
}

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.vcloud.director.v1_5.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.*;
import java.net.URI;
import java.util.Set;

View File

@ -20,7 +20,7 @@ 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.VCloudDirectorMediaType.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Set;
@ -31,7 +31,9 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
@ -46,7 +48,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ResourceType<T extends ResourceType<T>> {
public class ResourceType<T extends ResourceType<T>> implements URISupplier {
public static <T extends ResourceType<T>> Builder<T> builder() {
return new Builder<T>();
@ -110,7 +112,7 @@ public class ResourceType<T extends ResourceType<T>> {
private URI href;
@XmlAttribute
private String type;
@XmlElement(namespace = NS, name = "Link")
@XmlElement(namespace = XMLNS, name = "Link")
private Set<Link> links = Sets.newLinkedHashSet();
protected ResourceType(URI href) {
@ -138,6 +140,23 @@ public class ResourceType<T extends ResourceType<T>> {
return href;
}
/**
* @see URISupplier#getURI()
*/
@Override
public URI getURI() {
return getHref();
}
/**
* Returns the unique UUID string for this resource.
*
* @see ReferenceType#getUuid()
*/
public String getUuid() {
return Iterables.getLast(Splitter.on("/").split(href.getPath()));
}
/**
* Contains the type of the the entity.
*
@ -169,13 +188,6 @@ public class ResourceType<T extends ResourceType<T>> {
this.links.add(checkNotNull(link, "link"));
}
/**
* @see #getHref()
*/
public URI getURI() {
return getHref();
}
@Override
public boolean equals(Object o) {
if (this == o)

View File

@ -20,7 +20,7 @@ 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.VCloudDirectorMediaType.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Set;
@ -42,7 +42,7 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "Session")
@XmlRootElement(namespace = XMLNS, name = "Session")
@XmlAccessorType(XmlAccessType.FIELD)
public class Session {
@ -120,7 +120,7 @@ public class Session {
this.links = ImmutableSet.copyOf(links);
}
@XmlElement(namespace = NS, name = "Link")
@XmlElement(namespace = XMLNS, name = "Link")
private Set<Link> links = Sets.newLinkedHashSet();
@XmlAttribute
private String user;

View File

@ -43,7 +43,7 @@ public class SessionWithToken {
protected String token;
/**
* @see SessionWithToken#getType
* @see SessionWithToken#getSession()
*/
public Builder session(Session session) {
this.session = session;
@ -51,7 +51,7 @@ public class SessionWithToken {
}
/**
* @see SessionWithToken#getHref
* @see SessionWithToken#getToken()
*/
public Builder token(String token) {
this.token = token;

View File

@ -7,20 +7,20 @@
* "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
* http://www.apache.org/licenses/LICEXMLNSE-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
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIOXMLNS 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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.NS;
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.Date;
@ -43,7 +43,7 @@ import com.google.common.collect.Sets;
*
* @author grkvlt@apache.org
*/
@XmlRootElement(namespace = NS, name = "Task")
@XmlRootElement(namespace = XMLNS, name = "Task")
public class Task extends EntityType<Task> {
@SuppressWarnings("unchecked")
@ -282,17 +282,17 @@ public class Task extends EntityType<Task> {
super(href, name);
}
@XmlElement(namespace = NS, name = "Error")
@XmlElement(namespace = XMLNS, name = "Error")
private Error error;
@XmlElement(namespace = NS, name = "Organization")
@XmlElement(namespace = XMLNS, name = "Organization")
private Reference org;
@XmlElement(namespace = NS, name = "Progress")
@XmlElement(namespace = XMLNS, name = "Progress")
private Integer progress;
@XmlElement(namespace = NS, name = "Owner")
@XmlElement(namespace = XMLNS, name = "Owner")
private Reference owner;
@XmlElement(namespace = NS, name = "User")
@XmlElement(namespace = XMLNS, name = "User")
private Reference user;
@XmlElement(namespace = NS, name = "Params")
@XmlElement(namespace = XMLNS, name = "Params")
private Object params;
@XmlAttribute
private String status;

View File

@ -7,11 +7,11 @@
* "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
* http://www.apache.org/licenses/LICEXMLNSE-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
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIOXMLNS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
@ -20,7 +20,7 @@ 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.VCloudDirectorMediaType.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.util.Collection;
import java.util.Set;
@ -37,7 +37,7 @@ import com.google.common.collect.Sets;
/**
* @author grkvlt@apache.org
*/
@XmlRootElement(namespace = NS, name = "TasksInProgress")
@XmlRootElement(namespace = XMLNS, name = "TasksInProgress")
@XmlAccessorType(XmlAccessType.FIELD)
public class TasksInProgress {
@ -86,7 +86,7 @@ public class TasksInProgress {
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(namespace = NS, name = "Task")
@XmlElement(namespace = XMLNS, name = "Task")
private Set<Task> tasks = Sets.newLinkedHashSet();
public Set<Task> getTasks() {

View File

@ -20,7 +20,7 @@ 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.VCloudDirectorMediaType.*;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.*;
import java.net.URI;
import java.util.Set;
@ -38,7 +38,7 @@ import com.google.common.collect.Sets;
*
* @author Adrian Cole
*/
@XmlRootElement(namespace = NS, name = "TasksList")
@XmlRootElement(namespace = XMLNS, name = "TasksList")
public class TasksList extends EntityType<TasksList> {
@SuppressWarnings("unchecked")
@ -173,7 +173,7 @@ public class TasksList extends EntityType<TasksList> {
this.tasks = ImmutableSet.copyOf(tasks);
}
@XmlElement(namespace = NS, name = "Task")
@XmlElement(namespace = XMLNS, name = "Task")
private Set<Task> tasks = Sets.newLinkedHashSet();
public Set<Task> getTasks() {