Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This file is part of essential.
*
* essential is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* essential is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with essential. If not, see .
*/
package net.craftforge.essential.controller.resolvers;
import net.craftforge.essential.controller.ControllerConfiguration;
import net.craftforge.essential.controller.annotations.*;
import net.craftforge.essential.controller.utils.ControllerReflUtils;
import net.craftforge.essential.core.constants.Charsets;
import net.craftforge.essential.core.constants.HttpHeaders;
import net.craftforge.essential.core.exceptions.InjectionException;
import net.craftforge.essential.core.exceptions.MissingHeaderException;
import net.craftforge.essential.core.resolvers.*;
import net.craftforge.essential.supply.Consumer;
import net.craftforge.essential.supply.exceptions.BadInputException;
import net.craftforge.essential.supply.exceptions.UnsupportedMediaTypeException;
import net.craftforge.reflection.managers.ClassManager;
import net.craftforge.reflection.utils.ReflUtils;
import javax.inject.Inject;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* {@inheritDoc}
*
* @author Christian Bick
* @since 21.08.11
*/
public class DefaultInputResolver implements InputResolver {
private BodyResolver bodyResolver;
private HeaderResolver headerResolver;
private QueryParamResolver queryParamResolver;
private PathParamResolver pathParamResolver;
private ControllerConfiguration configuration;
@Inject
public DefaultInputResolver(BodyResolver bodyResolver, HeaderResolver headerResolver,
QueryParamResolver queryParamResolver, PathParamResolver pathParamResolver,
ControllerConfiguration configuration) {
this.bodyResolver = bodyResolver;
this.headerResolver = headerResolver;
this.queryParamResolver = queryParamResolver;
this.pathParamResolver = pathParamResolver;
this.configuration = configuration;
}
/**
* {@inheritDoc}
*/
public Object getInputForField(Field field, Consumer consumer)
throws BadInputException, UnsupportedMediaTypeException, UnsupportedEncodingException {
Class> type = field.getType();
// Try to obtain a body annotation
if (ControllerReflUtils.isBodyOnProperty(field)) {
return getBodyInput(consumer, type);
}
String[] defaultValues = ControllerReflUtils.getDefaultValuesFromProperty(field);
// Try to obtain a header annotation
String headerName = ControllerReflUtils.getHeaderFromProperty(field);
if (headerName != null) {
return getHeaderInput(type, headerName, defaultValues);
}
// Try to obtain a parameter annotation
String paramName = ControllerReflUtils.getParamFromProperty(field);
if (paramName != null) {
paramName = paramName.isEmpty() ? field.getName() : paramName;
Type genericType = field.getGenericType();
return getParameterInput(type, genericType, paramName, defaultValues);
}
// Try to obtain a property annotation
String propertyName = ControllerReflUtils.getPropertyFromProperty(field);
if (propertyName != null) {
return getPropertyInput(type, propertyName, defaultValues);
}
return null;
}
/**
* {@inheritDoc}
*/
public List