View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.vcloud.domain.network.internal;
20  
21  import java.net.URI;
22  import java.util.Set;
23  
24  import javax.annotation.Nullable;
25  
26  import org.jclouds.vcloud.domain.ReferenceType;
27  import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
28  import org.jclouds.vcloud.domain.network.FenceMode;
29  import org.jclouds.vcloud.domain.network.VCloudExpressNetwork;
30  import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
31  import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
32  
33  import com.google.common.collect.Sets;
34  
35  /**
36   * Locations of resources in vCloud
37   * 
38   * @author Adrian Cole
39   * 
40   */
41  public class VCloudExpressNetworkImpl extends ReferenceTypeImpl implements VCloudExpressNetwork {
42  
43     /** The serialVersionUID */
44     private static final long serialVersionUID = 8464716396538298809L;
45     protected final String description;
46     protected final Set<String> dnsServers = Sets.newHashSet();
47     protected final String gateway;
48     protected final String netmask;
49     protected final Set<FenceMode> fenceModes = Sets.newHashSet();
50     @Nullable
51     protected final Boolean dhcp;
52     protected final Set<PortForwardingRule> natRules = Sets.newHashSet();
53     protected final Set<FirewallRule> firewallRules = Sets.newHashSet();
54  
55     public VCloudExpressNetworkImpl(String name, String type, URI id, String description, Set<String> dnsServers,
56              String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
57              Set<FirewallRule> firewallRules) {
58        super(name, type, id);
59        this.description = description;
60        this.dnsServers.addAll(dnsServers);
61        this.gateway = gateway;
62        this.netmask = netmask;
63        this.fenceModes.addAll(fenceModes);
64        this.dhcp = dhcp;
65        this.natRules.addAll(natRules);
66        this.firewallRules.addAll(firewallRules);
67     }
68  
69     /**
70      * {@inheritDoc}
71      */
72     public String getDescription() {
73        return description;
74     }
75  
76     /**
77      * {@inheritDoc}
78      */
79     public Set<String> getDnsServers() {
80        return dnsServers;
81     }
82  
83     /**
84      * {@inheritDoc}
85      */
86     public String getGateway() {
87        return gateway;
88     }
89  
90     /**
91      * {@inheritDoc}
92      */
93     public String getNetmask() {
94        return netmask;
95     }
96  
97     /**
98      * {@inheritDoc}
99      */
100    public Set<FenceMode> getFenceModes() {
101       return fenceModes;
102    }
103 
104    /**
105     * {@inheritDoc}
106     */
107    public Boolean isDhcp() {
108       return dhcp;
109    }
110 
111    /**
112     * {@inheritDoc}
113     */
114    public Set<PortForwardingRule> getNatRules() {
115       return natRules;
116    }
117 
118    /**
119     * {@inheritDoc}
120     */
121    public Set<FirewallRule> getFirewallRules() {
122       return firewallRules;
123    }
124 
125    @Override
126    public int compareTo(ReferenceType o) {
127       return (this == o) ? 0 : getHref().compareTo(o.getHref());
128    }
129 
130    @Override
131    public int hashCode() {
132       final int prime = 31;
133       int result = super.hashCode();
134       result = prime * result + ((description == null) ? 0 : description.hashCode());
135       result = prime * result + ((dhcp == null) ? 0 : dhcp.hashCode());
136       result = prime * result + ((dnsServers == null) ? 0 : dnsServers.hashCode());
137       result = prime * result + ((fenceModes == null) ? 0 : fenceModes.hashCode());
138       result = prime * result + ((firewallRules == null) ? 0 : firewallRules.hashCode());
139       result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
140       result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
141       result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
142       return result;
143    }
144 
145    @Override
146    public boolean equals(Object obj) {
147       if (this == obj)
148          return true;
149       if (!super.equals(obj))
150          return false;
151       if (getClass() != obj.getClass())
152          return false;
153       VCloudExpressNetworkImpl other = (VCloudExpressNetworkImpl) obj;
154       if (description == null) {
155          if (other.description != null)
156             return false;
157       } else if (!description.equals(other.description))
158          return false;
159       if (dhcp == null) {
160          if (other.dhcp != null)
161             return false;
162       } else if (!dhcp.equals(other.dhcp))
163          return false;
164       if (dnsServers == null) {
165          if (other.dnsServers != null)
166             return false;
167       } else if (!dnsServers.equals(other.dnsServers))
168          return false;
169       if (fenceModes == null) {
170          if (other.fenceModes != null)
171             return false;
172       } else if (!fenceModes.equals(other.fenceModes))
173          return false;
174       if (firewallRules == null) {
175          if (other.firewallRules != null)
176             return false;
177       } else if (!firewallRules.equals(other.firewallRules))
178          return false;
179       if (gateway == null) {
180          if (other.gateway != null)
181             return false;
182       } else if (!gateway.equals(other.gateway))
183          return false;
184       if (natRules == null) {
185          if (other.natRules != null)
186             return false;
187       } else if (!natRules.equals(other.natRules))
188          return false;
189       if (netmask == null) {
190          if (other.netmask != null)
191             return false;
192       } else if (!netmask.equals(other.netmask))
193          return false;
194       return true;
195    }
196 
197    @Override
198    public String toString() {
199       return "[id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
200                + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes + ", firewallRules="
201                + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask=" + netmask + "]";
202    }
203 
204 }