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

View File

@ -20,11 +20,15 @@ package org.jclouds.rest.binders;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder; 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.common.collect.ImmutableMap;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@ -33,7 +37,7 @@ import com.google.inject.assistedinject.Assisted;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class BindToJsonPayloadWrappedWith implements Binder { public class BindToJsonPayloadWrappedWith implements MapBinder {
public static interface Factory { public static interface Factory {
BindToJsonPayloadWrappedWith create(String envelope); BindToJsonPayloadWrappedWith create(String envelope);
@ -53,4 +57,8 @@ public class BindToJsonPayloadWrappedWith implements Binder {
return jsonBinder.bindToRequest(request, (Object) ImmutableMap.of(envelope, checkNotNull(payload, "payload"))); 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()); return injector.getInstance(method.getAnnotation(MapBinder.class).value());
} else if (method.isAnnotationPresent(org.jclouds.rest.annotations.Payload.class)) { } else if (method.isAnnotationPresent(org.jclouds.rest.annotations.Payload.class)) {
return injector.getInstance(BindMapToStringPayload.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; return null;
} }