From d1b2a08d3c9709b0325c20196daa3f6377de7761 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 6 Feb 2012 23:43:11 +0000 Subject: [PATCH] Updated base classes for domain objects/entities --- .../v1_5/domain/BaseNamedResource.java | 129 ----------- .../vcloud/director/v1_5/domain/Entity.java | 200 ++++++++++++++++ .../vcloud/director/v1_5/domain/Error.java | 12 - .../vcloud/director/v1_5/domain/Link.java | 56 +---- .../vcloud/director/v1_5/domain/Org.java | 117 ++-------- .../vcloud/director/v1_5/domain/OrgLink.java | 74 ------ .../director/v1_5/domain/Reference.java | 219 ++++++++++++++++++ .../{BaseResource.java => Resource.java} | 127 +++++++--- 8 files changed, 544 insertions(+), 390 deletions(-) delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseNamedResource.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java delete mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java create mode 100644 labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java rename labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/{BaseResource.java => Resource.java} (56%) diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseNamedResource.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseNamedResource.java deleted file mode 100644 index 8d7ddd7ef0..0000000000 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseNamedResource.java +++ /dev/null @@ -1,129 +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 java.net.URI; -import java.util.Map; - -import javax.xml.bind.annotation.XmlAttribute; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Location of a Rest resource. - * - *
- * <xs:complexType name="ReferenceType">
- * 
- * - * @author Adrian Cole - */ -public class BaseNamedResource> extends BaseResource { - - public static > Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return new Builder().fromNamedResource(this); - } - - public static class Builder> extends BaseResource.Builder { - - protected String name; - - /** - * @see BaseNamedResource#getName - */ - public Builder name(String name) { - this.name = name; - return this; - } - - @Override - public BaseNamedResource build() { - return new BaseNamedResource(href, type, name); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromBaseResource(BaseResource in) { - return Builder.class.cast(super.fromBaseResource(in)); - } - - public Builder fromNamedResource(BaseNamedResource in) { - return fromBaseResource(in).name(in.getName()); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - public Builder fromAttributes(Map attributes) { - return Builder.class.cast(super.fromAttributes(attributes)).name(attributes.get("name")); - } - } - - @XmlAttribute - protected String name; - - protected BaseNamedResource(URI href, String type, String name) { - super(href, type); - this.name = name; - } - - protected BaseNamedResource() { - // For JAXB - } - - /** - * The name of the referenced object, taken from the value of that object's name attribute. - * Action links do not include a name attribute. - * - * @return name; - */ - public String getName() { - return name; - } - - @Override - public boolean equals(Object o) { - if (!super.equals(o)) - return false; - BaseNamedResource that = BaseNamedResource.class.cast(o); - return equal(name, that.name); - } - - @Override - public int hashCode() { - return super.hashCode() + Objects.hashCode(name); - } - - @Override - public ToStringHelper string() { - return super.string().add("name", name); - } -} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java new file mode 100644 index 0000000000..affc2c05eb --- /dev/null +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Entity.java @@ -0,0 +1,200 @@ +/** + * 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 org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; + +import java.net.URI; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * Basic entity type in the vCloud object model. + * + * Includes a name, an optional description, and an optional list of links + * + *
+ * <xs:complexType name="EntityType">
+ * 
+ * + * @author Adrian Cole + */ +public class Entity> extends Resource { + + public static > Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return new Builder().fromEntity(this); + } + + public static class Builder> extends Resource.Builder { + + protected String description; + protected TaskList tasks; + protected String name; + protected String id; + + /** + * @see Entity#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Entity#getDescription() + */ + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see Entity#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Entity#getTasks() + */ + public Builder tasks(TaskList tasks) { + this.tasks = tasks; + return this; + } + + @Override + public Entity build() { + Entity entity = new Entity(href, name); + entity.setDescription(description); + entity.setTasks(tasks); + entity.setId(id); + entity.setType(type); + entity.setLinks(links); + return entity; + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { + return Builder.class.cast(super.fromResource(in)); + } + + public Builder fromEntity(Entity in) { + return fromResource(in).description(in.getDescription()).tasks(in.getTasks()).id(in.getId()).name(in.getName()); + } + } + + @XmlElement(namespace = NS, name = "Description") + protected String description; + @XmlElement(namespace = NS, name = "TasksInProgress") + protected TaskList tasks; + @XmlAttribute + protected String id; + @XmlAttribute + protected String name; + + protected Entity(URI href, String name) { + super(href); + this.name = name; + } + + protected Entity() { + // For JAXB + } + + /** + * Optional description. + */ + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * A list of queued, running, or recently completed tasks associated with this entity. + */ + public TaskList getTasks() { + return tasks; + } + + public void setTasks(TaskList tasks) { + this.tasks = tasks; + } + + /** + * The resource identifier, expressed in URN format. + * + * The value of this attribute uniquely identifies the resource, persists for the life of the + * resource, and is never reused. + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = 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; + } + + @Override + public boolean equals(Object o) { + if (!super.equals(o)) + return false; + Entity that = Entity.class.cast(o); + return super.equals(that) && equal(this.id, that.id) && equal(this.description, that.description) && equal(this.tasks, that.tasks); + } + + @Override + public int hashCode() { + return super.hashCode() + Objects.hashCode(description, tasks, id, name); + } + + @Override + public ToStringHelper string() { + return super.string().add("description", description).add("tasks", tasks).add("id", id).add("name", name); + } +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java index c1e9616fa6..de87f8e493 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Error.java @@ -121,10 +121,6 @@ public class Error { return message; } - public void setMessage(String message) { - this.message = message; - } - /** * The class of the error. Matches the HTTP status code. */ @@ -132,10 +128,6 @@ public class Error { return majorErrorCode; } - public void setMajorErrorCode(int majorErrorCode) { - this.majorErrorCode = majorErrorCode; - } - /** * Specific API error code. * @@ -145,10 +137,6 @@ public class Error { return minorErrorCode; } - public void setMinorErrorCode(String minorErrorCode) { - this.minorErrorCode = minorErrorCode; - } - /** * A vendor/implementation specific error code that point to specific * modules/parts of the code and can make problem diagnostics easier. diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java index 6552c706d1..921e217fc4 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Link.java @@ -20,7 +20,7 @@ import com.google.common.base.Objects.ToStringHelper; * * @author Adrian Cole */ -public class Link extends BaseNamedResource { +public class Link extends Reference { @SuppressWarnings("unchecked") public static Builder builder() { @@ -35,7 +35,7 @@ public class Link extends BaseNamedResource { return new Builder().fromLink(this); } - public static class Builder extends BaseNamedResource.Builder { + public static class Builder extends Reference.Builder { protected String rel; @@ -47,59 +47,27 @@ public class Link extends BaseNamedResource { return this; } - @Override public Link build() { - return new Link(href, type, name, rel); + Link link = new Link(href, rel); + link.setId(id); + link.setName(name); + link.setType(type); } public Builder fromLink(Link in) { - return fromNamedResource(in).rel(in.getRel()); + return fromReference(in).rel(in.getRel()); } /** * {@inheritDoc} */ - @Override - public Builder fromBaseResource(BaseResource in) { - return Builder.class.cast(super.fromBaseResource(in)); + public Builder fromReference(Reference in) { + return Builder.class.cast(super.fromReference(in)); } /** * {@inheritDoc} */ - @Override - public Builder fromNamedResource(BaseNamedResource in) { - return Builder.class.cast(super.fromNamedResource(in)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder href(URI href) { - return Builder.class.cast(super.href(href)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder type(String type) { - return Builder.class.cast(super.type(type)); - } - - /** - * {@inheritDoc} - */ - @Override public Builder fromAttributes(Map attributes) { super.fromAttributes(attributes); rel(attributes.get("rel")); @@ -110,8 +78,8 @@ public class Link extends BaseNamedResource { @XmlAttribute protected String rel; - private Link(URI href, String type, String name, String rel) { - super(href, type, name); + private Link(URI href, String rel) { + super(href); this.rel = checkNotNull(rel, "rel"); } @@ -136,7 +104,7 @@ public class Link extends BaseNamedResource { if (!super.equals(o)) return false; Link that = (Link) o; - return equal(this.rel, that.rel); + return super.equals(that) && equal(this.rel, that.rel); } @Override diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java index 90e1751eed..3f03aaeae5 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Org.java @@ -29,13 +29,17 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.jclouds.vcloud.director.v1_5.domain.Entity.Builder; + 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; /** - * An organization. + * iRepresents an organization. + * + * Unit of multi-tenancy and a top-level container. Contain vDCs, TasksList, Catalogs and Shared Network entities. * *
  * <xs:complexType name="OrgType">
@@ -44,7 +48,7 @@ import com.google.common.collect.Sets;
  * @author Adrian Cole
  */
 @XmlRootElement(namespace = NS, name = "Org")
-public class Org extends BaseNamedResource {
+public class Org extends Entity {
 
    @SuppressWarnings("unchecked")
    public static Builder builder() {
@@ -56,28 +60,9 @@ public class Org extends BaseNamedResource {
       return new Builder().fromOrg(this);
    }
 
-   public static class Builder extends BaseNamedResource.Builder {
+   public static class Builder extends Entity.Builder {
 
-      private String id;
-      private String description;
       private String fullName;
-      private Set links = Sets.newLinkedHashSet();
-
-      /**
-       * @see Org#getId()
-       */
-      public Builder id(String id) {
-         this.id = id;
-         return this;
-      }
-
-      /**
-       * @see Org#getDescription()
-       */
-      public Builder description(String description) {
-         this.description = description;
-         return this;
-      }
 
       /**
        * @see Org#getFullName()
@@ -87,84 +72,38 @@ public class Org extends BaseNamedResource {
          return this;
       }
 
-      /**
-       * @see Org#getLinks()
-       */
-      public Builder links(Set links) {
-         this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
-         return this;
-      }
-
-      /**
-       * @see Org#getLinks()
-       */
-      public Builder addLink(Link org) {
-         links.add(checkNotNull(org, "org"));
-         return this;
+      @Override
+      public Org build() {
+         Org org = new Org(href, name, fullName);
+         org.setDescription(description);
+         org.setId(id);
+         org.setType(type);
+         org.setLinks(links);
+         org.setTasks(tasks);
+         return org;
       }
 
       @Override
-      public Org build() {
-         return new Org(href, type, name, id, description, fullName, links);
+      public Builder fromEntity(Entity in) {
+         return Builder.class.cast(super.fromEntity(in));
       }
 
       public Builder fromOrg(Org in) {
-         return id(in.getId()).description(in.getDescription()).fullName(in.getFullName()).links(in.getLinks());
+         return fromEntity(in).fullName(in.getFullName());
       }
-
-      @Override
-      public Builder name(String name) {
-         return Builder.class.cast(super.name(name));
-      }
-
-      @Override
-      public Builder href(URI href) {
-         return Builder.class.cast(super.href(href));
-      }
-
-      @Override
-      public Builder type(String type) {
-         return Builder.class.cast(super.type(type));
-      }
-      
    }
 
    private Org() {
       // For JAXB and builder use
    }
 
-   private Org(URI href, String type, String name, String id, String description, String fullName, Set links) {
-      super(href, type, name);
-      this.id = id;
-      this.description = description;
+   private Org(URI href, String name, String fullName) {
+      super(href, name);
       this.fullName = fullName;
-      this.links = ImmutableSet.copyOf(links);
    }
 
-   @XmlAttribute
-   private String id;
-   @XmlElement(namespace = NS, name = "Description")
-   private String description;
    @XmlElement(namespace = NS, name = "FullName")
    private String fullName;
-   @XmlElement(namespace = NS, name = "Link")
-   private Set links = Sets.newLinkedHashSet();
-
-   /**
-    * 
-    * @return id of the org
-    */
-   public String getId() {
-      return id;
-   }
-
-   /**
-    * 
-    * @return description of the org
-    */
-   public String getDescription() {
-      return description;
-   }
 
    /**
     * 
@@ -174,29 +113,21 @@ public class Org extends BaseNamedResource {
       return fullName;
    }
 
-   /**
-    * TODO
-    */
-   public Set getLinks() {
-      return ImmutableSet.copyOf(links);
-   }
-
    @Override
    public boolean equals(Object o) {
       if (!super.equals(o))
          return false;
       Org that = Org.class.cast(o);
-      return equal(id, that.id) && equal(description, that.description) && equal(fullName, that.fullName)
-               && equal(links, that.links);
+      return super.equals(that) && equal(fullName, that.fullName);
    }
 
    @Override
    public int hashCode() {
-      return super.hashCode() + Objects.hashCode(id, description, fullName, links);
+      return super.hashCode() + Objects.hashCode(fullName);
    }
 
    @Override
    public ToStringHelper string() {
-      return super.string().add("id", id).add("description", description).add("fullName", fullName).add("links", links);
+      return super.string().add("fullName", fullName);
    }
 }
diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java
deleted file mode 100644
index 8fcb156891..0000000000
--- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/OrgLink.java
+++ /dev/null
@@ -1,74 +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 java.net.URI;
-
-/**
- * A link to an organization.
- * 
- * @author Adrian Cole
- */
-public class OrgLink extends BaseNamedResource {
-
-   @SuppressWarnings("unchecked")
-   public static Builder builder() {
-      return new Builder();
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public Builder toBuilder() {
-      return Builder.class.cast(new Builder().fromNamedResource(this));
-   }
-
-   public static class Builder extends BaseNamedResource.Builder {
-
-      @Override
-      public OrgLink build() {
-         return new OrgLink(href, type, name);
-      }
-
-      @Override
-      public Builder name(String name) {
-         return Builder.class.cast(super.name(name));
-      }
-
-      @Override
-      public Builder href(URI href) {
-         return Builder.class.cast(super.href(href));
-      }
-
-      @Override
-      public Builder type(String type) {
-         return Builder.class.cast(super.type(type));
-      }
-
-   }
-
-   private OrgLink(URI href, String type, String name) {
-      super(href, type, name);
-   }
-
-   private OrgLink() {
-      // for JAXB
-   }
-}
diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java
new file mode 100644
index 0000000000..49aac7ad0b
--- /dev/null
+++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Reference.java
@@ -0,0 +1,219 @@
+/**
+ * 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 java.net.URI;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+
+/**
+ * A reference to a resource.
+ *
+ * Contains an href attribute and optional name and type attributes.
+ *
+ * 
+ * <xs:complexType name="ReferenceType">
+ * 
+ * + * @author Adrian Cole + */ +public class Reference> { + + public static > Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromReference(this); + } + + public static class Builder> { + + protected URI href; + protected String id; + protected String name; + protected String type; + + /** + * @see Reference#getHref() + */ + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see Reference#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Reference#getType() + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see Reference#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + public Reference build() { + Reference reference = new Reference(href); + reference.setId(id); + reference.setName(name); + reference.setType(type); + return reference; + } + + protected Builder fromReference(Reference in) { + return href(in.getHref()).id(in.getId()).name(in.getName()).type(in.getType()); + } + + protected Builder fromAttributes(Map attributes) { + return href(URI.create(attributes.get("href"))).id(attributes.get("id")).name(attributes.get("name")).type(attributes.get("type")); + } + + } + + @XmlAttribute + protected URI href; + @XmlAttribute + protected String id; + @XmlAttribute + protected String name; + @XmlAttribute + protected String type; + + protected Reference(URI href) { + this.href = href; + } + + protected Reference() { + // For JAXB + } + + /** + * Contains the URI to the entity. + * + * An object reference, expressed in URL format. Because this URL includes the object identifier + * portion of the id attribute value, it uniquely identifies the object, persists for the life of + * the object, and is never reused. The value of the href attribute is a reference to a view of + * the object, and can be used to access a representation of the object that is valid in a + * particular context. Although URLs have a well-known syntax and a well-understood + * interpretation, a client should treat each href as an opaque string. The rules that govern how + * the server constructs href strings might change in future releases. + * + * @return an opaque reference and should never be parsed + */ + public URI getHref() { + return href; + } + + /** + * The resource identifier, expressed in URN format. + * + * The value of this attribute uniquely identifies the resource, persists for the life of the + * resource, and is never reused. + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = 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; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Contains the type 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 getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + /** + * @see #getHref() + */ + public URI getURI() { + return getHref(); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Reference that = Reference.class.cast(o); + return equal(this.href, that.href) && equal(this.id, that.id) && equal(this.name, that.name) && equal(this.type, that.type); + } + + @Override + public int hashCode() { + return Objects.hashCode(href, id, name, type); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("href", href).add("id", id).add("name", name).add("type", type); + } +} \ No newline at end of file diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseResource.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java similarity index 56% rename from labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseResource.java rename to labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java index dee43207b9..2d5fb93515 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/BaseResource.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/domain/Resource.java @@ -19,37 +19,59 @@ package org.jclouds.vcloud.director.v1_5.domain; import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.*; +import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.*; import java.net.URI; import java.util.Map; +import java.util.Set; import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; + +import org.jclouds.vcloud.director.v1_5.domain.Task.Builder; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.Sets; /** - * Location of a Rest resource + * The base type for all objects in the vCloud model. + * + * Has an optional list of links and href and type attributes. + * + *
+ * <xs:complexType name="ResourceType">
+ * 
* * @author Adrian Cole */ -public class BaseResource> { +public class Resource> { - public static > Builder builder() { + public static > Builder builder() { return new Builder(); } public Builder toBuilder() { - return new Builder().fromBaseResource(this); + return new Builder().fromResource(this); } - public static class Builder> { + public static class Builder> { - protected String type; protected URI href; + protected String type; + protected Set links = Sets.newLinkedHashSet(); /** - * @see BaseResource#getType + * @see Reference#getHref() + */ + public Builder href(URI href) { + this.href = href; + return this; + } + + /** + * @see Reference#getType() */ public Builder type(String type) { this.type = type; @@ -57,53 +79,51 @@ public class BaseResource> { } /** - * @see BaseResource#getHref + * @see Reference#getLinks() */ - public Builder href(URI href) { - this.href = href; + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); return this; } - public BaseResource build() { - return new BaseResource(href, type); + /** + * @see Reference#getLinks() + */ + public Builder link(Link link) { + this.links.add(checkNotNull(link, "link")); + return this; } - protected Builder fromBaseResource(BaseResource in) { - return type(in.getType()).href(in.getHref()); + public Resource build() { + Resource reference = new Resource(href); + reference.setType(type); + reference.setLinks(links); + return reference; } - protected Builder fromAttributes(Map attributes) { - return href(URI.create(attributes.get("href"))).type(attributes.get("type")); + protected Builder fromResource(Resource in) { + return href(in.getHref()).type(in.getType()).links(in.getLinks()); } - } - @XmlAttribute - protected String type; - @XmlAttribute protected URI href; + @XmlAttribute + protected String type; + @XmlElement(namespace = NS, name = "Link") + protected Set links = Sets.newLinkedHashSet(); - protected BaseResource(URI href, String type) { - this.type = type; + protected Resource(URI href) { this.href = href; } - protected BaseResource() { + protected Resource() { // For JAXB } /** - * 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 getType() { - return type; - } - - /** + * Contains the URI to the entity. + * * An object reference, expressed in URL format. Because this URL includes the object identifier * portion of the id attribute value, it uniquely identifies the object, persists for the life of * the object, and is never reused. The value of the href attribute is a reference to a view of @@ -119,7 +139,38 @@ public class BaseResource> { } /** - * @see #getHref + * Contains the type 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 getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + /** + * Set of optional links to an entity or operation associated with this object. + */ + public SetgetLinks() { + return links; + } + + public void setLinks(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + } + + public void addLink(Link link) { + this.links.add(checkNotNull(link, "link")); + } + + /** + * @see #getHref() */ public URI getURI() { return getHref(); @@ -131,13 +182,13 @@ public class BaseResource> { return true; if (o == null || getClass() != o.getClass()) return false; - BaseResource that = BaseResource.class.cast(o); - return equal(href, that.href) && equal(type, that.type); + Resource that = Resource.class.cast(o); + return equal(this.href, that.href) && equal(this.links, that.links) && equal(this.type, that.type); } @Override public int hashCode() { - return Objects.hashCode(type, href); + return Objects.hashCode(href, links, type); } @Override @@ -146,6 +197,6 @@ public class BaseResource> { } protected ToStringHelper string() { - return Objects.toStringHelper("").add("href", href).add("type", type); + return Objects.toStringHelper("").add("href", href).add("links", links).add("type", type); } } \ No newline at end of file