Example usage for org.springframework.util ReflectionUtils invokeMethod

List of usage examples for org.springframework.util ReflectionUtils invokeMethod

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils invokeMethod.

Prototype

@Nullable
public static Object invokeMethod(Method method, @Nullable Object target) 

Source Link

Document

Invoke the specified Method against the supplied target object with no arguments.

Usage

From source file:by.creepid.docsreporter.converter.HtmlxConverterAdapterTest.java

public HtmlxConverterAdapterTest() {
    converter = new PoiXhtmlConverterAdapter() {

        @Override//from   w ww. j a  v a  2 s.com
        public ImageExtractObservable createImageExtractObservable() {
            return new ImageExtractObservableImpl();
        }
    };

    Method propSetMethod = ReflectionUtils.findMethod(PoiXhtmlConverterAdapter.class, "afterPropertiesSet");
    ReflectionUtils.invokeMethod(propSetMethod, converter);
}

From source file:by.creepid.docsreporter.converter.images.ImageConverterImplTest.java

public ImageConverterImplTest() {
    instance = new ImageConverterImpl();

    try {//  w  w  w.  j a v  a  2  s .c o  m
        Method initMethod = ImageConverterImpl.class.getDeclaredMethod("addCMYKServiceProvider");
        initMethod.setAccessible(true);
        ReflectionUtils.invokeMethod(initMethod, instance);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsQuartzJobBean.java

@SuppressWarnings("rawtypes")
@Override//w w w  .j a v  a 2  s  . c  om
public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
        Scheduler scheduler = (Scheduler) ReflectionUtils.invokeMethod(getSchedulerMethod, context);
        Map mergedJobDataMap = (Map) ReflectionUtils.invokeMethod(getMergedJobDataMapMethod, context);
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
        MutablePropertyValues pvs = new MutablePropertyValues();
        pvs.addPropertyValues(scheduler.getContext());
        pvs.addPropertyValues(mergedJobDataMap);
        bw.setPropertyValues(pvs, true);
    } catch (SchedulerException ex) {
        throw new JobExecutionException(ex);
    }
    executeInternal(context);
}

From source file:org.socialsignin.spring.data.dynamodb.repository.support.CompositeIdHashAndRangeKeyExtractor.java

@Override
public Object getRangeKey(ID id) {
    Method method = hashAndRangeKeyMethodExtractor.getRangeKeyMethod();
    if (method != null) {
        return ReflectionUtils.invokeMethod(method, id);
    } else {/*from w w  w  .j  a v a2s  .c  om*/
        return ReflectionUtils.getField(hashAndRangeKeyMethodExtractor.getRangeKeyField(), id);
    }
}

From source file:com.cloudera.csd.validation.references.constraints.AbstractReferenceConstraint.java

/**
 * Normalizes the results of invoking the method on the object.
 * If the method returns a single string, it is wrapped in a list.
 * If the result is a map, the values of the map are used to create
 * the collection of strings./*from w w  w .  j  a v  a  2 s.c  o  m*/
 * @param method the method to invoke
 * @param obj the object to invoke the method on.
 * @return the list of returned ids. Nulls are filtered out.
 */
protected Collection<String> getIds(Method method, Object obj) {
    Object result = ReflectionUtils.invokeMethod(method, obj);
    Collection<String> ids;
    if (result instanceof Collection) {
        ids = (Collection<String>) result;
    } else if (result instanceof Map) {
        ids = ((Map<?, String>) result).values();
    } else {
        ids = ImmutableList.of((String) result);
    }
    return Collections2.filter(ids, new Predicate<String>() {
        public boolean apply(@Nullable String input) {
            return (input != null);
        }
    });
}

From source file:org.shept.persistence.provider.hibernate.HibernateUtils_old.java

/**
 * Checking if it is a new model/* w  w  w  . j  a v  a 2 s.c o m*/
 * If the index is a compound index we must check all components if they are all non null
 * @param index
 * @return
 */
public static boolean isNewModel(HibernateDaoSupport dao, Object model) {
    final Object index = getIdValue(dao, model);
    final List<Field> nulls = new ArrayList<Field>();
    if (index == null)
        return true;

    ReflectionUtils.doWithFields(index.getClass(), new ReflectionUtils.FieldCallback() {
        public void doWith(Field field) {
            try {
                Method idMth = ReflectionUtils.findMethod(index.getClass(),
                        "get" + StringUtils.capitalize(field.getName()));
                Object value = ReflectionUtils.invokeMethod(idMth, index);
                if (value == null) {
                    nulls.add(field);
                }
            } catch (Exception ex) {
                // ignore all Exception here as they are quit frequent
                // e.g. serialVersionUid e.t.c. or do better filtering
                // TODO better eliminate error cases
            }
        }
    });
    return nulls.size() > 0;
}

From source file:org.cloudfoundry.reconfiguration.spring.AbstractJpaBasedCloudServiceBeanFactoryPostProcessorTest.java

private Object getSession(EntityManager manager) {
    Method method = ReflectionUtils.findMethod(manager.getClass(), "getDelegate");
    return ReflectionUtils.invokeMethod(method, manager);
}

From source file:com.ryantenney.metrics.spring.GaugeMethodAnnotationBeanPostProcessor.java

@Override
protected void withMethod(final Object bean, String beanName, Class<?> targetClass, final Method method) {
    if (method.getParameterTypes().length > 0) {
        throw new IllegalStateException(
                "Method " + method.getName() + " is annotated with @Gauge but requires parameters.");
    }//  w  w w  .  j a  v a2s.c  om

    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());
}

From source file:com.ryantenney.metrics.spring.CachedGaugeAnnotationBeanPostProcessor.java

@Override
protected void withMethod(final Object bean, String beanName, Class<?> targetClass, final Method method) {
    if (method.getParameterTypes().length > 0) {
        throw new IllegalStateException(
                "Method " + method.getName() + " is annotated with @CachedGauge but requires parameters.");
    }/* w ww. j  av  a 2  s  .c om*/

    final CachedGauge annotation = method.getAnnotation(CachedGauge.class);
    final String metricName = Util.forCachedGauge(targetClass, method, annotation);

    metrics.register(metricName,
            new com.codahale.metrics.CachedGauge<Object>(annotation.timeout(), annotation.timeoutUnit()) {
                @Override
                protected Object loadValue() {
                    return ReflectionUtils.invokeMethod(method, bean);
                }
            });

    LOG.debug("Created cached gauge {} for method {}.{}", metricName, targetClass.getCanonicalName(),
            method.getName());
}

From source file:org.cloudfoundry.reconfiguration.spring.AbstractJpaBasedCloudServiceBeanFactoryPostProcessorTest.java

private Object getSessionFactory(Object session) {
    Method method = ReflectionUtils.findMethod(session.getClass(), "getFactory");
    return ReflectionUtils.invokeMethod(method, session);
}