List of usage examples for org.springframework.util ReflectionUtils setField
public static void setField(Field field, @Nullable Object target, @Nullable Object value)
From source file:com.qcadoo.maven.plugins.jetty.JettyMojo.java
private void setField(final String name, final Object value) { Field field = ReflectionUtils.findField(getClass(), name); ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, this, value); }
From source file:com.agapple.asyncload.impl.pool.AsyncLoadThreadPool.java
private void initThreadLocal(Field field, Thread caller, Thread runner) { if (caller == null || runner == null) { return;/*from ww w . jav a2 s.co m*/ } // ? // 1. callerThreadLocalrunnerThreadLocal??caller // 2. ?caller,runnerThreadLocal?,set?ThreadLocal,???? // ??Runnable??ThreadLocalMaprunner???caller?????? // threadlocal?,?? Object callerThreadLocalMap = ReflectionUtils.getField(field, caller); if (callerThreadLocalMap != null) { ReflectionUtils.setField(field, runner, callerThreadLocalMap);// ?caller?runner } else { // ?,execute??? } }
From source file:com.agapple.asyncload.impl.pool.AsyncLoadThreadPool.java
private void recoverThreadLocal(Field field, Thread caller, Thread runner) { if (runner == null) { return;/* www . j a va 2 s . c o m*/ } // ?runnerThreadLocaltask? ReflectionUtils.setField(field, runner, null); }
From source file:com.ciphertool.zodiacengine.fitness.AbstractSolutionEvaluatorBaseTest.java
@Test public void testClearHasMatchValues_NullSolution() { ConcreteSolutionEvaluatorBase abstractSolutionEvaluatorBase = new ConcreteSolutionEvaluatorBase(); Field logField = ReflectionUtils.findField(ConcreteSolutionEvaluatorBase.class, "log"); Logger mockLogger = mock(Logger.class); ReflectionUtils.makeAccessible(logField); ReflectionUtils.setField(logField, abstractSolutionEvaluatorBase, mockLogger); abstractSolutionEvaluatorBase.clearHasMatchValues(null); verify(mockLogger, times(1))/*from w w w . j a v a 2 s . c om*/ .warn("Attempted to clear hasMatch values, but the SolutionChromosome was null. Returning early."); }
From source file:org.ff4j.spring.autowire.AutowiredFF4JBeanPostProcessor.java
private void injectValue(Field field, Object currentBean, String propName, Object propValue) { // Set as true for modifications ReflectionUtils.makeAccessible(field); // Update property ReflectionUtils.setField(field, currentBean, propValue); logger.debug("Injection of property '" + propName + "' on " + currentBean.getClass().getName() + "." + field.getName());/* w w w . j av a 2 s . com*/ }
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.OsgiAnnotationHandlerMapping.java
/** * Clear all handler mappings. Spring made the 'handlerMap' unmodifiable, * so we must resort to reflection.//from www . ja v a 2 s. com */ protected void clearHandlerMappings() { Field field; try { field = AbstractUrlHandlerMapping.class.getDeclaredField("handlerMap"); field.setAccessible(true); } catch (Exception e) { throw new RuntimeException(e); } ReflectionUtils.setField(field, OsgiAnnotationHandlerMapping.this, new LinkedHashMap<String, Object>()); }
From source file:com.groupon.jenkins.dynamic.build.DynamicSubProject.java
@Override public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { try {/*from www . ja v a 2 s. c o m*/ Field parentField = AbstractItem.class.getDeclaredField("parent"); parentField.setAccessible(true); ReflectionUtils.setField(parentField, this, parent); } catch (Exception e) { throw new RuntimeException(e); } doSetName(name); if (transientActions == null) { transientActions = new Vector<Action>(); } updateTransientActions(); getBuildersList().setOwner(this); getPublishersList().setOwner(this); getBuildWrappersList().setOwner(this); initRepos(); }
From source file:de.extra.client.core.builder.impl.MessageBuilderLocatorTest.java
/** * Setzt eine Value ber ReflectionUtils/*from w ww. j a v a 2 s. c om*/ * * @param messageBuilderLocator * @param rootElementsBuilderMap * @param string */ private void injectValue(final Object object, final Object value, final String fieldName) { final Field fieldToSet = ReflectionUtils.findField(object.getClass(), fieldName); ReflectionUtils.makeAccessible(fieldToSet); ReflectionUtils.setField(fieldToSet, object, value); }
From source file:com.ciphertool.zodiacengine.service.GeneticCipherSolutionServiceTest.java
@Test public void testBegin_DebugMode() throws IOException { GeneticCipherSolutionService geneticCipherSolutionService = new GeneticCipherSolutionService(); GeneticAlgorithm geneticAlgorithm = mock(GeneticAlgorithm.class); Population population = new Population(); SolutionChromosome solutionChromosome = new SolutionChromosome(); solutionChromosome.setEvaluationNeeded(false); population.addIndividual(solutionChromosome); when(geneticAlgorithm.getPopulation()).thenReturn(population); geneticCipherSolutionService.setGeneticAlgorithm(geneticAlgorithm); GenericCallback genericCallbackMock = mock(GenericCallback.class); GeneticAlgorithmStrategy geneticAlgorithmStrategy = new GeneticAlgorithmStrategy(); Runtime runtimeMock = mock(Runtime.class); Field runtimeField = ReflectionUtils.findField(GeneticCipherSolutionService.class, "runtime"); ReflectionUtils.makeAccessible(runtimeField); ReflectionUtils.setField(runtimeField, geneticCipherSolutionService, runtimeMock); String[] commandsBefore = { "command3", "command4" }; geneticCipherSolutionService.setCommandsBefore(commandsBefore); assertFalse(geneticCipherSolutionService.isRunning()); geneticCipherSolutionService.begin(geneticAlgorithmStrategy, genericCallbackMock, true); assertTrue(geneticCipherSolutionService.isRunning()); verify(runtimeMock, times(1)).exec(eq("command3")); verify(runtimeMock, times(1)).exec(eq("command4")); verifyNoMoreInteractions(runtimeMock); verifyZeroInteractions(genericCallbackMock); verify(geneticAlgorithm, times(1)).initialize(); verify(geneticAlgorithm, times(1)).getPopulation(); verify(geneticAlgorithm, times(1)).proceedWithNextGeneration(); verify(geneticAlgorithm, times(1)).setStrategy(same(geneticAlgorithmStrategy)); }
From source file:com.ciphertool.genetics.algorithms.ConcurrentMultigenerationalGeneticAlgorithmTest.java
@SuppressWarnings("unchecked") @Test//w w w.j a v a2 s. co m public void testCrossover_SmallPopulation() { ConcurrentMultigenerationalGeneticAlgorithm concurrentMultigenerationalGeneticAlgorithm = new ConcurrentMultigenerationalGeneticAlgorithm(); Population population = new Population(); Chromosome chromosome = new MockKeylessChromosome(); population.addIndividual(chromosome); concurrentMultigenerationalGeneticAlgorithm.setPopulation(population); CrossoverAlgorithm crossoverAlgorithmMock = mock(CrossoverAlgorithm.class); Field crossoverAlgorithmField = ReflectionUtils.findField(ConcurrentMultigenerationalGeneticAlgorithm.class, "crossoverAlgorithm"); ReflectionUtils.makeAccessible(crossoverAlgorithmField); ReflectionUtils.setField(crossoverAlgorithmField, concurrentMultigenerationalGeneticAlgorithm, crossoverAlgorithmMock); Field ineligibleForReproductionField = ReflectionUtils.findField(Population.class, "ineligibleForReproduction"); ReflectionUtils.makeAccessible(ineligibleForReproductionField); List<Chromosome> ineligibleForReproductionFromObject = (List<Chromosome>) ReflectionUtils .getField(ineligibleForReproductionField, population); assertEquals(0, ineligibleForReproductionFromObject.size()); int childrenProduced = concurrentMultigenerationalGeneticAlgorithm.crossover(10); ineligibleForReproductionFromObject = (List<Chromosome>) ReflectionUtils .getField(ineligibleForReproductionField, population); assertEquals(1, population.size()); assertEquals(0, ineligibleForReproductionFromObject.size()); assertEquals(0, childrenProduced); verifyZeroInteractions(crossoverAlgorithmMock); }