| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.savvis.vpdc.domain; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | |
| 23 | /** |
| 24 | * API returns a firewall rule in a firewall service |
| 25 | * |
| 26 | * @author Kedar Dave |
| 27 | */ |
| 28 | public class FirewallRule extends ResourceImpl { |
| 29 | |
| 30 | public static Builder builder() { |
| 31 | return new Builder(); |
| 32 | } |
| 33 | |
| 34 | public static class Builder extends ResourceImpl.Builder { |
| 35 | |
| 36 | private String firewallType; |
| 37 | private boolean isEnabled; |
| 38 | private String source; |
| 39 | private String destination; |
| 40 | private String port; |
| 41 | private String policy; |
| 42 | private String description; |
| 43 | private boolean isLogged; |
| 44 | private String protocol; |
| 45 | |
| 46 | @Override |
| 47 | public FirewallRule build() { |
| 48 | return new FirewallRule(id, name, type, href, firewallType, isEnabled, source, destination, port, |
| 49 | policy, description, isLogged, protocol); |
| 50 | } |
| 51 | |
| 52 | public Builder firewallType(String firewallType) { |
| 53 | this.firewallType = firewallType; |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public Builder isEnabled(boolean isEnabled) { |
| 58 | this.isEnabled = isEnabled; |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public Builder source(String source) { |
| 63 | this.source = source; |
| 64 | return this; |
| 65 | } |
| 66 | |
| 67 | public Builder destination(String destination) { |
| 68 | this.destination = destination; |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | public Builder port(String port) { |
| 73 | this.port = port; |
| 74 | return this; |
| 75 | } |
| 76 | |
| 77 | public Builder policy(String policy) { |
| 78 | this.policy = policy; |
| 79 | return this; |
| 80 | } |
| 81 | |
| 82 | public Builder description(String description) { |
| 83 | this.description = description; |
| 84 | return this; |
| 85 | } |
| 86 | |
| 87 | public Builder isLogged(boolean isLogged) { |
| 88 | this.isLogged = isLogged; |
| 89 | return this; |
| 90 | } |
| 91 | |
| 92 | public Builder protocol(String protocol) { |
| 93 | this.protocol = protocol; |
| 94 | return this; |
| 95 | } |
| 96 | |
| 97 | public static Builder fromFirewallRule(FirewallRule in) { |
| 98 | return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) |
| 99 | .firewallType(in.getFirewallType()).isEnabled(in.isEnabled()).source(in.getSource()) |
| 100 | .destination(in.getDestination()).port(in.getPort()).policy(in.getPolicy()).description(in.getDescription()) |
| 101 | .isLogged(in.isLogged()).protocol(in.getProtocol()); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Builder id(String id) { |
| 106 | return Builder.class.cast(super.id(id)); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public Builder name(String name) { |
| 111 | return Builder.class.cast(super.name(name)); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public Builder type(String type) { |
| 116 | return Builder.class.cast(super.type(type)); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Builder href(URI href) { |
| 121 | return Builder.class.cast(super.href(href)); |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | private final String firewallType; |
| 127 | private final boolean isEnabled; |
| 128 | private final String source; |
| 129 | private final String destination; |
| 130 | private final String port; |
| 131 | private final String policy; |
| 132 | private final String description; |
| 133 | private final boolean isLogged; |
| 134 | private final String protocol; |
| 135 | |
| 136 | public FirewallRule(String id, String name, String type, URI href, String firewallType, boolean isEnabled, |
| 137 | String source, String destination, String port, String policy, String description, boolean isLogged, String protocol) { |
| 138 | super(id, name, type, href); |
| 139 | this.firewallType = firewallType; |
| 140 | this.isEnabled = isEnabled; |
| 141 | this.source = source; |
| 142 | this.destination = destination; |
| 143 | this.port = port; |
| 144 | this.policy = policy; |
| 145 | this.description = description; |
| 146 | this.isLogged = isLogged; |
| 147 | this.protocol = protocol; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public Builder toBuilder() { |
| 152 | return Builder.fromFirewallRule(this); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean equals(Object obj) { |
| 157 | if (this == obj) |
| 158 | return true; |
| 159 | if (obj == null) |
| 160 | return false; |
| 161 | if (getClass() != obj.getClass()) |
| 162 | return false; |
| 163 | FirewallRule other = (FirewallRule) obj; |
| 164 | if (firewallType == null) { |
| 165 | if (other.firewallType != null) |
| 166 | return false; |
| 167 | } else if (!firewallType.equals(other.firewallType)) |
| 168 | return false; |
| 169 | if (source == null) { |
| 170 | if (other.source != null) |
| 171 | return false; |
| 172 | } else if (!source.equals(other.source)) |
| 173 | return false; |
| 174 | if (destination == null) { |
| 175 | if (other.destination != null) |
| 176 | return false; |
| 177 | } else if (!destination.equals(other.destination)) |
| 178 | return false; |
| 179 | if (port == null) { |
| 180 | if (other.port != null) |
| 181 | return false; |
| 182 | } else if (!port.equals(other.port)) |
| 183 | return false; |
| 184 | if (policy == null) { |
| 185 | if (other.policy != null) |
| 186 | return false; |
| 187 | } else if (!policy.equals(other.policy)) |
| 188 | return false; |
| 189 | if (protocol == null) { |
| 190 | if (other.protocol != null) |
| 191 | return false; |
| 192 | } else if (!protocol.equals(other.protocol)) |
| 193 | return false; |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | public boolean isEnabled() { |
| 198 | return isEnabled; |
| 199 | } |
| 200 | |
| 201 | public String getSource() { |
| 202 | return source; |
| 203 | } |
| 204 | |
| 205 | public String getDestination() { |
| 206 | return destination; |
| 207 | } |
| 208 | |
| 209 | public String getFirewallType() { |
| 210 | return firewallType; |
| 211 | } |
| 212 | |
| 213 | public String getPort() { |
| 214 | return port; |
| 215 | } |
| 216 | |
| 217 | public String getPolicy() { |
| 218 | return policy; |
| 219 | } |
| 220 | |
| 221 | public String getDescription() { |
| 222 | return description; |
| 223 | } |
| 224 | |
| 225 | public boolean isLogged() { |
| 226 | return isLogged; |
| 227 | } |
| 228 | |
| 229 | public String getProtocol() { |
| 230 | return protocol; |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public String toString() { |
| 235 | return "[firewallType=" + firewallType + ", description=" + description + ", source=" + source + ", destination=" + destination |
| 236 | + ", port=" + port + ", protocol=" + protocol + ", policy=" + policy + ", isLogged=" + isLogged; |
| 237 | } |
| 238 | |
| 239 | } |