Example usage for org.springframework.util ReflectionUtils getField

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

Introduction

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

Prototype

@Nullable
public static Object getField(Field field, @Nullable Object target) 

Source Link

Document

Get the field represented by the supplied Field field object on the specified Object target object .

Usage

From source file:com.ciphertool.genetics.algorithms.crossover.LiberalCrossoverAlgorithmTest.java

@Test
public void testSetGeneDao() {
    GeneDao geneDaoToSet = mock(GeneDao.class);
    LiberalCrossoverAlgorithm liberalCrossoverAlgorithm = new LiberalCrossoverAlgorithm();
    liberalCrossoverAlgorithm.setGeneDao(geneDaoToSet);

    Field geneDaoField = ReflectionUtils.findField(LiberalCrossoverAlgorithm.class, "geneDao");
    ReflectionUtils.makeAccessible(geneDaoField);
    GeneDao geneDaoFromObject = (GeneDao) ReflectionUtils.getField(geneDaoField, liberalCrossoverAlgorithm);

    assertSame(geneDaoToSet, geneDaoFromObject);
}

From source file:py.una.pol.karaku.replication.client.ReplicationResponseHandler.java

/**
 * @param response//from ww w . j  av  a  2s.  c o  m
 * @return
 */
@SuppressWarnings("rawtypes")
private Collection getItems(Object response) {

    Object respuesta = notNull(response, "Cant get changes from null response");
    Class<?> clazz = notNull(respuesta.getClass());
    Field f = KarakuReflectionUtils.findField(clazz, CHANGE_FIELDS);

    if (f == null) {
        f = ReflectionUtils.findField(response.getClass(), null, List.class);
    }

    notNull(f,
            "Cant get the id field, " + "use the @ReplicationData annotation or create "
                    + "a field with name %s, please see %s",
            Arrays.toString(CHANGE_FIELDS), response.getClass().getName());
    f.setAccessible(true);
    Collection c = (Collection) ReflectionUtils.getField(f, response);

    if (c == null) {
        return Collections.EMPTY_LIST;
    }
    return c;
}

From source file:com.ciphertool.zodiacengine.service.GeneticCipherSolutionServiceTest.java

@Test
public void testSetGeneticAlgorithm() {
    GeneticAlgorithm geneticAlgorithmToSet = mock(GeneticAlgorithm.class);
    GeneticCipherSolutionService geneticCipherSolutionService = new GeneticCipherSolutionService();
    geneticCipherSolutionService.setGeneticAlgorithm(geneticAlgorithmToSet);

    Field geneticAlgorithmField = ReflectionUtils.findField(GeneticCipherSolutionService.class,
            "geneticAlgorithm");
    ReflectionUtils.makeAccessible(geneticAlgorithmField);
    GeneticAlgorithm geneticAlgorithmFromObject = (GeneticAlgorithm) ReflectionUtils
            .getField(geneticAlgorithmField, geneticCipherSolutionService);

    assertSame(geneticAlgorithmToSet, geneticAlgorithmFromObject);
}

From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImplTest.java

@Test
public void testSetWordDao() {
    WordDao wordDaoToSet = mock(WordDao.class);
    FrequencyListImporterImpl frequencyListImporterImpl = new FrequencyListImporterImpl();
    frequencyListImporterImpl.setWordDao(wordDaoToSet);

    Field wordDaoField = ReflectionUtils.findField(FrequencyListImporterImpl.class, "wordDao");
    ReflectionUtils.makeAccessible(wordDaoField);
    WordDao wordDaoFromObject = (WordDao) ReflectionUtils.getField(wordDaoField, frequencyListImporterImpl);

    assertSame(wordDaoToSet, wordDaoFromObject);
}

From source file:com.ciphertool.zodiacengine.dao.WordGeneDaoTest.java

