/**
 * 
 */
package me.bayes.vertx.vest.util;

import java.lang.annotation.Annotation;

import javax.ws.rs.CookieParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vertx.java.core.http.HttpServerRequest;

/**
 * <pre>
 * A util to inject parameters into the methods handling REST requests.
 * 
 * TODO: Add support for {@link MatrixParam}
 * TODO: Add support for {@link CookieParam}
 * </pre>
 * 
 * @author Kevin Bayes
 * @since 1.0
 * @version 1.0
 */
public final class ParameterUtil {
	
	private static final Logger LOG = LoggerFactory.getLogger(ParameterUtil.class);
	
	private ParameterUtil() { }
	
	/**
	 * <pre>
	 * Using the context we try resolve a object that can be used for this parameter type.
	 * </pre>
	 * 
	 * @param parameterType that needs to be resolved
	 * @param annotations of the parameter
	 * @param request from vertx
	 * @return object to populate
	 */
	public static Object resolveParameter(final Class<?> parameterType, final Annotation[] annotations, final HttpServerRequest request) {
		
		Object returnObject = null;
		
		for(Annotation annotation : annotations) {
			
			if(annotation.annotationType().equals(PathParam.class)) {
				//Path Parameters
				PathParam pathParam = (PathParam) annotation;
				returnObject = request.params().get(pathParam.value());
			} else if(annotation.annotationType().equals(HeaderParam.class)) {
				//Query Parameters
				QueryParam queryParam = (QueryParam) annotation;
				returnObject = request.params().get(queryParam.value());
			} else if(annotation.annotationType().equals(HeaderParam.class)) {
				//HTTP Headers
				HeaderParam pathParam = (HeaderParam) annotation;
				returnObject = request.headers().get(pathParam.value());
			} else if(annotation.annotationType().equals(DefaultValue.class)) {
				DefaultValue defaultValue = (DefaultValue) annotation;
				returnObject = defaultValue.value();
			} else if(annotation.annotationType().equals(MatrixParam.class) ||
					annotation.annotationType().equals(CookieParam.class) ||
					annotation.annotationType().equals(FormParam.class)) {
				LOG.warn("Matrix & cookie && form parameters are not supported.");
			}
			
			if(returnObject != null) {
				break;
			}
		}
		
		return returnObject;
	}

}

@@ -1257,16 +1257,46 @@
 = null;%0A
+%09%09Object defaultValue = null;%0A
 %09%09%0A%09%09for
@@ -2043,16 +2043,26 @@
 ultValue
+Annotation
  = (Defa
@@ -2087,28 +2087,28 @@
 on;%0A%09%09%09%09
-returnObject
+defaultValue
  = defau
@@ -2114,16 +2114,26 @@
 ultValue
+Annotation
 .value()
@@ -2467,16 +2467,54 @@
 %09%09return
+ returnObject == null ? defaultValue :
  returnO

Support for @Default