Example usage for org.springframework.util ReflectionUtils findField

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

Introduction

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

Prototype

@Nullable
public static Field findField(Class<?> clazz, String name) 

Source Link

Document

Attempt to find a Field field on the supplied Class with the supplied name .

Usage

From source file:net.ggtools.maven.ddlgenerator.DDLGenerator.java

public void createSchema() {
    log.info("Exporting DDL file to " + ddlFile);
    createDirectoriesIfNeeded();//from   ww w. jav a  2  s  . c  om
    puManager.preparePersistenceUnitInfos();
    final PersistenceUnitInfo puInfo = puManager.obtainPersistenceUnitInfo(persistenceUnitName);
    final Ejb3Configuration ejb3Config = new Ejb3Configuration();
    ejb3Config.configure(puInfo, configProperties);
    final Field field = ReflectionUtils.findField(Ejb3Configuration.class, "cfg");
    ReflectionUtils.makeAccessible(field);
    final ServiceRegistry registry = new ServiceRegistryBuilder().applySettings(configProperties)
            .buildServiceRegistry();
    final Configuration configuration = (Configuration) ReflectionUtils.getField(field, ejb3Config);
    final SchemaExport export = new SchemaExport(registry, configuration);
    export.setDelimiter(";"); // TODO introduce parameter
    export.setOutputFile(ddlFile.getAbsolutePath());
    export.execute(true, false, false, true);
}

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

@Test
public void testSetFitnessEvaluator() {
    FitnessEvaluator fitnessEvaluatorToSet = mock(FitnessEvaluator.class);
    LowestCommonGroupCrossoverAlgorithm lowestCommonGroupCrossoverAlgorithm = new LowestCommonGroupCrossoverAlgorithm();
    lowestCommonGroupCrossoverAlgorithm.setFitnessEvaluator(fitnessEvaluatorToSet);

    Field fitnessEvaluatorField = ReflectionUtils.findField(LowestCommonGroupCrossoverAlgorithm.class,
            "fitnessEvaluator");
    ReflectionUtils.makeAccessible(fitnessEvaluatorField);
    FitnessEvaluator fitnessEvaluatorFromObject = (FitnessEvaluator) ReflectionUtils
            .getField(fitnessEvaluatorField, lowestCommonGroupCrossoverAlgorithm);

    assertSame(fitnessEvaluatorToSet, fitnessEvaluatorFromObject);
}

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

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

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

    assertSame(wordDaoToSet, wordDaoFromObject);
}

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

public DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl(final Class<T> domainType) {
    super(domainType);
    this.hashAndRangeKeyMethodExtractor = new DynamoDBHashAndRangeKeyMethodExtractorImpl<T>(getJavaType());
    ReflectionUtils.doWithMethods(domainType, new MethodCallback() {
        public void doWith(Method method) {
            if (method.getAnnotation(DynamoDBHashKey.class) != null) {
                String setterMethodName = toSetterMethodNameFromAccessorMethod(method);
                if (setterMethodName != null) {
                    hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName,
                            method.getReturnType());
                }/*ww w  .  j  a  va  2  s  .co m*/
            }
        }
    });
    ReflectionUtils.doWithFields(domainType, new FieldCallback() {
        public void doWith(Field field) {
            if (field.getAnnotation(DynamoDBHashKey.class) != null) {

                hashKeyField = ReflectionUtils.findField(domainType, field.getName());

            }
        }
    });
    Assert.isTrue(hashKeySetterMethod != null || hashKeyField != null,
            "Unable to find hash key field or setter method on " + domainType + "!");
    Assert.isTrue(hashKeySetterMethod == null || hashKeyField == null,
            "Found both hash key field and setter method on " + domainType + "!");

}

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

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

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

    assertSame(geneDaoToSet, geneDaoFromObject);
}

From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java

@Override
@Transactional//from  ww w .j  a va  2 s  .c o  m
public void delete(T entity) {
    logger.trace("----->MyRepositoryImpl.delete(T entity)");
    Assert.notNull(entity, "The entity must not be null!");
    Class<?> clazz = entity.getClass();
    if (clazz.isAnnotationPresent(LogicallyDelete.class)) {
        LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class);
        Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz());
        Field field = ReflectionUtils.findField(entity.getClass(), logicallyDelete.name());
        ReflectionUtils.makeAccessible(field);
        ReflectionUtils.setField(field, entity, value);
        save(entity);
    } else {
        super.delete(entity);
    }
}

From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java

@BeforeClass
public static void setUp() {
    liberalMutationAlgorithm = new LiberalMutationAlgorithm();

    geneDaoMock = mock(VariableLengthGeneDao.class);
    liberalMutationAlgorithm.setGeneDao(geneDaoMock);
    chromosomeHelperSpy = spy(new KeylessChromosomeHelper());
    geneDaoMockForChromosomeHelper = mock(VariableLengthGeneDao.class);
    liberalMutationAlgorithm.setChromosomeHelper(chromosomeHelperSpy);

    logMock = mock(Logger.class);
    Field logField = ReflectionUtils.findField(LiberalMutationAlgorithm.class, "log");
    ReflectionUtils.makeAccessible(logField);
    ReflectionUtils.setField(logField, liberalMutationAlgorithm, logMock);
}

From source file:es.logongas.ix3.util.ReflectionUtilTest.java

@Test
public void testGetAnnotationPropertyNested() throws Exception {
    System.out.println("getAnnotation PropertyNested");
    TestAnnotation expResult = ReflectionUtils.findField(BeanTestC.class, "propBooleanReadOnly")
            .getAnnotation(TestAnnotation.class);
    TestAnnotation result = ReflectionUtil.getAnnotation(BeanTestA.class, "prop1.beanTestC.propBooleanReadOnly",
            TestAnnotation.class);
    assertEquals(expResult, result);/*ww  w.  j  av  a 2 s.com*/
}

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