List of usage examples for org.springframework.util ReflectionUtils makeAccessible
@SuppressWarnings("deprecation") public static void makeAccessible(Field field)
From source file:org.jdal.annotation.AnnotatedElementAccessor.java
public static Object getValue(AnnotatedElement element, Object target) { if (element instanceof Field) { ReflectionUtils.makeAccessible((Field) element); return ReflectionUtils.getField((Field) element, target); } else if (element instanceof Method) { Method method = (Method) element; String name = method.getName(); if (name.startsWith("set")) { return PropertyAccessorFactory.forBeanPropertyAccess(target) .getPropertyValue(getPropertyName(name)); }/*ww w .j av a 2 s .c o m*/ } return null; }
From source file:com.ciphertool.genetics.algorithms.crossover.LowestCommonGroupUnevaluatedCrossoverAlgorithmTest.java
@Test public void testSetCoin() { Coin coinToSet = mock(Coin.class); LowestCommonGroupUnevaluatedCrossoverAlgorithm lowestCommonGroupUnevaluatedCrossoverAlgorithm = new LowestCommonGroupUnevaluatedCrossoverAlgorithm(); lowestCommonGroupUnevaluatedCrossoverAlgorithm.setCoin(coinToSet); Field coinField = ReflectionUtils.findField(LowestCommonGroupUnevaluatedCrossoverAlgorithm.class, "coin"); ReflectionUtils.makeAccessible(coinField); Coin coinFromObject = (Coin) ReflectionUtils.getField(coinField, lowestCommonGroupUnevaluatedCrossoverAlgorithm); assertSame(coinToSet, coinFromObject); }
From source file:com.ciphertool.genetics.algorithms.selection.modes.TournamentSelectorTest.java
@Test public void testSetSelectionAccuracy() { Double selectionAccuracyToSet = 0.9; TournamentSelector tournamentSelector = new TournamentSelector(); tournamentSelector.setSelectionAccuracy(selectionAccuracyToSet); Field selectionAccuracyField = ReflectionUtils.findField(TournamentSelector.class, "selectionAccuracy"); ReflectionUtils.makeAccessible(selectionAccuracyField); assertEquals(selectionAccuracyToSet, ReflectionUtils.getField(selectionAccuracyField, tournamentSelector)); }
From source file:com.ciphertool.genetics.util.KeylessChromosomeHelperTest.java
@Test public void testSetGeneDao() { KeylessChromosomeHelper keylessChromosomeHelper = new KeylessChromosomeHelper(); keylessChromosomeHelper.setGeneDao(geneDaoMock); Field geneDaoField = ReflectionUtils.findField(KeylessChromosomeHelper.class, "geneDao"); ReflectionUtils.makeAccessible(geneDaoField); GeneDao geneDaoFromObject = (GeneDao) ReflectionUtils.getField(geneDaoField, keylessChromosomeHelper); assertSame(geneDaoMock, geneDaoFromObject); }
From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHandlerRegistry.java
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) { Field registrationsField = ReflectionUtils.findField(ResourceHandlerRegistry.class, "registrations"); ReflectionUtils.makeAccessible(registrationsField); @SuppressWarnings("unchecked") List<ResourceHandlerRegistration> registrations = (List<ResourceHandlerRegistration>) ReflectionUtils .getField(registrationsField, resourceHandlerRegistry); ResourceHandlerRegistration registration = new Vfs2ResourceHandlerRegistration(applicationContext, pathPatterns);/*from www. j av a2 s .com*/ registrations.add(registration); return registration; }
From source file:de.zib.gndms.infra.system.PluggableTaskFlowProvider.java
public void loadPlugins(boolean checkDeps) { Map<String, TaskFlowFactory> plugins = new HashMap<String, TaskFlowFactory>(10); ServiceLoader<TaskFlowFactory> sl; if (getCl() != null) sl = ServiceLoader.load(TaskFlowFactory.class, getCl()); else/*from w ww . j a va2s . c om*/ sl = ServiceLoader.load(TaskFlowFactory.class); for (TaskFlowFactory bp : sl) { try { register(bp, plugins); } catch (IllegalStateException e) { logger.warn(e.getMessage()); } } setFactories(plugins); if (checkDeps) checkDeps(); // call all PostConstruct methods for (TaskFlowFactory bp : sl) { for (Method method : bp.getClass().getDeclaredMethods()) { if (method.getAnnotation(PostConstruct.class) != null) { ReflectionUtils.makeAccessible(method); try { method.invoke(bp, (Object[]) null); } catch (IllegalAccessException e) { throw new RuntimeException( "THIS IS NOT HAPPENING!!! Method had been made accessible but is not accessible anyway", e); } catch (InvocationTargetException e) { throw new RuntimeException( "Could not call PostConstruct method (" + method.toGenericString() + ")", e); } } } } // todo this is just for development change this for releases: // if ( getFactories().size() == 0 ) // throw new IllegalStateException( "no plugs found" ); }
From source file:com.ciphertool.zodiacengine.dao.SolutionDaoTest.java
@Test public void testSetMongoTemplate() { SolutionDao solutionDao = new SolutionDao(); solutionDao.setMongoTemplate(mongoTemplateMock); Field mongoOperationsField = ReflectionUtils.findField(SolutionDao.class, "mongoOperations"); ReflectionUtils.makeAccessible(mongoOperationsField); MongoOperations mongoOperationsFromObject = (MongoOperations) ReflectionUtils.getField(mongoOperationsField, solutionDao);//from w w w . j a v a 2 s .c om assertSame(mongoTemplateMock, mongoOperationsFromObject); }
From source file:de.widone.web.HomePageTest.java
@Before public void setUp() throws Exception { User user = new User(); user.setUsername("username"); user.setGroup(GroupsEnum.USER);//from ww w. j a va2 s .c o m List<TaskList> taskLists = new ArrayList<TaskList>(); TaskList taskList = new TaskList(); taskList.setInbox(Boolean.TRUE); taskList.setDescription("The default inbox"); taskLists.add(taskList); user.setTaskLists(taskLists); tester = new WicketTester(new WiDoneApplication()); when(userService.initTaskLists(Matchers.<User>any())).thenReturn(user); Field userField = ReflectionUtils.findField(WiDoneSession.class, "user"); ReflectionUtils.makeAccessible(userField); userField.set(((WiDoneSession) tester.getSession()), user); }
From source file:org.web4thejob.orm.AbstractHibernateEntity.java
@SuppressWarnings("CloneDoesntCallSuperClone") @Override/* w w w .j av a 2s. c o m*/ public Entity clone() { try { final Entity clone = (Entity) ReflectHelper.getDefaultConstructor(getClass()) .newInstance((Object[]) null); clone.addDirtyListener(dirtyListener); ReflectionUtils.doWithFields(getClass(), new ReflectionUtils.FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(field); if (!Collection.class.isAssignableFrom(field.getType())) { // don't clone one-to-many fields field.set(clone, field.get(AbstractHibernateEntity.this)); } } }, ReflectionUtils.COPYABLE_FIELDS); return clone; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Clone failed for " + toString(), e); } }
From source file:com.ciphertool.zodiacengine.dao.WordGeneDaoTest.java
@Test public void testSetWordListDao() { WordGeneDao wordGeneDao = new WordGeneDao(); wordGeneDao.setWordListDao(wordListDaoMock); Field wordListDaoField = ReflectionUtils.findField(WordGeneDao.class, "wordListDao"); ReflectionUtils.makeAccessible(wordListDaoField); WordListDao wordListDaoFromObject = (WordListDao) ReflectionUtils.getField(wordListDaoField, wordGeneDao); assertSame(wordListDaoMock, wordListDaoFromObject); }