List of usage examples for java.lang.reflect Parameter getName
public String getName()
From source file:com.phoenixnap.oss.ramlapisync.data.ApiParameterMetadata.java
/** * Simple method to prefer a string (which usually is specified by annotation) * @param preferredOption The first choice for the parameter name * @param fallback if the preferred sources is empty use this string * @return the better choice between these two strings *//*from ww w .ja va2s .c om*/ private String resolveParameterName(String preferredOption, Parameter fallback) { if (StringUtils.hasText(preferredOption)) { return preferredOption; } else { return fallback != null ? fallback.getName() : null; } }
From source file:telegram.polling.BotApiProxy.java
@Override public Object invoke(Object o, Method method, Object[] os) throws Throwable { ArrayList<NameValuePair> nvps = new ArrayList<>(); for (int i = 0; i < method.getParameterCount(); i++) { Parameter parameter = method.getParameters()[i]; if (os[i] != null) { String name;/*www. j a v a 2s. co m*/ if (parameter.isAnnotationPresent(Param.class)) { name = parameter.getDeclaredAnnotation(Param.class).name(); } else { name = parameter.getName(); } nvps.add(new BasicNameValuePair(name, os[i].toString())); } } return callApiMethod(method.getName(), nvps, method.getReturnType()); }
From source file:ca.oson.json.util.ObjectUtil.java
public static String[] getParameterNames(Parameter[] parameters) { int length = parameters.length; String[] parameterNames = new String[length]; for (int i = 0; i < length; i++) { Parameter parameter = parameters[i]; String parameterName = null; for (Annotation annotation : parameter.getAnnotations()) { //getDeclaredAnnotations String name = getName(annotation); if (name != null) { parameterName = name;/*from w w w . j a v a 2 s . c om*/ if (annotation instanceof ca.oson.json.annotation.FieldMapper) { break; } } } if (parameterName == null) { parameterName = parameter.getName(); } parameterNames[i] = parameterName; } return parameterNames; }
From source file:org.jspare.server.transaction.TransactionExecutorImpl.java
/** * Resolve parameter./*from ww w.j a va2 s. c om*/ * * @param parameter * the parameter * @param request * the request * @param response * the response * @return the object */ private Object resolveParameter(Parameter parameter, Request request, Response response) { if (parameter.getType().equals(Request.class)) { return request; } if (parameter.getType().equals(Response.class)) { return response; } if (!StringUtils.isEmpty(request.getParameter(parameter.getName()))) { return request.getParameter(parameter.getName()); } if (parameter.getType().getPackage().getName().endsWith(".model") || parameter.getType().isAnnotationPresent(Model.class) || parameter.isAnnotationPresent(Model.class)) { try { return my(Serializer.class).fromJSON(String.valueOf(request.getEntity().get()), parameter.getType()); } catch (SerializationException e) { log.warn("Invalid content of entity for class [{}] on parameter [{}]", parameter.getClass(), parameter.getName()); return null; } } if (parameter.isAnnotationPresent(org.jspare.server.mapping.Parameter.class)) { String parameterName = parameter.getAnnotation(org.jspare.server.mapping.Parameter.class).value(); return request.getParameter(parameterName); } return null; }
From source file:com.kelveden.rastajax.core.ResourceClassLoader.java
private List<Parameter> loadMethodParameters(Class<?> resourceClass, Method method) { final String logPrefix = " |-"; final List<Parameter> parameters = new ArrayList<Parameter>(); final Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { final Parameter parameter = loadMethodParameter(resourceClass, method, i); if (parameter != null) { LOGGER.debug("{} Found {} parameter '{}' of type '{}'.", logPrefix, parameter.getJaxRsAnnotationType().getSimpleName(), parameter.getName(), parameter.getType().getName()); parameters.add(parameter);//from w w w.ja va 2 s . c o m } } return parameters; }
From source file:com.kelveden.rastajax.core.ResourceClassLoader.java
private List<Parameter> loadClassFields(final Class<?> resourceClass) { final String logPrefix = " |-"; final List<Parameter> fields = new ArrayList<Parameter>(); for (Field field : resourceClass.getFields()) { final Set<Annotation> annotations = JaxRsAnnotationScraper.scrapeJaxRsAnnotationsFrom(field); try {/*from www. j a va2 s . co m*/ final Parameter parameter = buildParameterFromJaxRsAnnotations(annotations, field.getType()); if (parameter != null) { LOGGER.debug("{} Found {} field '{}' of type '{}'.", logPrefix, parameter.getJaxRsAnnotationType().getSimpleName(), parameter.getName(), parameter.getType().getName()); fields.add(parameter); } } catch (IllegalAccessException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } catch (InvocationTargetException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } catch (NoSuchMethodException e) { throw new ResourceClassLoadingException(String.format("Could not load field '%s' on class '%s'", field.getName(), resourceClass.getName()), e); } } return fields; }
From source file:com.kelveden.rastajax.core.ResourceClassLoader.java
private List<Parameter> loadClassProperties(final Class<?> resourceClass) { final String logPrefix = " |-"; final List<Parameter> fields = new ArrayList<Parameter>(); for (Method method : resourceClass.getDeclaredMethods()) { final Set<Annotation> annotations = JaxRsAnnotationScraper.scrapeJaxRsAnnotationsFrom(resourceClass, method);/* ww w.j a v a 2 s . com*/ try { final Parameter parameter = buildParameterFromJaxRsAnnotations(annotations, method.getReturnType()); if (parameter != null) { LOGGER.debug("{} Found {} property '{}' of type '{}'.", logPrefix, parameter.getJaxRsAnnotationType().getSimpleName(), parameter.getName(), parameter.getType().getName()); fields.add(parameter); } else { LOGGER.debug( "{} Method {} was not annotated with any annotations that describe the JAX-RS parameter type and so will be ignored.", logPrefix, method.getName()); } } catch (IllegalAccessException e) { throw new ResourceClassLoadingException(String.format("Could not load property '%s' on class '%s'", method.getName(), resourceClass.getName()), e); } catch (InvocationTargetException e) { throw new ResourceClassLoadingException(String.format("Could not load property '%s' on class '%s'", method.getName(), resourceClass.getName()), e); } catch (NoSuchMethodException e) { throw new ResourceClassLoadingException(String.format("Could not load property'%s' on class '%s'", method.getName(), resourceClass.getName()), e); } } return fields; }
From source file:org.wrml.runtime.rest.DefaultApiLoader.java
protected Object decipherDocumentSurrogateKeyValue(final URI uri, final Prototype prototype) { final ApiNavigator apiNavigator = getParentApiNavigator(uri); if (apiNavigator == null) { return null; }//from w w w . j a v a2 s. c o m final SortedSet<Parameter> surrogateKeyComponents = apiNavigator.getSurrogateKeyComponents(uri, prototype); if (surrogateKeyComponents == null || surrogateKeyComponents.isEmpty()) { return null; } final Set<String> allKeySlotNames = prototype.getAllKeySlotNames(); final Object surrogateKeyValue; if (surrogateKeyComponents.size() == 1) { final Parameter surrogateKeyPair = surrogateKeyComponents.first(); final String slotName = surrogateKeyPair.getName(); if (!allKeySlotNames.contains(slotName)) { return null; } final String slotTextValue = surrogateKeyPair.getValue(); final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue); surrogateKeyValue = slotValue; } else { final SortedMap<String, Object> keySlots = new TreeMap<String, Object>(); for (final Parameter surrogateKeyPair : surrogateKeyComponents) { final String slotName = surrogateKeyPair.getName(); if (!allKeySlotNames.contains(slotName)) { continue; } final String slotTextValue = surrogateKeyPair.getValue(); final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue); if (slotValue == null) { continue; } keySlots.put(slotName, slotValue); } if (keySlots.size() == 1) { surrogateKeyValue = keySlots.get(keySlots.firstKey()); } else { surrogateKeyValue = new CompositeKey(keySlots); } } return surrogateKeyValue; }
From source file:org.pentaho.platform.dataaccess.client.ConnectionServiceClient.java
/** * Generates a SOAP request for an Axis service. * @param params//from w w w . j a v a 2 s . c om * @return */ protected String getRequestXml(Parameter... params) { Document doc = DocumentHelper.createDocument(); Element envelopeNode = DocumentHelper.createElement("soapenv:Envelope"); //$NON-NLS-1$ envelopeNode.addAttribute("xmlns:soapenv", "http://www.w3.org/2003/05/soap-envelope"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:wsa", "http://www.w3.org/2005/08/addressing"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:pho", //$NON-NLS-1$ "http://impl.service.wizard.datasource.dataaccess.platform.pentaho.org"); //$NON-NLS-1$ doc.add(envelopeNode); // create a Body node Element bodyNode = DocumentHelper.createElement("soapenv:Body"); //$NON-NLS-1$ envelopeNode.add(bodyNode); if (params == null || params.length == 0) { return doc.asXML(); } // create a parameter called 'parameters' Element parametersNode = DocumentHelper.createElement("pho:parameters"); //$NON-NLS-1$ bodyNode.add(parametersNode); for (Parameter param : params) { // create a parameter called 'name' Element nameNode = DocumentHelper.createElement("pho:" + param.getName()); //$NON-NLS-1$ parametersNode.add(nameNode); nameNode.setText(param.getValue().toString()); nameNode.addAttribute("type", param.getValue().getClass().getCanonicalName()); //$NON-NLS-1$ } return doc.asXML(); }
From source file:org.structr.core.entity.SchemaMethod.java
private boolean getSignature(final Class type, final String methodName, final ActionEntry entry) { // superclass is AbstractNode for (final Method method : type.getMethods()) { if (methodName.equals(method.getName()) && (method.getModifiers() & Modifier.STATIC) == 0) { final Type[] parameterTypes = method.getGenericParameterTypes(); final Type returnType = method.getGenericReturnType(); final List<Type> types = new LinkedList<>(); // compile list of types to check for generic type parameter types.addAll(Arrays.asList(parameterTypes)); types.add(returnType);//from w w w. jav a 2 s . c o m final String genericTypeParameter = getGenericMethodParameter(types, method); // check for generic return type, and if the method defines its own generic type if (returnType instanceof TypeVariable && ((TypeVariable) returnType).getGenericDeclaration().equals(method)) { // method defines its own generic type entry.setReturnType(genericTypeParameter + returnType.getTypeName()); } else { // non-generic return type final Class returnClass = method.getReturnType(); if (returnClass.isArray()) { entry.setReturnType(genericTypeParameter + returnClass.getComponentType().getName() + "[]"); } else { entry.setReturnType(genericTypeParameter + method.getReturnType().getName()); } } for (final Parameter parameter : method.getParameters()) { String typeName = parameter.getParameterizedType().getTypeName(); String name = parameter.getType().getSimpleName(); if (typeName.contains("$")) { typeName = typeName.replace("$", "."); } entry.addParameter(typeName, parameter.getName()); } for (final Class exception : method.getExceptionTypes()) { entry.addException(exception.getName()); } entry.setOverrides(getProperty(overridesExisting)); entry.setCallSuper(getProperty(callSuper)); // success return true; } } return false; }