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.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); }
From source file:org.grails.datastore.mapping.keyvalue.mapping.config.AnnotationKeyValueMappingFactory.java
@Override public KeyValue createMappedForm(PersistentProperty mpp) { final Class javaClass = mpp.getOwner().getJavaClass(); final ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); final PropertyDescriptor pd = cpf.getPropertyDescriptor(mpp.getName()); final KeyValue kv = super.createMappedForm(mpp); Index index = AnnotationUtils.getAnnotation(pd.getReadMethod(), Index.class); if (index == null) { final Field field = ReflectionUtils.findField(javaClass, mpp.getName()); if (field != null) { ReflectionUtils.makeAccessible(field); index = field.getAnnotation(Index.class); }// w w w. j a v a 2 s. c om } if (index != null) { kv.setIndex(true); } return kv; }
From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHandlerRegistration.java
@Override protected ResourceHttpRequestHandler getRequestHandler() { Field locationsField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "locations"); ReflectionUtils.makeAccessible(locationsField); @SuppressWarnings("unchecked") List<Resource> locations = (List<Resource>) ReflectionUtils.getField(locationsField, this); Field cachePeriodField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "cachePeriod"); ReflectionUtils.makeAccessible(cachePeriodField); Integer cachePeriod = (Integer) ReflectionUtils.getField(cachePeriodField, this); // Initial code is replace by a new Vfs2ResourceHttpRequestHandler() Assert.isTrue(!CollectionUtils.isEmpty(locations), "At least one location is required for resource handling."); ResourceHttpRequestHandler requestHandler = new Vfs2ResourceHttpRequestHandler(); requestHandler.setLocations(locations); if (cachePeriod != null) { requestHandler.setCacheSeconds(cachePeriod); }/*from w w w . j ava 2 s. c om*/ return requestHandler; }
From source file:com.ciphertool.sentencebuilder.etl.parsers.FrequencyFileParserTest.java
@Test public void testSetFilename() { String fileNameToSet = "arbitraryFileName"; FrequencyFileParser frequencyFileParser = new FrequencyFileParser(); frequencyFileParser.setFileName(fileNameToSet); Field fileNameField = ReflectionUtils.findField(FrequencyFileParser.class, "fileName"); ReflectionUtils.makeAccessible(fileNameField); String fileNameFromObject = (String) ReflectionUtils.getField(fileNameField, frequencyFileParser); assertSame(fileNameToSet, fileNameFromObject); }
From source file:com.orange.clara.cloud.boot.ssl.SslDefaultTrustStoreAppenderListenerTest.java
@Before public void setup() throws IllegalArgumentException, IllegalAccessException { sslTrustStoreGeneratorListener = new SslTrustStoreGeneratorListener(); Field envField = ReflectionUtils.findField(SslTrustStoreGeneratorListener.class, "propertyResolver"); ReflectionUtils.makeAccessible(envField); ReflectionUtils.setField(envField, sslTrustStoreGeneratorListener, propertyResolver); Field sslCertTrusterField = ReflectionUtils.findField(SslTrustStoreGeneratorListener.class, "trustStoreAppender"); ReflectionUtils.makeAccessible(sslCertTrusterField); ReflectionUtils.setField(sslCertTrusterField, sslTrustStoreGeneratorListener, trustStoreAppender); }
From source file:com.ciphertool.sentencebuilder.etl.parsers.PartOfSpeechFileParserTest.java
@Test public void testSetFilename() { String fileNameToSet = "arbitraryFileName"; PartOfSpeechFileParser partOfSpeechFileParser = new PartOfSpeechFileParser(); partOfSpeechFileParser.setFileName(fileNameToSet); Field fileNameField = ReflectionUtils.findField(PartOfSpeechFileParser.class, "fileName"); ReflectionUtils.makeAccessible(fileNameField); String fileNameFromObject = (String) ReflectionUtils.getField(fileNameField, partOfSpeechFileParser); assertSame(fileNameToSet, fileNameFromObject); }
From source file:org.jboss.instrument.classloading.JBossModulesLoadTimeWeaver.java
public void addTransformer(ClassFileTransformer transformer) { try {/*from w w w .j ava 2 s .c o m*/ Field transformers = ReflectionUtils.findField(classLoader.getClass(), "transformer"); transformers.setAccessible(true); Object delegatingTransformer = transformers.get(classLoader); Method ADD_TRANSFORMER = ReflectionUtils.findMethod(delegatingTransformer.getClass(), "addTransformer", new Class<?>[] { ClassFileTransformer.class }); ADD_TRANSFORMER.setAccessible(true); ADD_TRANSFORMER.invoke(delegatingTransformer, transformer); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.web4thejob.orm.serial.MyXStreamMarshaller.java
private void customizeMappers(XStream xstream) { // huge HACK since there seems to be no direct way of adding // HibernateMapper final Converter reflectionConverter = xstream.getConverterLookup().lookupConverterForType(Entity.class); if (!ReflectionConverter.class.isInstance(reflectionConverter)) throw new IllegalStateException("expected " + ReflectionConverter.class.getName() + " but got " + reflectionConverter.getClass().getName()); final Field field = ReflectionUtils.findField(ReflectionConverter.class, "mapper"); ReflectionUtils.makeAccessible(field); CachingMapper mapper = (CachingMapper) ReflectionUtils.getField(field, reflectionConverter); mapper = new CachingMapper(new MyHibernateMapper(mapper)); ReflectionUtils.setField(field, reflectionConverter, mapper); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsNtlmProcessingFilterEntryPoint.java
private Object getFieldValue(final String name) throws IllegalAccessException { Field field = ReflectionUtils.findField(NtlmProcessingFilter.class, name); field.setAccessible(true);/*from ww w .j a va 2 s . com*/ return field.get(null); }
From source file:com.couchbase.spring.core.mapping.BasicCouchbasePersistentPropertyTest.java
/** * Verifies the name of the property without annotations. *//*from w w w . jav a 2s .c o m*/ @Test public void usesPropertyFieldName() { Field field = ReflectionUtils.findField(Beer.class, "description"); assertEquals("description", getPropertyFor(field).getFieldName()); }