@Test
public void testSetWordMapDao() {
    WordGeneDao wordGeneDao = new WordGeneDao();
    wordGeneDao.setWordMapDao(wordMapDaoMock);

    Field wordMapDaoField = ReflectionUtils.findField(WordGeneDao.class, "wordMapDao");
    ReflectionUtils.makeAccessible(wordMapDaoField);
    WordMapDao wordMapDaoFromObject = (WordMapDao) ReflectionUtils.getField(wordMapDaoField, wordGeneDao);

    assertSame(wordMapDaoMock, wordMapDaoFromObject);
}

From source file:com.ciphertool.genetics.algorithms.ConcurrentMultigenerationalGeneticAlgorithmTest.java

@Test
public void testSetTaskExecutor() {
    TaskExecutor taskExecutorToSet = mock(TaskExecutor.class);

    ConcurrentMultigenerationalGeneticAlgorithm concurrentMultigenerationalGeneticAlgorithm = new ConcurrentMultigenerationalGeneticAlgorithm();
    concurrentMultigenerationalGeneticAlgorithm.setTaskExecutor(taskExecutorToSet);

    Field taskExecutorField = ReflectionUtils.findField(ConcurrentMultigenerationalGeneticAlgorithm.class,
            "taskExecutor");
    ReflectionUtils.makeAccessible(taskExecutorField);
    TaskExecutor taskExecutorFromObject = (TaskExecutor) ReflectionUtils.getField(taskExecutorField,
            concurrentMultigenerationalGeneticAlgorithm);

    assertSame(taskExecutorToSet, taskExecutorFromObject);
}

From source file:org.lightadmin.core.config.domain.field.PersistentFieldMetadata.java

@Override
public Object getValue(Object entity) {
    Method getter = persistentProperty.getGetter();
    if (null != getter) {
        return invokeMethod(getter, entity);
    }/*  w ww . ja  va 2s . co  m*/
    Field fld = persistentProperty.getField();
    if (null != fld) {
        return ReflectionUtils.getField(fld, entity);
    }
    return null;
}

From source file:cn.guoyukun.spring.utils.AopProxyUtils.java

private static ProxyFactory findJdkDynamicProxyFactory(final Object proxy) {
    Object jdkDynamicAopProxy = ReflectionUtils.getField(JdkDynamicProxy_h_FIELD, proxy);
    return (ProxyFactory) ReflectionUtils.getField(JdkDynamicAopProxy_advised_FIELD, jdkDynamicAopProxy);
}

From source file:com.ciphertool.genetics.algorithms.crossover.ConservativeUnevaluatedCrossoverAlgorithmTest.java

@Test
public void testSetMutateDuringCrossover() {
    boolean mutateDuringCrossoverToSet = true;

    ConservativeUnevaluatedCrossoverAlgorithm conservativeUnevaluatedCrossoverAlgorithm = new ConservativeUnevaluatedCrossoverAlgorithm();
    conservativeUnevaluatedCrossoverAlgorithm.setMutateDuringCrossover(mutateDuringCrossoverToSet);

    Field mutateDuringCrossoverField = ReflectionUtils
            .findField(ConservativeUnevaluatedCrossoverAlgorithm.class, "mutateDuringCrossover");
    ReflectionUtils.makeAccessible(mutateDuringCrossoverField);
    boolean mutateDuringCrossoverFromObject = (boolean) ReflectionUtils.getField(mutateDuringCrossoverField,
            conservativeUnevaluatedCrossoverAlgorithm);

    assertEquals(mutateDuringCrossoverToSet, mutateDuringCrossoverFromObject);
}

From source file:org.slf4j.plus.ExceptionLoggerFactoryTests.java

/**
 * Get max frame length//  w w  w . jav a  2s.  c o m
 * 
 * @param logger {@link ExceptionLogger}
 * @return max frame length
 */
private int getMaxFrameLength(ExceptionLogger logger) {

    Field field = ReflectionUtils.findField(ExceptionLogger.class, "maxFrameLength");
    ReflectionUtils.makeAccessible(field);

    return (int) ReflectionUtils.getField(field, logger);
}