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;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import java.util.List;
24  
25  import javax.annotation.Nullable;
26  
27  import org.jclouds.vcloud.domain.network.nat.NatPolicy;
28  import org.jclouds.vcloud.domain.network.nat.NatRule;
29  import org.jclouds.vcloud.domain.network.nat.NatType;
30  
31  import com.google.common.collect.Iterables;
32  import com.google.common.collect.Lists;
33  
34  /**
35   * The NatService element defines the network address translation capabilities of a network.
36   */
37  public class NatService {
38     private final boolean enabled;
39     @Nullable
40     private final NatType type;
41     @Nullable
42     private final NatPolicy policy;
43     private final List<NatRule> natRules = Lists.newArrayList();
44  
45     public NatService(boolean enabled, @Nullable NatType type, @Nullable NatPolicy policy,
46              Iterable<? extends NatRule> natRules) {
47        this.enabled = enabled;
48        this.type = type;
49        this.policy = policy;
50        Iterables.addAll(this.natRules, checkNotNull(natRules, "natRules"));
51     }
52  
53     /**
54      * @return Nat rules for the network
55      * 
56      * @since vcloud api 0.8
57      */
58     public List<? extends NatRule> getNatRules() {
59        return natRules;
60     }
61  
62     /**
63      * @return true if the service is enabled
64      * 
65      * @since vcloud api 0.9
66      */
67     public boolean isEnabled() {
68        return enabled;
69     }
70  
71     /**
72      * @return specifies how Network Address Translation is implemented by the NAT service
73      * 
74      * @since vcloud api 0.9
75      */
76     @Nullable
77     public NatType getType() {
78        return type;
79     }
80  
81     /**
82      * @return specifies how packets are handled by the NAT service.
83      * 
84      * @since vcloud api 0.9
85      */
86     @Nullable
87     public NatPolicy getPolicy() {
88        return policy;
89     }
90  
91     @Override
92     public int hashCode() {
93        final int prime = 31;
94        int result = 1;
95        result = prime * result + (enabled ? 1231 : 1237);
96        result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
97        result = prime * result + ((policy == null) ? 0 : policy.hashCode());
98        result = prime * result + ((type == null) ? 0 : type.hashCode());
99        return result;
100    }
101 
102    @Override
103    public boolean equals(Object obj) {
104       if (this == obj)
105          return true;
106       if (obj == null)
107          return false;
108       if (getClass() != obj.getClass())
109          return false;
110       NatService other = (NatService) obj;
111       if (enabled != other.enabled)
112          return false;
113       if (natRules == null) {
114          if (other.natRules != null)
115             return false;
116       } else if (!natRules.equals(other.natRules))
117          return false;
118       if (policy == null) {
119          if (other.policy != null)
120             return false;
121       } else if (!policy.equals(other.policy))
122          return false;
123       if (type == null) {
124          if (other.type != null)
125             return false;
126       } else if (!type.equals(other.type))
127          return false;
128       return true;
129    }
130 
131    @Override
132    public String toString() {
133       return "[enabled=" + enabled + ", natRules=" + natRules + ", policy=" + policy + ", type=" + type + "]";
134    }
135 
136 }