| 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 static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import com.google.common.collect.ImmutableSet; |
| 27 | import com.google.common.collect.Sets; |
| 28 | |
| 29 | /** |
| 30 | * API returns the firewall service containing firewall rules for a given VDC |
| 31 | * |
| 32 | * @author Kedar Dave |
| 33 | */ |
| 34 | public class FirewallService extends ResourceImpl { |
| 35 | |
| 36 | public static Builder builder() { |
| 37 | return new Builder(); |
| 38 | } |
| 39 | |
| 40 | public static class Builder extends ResourceImpl.Builder { |
| 41 | private boolean isEnabled; |
| 42 | private Set<FirewallRule> firewallRules = Sets.newLinkedHashSet(); |
| 43 | |
| 44 | @Override |
| 45 | public FirewallService build() { |
| 46 | return new FirewallService(id, name, type, href, isEnabled, firewallRules); |
| 47 | } |
| 48 | |
| 49 | public Builder isEnabled(boolean isEnabled) { |
| 50 | this.isEnabled = isEnabled; |
| 51 | return this; |
| 52 | } |
| 53 | |
| 54 | public Builder firewallRule(FirewallRule in) { |
| 55 | this.firewallRules.add(checkNotNull(in, "firewallRule")); |
| 56 | return this; |
| 57 | } |
| 58 | |
| 59 | public Builder firewallRules(Set<FirewallRule> firewallRules) { |
| 60 | this.firewallRules.addAll(checkNotNull(firewallRules, "firewallRules")); |
| 61 | return this; |
| 62 | } |
| 63 | |
| 64 | public static Builder fromFirewallService(FirewallService in) { |
| 65 | return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) |
| 66 | .isEnabled(in.isEnabled()).firewallRules(in.getFirewallRules()); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public Builder id(String id) { |
| 71 | return Builder.class.cast(super.id(id)); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public Builder name(String name) { |
| 76 | return Builder.class.cast(super.name(name)); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public Builder type(String type) { |
| 81 | return Builder.class.cast(super.type(type)); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Builder href(URI href) { |
| 86 | return Builder.class.cast(super.href(href)); |
| 87 | } |
| 88 | |
| 89 | } |
| 90 | |
| 91 | private final boolean isEnabled; |
| 92 | private final Set<FirewallRule> firewallRules; |
| 93 | |
| 94 | public FirewallService(String id, String name, String type, URI href, boolean isEnabled, Set<FirewallRule> firewallRules) { |
| 95 | super(id, name, type, href); |
| 96 | this.isEnabled = isEnabled; |
| 97 | this.firewallRules = ImmutableSet.copyOf(checkNotNull(firewallRules, "firewallRules")); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public Builder toBuilder() { |
| 102 | return Builder.fromFirewallService(this); |
| 103 | } |
| 104 | |
| 105 | public Set<FirewallRule> getFirewallRules() { |
| 106 | return firewallRules; |
| 107 | } |
| 108 | |
| 109 | public boolean isEnabled() { |
| 110 | return isEnabled; |
| 111 | } |
| 112 | |
| 113 | } |