Example usage for org.springframework.util ReflectionUtils setField

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

Introduction

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

Prototype

public static void setField(Field field, @Nullable Object target, @Nullable Object value) 

Source Link

Document

Set the field represented by the supplied Field field object on the specified Object target object to the specified value .

Usage

From source file:org.red5.server.net.rtmp.codec.MuleRTMPMinaProtocolEncoder.java

public MuleRTMPMinaProtocolEncoder() {
    super();/*from  w w w  . jav a  2s  .  c o m*/
    Field field = ReflectionUtils.findField(RTMPMinaProtocolEncoder.class, "encoder");
    field.setAccessible(true);
    ReflectionUtils.setField(field, this, new MuleRTMPProtocolEncoder());
}

From source file:org.red5.server.MuleRTMPGlobalContext.java

@Override
public void setApplicationContext(ApplicationContext context) {
    Field field = ReflectionUtils.findField(Context.class, "applicationContext");
    field.setAccessible(true);/*  w  w w  . j a v a  2  s.c o m*/
    ReflectionUtils.setField(field, this, context);
    Field field2 = ReflectionUtils.findField(Context.class, "coreContext");
    field2.setAccessible(true);
    ReflectionUtils.setField(field2, this, context.getParentBeanFactory());
}

From source file:com.jim.im.offline.repo.MessageConverter.java

private static ImMessage convert(DBObject dbObject) {
    ImMessage imMessage = new ImMessage();
    imMessage.setCreateTime(0L);//from   w ww  .ja  v  a 2 s.  com
    Map map = dbObject.toMap();
    for (String key : FIELD_KEYS) {
        Field field = FIELD_MAP.get(key);
        org.springframework.data.mongodb.core.mapping.Field annotation = field.getAnnotation(ALIAS_NAME);
        if (annotation != null)
            key = annotation.value();
        field.setAccessible(true);
        Object value = getValue(field, map.get(key));
        if (value == null)
            continue;
        ReflectionUtils.setField(field, imMessage, value);
    }

    return imMessage;
}

From source file:com.oembedler.moon.graphql.engine.dfs.SchemaHelper.java

public static void replaceTypeReferencesForUnionType(final GraphQLSchema schema,
        final Set<GraphQLUnionType> graphQLUnionTypeMap) {
    Field graphQLTypesField = ReflectionUtils.findField(GraphQLUnionType.class, "types");
    graphQLTypesField.setAccessible(true);
    for (GraphQLUnionType graphQLUnionType : graphQLUnionTypeMap) {
        List<GraphQLType> graphQLTypes = new ArrayList<>();
        for (GraphQLType graphQLType : graphQLUnionType.getTypes()) {
            if (graphQLType instanceof GraphQLTypeReference) {
                graphQLTypes.add(schema.getType(graphQLType.getName()));
            } else {
                graphQLTypes.add(graphQLType);
            }/*w ww.j  ava  2 s.  c  o m*/
        }
        ReflectionUtils.setField(graphQLTypesField, graphQLUnionType, graphQLTypes);
    }
}

From source file:my.school.spring.beans.DataProviderPostProcessor.java

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

    Arrays.stream(bean.getClass().getDeclaredFields()).forEach(f -> {
        CustomDataProvider annotation = f.getAnnotation(CustomDataProvider.class);
        if (annotation != null) {
            String seedValue = annotation.data();
            f.setAccessible(true);//  w  ww  .  j av  a2 s .c o  m
            ReflectionUtils.setField(f, bean, seedValue);
        }
    });

    return bean;
}

From source file:com.angstoverseer.util.ReflectionUtil.java

public static void setField(String fieldName, Object target, Object value) {
    final Field field = ReflectionUtils.findField(target.getClass(), fieldName);
    field.setAccessible(true);// w  w w .j a  v  a2  s  .  co m
    ReflectionUtils.setField(field, target, value);
}

From source file:com.ciphertool.genetics.algorithms.selection.TournamentSelectionAlgorithmTest.java

@BeforeClass
public static void setUp() {
    tournamentSelectionAlgorithm = new TournamentSelectionAlgorithm();
    tournamentSelectionAlgorithm.setGroupSize(3);
    TournamentSelector tournamentSelector = new TournamentSelector();
    tournamentSelector.setSelectionAccuracy(0.9);
    tournamentSelectionAlgorithm.setGroupSelector(tournamentSelector);

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

From source file:com.ciphertool.sentencebuilder.dao.WordDaoTest.java

@BeforeClass
public static void setUp() {
    queryMock = mock(Query.class);
    sessionMock = mock(Session.class);
    logMock = mock(Logger.class);
    sessionFactoryMock = mock(SessionFactory.class);

    wordDao = new WordDao();
    wordDao.setSessionFactory(sessionFactoryMock);

    Field logField = ReflectionUtils.findField(WordDao.class, "log");
    ReflectionUtils.makeAccessible(logField);
    ReflectionUtils.setField(logField, wordDao, logMock);
}

From source file:springobjectmapper.FieldPropertyRowMapper.java

@Override
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
    try {/* w ww.  j  a v  a  2 s.  co  m*/
        T result = newObject(typeClass);
        for (Entry<String, Field> entry : fieldMapping.entrySet()) {
            Object value = rs.getObject(entry.getKey());
            ReflectionUtils.setField(entry.getValue(), result, value);
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ciphertool.genetics.algorithms.mutation.cipherkey.RandomValueMutationAlgorithmTest.java

@BeforeClass
public static void setUp() {
    randomValueMutationAlgorithm = new RandomValueMutationAlgorithm();

    geneDaoMock = mock(GeneDao.class);
    randomValueMutationAlgorithm.setGeneDao(geneDaoMock);

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