Example usage for java.lang.reflect Method getGenericParameterTypes

List of usage examples for java.lang.reflect Method getGenericParameterTypes

Introduction

In this page you can find the example usage for java.lang.reflect Method getGenericParameterTypes.

Prototype

@Override
public Type[] getGenericParameterTypes() 

Source Link

Usage

From source file:org.apache.servicecomb.common.rest.definition.RestOperationMeta.java

public void init(OperationMeta operationMeta) {
    this.operationMeta = operationMeta;

    Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
    Operation operation = operationMeta.getSwaggerOperation();
    this.produces = operation.getProduces();
    if (produces == null) {
        this.produces = swagger.getProduces();
    }//from w  w  w.  j  a v  a2 s  .co  m

    this.createProduceProcessors();

    Method method = operationMeta.getMethod();
    Type[] genericParamTypes = method.getGenericParameterTypes();
    if (genericParamTypes.length != operation.getParameters().size()) {
        throw new Error("Param count is not equal between swagger and method, path=" + absolutePath
                + ";operation=" + operationMeta.getMicroserviceQualifiedName());
    }

    // ?rest param
    for (int idx = 0; idx < genericParamTypes.length; idx++) {
        Parameter parameter = operation.getParameters().get(idx);
        Type genericParamType = genericParamTypes[idx];

        if ("formData".equals(parameter.getIn())) {
            formData = true;
        }

        RestParam param = new RestParam(idx, parameter, genericParamType);
        addParam(param);
    }

    setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
}

From source file:org.mashti.jetson.json.JsonRequestDecoder.java

private Object[] readArguments(final JsonParser parser, final Method method) throws IOException {

    JsonParserUtil.expectFieldName(parser, JsonRequestEncoder.PARAMETERS_KEY);
    final Type[] param_types = method.getGenericParameterTypes();
    return JsonParserUtil.readArrayValuesAs(parser, param_types);
}

From source file:io.servicecomb.common.rest.definition.RestOperationMeta.java

public void init(OperationMeta operationMeta) {
    this.operationMeta = operationMeta;

    Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
    Operation operation = operationMeta.getSwaggerOperation();
    this.produces = operation.getProduces();
    if (produces == null) {
        this.produces = swagger.getProduces();
    }/*from  w  ww  .j a v  a 2s. c  o m*/

    this.createProduceProcessors();

    Method method = operationMeta.getMethod();
    Type[] genericParamTypes = method.getGenericParameterTypes();
    if (genericParamTypes.length != operation.getParameters().size()) {
        throw new Error("Param count is not equal between swagger and method,  path=" + absolutePath);
    }

    // ?rest param
    for (int idx = 0; idx < genericParamTypes.length; idx++) {
        Parameter parameter = operation.getParameters().get(idx);
        Type genericParamType = genericParamTypes[idx];

        if ("formData".equals(parameter.getIn())) {
            formData = true;
        }

        RestParam param = new RestParam(idx, parameter, genericParamType);
        addParam(param);
    }

    setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
}

From source file:org.debux.webmotion.server.handler.ExecutorParametersConvertorHandlerTest.java

@Test
public void testConvertListObject() throws Exception {
    Method method = getClass().getMethod("testConvertListObject", List.class);
    Class<?> type = method.getParameterTypes()[0];
    Type genericType = method.getGenericParameterTypes()[0];

    Object convert = handler//from  www. ja  v  a 2s  . c o m
            .convert(
                    toParameterTreeArray(toParameterTreeMap("attribute1", "value", "attribute2", "value"),
                            toParameterTreeMap("attribute1", "value", "attribute2", "value")),
                    type, genericType);

    AssertJUnit.assertEquals(ArrayList.class, convert.getClass());
    AssertJUnit.assertEquals(2, ((ArrayList) convert).size());
}

From source file:org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingConverter.java

@Override
public void setProperty(Object instance, String propertyName, Object value) throws ConversionException {
    try {/*from   w  ww  .j ava  2 s.c om*/
        // try to find a @PropertySetter-annotated method
        Method annotatedSetter = ReflectionUtil.findPropertySetterMethod(this, propertyName);
        if (annotatedSetter != null) {
            Type expectedType = annotatedSetter.getGenericParameterTypes()[1];
            value = ConversionUtil.convert(value, expectedType);
            annotatedSetter.invoke(this, instance, value);
            return;
        }

        // we need the generic type of this property, not just the class
        Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod();

        // Convert the value to the specified type
        value = ConversionUtil.convert(value, setter.getGenericParameterTypes()[0], instance);

        setPropertyWhichMayBeAHibernateCollection(instance, propertyName, value);
    } catch (Exception ex) {
        throw new ConversionException(propertyName + " on " + instance.getClass(), ex);
    }
}

