| 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.blobstore.util.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Provider; |
| 25 | import javax.inject.Singleton; |
| 26 | |
| 27 | import org.jclouds.blobstore.domain.Blob; |
| 28 | import org.jclouds.blobstore.domain.BlobBuilder; |
| 29 | import org.jclouds.blobstore.options.ListContainerOptions; |
| 30 | import org.jclouds.blobstore.strategy.ClearListStrategy; |
| 31 | import org.jclouds.blobstore.strategy.CountListStrategy; |
| 32 | import org.jclouds.blobstore.strategy.DeleteDirectoryStrategy; |
| 33 | import org.jclouds.blobstore.strategy.GetDirectoryStrategy; |
| 34 | import org.jclouds.blobstore.strategy.MkdirStrategy; |
| 35 | import org.jclouds.blobstore.util.BlobUtils; |
| 36 | |
| 37 | /** |
| 38 | * Encryption, Hashing, and IO Utilities needed to sign and verify blobstore requests and responses. |
| 39 | * |
| 40 | * @author Adrian Cole |
| 41 | */ |
| 42 | @Singleton |
| 43 | public class BlobUtilsImpl implements BlobUtils { |
| 44 | |
| 45 | protected final Provider<BlobBuilder> blobBuilders; |
| 46 | protected final ClearListStrategy clearContainerStrategy; |
| 47 | protected final GetDirectoryStrategy getDirectoryStrategy; |
| 48 | protected final MkdirStrategy mkdirStrategy; |
| 49 | protected final DeleteDirectoryStrategy rmDirStrategy; |
| 50 | protected final CountListStrategy countBlobsStrategy; |
| 51 | |
| 52 | @Inject |
| 53 | protected BlobUtilsImpl(Provider<BlobBuilder> blobBuilders, ClearListStrategy clearContainerStrategy, |
| 54 | GetDirectoryStrategy getDirectoryStrategy, MkdirStrategy mkdirStrategy, CountListStrategy countBlobsStrategy, |
| 55 | DeleteDirectoryStrategy rmDirStrategy) { |
| 56 | this.blobBuilders = checkNotNull(blobBuilders, "blobBuilders"); |
| 57 | this.clearContainerStrategy = checkNotNull(clearContainerStrategy, "clearContainerStrategy"); |
| 58 | this.getDirectoryStrategy = checkNotNull(getDirectoryStrategy, "getDirectoryStrategy"); |
| 59 | this.mkdirStrategy = checkNotNull(mkdirStrategy, "mkdirStrategy"); |
| 60 | this.rmDirStrategy = checkNotNull(rmDirStrategy, "rmDirStrategy"); |
| 61 | this.countBlobsStrategy = checkNotNull(countBlobsStrategy, "countBlobsStrategy"); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Blob newBlob(String name) { |
| 66 | return blobBuilder().name(name).build(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public BlobBuilder blobBuilder() { |
| 71 | return blobBuilders.get(); |
| 72 | } |
| 73 | |
| 74 | public boolean directoryExists(String containerName, String directory) { |
| 75 | return getDirectoryStrategy.execute(containerName, directory) != null; |
| 76 | } |
| 77 | |
| 78 | public void createDirectory(String containerName, String directory) { |
| 79 | mkdirStrategy.execute(containerName, directory); |
| 80 | } |
| 81 | |
| 82 | public long countBlobs(String container, ListContainerOptions options) { |
| 83 | return countBlobsStrategy.execute(container, options); |
| 84 | } |
| 85 | |
| 86 | public void clearContainer(String container, ListContainerOptions options) { |
| 87 | clearContainerStrategy.execute(container, options); |
| 88 | } |
| 89 | |
| 90 | public void deleteDirectory(String container, String directory) { |
| 91 | rmDirStrategy.execute(container, directory); |
| 92 | } |
| 93 | |
| 94 | } |