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.compute.domain; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.net.URI; |
24 | import java.util.Map; |
25 | |
26 | import org.jclouds.compute.domain.internal.ComputeMetadataImpl; |
27 | import org.jclouds.domain.Location; |
28 | import org.jclouds.domain.ResourceMetadataBuilder; |
29 | |
30 | /** |
31 | * |
32 | * @author Adrian Cole |
33 | */ |
34 | public class ComputeMetadataBuilder extends ResourceMetadataBuilder<ComputeType> { |
35 | protected String id; |
36 | protected ComputeType type; |
37 | |
38 | public ComputeMetadataBuilder(ComputeType type) { |
39 | super(); |
40 | this.type = checkNotNull(type, "type"); |
41 | } |
42 | |
43 | public ComputeMetadataBuilder id(String id) { |
44 | this.id = id; |
45 | return this; |
46 | } |
47 | |
48 | /** |
49 | * set id and providerId to the same value; |
50 | */ |
51 | public ComputeMetadataBuilder ids(String id) { |
52 | id(id).providerId(id); |
53 | return this; |
54 | } |
55 | |
56 | @Override |
57 | public ComputeMetadataBuilder providerId(String providerId) { |
58 | return ComputeMetadataBuilder.class.cast(super.providerId(providerId)); |
59 | } |
60 | |
61 | @Override |
62 | public ComputeMetadataBuilder name(String name) { |
63 | return ComputeMetadataBuilder.class.cast(super.name(name)); |
64 | } |
65 | |
66 | @Override |
67 | public ComputeMetadataBuilder location(Location location) { |
68 | return ComputeMetadataBuilder.class.cast(super.location(location)); |
69 | } |
70 | |
71 | @Override |
72 | public ComputeMetadataBuilder uri(URI uri) { |
73 | return ComputeMetadataBuilder.class.cast(super.uri(uri)); |
74 | } |
75 | |
76 | @Override |
77 | public ComputeMetadataBuilder userMetadata(Map<String, String> userMetadata) { |
78 | return ComputeMetadataBuilder.class.cast(super.userMetadata(userMetadata)); |
79 | } |
80 | |
81 | public ComputeMetadata build() { |
82 | return new ComputeMetadataImpl(type, providerId, name, id, location, uri, userMetadata); |
83 | } |
84 | |
85 | public static ComputeMetadataBuilder fromComputeMetadata(ComputeMetadata in) { |
86 | return new ComputeMetadataBuilder(in.getType()).id(in.getId()).location(in.getLocation()).name(in.getName()) |
87 | .uri(in.getUri()).userMetadata(in.getUserMetadata()); |
88 | } |
89 | } |