List of usage examples for org.springframework.util ReflectionUtils findField
@Nullable public static Field findField(Class<?> clazz, String name)
From source file:com.ciphertool.genetics.algorithms.selection.TruncationSelectionAlgorithmTest.java
@BeforeClass public static void setUp() { truncationSelectionAlgorithm = new TruncationSelectionAlgorithm(); logMock = mock(Logger.class); Field logField = ReflectionUtils.findField(TruncationSelectionAlgorithm.class, "log"); ReflectionUtils.makeAccessible(logField); ReflectionUtils.setField(logField, truncationSelectionAlgorithm, logMock); }
From source file:org.red5.server.net.rtmp.codec.MuleRTMPMinaProtocolDecoder.java
public MuleRTMPMinaProtocolDecoder() { super();// w w w .j av a2 s. c o m Field field = ReflectionUtils.findField(RTMPMinaProtocolDecoder.class, "decoder"); field.setAccessible(true); ReflectionUtils.setField(field, this, new MuleRTMPProtocolDecoder()); }
From source file:org.red5.server.net.rtmp.codec.MuleRTMPMinaProtocolEncoder.java
public MuleRTMPMinaProtocolEncoder() { super();/* www . j a v a2s . 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);//from w ww. j a v a 2 s. com ReflectionUtils.setField(field, this, context); Field field2 = ReflectionUtils.findField(Context.class, "coreContext"); field2.setAccessible(true); ReflectionUtils.setField(field2, this, context.getParentBeanFactory()); }
From source file:es.logongas.ix3.util.ReflectionUtilTest.java
/** * Test of getAnnotation method, of class ReflectionUtil. *//*from ww w.j a v a 2 s.c o m*/ @Test public void testGetAnnotationField() throws Exception { System.out.println("getAnnotation en un campo"); TestAnnotation expResult = ReflectionUtils.findField(BeanTestC.class, "prop") .getAnnotation(TestAnnotation.class); TestAnnotation result = ReflectionUtil.getAnnotation(BeanTestC.class, "prop", TestAnnotation.class); assertEquals(expResult, result); }
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);/* ww w . j av a2s . c o m*/ ReflectionUtils.setField(field, target, value); }
From source file:com.dianping.avatar.cache.util.CacheAnnotationUtils.java
/** * Retrieve the cache key values from entity instance *//*from ww w.j a va2 s. c om*/ public static Object[] getCacheKeyValues(Object entity) { if (entity == null) { throw new IllegalArgumentException("Entity is null."); } Class<?> cz = entity.getClass(); Cache cache = cz.getAnnotation(Cache.class); if (cache == null) { throw new SystemException("The entity must be annotated by Cache."); } Field[] fields = ClassUtils.getDeclaredFields(cz); final List<OrderedField> cacheFields = new ArrayList<OrderedField>(); // Extract annotated fields for (int i = 0; i < fields.length; i++) { Field f = fields[i]; CacheParam fCache = f.getAnnotation(CacheParam.class); if (fCache != null) { cacheFields.add(new OrderedField(f, i, fCache.order())); } } // Extract declared fields for (int i = 0; i < cache.fields().length; i++) { String fieldName = cache.fields()[i]; if (fieldName.isEmpty()) { continue; } Field f = ReflectionUtils.findField(cz, fieldName); if (f == null) { throw new IllegalArgumentException( "Invalid cahce parameter " + fieldName + ", the filed is not exists."); } cacheFields.add(new OrderedField(f, i, -Integer.MAX_VALUE + i)); } Collections.sort(cacheFields); Object[] values = new Object[cacheFields.size()]; for (int i = 0; i < cacheFields.size(); i++) { OrderedField oField = cacheFields.get(i); ReflectionUtils.makeAccessible((Field) oField.field); values[i] = ReflectionUtils.getField((Field) oField.field, entity); } return values; }
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:net.prasenjit.auth.validation.FieldMatchValidator.java
/** {@inheritDoc} */ @Override//from w w w . ja v a2s . c o m public boolean isValid(final Object value, final ConstraintValidatorContext context) { try { Field field = ReflectionUtils.findField(value.getClass(), firstFieldName); ReflectionUtils.makeAccessible(field); final Object firstObj = ReflectionUtils.getField(field, value); field = ReflectionUtils.findField(value.getClass(), secondFieldName); ReflectionUtils.makeAccessible(field); final Object secondObj = ReflectionUtils.getField(field, value); return firstObj == null && secondObj == null || firstObj != null && firstObj.equals(secondObj); } catch (final Exception ignore) { // ignore } return true; }
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); }