From source file:org.apache.axis2.jaxws.runtime.description.marshal.impl.PackageSetBuilder.java

/**
 * add package information by reflecting the parameters on Method m
 * @param set/*  w ww .j  a v a  2s  . c  o m*/
 * @param m
 */
private static void addPackagesFromParameters(TreeSet<String> set, Method m) {
    if (log.isDebugEnabled()) {
        log.debug("enter addPackagesFromParameters for " + m);
    }
    try {
        if (m != null) {
            Set<Class> classes = new HashSet<Class>();
            // Build a set of all of the classes referenced in the parameters (including
            // generic argument references
            for (Type type : m.getGenericParameterTypes()) {
                classes = ClassUtils.getClasses(type, classes);
            }
            addClassesToPackageSet(classes, set);
        }
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug("Could not reflect the information on method " + m + " due to " + t);
            log.debug("Processing continues");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("exit addPackagesFromParameters");
    }
}

From source file:info.magnolia.jcr.node2bean.impl.TypeMappingImpl.java

private List<Class<?>> inferGenericTypes(Method method) {
    List<Class<?>> inferredTypes = new ArrayList<Class<?>>();
    Type[] parameterTypes = method.getGenericParameterTypes();
    for (Type parameterType : parameterTypes) {
        if (parameterType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType) parameterType;
            for (Type t : type.getActualTypeArguments()) {
                if (t instanceof ParameterizedType) {
                    // this the case when parameterized type looks like this: Collection<List<String>>
                    // we care only for raw type List
                    inferredTypes.add((Class<?>) ((ParameterizedType) t).getRawType());
                } else {
                    inferredTypes.add((Class<?>) t);
                }//from   w ww .j a v  a  2 s.  c o  m
            }
        }
    }
    return inferredTypes;
}

From source file:org.xwiki.filter.internal.DefaultFilterDescriptorManager.java

/**
 * @param element the element/*from   ww  w.j a  v a2 s .com*/
 * @param method the method to add to the element
 */
private void addMethod(FilterElementDescriptor element, Method method) {
    String methodName = method.getName();
    Type[] methodTypes = method.getGenericParameterTypes();

    if (methodName.startsWith(PREFIX_BEGIN)) {
        if (element.getBeginMethod() == null
                || element.getBeginMethod().getGenericParameterTypes().length < methodTypes.length) {
            element.setBeginMethod(method);
        }
    } else if (methodName.startsWith(PREFIX_END)) {
        if (element.getEndMethod() == null
                || element.getEndMethod().getGenericParameterTypes().length < methodTypes.length) {
            element.setEndMethod(method);
        }
    } else {
        if (element.getOnMethod() == null
                || element.getOnMethod().getGenericParameterTypes().length < methodTypes.length) {
            element.setOnMethod(method);
        }
    }
}

From source file:pl.bristleback.server.bristle.conf.resolver.action.ActionResolver.java

public ActionInformation prepareActionInformation(Class<?> clazz, Method action) {
    ActionInformation actionInformation = prepareAction(clazz, action);

    List<ActionParameterInformation> parameters = new ArrayList<ActionParameterInformation>();
    for (int i = 0; i < action.getParameterTypes().length; i++) {
        Type parameterType = action.getGenericParameterTypes()[i];
        ActionParameterInformation parameterInformation = parametersResolver
                .prepareActionParameter(parameterType, action.getParameterAnnotations()[i]);
        parameters.add(parameterInformation);
    }/*from  w  ww.ja  v a2s .  co  m*/
    actionInformation.setParameters(parameters);
    ActionResponseInformation responseInformation = responseResolver.resolveResponse(action);
    actionInformation.setResponseInformation(responseInformation);
    return actionInformation;
}

From source file:pl.bristleback.server.bristle.conf.resolver.action.client.ClientActionResolver.java

private List<ClientActionParameterInformation> resolveActionParameters(Method actionMethod) {
    SerializationResolver serializationResolver = serializationEngine.getSerializationResolver();
    List<ClientActionParameterInformation> parameters = new ArrayList<ClientActionParameterInformation>();
    for (int i = 0; i < actionMethod.getParameterTypes().length; i++) {
        Type parameterType = actionMethod.getGenericParameterTypes()[i];
        ClientActionParameterInformation parameterInformation = parameterResolver.prepareActionParameter(
                serializationResolver, parameterType, actionMethod.getParameterAnnotations()[i]);
        parameters.add(parameterInformation);
    }/*from  w  w  w  .j  a  va 2 s .c o  m*/
    return parameters;
}