reduced casting on xml handlers

This commit is contained in:
Adrian Cole 2010-08-08 13:08:50 -07:00
parent 05bab93ce8
commit 1bb15418fe
16 changed files with 41 additions and 58 deletions

View File

@ -29,7 +29,6 @@ import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -52,7 +51,7 @@ public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithRe
private Date attachTime;
public Attachment getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime);

View File

@ -35,7 +35,6 @@ import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Maps;
@ -220,7 +219,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
this.attachTime = null;
this.deleteOnTermination = true;
} else if (inInstances && !inProductCodes && !inBlockDeviceMapping) {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
// Eucalyptus
if (ipAddress == null && dnsName != null && dnsName.matches(".*[0-9]$")) {
@ -236,8 +235,8 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
region = defaultRegion;
instances.add(new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId,
instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, monitoring, availabilityZone,
placementGroup, virtualizationType, platform, privateDnsName, privateIpAddress, productCodes,
ramdiskId, reason, subnetId, vpcId, rootDeviceType, rootDeviceName, ebsBlockDevices));
placementGroup, virtualizationType, platform, privateDnsName, privateIpAddress, productCodes, ramdiskId,
reason, subnetId, vpcId, rootDeviceType, rootDeviceName, ebsBlockDevices));
this.amiLaunchIndex = null;
this.dnsName = null;
this.imageId = null;
@ -271,7 +270,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
}
protected Reservation<? extends RunningInstance> newReservation() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupIds, instances,

View File

@ -27,7 +27,6 @@ import org.jclouds.aws.ec2.domain.BundleTask;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -54,7 +53,7 @@ public class BundleTaskHandler extends ParseSax.HandlerForGeneratedRequestWithRe
private Date updateTime;
public BundleTask getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
BundleTask.Error error = null;

View File

@ -35,7 +35,6 @@ import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
@ -158,9 +157,9 @@ public class CreateVolumeResponseHandler extends
@Override
public CreateVolumeResponseHandler setContext(HttpRequest request) {
super.setContext(request);
region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null) {
String zone = EC2Utils.findAvailabilityZoneInArgsOrNull((GeneratedHttpRequest<?>) request);
String zone = EC2Utils.findAvailabilityZoneInArgsOrNull(getRequest());
if (zone != null) {
region = checkNotNull(availabilityZoneToRegion.get(zone), String.format(
"zone %s not in %s", zone, availabilityZoneToRegion));

View File

@ -28,7 +28,6 @@ import org.jclouds.aws.ec2.domain.PublicIpInstanceIdPair;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.Sets;
@ -60,7 +59,7 @@ public class DescribeAddressesResponseHandler extends
} else if (qName.equals("instanceId")) {
instanceId = currentOrNull();
} else if (qName.equals("item")) {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId));

View File

