| 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.trmk.vcloud_0_8.options; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import org.jclouds.http.HttpRequest; |
| 24 | import org.jclouds.trmk.vcloud_0_8.binders.BindAddInternetServiceToXmlPayload; |
| 25 | |
| 26 | import com.google.common.annotations.VisibleForTesting; |
| 27 | import com.google.common.collect.ImmutableMap; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | * |
| 33 | */ |
| 34 | public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayload { |
| 35 | |
| 36 | @VisibleForTesting |
| 37 | String description = null; |
| 38 | @VisibleForTesting |
| 39 | String enabled = "true"; |
| 40 | @VisibleForTesting |
| 41 | Boolean monitorEnabled = null; |
| 42 | |
| 43 | @Override |
| 44 | public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { |
| 45 | ImmutableMap.Builder<String, String> copy = ImmutableMap.<String, String> builder(); |
| 46 | copy.putAll(postParams); |
| 47 | if (description != null) |
| 48 | copy.put("description", description); |
| 49 | copy.put("enabled", enabled); |
| 50 | if (monitorEnabled != null) |
| 51 | copy.put("monitor", monitorEnabled.toString()); |
| 52 | return super.bindToRequest(request, copy.build()); |
| 53 | } |
| 54 | |
| 55 | public AddInternetServiceOptions disabled() { |
| 56 | this.enabled = "false"; |
| 57 | return this; |
| 58 | } |
| 59 | |
| 60 | public AddInternetServiceOptions monitorDisabled() { |
| 61 | this.monitorEnabled = false; |
| 62 | return this; |
| 63 | } |
| 64 | |
| 65 | public AddInternetServiceOptions withDescription(String description) { |
| 66 | this.description = description; |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | public static class Builder { |
| 71 | |
| 72 | /** |
| 73 | * @see AddInternetServiceOptions#withDescription(String) |
| 74 | */ |
| 75 | public static AddInternetServiceOptions withDescription(String description) { |
| 76 | AddInternetServiceOptions options = new AddInternetServiceOptions(); |
| 77 | return options.withDescription(description); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @see AddInternetServiceOptions#monitorDisabled() |
| 82 | */ |
| 83 | public static AddInternetServiceOptions monitorDisabled() { |
| 84 | AddInternetServiceOptions options = new AddInternetServiceOptions(); |
| 85 | return options.monitorDisabled(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @see AddInternetServiceOptions#disabled() |
| 90 | */ |
| 91 | public static AddInternetServiceOptions disabled() { |
| 92 | AddInternetServiceOptions options = new AddInternetServiceOptions(); |
| 93 | return options.disabled(); |
| 94 | } |
| 95 | } |
| 96 | } |