List of usage examples for org.springframework.util ReflectionUtils invokeMethod
@Nullable public static Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args)
From source file:org.solq.dht.db.redis.service.JedisConnectionFactory.java
private void setTimeoutOn(JedisShardInfo shardInfo, int timeout) { ReflectionUtils.invokeMethod(SET_TIMEOUT_METHOD, shardInfo, timeout); }
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected Object getParamValue(GrailsParameterMap params, String conversionMethodName, String paramName) { Method method = PARAMS_METHODS.get(conversionMethodName); if (method == null) { log.warn("No method found for " + conversionMethodName + " in GrailsParameterMap"); return null; }/*from www . j a v a2 s.co m*/ return ReflectionUtils.invokeMethod(method, params, paramName); }
From source file:demo.ChildMethodRule.java
@Override public Statement apply(Statement base, FrameworkMethod frameworkMethod, Object testInstance) { Class<?> testClass = testInstance.getClass(); Method method = ReflectionUtils.findMethod(SpringClassRule.class, "getTestContextManager", Class.class); ReflectionUtils.makeAccessible(method); TestContextManager testContextManager = (TestContextManager) ReflectionUtils.invokeMethod(method, null, testClass);//from w w w . jav a 2 s . c om TestContext testContext = (TestContext) ReflectionTestUtils.getField(testContextManager, "testContext"); if (logger.isDebugEnabled()) { logger.debug("Applying ChildMethodRule to test method [" + frameworkMethod.getMethod() + "]."); } return new Statement() { @Override public void evaluate() throws Throwable { delegate(base, frameworkMethod, testInstance, testContext); } }; }
From source file:ductive.console.commands.register.CommandInvoker.java
protected Object execute(CommandContext ctx, MethodCommandTarget target, ParameterType[] paramTypes, List<Parameter> params) { try {/*from w ww. ja v a 2s .co m*/ Preprocessed pp = preprocess(params); Class<?>[] parameters = target.method.getParameterTypes(); Object[] args = new Object[parameters.length]; int aidx = 0; for (int i = 0; i < parameters.length; ++i) { Class<?> param = parameters[i]; if (Terminal.class.isAssignableFrom(param)) { if (!param.isInstance(ctx.terminal)) throw new RuntimeException(String.format("method '%s' does not support terminal '%s'", target.method, ctx.terminal)); args[i] = ctx.terminal; continue; } else if (TerminalUser.class.isAssignableFrom(param)) { args[i] = ctx.user; continue; } ParameterType t = paramTypes[aidx++]; args[i] = handleParam(pp, t); } Validate.isTrue(aidx == paramTypes.length); // http://stackoverflow.com/questions/2659517/access-exception-when-invoking-method-of-an-anonymous-class-using-java-reflectio target.method.setAccessible(true); return ReflectionUtils.invokeMethod(target.method, target.bean, args); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:org.apache.geode.management.internal.cli.remote.CommandExecutor.java
protected Object invokeCommand(ParseResult parseResult) { return ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); }
From source file:org.artifactory.webapp.servlet.ArtifactoryContextConfigListener.java
/** * Disable sessionId in URL (Servlet 3.0 containers) by setting the session tracking mode to SessionTrackingMode.COOKIE * For Servlet container < 3.0 we use different method (for tomcat 6 we use custom context.xml and for jetty * there is a custom jetty.xml file)./*w ww .j av a 2 s.c om*/ */ @SuppressWarnings("unchecked") private void setSessionTrackingMode(ServletContext servletContext) { // Only for Servlet container version 3.0 and above if (servletContext.getMajorVersion() < 3) { return; } // We cannot use ConstantValue.enableURLSessionId.getBoolean() since ArtifactoryHome is not binded yet. ArtifactoryHome artifactoryHome = (ArtifactoryHome) servletContext .getAttribute(ArtifactoryHome.SERVLET_CTX_ATTR); if (artifactoryHome == null) { throw new IllegalStateException("Artifactory home not initialized."); } if (artifactoryHome.getArtifactoryProperties() .getBooleanProperty(ConstantValues.supportUrlSessionTracking)) { getLogger().debug("Skipping setting session tracking mode to COOKIE, enableURLSessionId flag it on."); return; } try { // load enum with reflection ClassLoader cl = ClassUtils.getDefaultClassLoader(); Class<Enum> trackingModeEnum = (Class<Enum>) cl.loadClass("javax.servlet.SessionTrackingMode"); Enum cookieTrackingMode = Enum.valueOf(trackingModeEnum, "COOKIE"); // reflective call servletContext.setSessionTrackingModes(trackingModes) Method method = servletContext.getClass().getMethod("setSessionTrackingModes", Set.class); method.setAccessible(true); ReflectionUtils.invokeMethod(method, servletContext, Sets.newHashSet(cookieTrackingMode)); getLogger().debug("Successfully set session tracking mode to COOKIE"); } catch (Exception e) { getLogger().warn("Failed to set session tracking mode: " + e.getMessage()); } }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
protected void addCriterionAdaptor(final Class<?> clazz, final String constraintName, final Class<?> valueClass) { criterionAdaptors.put(clazz, new CriterionAdaptor() { @Override//from w ww. j av a 2 s . c om public org.hibernate.criterion.Criterion toHibernateCriterion(AbstractHibernateQuery hibernateQuery, Query.Criterion criterion, String alias) { Query.PropertyCriterion propertyCriterion = (Query.PropertyCriterion) criterion; Object value = propertyCriterion.getValue(); String propertyName = getPropertyName(criterion, alias); if (value instanceof DetachedCriteria) { Method propertyMethod = ReflectionUtils.findMethod(Property.class, constraintName, new Class[] { DetachedCriteria.class }); if (propertyMethod != null) { // if supports subqueries return (Criterion) ReflectionUtils.invokeMethod(propertyMethod, Property.forName(propertyName), new Object[] { value }); } } return callRestrictionsMethod(constraintName, new Class[] { String.class, valueClass }, new Object[] { propertyName, value }); } }); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriterionAdapter.java
/** * utility method that generically returns a criterion using methods in Restrictions * * @param constraintName - the criteria/*from ww w . j a va 2 s . co m*/ */ protected Criterion callRestrictionsMethod(String constraintName, Class<?>[] paramTypes, Object[] params) { final Method restrictionsMethod = ReflectionUtils.findMethod(Restrictions.class, constraintName, paramTypes); Assert.notNull(restrictionsMethod, "Could not find method: " + constraintName + " in class Restrictions for parameters: " + ArrayUtils.toString(params) + " with types: " + ArrayUtils.toString(paramTypes)); return (Criterion) ReflectionUtils.invokeMethod(restrictionsMethod, null, params); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.HibernateCriterionAdapter.java
private static void addCriterionAdaptor(final Class<?> clazz, final String constraintName, final Class<?> valueClass) { criterionAdaptors.put(clazz, new CriterionAdaptor() { @Override/* ww w .jav a2 s . c o m*/ public org.hibernate.criterion.Criterion toHibernateCriterion(HibernateQuery hibernateQuery, Query.Criterion criterion, String alias) { Query.PropertyCriterion propertyCriterion = (Query.PropertyCriterion) criterion; Object value = propertyCriterion.getValue(); String propertyName = getPropertyName(criterion, alias); if (value instanceof DetachedCriteria) { Method propertyMethod = ReflectionUtils.findMethod(Property.class, constraintName, new Class[] { DetachedCriteria.class }); if (propertyMethod != null) { // if supports subqueries return (Criterion) ReflectionUtils.invokeMethod(propertyMethod, Property.forName(propertyName), new Object[] { value }); } } return callRestrictionsMethod(constraintName, new Class[] { String.class, valueClass }, new Object[] { propertyName, value }); } }); }
From source file:org.codehaus.groovy.grails.orm.hibernate.query.HibernateCriterionAdapter.java
/** * utility method that generically returns a criterion using methods in Restrictions * * @param constraintName - the criteria/*from w w w . j a v a2s .c o m*/ */ private static Criterion callRestrictionsMethod(String constraintName, Class<?>[] paramTypes, Object[] params) { final Method restrictionsMethod = ReflectionUtils.findMethod(Restrictions.class, constraintName, paramTypes); Assert.notNull(restrictionsMethod, "Could not find method: " + constraintName + " in class Restrictions for parameters: " + ArrayUtils.toString(params) + " with types: " + ArrayUtils.toString(paramTypes)); return (Criterion) ReflectionUtils.invokeMethod(restrictionsMethod, null, params); }