@ -34,7 +34,6 @@ import org.jclouds.aws.ec2.domain.Image.ImageType;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Maps;
@ -158,7 +157,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
this.deleteOnTermination = true;
} else if (!inProductCodes) {
try {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,

View File

@ -26,7 +26,6 @@ import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.Sets;
@ -57,7 +56,7 @@ public class DescribeKeyPairsResponseHandler extends
if (qName.equals("keyFingerprint")) {
this.keyFingerprint = currentText.toString().trim();
} else if (qName.equals("item")) {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
keyPairs.add(new KeyPair(region, keyName, keyFingerprint, null));

View File

@ -29,7 +29,6 @@ import org.jclouds.aws.ec2.domain.SecurityGroup;
import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
@ -118,7 +117,7 @@ public class DescribeSecurityGroupsResponseHandler extends
this.userId = null;
this.userIdGroupName = null;
} else if (!inIpPermissions && !inIpRanges && !inGroups) {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
securtyGroups.add(new SecurityGroup(region, groupName, ownerId, groupDescription,

View File

@ -27,7 +27,6 @@ import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.InstanceStateChange;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
@ -91,7 +90,7 @@ public class InstanceStateChangeHandler extends
previousState = InstanceState.fromValue(currentOrNull());
}
} else if (qName.equals("item")) {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
instances.add(new InstanceStateChange(region, instanceId, shutdownState, previousState));

View File

@ -24,7 +24,6 @@ import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -43,7 +42,7 @@ public class KeyPairResponseHandler extends ParseSax.HandlerForGeneratedRequestW
private String keyName;
public KeyPair getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
return new KeyPair(region, keyName, keyFingerprint, keyMaterial);

View File

@ -26,7 +26,6 @@ import org.jclouds.aws.ec2.domain.PlacementGroup.State;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -47,7 +46,7 @@ public class PlacementGroupHandler extends
private State state;
public PlacementGroup getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
PlacementGroup returnVal = new PlacementGroup(region, name, strategy, state);

View File

@ -24,7 +24,6 @@ import org.jclouds.aws.Region;
import org.jclouds.aws.ec2.domain.ReservedInstancesOffering;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -32,7 +31,8 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
* />
* @author Adrian Cole
*/
public class ReservedInstancesOfferingHandler extends ParseSax.HandlerWithResult<ReservedInstancesOffering> {
public class ReservedInstancesOfferingHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<ReservedInstancesOffering> {
@Inject
@Region
String defaultRegion;
@ -48,7 +48,7 @@ public class ReservedInstancesOfferingHandler extends ParseSax.HandlerWithResult
private float usagePrice = 0;
public ReservedInstancesOffering getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;

View File

@ -28,7 +28,6 @@ import org.jclouds.aws.ec2.domain.Snapshot.Status;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
/**
*
@ -57,7 +56,7 @@ public class SnapshotHandler extends ParseSax.HandlerForGeneratedRequestWithResu
}
public Snapshot getResult() {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;
Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime,

View File

@ -130,7 +130,7 @@ public class DescribeLoadBalancersResponseHandler extends
} else if (!(inListenerDescriptions || inAppCookieStickinessPolicies || inInstances
|| inLBCookieStickinessPolicies || inAvailabilityZones)) {
try {
String region = EC2Utils.findRegionInArgsOrNull((GeneratedHttpRequest<?>) request);
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
if (region == null)
region = defaultRegion;

View File

@ -41,23 +41,11 @@
*/
package org.jclouds.chef.config;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.io.IOException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.chef.ChefAsyncClient;
import org.jclouds.chef.ChefClient;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.inject.Provides;
/**
* Configures the Chef connection.
*

View File

@ -43,8 +43,8 @@ import org.xml.sax.helpers.DefaultHandler;
import com.google.common.base.Function;
/**
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
* caller.
* This object will parse the body of an HttpResponse and return the result of
* type <T> back to the caller.
*
* @author Adrian Cole
*/
@ -135,13 +135,17 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
}
/**
* Handler that produces a useable domain object accessible after parsing completes.
* Handler that produces a useable domain object accessible after parsing
* completes.
*
* @author Adrian Cole
*/
public abstract static class HandlerWithResult<T> extends DefaultHandler implements
InvocationContext {
protected HttpRequest request;
public abstract static class HandlerWithResult<T> extends DefaultHandler implements InvocationContext {
private HttpRequest request;
protected HttpRequest getRequest() {
return request;
}
public abstract T getResult();
@ -152,12 +156,15 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
}
}
public abstract static class HandlerForGeneratedRequestWithResult<T> extends
HandlerWithResult<T> {
public abstract static class HandlerForGeneratedRequestWithResult<T> extends HandlerWithResult<T> {
@Override
protected GeneratedHttpRequest<?> getRequest() {
return (GeneratedHttpRequest<?>) super.getRequest();
}
@Override
public HandlerForGeneratedRequestWithResult<T> setContext(HttpRequest request) {
checkArgument(request instanceof GeneratedHttpRequest<?>,
"note this handler requires a GeneratedHttpRequest");
checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
super.setContext(request);
return this;
}