openstack-nova: Adding support for @WrapWith on methods

This commit is contained in:
Adam Lowe 2012-05-14 11:38:41 +01:00
parent 95399121bd
commit 42b8071682
3 changed files with 15 additions and 3 deletions

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.rest.annotations;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@ -31,7 +32,7 @@ import java.lang.annotation.Target;
*
* @author Adrian Cole
*/
@Target(PARAMETER)
@Target( { METHOD, PARAMETER })
@Retention(RUNTIME)
public @interface WrapWith {

View File

@ -20,20 +20,24 @@ package org.jclouds.rest.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.MapBinder;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.inject.assistedinject.Assisted;
/**
* Sometimes, cloud apis wrap requests inside an envelope. This addresses this.
*
*
* @author Adrian Cole
*/
public class BindToJsonPayloadWrappedWith implements Binder {
public class BindToJsonPayloadWrappedWith implements MapBinder {
public static interface Factory {
BindToJsonPayloadWrappedWith create(String envelope);
@ -53,4 +57,8 @@ public class BindToJsonPayloadWrappedWith implements Binder {
return jsonBinder.bindToRequest(request, (Object) ImmutableMap.of(envelope, checkNotNull(payload, "payload")));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
return this.bindToRequest(request, (Object) postParams);
}
}

View File

@ -916,6 +916,9 @@ public class RestAnnotationProcessor<T> {
return injector.getInstance(method.getAnnotation(MapBinder.class).value());
} else if (method.isAnnotationPresent(org.jclouds.rest.annotations.Payload.class)) {
return injector.getInstance(BindMapToStringPayload.class);
} else if (method.isAnnotationPresent(WrapWith.class)) {
return injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create(
method.getAnnotation(WrapWith.class).value());
}
return null;
}