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 | /** |
20 | * |
21 | s * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com> |
22 | * |
23 | * ==================================================================== |
24 | * Licensed under the Apache License, Version 2.0 (the "License"); |
25 | * you may not use this file except in compliance with the License. |
26 | * You may obtain a copy of the License at |
27 | * |
28 | * http://www.apache.org/licenses/LICENSE-2.0 |
29 | * |
30 | * Unless required by applicable law or agreed to in writing, software |
31 | * distributed under the License is distributed on an "AS IS" BASIS, |
32 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
33 | * See the License for the specific language governing permissions and |
34 | * limitations under the License. |
35 | * ==================================================================== |
36 | */ |
37 | |
38 | package org.jclouds.openstack.swift.blobstore.functions; |
39 | |
40 | import static com.google.common.base.Preconditions.checkNotNull; |
41 | |
42 | import javax.inject.Inject; |
43 | import javax.inject.Singleton; |
44 | |
45 | import org.jclouds.blobstore.domain.Blob; |
46 | import org.jclouds.openstack.swift.domain.SwiftObject; |
47 | |
48 | import com.google.common.base.Function; |
49 | |
50 | /** |
51 | * @author Adrian Cole |
52 | */ |
53 | @Singleton |
54 | public class BlobToObject implements Function<Blob, SwiftObject> { |
55 | private final ResourceToObjectInfo blob2ObjectMd; |
56 | private final SwiftObject.Factory objectProvider; |
57 | |
58 | @Inject |
59 | BlobToObject(ResourceToObjectInfo blob2ObjectMd, SwiftObject.Factory objectProvider) { |
60 | this.blob2ObjectMd = blob2ObjectMd; |
61 | this.objectProvider = objectProvider; |
62 | } |
63 | |
64 | public SwiftObject apply(Blob from) { |
65 | if (from == null) |
66 | return null; |
67 | SwiftObject object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata())); |
68 | object.setPayload(checkNotNull(from.getPayload(), "payload: " + from)); |
69 | object.setAllHeaders(from.getAllHeaders()); |
70 | return object; |
71 | } |
72 | } |