separate out NetworkType hierarchy

This commit is contained in:
danikov 2012-02-10 17:47:50 +00:00
parent 8740b7211d
commit 8d26cf75bc
3 changed files with 203 additions and 4 deletions

View File

@ -51,6 +51,8 @@ public class VCloudDirectorMediaType {
public static final String TASK = "application/vnd.vmware.vcloud.task+xml";
public static final String NETWORK = "application/vnd.vmware.vcloud.entity.network+xml";
public static final String ORG_NETWORK = "application/vnd.vmware.vcloud.orgNetwork+xml";
public static final String CATALOG = "application/vnd.vmware.vcloud.catalog+xml";

View File

@ -0,0 +1,197 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
*(Link.builder().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(Link.builder().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 static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_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.Sets;
@XmlRootElement(namespace = VCLOUD_1_5_NS, name = "NetworkType")
public class NetworkType<T extends NetworkType<T>> extends EntityType<T> {
public static <T extends NetworkType<T>> Builder<T> builder() {
return new Builder<T>();
}
@Override
public Builder<T> toBuilder() {
return new Builder<T>().fromNetworkType(this);
}
public static class Builder<T extends NetworkType<T>> extends EntityType.Builder<T> {
protected NetworkConfiguration networkConfiguration;
/**
* @see NetworkType#getConfiguration()
*/
public Builder<T> configuration(NetworkConfiguration networkConfiguration) {
this.networkConfiguration = networkConfiguration;
return this;
}
@Override
public NetworkType<T> build() {
NetworkType<T> network = new NetworkType<T>(href, name);
network.setConfiguration(networkConfiguration);
network.setDescription(description);
network.setId(id);
network.setType(type);
network.setLinks(links);
network.setTasksInProgress(tasksInProgress);
return network;
}
/**
* @see EntityType#getName()
*/
@Override
public Builder<T> name(String name) {
this.name = name;
return this;
}
/**
* @see EntityType#getDescription()
*/
@Override
public Builder<T> description(String description) {
this.description = description;
return this;
}
/**
* @see EntityType#getId()
*/
@Override
public Builder<T> id(String id) {
this.id = id;
return this;
}
/**
* @see EntityType#getTasksInProgress()
*/
@Override
public Builder<T> tasksInProgress(TasksInProgress tasksInProgress) {
this.tasksInProgress = tasksInProgress;
return this;
}
/**
* @see ReferenceType#getHref()
*/
@Override
public Builder<T> href(URI href) {
this.href = href;
return this;
}
/**
* @see ReferenceType#getType()
*/
@Override
public Builder<T> type(String type) {
this.type = type;
return this;
}
/**
* @see ReferenceType#getLinks()
*/
@Override
public Builder<T> links(Set<Link> links) {
this.links = Sets.newLinkedHashSet(checkNotNull(links, "links"));
return this;
}
/**
* @see ReferenceType#getLinks()
*/
@Override
public Builder<T> link(Link link) {
this.links.add(checkNotNull(link, "link"));
return this;
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Builder<T> fromEntityType(EntityType<T> in) {
return Builder.class.cast(super.fromEntityType(in));
}
public Builder<T> fromNetworkType(NetworkType<T> in) {
return fromEntityType(in).configuration(in.getConfiguration());
}
}
protected NetworkType() {
// For JAXB and builder use
}
protected NetworkType(URI href, String name) {
super(href, name);
}
@XmlElement(namespace = VCLOUD_1_5_NS, name = "Configuration")
private NetworkConfiguration networkConfiguration;
/**
* @return optional configuration
*/
public NetworkConfiguration getConfiguration() {
return networkConfiguration;
}
public void setConfiguration(NetworkConfiguration networkConfiguration) {
this.networkConfiguration = networkConfiguration;
}
@Override
public boolean equals(Object o) {
if (!super.equals(o))
return false;
NetworkType<?> that = NetworkType.class.cast(o);
return super.equals(that) && equal(networkConfiguration, that.networkConfiguration);
}
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(networkConfiguration);
}
@Override
public ToStringHelper string() {
return super.string().add("configuration", networkConfiguration);
}
}

View File

@ -18,13 +18,13 @@
*/
package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.OrgNetwork;
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
/**
* Provides synchronous access to Network.
@ -42,20 +42,20 @@ public interface NetworkClient {
*
* @return the network or null if not found
*/
OrgNetwork getNetwork(URI networkRef);
OrgNetwork getNetwork(ReferenceType<?> networkRef);
/**
* Retrieves an list of the network's metadata
*
* @return a list of metadata
*/
Metadata getMetadata(URI networkRef);
Metadata getMetadata(ReferenceType<?> networkRef);
/**
* Retrieves a metadata entry
*
* @return the metadata entry, or null if not found
*/
MetadataEntry getMetadataEntry(URI metaDataRef);
MetadataEntry getMetadataEntry(ReferenceType<?> networkRef, String key);
}