fixed bad cast

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1090 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-08 01:27:09 +00:00
parent 9cec8159d4
commit 5cb5a3bb71
3 changed files with 48 additions and 56 deletions

View File

@ -37,56 +37,53 @@ import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* The DELETE request operation deletes the bucket named in the URI. All objects
* in the bucket must be deleted before the bucket itself can be deleted.
* The DELETE request operation deletes the bucket named in the URI. All objects in the bucket must
* be deleted before the bucket itself can be deleted.
* <p />
* Only the owner of a bucket can delete it, regardless of the bucket's access
* control policy.
* Only the owner of a bucket can delete it, regardless of the bucket's access control policy.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketDELETE.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketDELETE.html"
* />
* @author Adrian Cole
*/
public class DeleteBucket extends S3FutureCommand<Boolean> {
@Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super("DELETE", "/", callable, amazonHost, s3Bucket);
}
@Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String s3Bucket) {
super("DELETE", "/", callable, amazonHost, s3Bucket);
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
AWSResponseException responseException = (AWSResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return true;
} else if ("BucketNotEmpty".equals(responseException.getError()
.getCode())) {
return false;
}
}
throw e;
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return true;
} else if ("BucketNotEmpty".equals(responseException.getError().getCode())) {
return false;
}
}
throw e;
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -51,17 +51,14 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket)
{
@Assisted("bucketName") String bucket) {
super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
}
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket,
@Assisted("objectKey") String objectKey)
{
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
}
@ -76,11 +73,10 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@VisibleForTesting
AccessControlList attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if ("NoSuchBucket".equals(responseException.getError().getCode())
|| "NoSuchObject".equals(responseException.getError().getCode()))
{
|| "NoSuchObject".equals(responseException.getError().getCode())) {
return AccessControlList.NOT_FOUND;
}
}
@ -88,8 +84,8 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
}
@Override
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {

View File

@ -31,7 +31,6 @@ import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.commands.options.ListBucketOptions;
import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.aws.s3.xml.ListBucketHandler;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;
@ -75,7 +74,7 @@ public class ListBucket extends S3FutureCommand<S3Bucket> {
@VisibleForTesting
S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if ("NoSuchBucket".equals(responseException.getError().getCode())) {
return S3Bucket.NOT_FOUND;