List of usage examples for java.lang.reflect Method getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:mil.army.usace.data.dataquery.rdbms.implementations.OracleConverter.java
@Override public Object convertType(Object obj, Method method) throws ClassNotFoundException, ConversionException, SQLException { Class methodParam = method.getParameterTypes()[0]; if (obj == null) return null; else if (obj instanceof oracle.sql.TIMESTAMPTZ) { java.sql.Date sqlDate = ((oracle.sql.TIMESTAMPTZ) obj).dateValue(oc); return ConversionUtility.convertType(sqlDate, methodParam); } else {/* w ww . j av a2 s . com*/ if (methodParam.isPrimitive()) { return obj; } else { return ConversionUtility.convertType(obj, methodParam); } } }
From source file:com.haulmont.chile.core.model.utils.MethodsCache.java
public MethodsCache(Class clazz) { final Method[] methods = clazz.getMethods(); for (Method method : methods) { String name = method.getName(); if (name.startsWith("get") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true);/* w ww.j a va2s . c o m*/ getters.put(name, method); } if (name.startsWith("is") && method.getParameterTypes().length == 0) { name = StringUtils.uncapitalize(name.substring(2)); method.setAccessible(true); getters.put(name, method); } else if (name.startsWith("set") && method.getParameterTypes().length == 1) { name = StringUtils.uncapitalize(name.substring(3)); method.setAccessible(true); setters.put(name, method); } } }
From source file:org.openmrs.module.programlocation.advisor.ProgramWorkflowServiceAroundAdvisor.java
public boolean matches(Method method, Class targetClass) { if (method.getName().equals("triggerStateConversion") && method.getParameterTypes().length == 3) { return true; }/*from ww w.j a v a 2 s. c om*/ return false; }
From source file:fr.putnami.pwt.core.service.server.service.CommandExecutorImpl.java
public CommandExecutorImpl(Object service, Method method) { this.service = service; this.method = method; String[] paramTypes = new String[method.getParameterTypes().length]; for (int i = 0; i < method.getParameterTypes().length; i++) { paramTypes[i] = method.getParameterTypes()[i].getCanonicalName(); }/*www . j a va2 s .c om*/ CommandDefinition definition = new CommandDefinition(method.getDeclaringClass().getName(), method.getName(), method.getReturnType().getCanonicalName(), paramTypes); this.setCommandDefinition(definition); this.executorLogger = LogFactory.getLog(method.getDeclaringClass().getCanonicalName()); }
From source file:net.arnx.jsonic.web.extension.SpringContainer.java
@Override public Object getComponent(String className) throws Exception { Object component;//from ww w . j a v a2 s . co m try { component = appContext.getBean(className); } catch (Exception e) { throw new ClassNotFoundException("class not found: " + className, e); } if (component instanceof ApplicationContextAware) { ((ApplicationContextAware) component).setApplicationContext(appContext); } for (Method method : component.getClass().getMethods()) { Class<?>[] params = method.getParameterTypes(); if (void.class.equals(method.getReturnType()) && method.getName().startsWith("set") && params.length == 1) { Class<?> c = params[0]; if (HttpServletRequest.class.equals(c)) { method.invoke(component, ExternalContext.getRequest()); } else if (HttpServletResponse.class.equals(c)) { method.invoke(component, ExternalContext.getResponse()); } } } return component; }
From source file:com.delphix.session.module.rmi.impl.RmiMethodOrdering.java
public RmiMethodOrdering(Class<?> clazz) { Map<String, Method> methodMap = Maps.newHashMap(); for (Method m : clazz.getMethods()) { List<String> paramNames = Lists.newArrayList(); for (Class<?> paramType : m.getParameterTypes()) { paramNames.add(paramType.getCanonicalName()); }//from w ww .j a va 2 s.c o m String str = String.format("%s(%s)", m.getName(), StringUtils.join(paramNames, ", ")); methodMap.put(str, m); } List<String> sortedNames = new ArrayList<String>(methodMap.keySet()); Collections.sort(sortedNames); for (String name : sortedNames) { Method m = methodMap.get(name); placement.put(m, methods.size()); methods.add(m); } }
From source file:com.gu.management.spring.ManagementUrlDiscoveryService.java
private boolean isRequestableMethod(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); boolean isPublic = Modifier.isPublic(method.getModifiers()); boolean isProtected = Modifier.isProtected(method.getModifiers()); boolean returnsModelAndView = method.getReturnType().equals(ModelAndView.class); boolean takesRequestAndResponse = parameterTypes.length >= 2 && HttpServletRequest.class.isAssignableFrom(parameterTypes[0]) && HttpServletResponse.class.isAssignableFrom(parameterTypes[1]); return (isPublic || isProtected) && (returnsModelAndView || takesRequestAndResponse); }
From source file:com.comphenix.pulse.Button.java
private Method findObsfucatedMethod(Class<BlockButton> clazz) { Class<?>[] expected = new Class<?>[] { World.class, int.class, int.class, int.class, Random.class }; // Find the correct method to call for (Method method : clazz.getMethods()) { if (ArrayUtils.isEquals(method.getParameterTypes(), expected)) { return method; }/*from ww w .ja v a 2s .c om*/ } // Damn throw new RuntimeException("Unable to find updateTick-method in BlockButton."); }
From source file:com.ryantenney.metrics.spring.GaugeAnnotationBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(final Object bean, String beanName) { final Class<?> targetClass = AopUtils.getTargetClass(bean); ReflectionUtils.doWithFields(targetClass, new FieldCallback() { @Override/*from w w w . ja va2s .com*/ public void doWith(final Field field) throws IllegalAccessException { ReflectionUtils.makeAccessible(field); final Gauge annotation = field.getAnnotation(Gauge.class); final String metricName = Util.forGauge(targetClass, field, annotation); metrics.register(metricName, new com.codahale.metrics.Gauge<Object>() { @Override public Object getValue() { Object value = ReflectionUtils.getField(field, bean); if (value instanceof com.codahale.metrics.Gauge) { value = ((com.codahale.metrics.Gauge<?>) value).getValue(); } return value; } }); LOG.debug("Created gauge {} for field {}.{}", metricName, targetClass.getCanonicalName(), field.getName()); } }, FILTER); ReflectionUtils.doWithMethods(targetClass, new MethodCallback() { @Override public void doWith(final Method method) throws IllegalAccessException { if (method.getParameterTypes().length > 0) { throw new IllegalStateException( "Method " + method.getName() + " is annotated with @Gauge but requires parameters."); } final Gauge annotation = method.getAnnotation(Gauge.class); final String metricName = Util.forGauge(targetClass, method, annotation); metrics.register(metricName, new com.codahale.metrics.Gauge<Object>() { @Override public Object getValue() { return ReflectionUtils.invokeMethod(method, bean); } }); LOG.debug("Created gauge {} for method {}.{}", metricName, targetClass.getCanonicalName(), method.getName()); } }, FILTER); return bean; }
From source file:hydrograph.ui.expression.editor.evaluate.EvaluateExpression.java
@SuppressWarnings({ "unchecked" }) String invokeEvaluateFunctionFromJar(String expression, String[] fieldNames, Object[] values) { LOGGER.debug("Evaluating expression from jar"); String output = null;/*from w w w . jav a 2 s. c om*/ Object[] returnObj; expression = ValidateExpressionToolButton.getExpressionText(expression); URLClassLoader child = null; try { returnObj = ValidateExpressionToolButton.getBuildPathForMethodInvocation(); List<URL> urlList = (List<URL>) returnObj[0]; String userFunctionsPropertyFileName = (String) returnObj[2]; child = URLClassLoader.newInstance(urlList.toArray(new URL[urlList.size()])); Thread.currentThread().setContextClassLoader(child); Class<?> class1 = Class.forName( ValidateExpressionToolButton.HYDROGRAPH_ENGINE_EXPRESSION_VALIDATION_API_CLASS, true, child); Method[] methods = class1.getDeclaredMethods(); for (Method method : methods) { if (method.getParameterTypes().length == 4 && StringUtils.equals(method.getName(), EVALUATE_METHOD_OF_EXPRESSION_JAR)) { method.getDeclaringClass().getClassLoader(); output = String.valueOf( method.invoke(null, expression, userFunctionsPropertyFileName, fieldNames, values)); break; } } } catch (JavaModelException | MalformedURLException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException exception) { evaluateDialog.showError(Messages.ERROR_OCCURRED_WHILE_EVALUATING_EXPRESSION); LOGGER.error(Messages.ERROR_OCCURRED_WHILE_EVALUATING_EXPRESSION, exception); } catch (InvocationTargetException | RuntimeException exception) { if (exception.getCause().getCause() != null) { if (StringUtils.equals(exception.getCause().getCause().getClass().getSimpleName(), TARGET_ERROR_EXCEPTION_CLASS)) { evaluateDialog.showError(getTargetException(exception.getCause().getCause().toString())); } else evaluateDialog.showError(exception.getCause().getCause().getMessage()); } else evaluateDialog.showError(exception.getCause().getMessage()); LOGGER.debug("Invalid Expression....", exception); } finally { if (child != null) { try { child.close(); } catch (IOException ioException) { LOGGER.error("Error occurred while closing classloader", ioException); } } } return output; }