All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jd.httpservice.agent.RequestParamDefinition Maven / Gradle / Ivy

There is a newer version: 2.1.4.RELEASE
Show newest version
package com.jd.httpservice.agent;

import java.util.LinkedList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.jd.httpservice.RequestParam;
import com.jd.httpservice.StringConverter;

class RequestParamDefinition {

	private String name;

	private boolean required;

	private boolean array;

	private String ignoreValue;

	private StringConverter converter;

	public RequestParamDefinition(String name, boolean required, boolean array, String ignoreValue,
			StringConverter converter) {
		this.name = name;
		this.required = required;
		this.array = array;
		this.ignoreValue = ignoreValue;
		this.converter = converter;
	}

	public String getName() {
		return name;
	}

	public boolean isRequired() {
		return required;
	}
	
	public boolean isArray() {
		return array;
	}

	public String getIgnoreValue() {
		return ignoreValue;
	}

	public StringConverter getConverter() {
		return converter;
	}

	public static List> resolveSingleParamDefinitions(
			List> reqParamAnnos) {
		List> reqDefs = new LinkedList>();
		for (ArgDefEntry entry : reqParamAnnos) {
			RequestParam reqParamAnno = entry.getDefinition();
			RequestParamDefinition reqDef = resolveDefinition(reqParamAnno);
			reqDefs.add(new ArgDefEntry(entry.getIndex(), entry.getArgType(), reqDef));
		}
		return reqDefs;
	}

	public static RequestParamDefinition resolveDefinition(RequestParam reqParamAnno) {
		if (StringUtils.isEmpty(reqParamAnno.name())) {
			throw new IllegalHttpServiceDefinitionException("The name of request parameter is empty!");
		}

		Class converterClazz = reqParamAnno.converter();
		StringConverter converter = StringConverterFactory.instantiateStringConverter(converterClazz);
		RequestParamDefinition reqDef = new RequestParamDefinition(reqParamAnno.name(), reqParamAnno.required(),
				reqParamAnno.array(), reqParamAnno.ignoreValue(), converter);
		return reqDef;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy