View Javadoc

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.azureblob.domain.internal;
20  
21  import java.io.Serializable;
22  import java.net.URI;
23  import java.util.Date;
24  import java.util.Map;
25  
26  import org.jclouds.azureblob.domain.BlobProperties;
27  import org.jclouds.azureblob.domain.BlobType;
28  import org.jclouds.azureblob.domain.LeaseStatus;
29  import org.jclouds.azureblob.domain.MutableBlobProperties;
30  import org.jclouds.http.HttpUtils;
31  import org.jclouds.io.MutableContentMetadata;
32  import org.jclouds.io.payloads.BaseMutableContentMetadata;
33  
34  import com.google.common.collect.Maps;
35  
36  /**
37   * Allows you to manipulate metadata.
38   * 
39   * @author Adrian Cole
40   */
41  public class MutableBlobPropertiesImpl implements Serializable, MutableBlobProperties {
42  
43     /** The serialVersionUID */
44     private static final long serialVersionUID = -4648755473986695062L;
45  
46     private BlobType type = BlobType.BLOCK_BLOB;
47     private LeaseStatus leaseStatus = LeaseStatus.UNLOCKED;
48  
49     private String name;
50     private String container;
51     private URI url;
52     private Date lastModified;
53     private String eTag;
54     private MutableContentMetadata contentMetadata;
55     private Map<String, String> metadata = Maps.newHashMap();
56  
57     public MutableBlobPropertiesImpl() {
58        super();
59        this.contentMetadata = new BaseMutableContentMetadata();
60     }
61  
62     public MutableBlobPropertiesImpl(BlobProperties from) {
63        this.contentMetadata = new BaseMutableContentMetadata();
64        this.name = from.getName();
65        this.container = from.getContainer();
66        this.url = from.getUrl();
67        this.lastModified = from.getLastModified();
68        this.eTag = from.getETag();
69        this.metadata.putAll(from.getMetadata());
70        HttpUtils.copy(from.getContentMetadata(), this.contentMetadata);
71     }
72  
73     /**
74      *{@inheritDoc}
75      */
76     @Override
77     public BlobType getType() {
78        return type;
79     }
80  
81     /**
82      *{@inheritDoc}
83      */
84     public void setType(BlobType type) {
85        this.type = type;
86     }
87  
88     /**
89      *{@inheritDoc}
90      */
91     public String getName() {
92        return name;
93     }
94  
95     /**
96      *{@inheritDoc}
97      */
98     public Date getLastModified() {
99        return lastModified;
100    }
101 
102    /**
103     *{@inheritDoc}
104     */
105    public String getETag() {
106       return eTag;
107    }
108 
109    /**
110     *{@inheritDoc}
111     */
112    public int compareTo(BlobProperties o) {
113       return (this == o) ? 0 : getName().compareTo(o.getName());
114    }
115 
116    /**
117     *{@inheritDoc}
118     */
119    public Map<String, String> getMetadata() {
120       return metadata;
121    }
122 
123    /**
124     *{@inheritDoc}
125     */
126    @Override
127    public LeaseStatus getLeaseStatus() {
128       return leaseStatus;
129    }
130 
131    /**
132     *{@inheritDoc}
133     */
134    public void setETag(String eTag) {
135       this.eTag = eTag;
136    }
137 
138    /**
139     *{@inheritDoc}
140     */
141    public void setName(String name) {
142       this.name = name;
143    }
144 
145    /**
146     *{@inheritDoc}
147     */
148    public void setLastModified(Date lastModified) {
149       this.lastModified = lastModified;
150    }
151 
152    /**
153     *{@inheritDoc}
154     */
155    public void setMetadata(Map<String, String> metadata) {
156       this.metadata = metadata;
157    }
158 
159    public void setUrl(URI url) {
160       this.url = url;
161    }
162 
163    public URI getUrl() {
164       return url;
165    }
166 
167    @Override
168    public int hashCode() {
169       final int prime = 31;
170       int result = 1;
171       result = prime * result + ((url == null) ? 0 : url.hashCode());
172       return result;
173    }
174 
175    @Override
176    public boolean equals(Object obj) {
177       if (this == obj)
178          return true;
179       if (obj == null)
180          return false;
181       if (getClass() != obj.getClass())
182          return false;
183       MutableBlobPropertiesImpl other = (MutableBlobPropertiesImpl) obj;
184       if (url == null) {
185          if (other.url != null)
186             return false;
187       } else if (!url.equals(other.url))
188          return false;
189       return true;
190    }
191 
192    @Override
193    public String toString() {
194       return String
195                .format(
196                         "[name=%s, container=%s, url=%s, contentMetadata=%s, eTag=%s, lastModified=%s, leaseStatus=%s, metadata=%s, type=%s]",
197                         name, container, url, contentMetadata, eTag, lastModified, leaseStatus, metadata, type);
198    }
199 
200    /**
201     * {@inheritDoc}
202     */
203    @Override
204    public MutableContentMetadata getContentMetadata() {
205       return contentMetadata;
206    }
207 
208    /**
209     * {@inheritDoc}
210     */
211    @Override
212    public void setContentMetadata(MutableContentMetadata contentMetadata) {
213       this.contentMetadata = contentMetadata;
214    }
215 
216    /**
217     *{@inheritDoc}
218     */
219    @Override
220    public String getContainer() {
221       return container;
222    }
223 
224    /**
225     *{@inheritDoc}
226     */
227    @Override
228    public void setContainer(String container) {
229       this.container = container;
230    }
231 
232 }