| 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.azure.storage.options; |
| 20 | |
| 21 | import java.util.Map.Entry; |
| 22 | |
| 23 | import org.jclouds.azure.storage.reference.AzureStorageHeaders; |
| 24 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 25 | |
| 26 | import com.google.common.collect.Multimap; |
| 27 | |
| 28 | /** |
| 29 | * Contains common options supported in the REST API for the Create operation. <h2> |
| 30 | * Usage</h2> The recommended way to instantiate a CreateOptions object is to statically import |
| 31 | * CreateOptions.* and invoke a static creation method followed by an instance mutator (if |
| 32 | * needed): |
| 33 | * <p/> |
| 34 | * <code> |
| 35 | * import static org.jclouds.azure.storage.options.CreateOptions.Builder.* |
| 36 | * import org.jclouds.azure.storage.queue.AzureQueueClient; |
| 37 | * <p/> |
| 38 | * AzureQueueClient connection = // get connection |
| 39 | * Multimap<String,String> metadata = // ... |
| 40 | * boolean createdWithPublicAcl = connection.createQueue("containerName", withMetdata(metadata)); |
| 41 | * <code> * |
| 42 | * |
| 43 | * @see <a href="http://msdn.microsoft.com/en-us/library/dd179466.aspx" /> |
| 44 | * @author Adrian Cole |
| 45 | */ |
| 46 | public class CreateOptions extends BaseHttpRequestOptions { |
| 47 | public static final CreateOptions NONE = new CreateOptions(); |
| 48 | |
| 49 | /** |
| 50 | * A name-value pair to associate with the container as metadata. |
| 51 | * |
| 52 | * Note that these are stored at the server under the prefix: x-ms-meta- |
| 53 | */ |
| 54 | public CreateOptions withMetadata(Multimap<String, String> metadata) { |
| 55 | for (Entry<String, String> entry : metadata.entries()) { |
| 56 | if (entry.getKey().startsWith(AzureStorageHeaders.USER_METADATA_PREFIX)) |
| 57 | headers.put(entry.getKey(), entry.getValue()); |
| 58 | else |
| 59 | headers |
| 60 | .put(AzureStorageHeaders.USER_METADATA_PREFIX + entry.getKey(), entry |
| 61 | .getValue()); |
| 62 | } |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | public static class Builder { |
| 67 | |
| 68 | /** |
| 69 | * @see CreateOptions#withMetadata(Multimap<String, String>) |
| 70 | */ |
| 71 | public static CreateOptions withMetadata(Multimap<String, String> metadata) { |
| 72 | CreateOptions options = new CreateOptions(); |
| 73 | return options.withMetadata(metadata); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | } |