Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.sparta.springwebutils;
  
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
 

Author(s):
Carlos Eduardo Endler Genz – Sparta Java Team History: Mar 4, 2014 - Carlos Eduardo Endler Genz Mar 14, 2014 - Daniel Conde Diehl - Not ignoring list on object scan
  
 public class RequestUtils {
 	private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtils.class);
 	
 	
 	
 	private List<Class<?>> paramTypesBlacklist;
 	
 	private boolean scanEntryPointAnnotation;
 	
 	
 	private Integer maxDeepLevel;

Class constructor, no parameters
 
 	public RequestUtils() {
 		// No default naming blacklist
 		
 		// Default types blacklist
 		
 		// Set scanning to true as default
 		
 		// Default parameter name discoverer
 		
 		// Default is 3
 		 = 3;
 	}

Goes through

Returns:
List<EntryPoint> List with all entry points and parameters
RequestMapping:
annotations from Spring and return a list of its elements.
 
 		
 		final List<EntryPointentryPoints = new ArrayList<EntryPoint>();
 		
 		
 		for (RequestMappingInfo mappingInfo : allUrls.keySet()) {
 			final HandlerMethod handlerMethod = allUrls.get(mappingInfo);
 			
 			// If no pattern is defined, we do not add to the list
 			if (mappingInfo.getPatternsCondition() != null && ExternalEntryPointHelper.isAnEntryPoint(handlerMethod.getMethod(), )) {
				final EntryPoint entryPoint = new EntryPoint();
				// All the url's this method can handle
				entryPoint.setUrls(mappingInfo.getPatternsCondition().getPatterns());
				// If there specified methods, we add them to the returned object
				if (mappingInfo.getMethodsCondition() != null) { 
				}
				final Method method = handlerMethod.getMethod();
				entryPoint.setMethodName(method.getName());
				entryPoint.setMethodDecorationName(ExternalEntryPointHelper.getEntryPointDecoratedName(method));
				entryPoint.setType(method.getDeclaringClass());
				entryPoint.setResponseType(method.getReturnType());
				// Get the defined parameter names, they might be overwritten by a @RequestParam
				final String[] parameterNames = .getParameterNames(method);
				// Consolidated blacklist, if might have details on @ExternalEntryPoint
				final Set<Class<?>> consolidatedTypeBlacklist = ExternalEntryPointHelper.getConsolidatedTypeBlacklist(method);
				final Set<StringconsolidatedNameBlacklist = ExternalEntryPointHelper.getConsolidatedNameBlacklist(method);
				// Time to retrieve all the parameters
				for (MethodParameter methodParameter : handlerMethod.getMethodParameters()) {
					computeInputParatemeter(entryPointparameterNamesconsolidatedTypeBlacklistconsolidatedNameBlacklistmethodParameter);
				}
				entryPoints.add(entryPoint);
			}
		}
		return entryPoints;
	}

Checks whether or not the supplied parameter should be part of the response or not. It adds to the entry point, if necessary.

Parameters:
entryPoint
parameterNames
consolidatedTypeBlacklist
consolidatedNameBlacklist
methodParameter
	private void computeInputParatemeter(final EntryPoint entryPointfinal String[] parameterNamesfinal Set<Class<?>> consolidatedTypeBlacklist,
		final Set<StringconsolidatedNameBlacklistMethodParameter methodParameter) {
		// If the type is part of the blacklist, we discard it
		if (consolidatedTypeBlacklist.contains(methodParameter.getParameterType())) {
			.debug("Ignoring parameter type [{}]. It is on the blacklist."methodParameter.getParameterType());
			return;
		}
		// If we have a simple parameter type (primitives, wrappers, collections, arrays of primitives), we just get the name and we are done
		if (ExternalEntryPointHelper.isSimpleRequestParameter(methodParameter.getParameterType())) {
			// We need to look for @RequestParam in order to define its name
			final String parameterRealName = parameterNames[methodParameter.getParameterIndex()];
			.debug("Parameter Real Name [{}]"parameterRealName);
			// If the real name is part of the blacklist, we don't need to go any further
			if (consolidatedNameBlacklist.contains(parameterRealName)) {
				.debug("Ignoring parameter name [{}]. It is on the blacklist."parameterRealName);
				return;
			}
			final EntryPointParameter entryPointParameter = new EntryPointParameter();
			entryPointParameter.setName(parameterRealName);
			entryPointParameter.setType(methodParameter.getParameterType());
			// Look for a change of names and the required attribute, true by default
			if (methodParameter.hasParameterAnnotation(RequestParam.class)) {
				final RequestParam requestParam = methodParameter.getParameterAnnotation(RequestParam.class);
				final String definedName = StringUtils.trimToEmpty(requestParam.value());
				// If the defined name is part of the blacklist, we don't need to go any further
				if (consolidatedNameBlacklist.contains(definedName)) {
					.debug("Ignoring parameter @RequestParam defined name [{}]. It is on the blacklist."definedName);
					return;
				}
				entryPointParameter.setName(StringUtils.isNotBlank(definedName) ? definedName : entryPointParameter.getName());
				entryPointParameter.setRequired(requestParam.required());
				entryPointParameter.setDefaultValue(StringUtils.equals(.requestParam.defaultValue()) ? "" : requestParam.defaultValue());
			}
			entryPoint.getParameters().add(entryPointParameter);
else if (!methodParameter.getParameterType().isArray()) {
			// Here we have an object, that we need to deep dive and get all its attributes, object arrays are not supported
			entryPoint.getParameters().addAll(ExternalEntryPointHelper.getInternalEntryPointParametersRecursively(methodParameter.getParameterType(), consolidatedTypeBlacklistconsolidatedNameBlacklist));
		}
	}

Setter method for paramNamesBlacklist

Parameters:
paramNamesBlacklist the paramNamesBlacklist to set
	public void setParamNamesBlacklist(List<StringparamNamesBlacklist) {
		this. = paramNamesBlacklist;
	}

Setter method for paramTypesBlacklist

Parameters:
paramTypesBlacklist the paramTypesBlacklist to set
	public void setParamTypesBlacklist(List<Class<?>> paramTypesBlacklist) {
		this. = paramTypesBlacklist;
	}

Append more param types to blacklist this method keeps the default blacklist and add these are extra ones

Parameters:
paramTypesBlacklist extra list
	public void setExtraParamTypesBlacklist(List<Class<?>> extraParamTypesBlacklist) {
		this..addAll(extraParamTypesBlacklist);
	}

Setter method for scanEntryPointAnnotation

Parameters:
scanEntryPointAnnotation the scanEntryPointAnnotation to set
	public void setScanEntryPointAnnotation(boolean scanEntryPointAnnotation) {
		this. = scanEntryPointAnnotation;
	}

Setter method for nameDiscover

Parameters:
nameDiscover the nameDiscover to set
	public void setNameDiscover(ParameterNameDiscoverer nameDiscover) {
		this. = nameDiscover;
	}

Setter method for maxDeepLevel

Parameters:
maxDeepLevel the maxDeepLevel to set
	public void setMaxDeepLevel(Integer maxDeepLevel) {
		this. = maxDeepLevel;
	}
New to GrepCode? Check out our FAQ X