| 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.s3.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.io.Serializable; |
| 24 | import java.net.URI; |
| 25 | import java.util.Date; |
| 26 | import java.util.Map; |
| 27 | |
| 28 | import org.jclouds.io.ContentMetadata; |
| 29 | import org.jclouds.io.payloads.BaseImmutableContentMetadata; |
| 30 | import org.jclouds.s3.domain.CanonicalUser; |
| 31 | import org.jclouds.s3.domain.ObjectMetadata; |
| 32 | |
| 33 | import com.google.common.collect.ImmutableMap; |
| 34 | |
| 35 | /** |
| 36 | * Returns the metadata parsable from a bucket listing |
| 37 | * |
| 38 | * @author Adrian Cole |
| 39 | */ |
| 40 | public class BucketListObjectMetadata implements Serializable, ObjectMetadata { |
| 41 | |
| 42 | /** The serialVersionUID */ |
| 43 | private static final long serialVersionUID = -4415449798024051115L; |
| 44 | |
| 45 | private final String key; |
| 46 | private final String bucket; |
| 47 | private final URI uri; |
| 48 | private final Date lastModified; |
| 49 | private final String eTag; |
| 50 | private final CanonicalUser owner; |
| 51 | private final StorageClass storageClass; |
| 52 | private final ContentMetadata contentMetadata; |
| 53 | |
| 54 | public BucketListObjectMetadata(String key, String bucket, URI uri, Date lastModified, String eTag, byte[] md5, |
| 55 | long contentLength, CanonicalUser owner, StorageClass storageClass) { |
| 56 | this.key = checkNotNull(key, "key"); |
| 57 | this.bucket = checkNotNull(bucket, "bucket"); |
| 58 | this.uri = checkNotNull(uri, "uri"); |
| 59 | this.lastModified = lastModified; |
| 60 | this.eTag = eTag; |
| 61 | this.owner = owner; |
| 62 | this.contentMetadata = new BaseImmutableContentMetadata(null, contentLength, md5, null, null, null); |
| 63 | this.storageClass = storageClass; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | *{@inheritDoc} |
| 68 | */ |
| 69 | @Override |
| 70 | public URI getUri() { |
| 71 | return uri; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | *{@inheritDoc} |
| 76 | */ |
| 77 | @Override |
| 78 | public String getKey() { |
| 79 | return key; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | *{@inheritDoc} |
| 84 | */ |
| 85 | @Override |
| 86 | public String getBucket() { |
| 87 | return bucket; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | *{@inheritDoc} |
| 92 | */ |
| 93 | @Override |
| 94 | public CanonicalUser getOwner() { |
| 95 | return owner; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | *{@inheritDoc} |
| 100 | */ |
| 101 | @Override |
| 102 | public StorageClass getStorageClass() { |
| 103 | return storageClass; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | *{@inheritDoc} |
| 108 | */ |
| 109 | @Override |
| 110 | public String getCacheControl() { |
| 111 | return null; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | *{@inheritDoc} |
| 116 | */ |
| 117 | @Override |
| 118 | public Date getLastModified() { |
| 119 | return lastModified; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | *{@inheritDoc} |
| 124 | */ |
| 125 | @Override |
| 126 | public String getETag() { |
| 127 | return eTag; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | *{@inheritDoc} |
| 132 | */ |
| 133 | @Override |
| 134 | public int compareTo(ObjectMetadata o) { |
| 135 | return (this == o) ? 0 : getUri().compareTo(o.getUri()); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | *{@inheritDoc} |
| 140 | */ |
| 141 | @Override |
| 142 | public Map<String, String> getUserMetadata() { |
| 143 | return ImmutableMap.of(); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | *{@inheritDoc} |
| 148 | */ |
| 149 | @Override |
| 150 | public ContentMetadata getContentMetadata() { |
| 151 | return contentMetadata; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public int hashCode() { |
| 156 | final int prime = 31; |
| 157 | int result = 1; |
| 158 | result = prime * result + ((uri == null) ? 0 : uri.hashCode()); |
| 159 | return result; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public boolean equals(Object obj) { |
| 164 | if (this == obj) |
| 165 | return true; |
| 166 | if (obj == null) |
| 167 | return false; |
| 168 | if (getClass() != obj.getClass()) |
| 169 | return false; |
| 170 | BucketListObjectMetadata other = (BucketListObjectMetadata) obj; |
| 171 | if (uri == null) { |
| 172 | if (other.uri != null) |
| 173 | return false; |
| 174 | } else if (!uri.equals(other.uri)) |
| 175 | return false; |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public String toString() { |
| 181 | return String.format( |
| 182 | "[uri=%s, key=%s, bucket=%s, contentMetadata=%s, eTag=%s, lastModified=%s, owner=%s, storageClass=%s]", |
| 183 | uri, key, bucket, contentMetadata, eTag, lastModified, owner, storageClass); |
| 184 | } |
| 185 | |
| 186 | } |