本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.getDeclaredField方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.getDeclaredField方法的具体用法?Java FieldUtils.getDeclaredField怎么用?Java FieldUtils.getDeclaredField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.getDeclaredField方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateTransformTaskConfig
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Update the parameters for the transformTask
*
* @param transformTask
* @param consumedInputStreams
* @param referencedInputStreams
* @param outputStream
*/
private void updateTransformTaskConfig(TransformTask transformTask,
@NonNull Collection<TransformStream> consumedInputStreams,
@NonNull Collection<TransformStream> referencedInputStreams,
@Nullable IntermediateStream outputStream) throws IllegalAccessException {
Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"consumedInputStreams",
true);
Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"referencedInputStreams",
true);
Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"outputStream",
true);
if (null == consumedInputStreamsField ||
null == referencedInputStreamsField ||
null == outputStreamField) {
throw new StopExecutionException(
"The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!");
}
consumedInputStreamsField.set(transformTask, consumedInputStreams);
referencedInputStreamsField.set(transformTask, referencedInputStreams);
outputStreamField.set(transformTask, outputStream);
}
示例2: getTransformParam
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Gets the parameters of a transformTask
*
* @param transformTask
* @return
* @throws IllegalAccessException
*/
private TransformTaskParam getTransformParam(TransformTask transformTask) throws IllegalAccessException {
TransformTaskParam transformTaskParam = new TransformTaskParam();
Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"consumedInputStreams",
true);
Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"referencedInputStreams",
true);
Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class,
"outputStream",
true);
if (null == consumedInputStreamsField ||
null == referencedInputStreamsField ||
null == outputStreamField) {
throw new StopExecutionException(
"The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!");
}
transformTaskParam.consumedInputStreams = (Collection<TransformStream>) consumedInputStreamsField
.get(transformTask);
transformTaskParam.referencedInputStreams = (Collection<TransformStream>) referencedInputStreamsField
.get(transformTask);
transformTaskParam.outputStream = (IntermediateStream) outputStreamField.get(transformTask);
return transformTaskParam;
}
示例3: getTargetField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static Field getTargetField(Class<?> targetClass, String fieldName) {
Field field = null;
try {
if (targetClass == null) {
return field;
}
if (Object.class.equals(targetClass)) {
return field;
}
field = FieldUtils.getDeclaredField(targetClass, fieldName, true);
if (field == null) {
field = getTargetField(targetClass.getSuperclass(), fieldName);
}
} catch (Exception e) {
}
return field;
}
示例4: getConstantValue
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Nullable
private static <T> T getConstantValue(String fieldName, Class<T> valueClass, Class<?> clazz) {
Class<?> implClass = buildImplClass(clazz);
if (implClass == null) {
return null;
}
Field field = FieldUtils.getDeclaredField(clazz, fieldName);
if (field == null) {
return null;
}
try {
return valueClass.cast(FieldUtils.readStaticField(field));
} catch (IllegalAccessException e) {
throw new SdcctException(String.format("Unable to read datatype (class=%s, implClass=%s) constant declared field (name=%s) value (class=%s).",
clazz, implClass, fieldName, valueClass), e);
}
}
示例5: readAnnotations
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private static void readAnnotations(List<Annotation> l, Class<?> type, String name) {
Column ao = getAttributeOverride(type, name);
if (ao != null) {
l.add(ao);
}
Field field = FieldUtils.getDeclaredField(type, name, true);
if (field != null) {
addAll(l, field.getAnnotations());
}
PropertyDescriptor pd = getPropertyDescriptor(type, name);
if (pd != null) {
if (pd.getReadMethod() != null) {
addAll(l, pd.getReadMethod().getAnnotations());
}
}
if (type.getSuperclass() != null) {
readAnnotations(l, type.getSuperclass(), name);
}
}
示例6: checkPlugin
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected boolean checkPlugin(Class<?> clazz, Context context){
Field field = FieldUtils.getDeclaredField(Context.class,"pluginConfigurations",true);
try {
List<PluginConfiguration> pluginConfigurations = (List<PluginConfiguration>) field.get(context);
for(PluginConfiguration pluginConfiguration : pluginConfigurations){
if(pluginConfiguration.getConfigurationType().equals(clazz.getTypeName())){
return true;
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
示例7: test1
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Test 1.
*/
@Test
public void test1(){
Field field = FieldUtils.getDeclaredField(DangaMemCachedConfig.class, "serverList", true);
Alias alias = field.getAnnotation(Alias.class);
assertEquals(
"@com.feilong.core.bean.Alias(name=memcached.serverlist, sampleValue=172.20.31.23:11211,172.20.31.22:11211)",
annotationToStringBuilder.build(alias));
}
示例8: readPrivateStatic
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Read private static field on given class.
*
* @param klass The class.
* @param name The field name.
* @param <T> Type of returned value.
* @return The field value.
*/
public static <T> T readPrivateStatic(Class<?> klass, String name) {
Field field = FieldUtils.getDeclaredField(klass, name, true);
FieldUtils.removeFinalModifier(field);
try {
@SuppressWarnings("unchecked")
T value = (T) FieldUtils.readStaticField(field, true);
return value;
} catch (IllegalAccessException ex) {
throw new AssertionError(ex);
}
}
示例9: writeStaticFinal
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Write value on given static final field.
*
* @param klass The class.
* @param name The field name.
* @param value The new field value.
*/
public static void writeStaticFinal(Class<?> klass, String name, Object value) {
Field field = FieldUtils.getDeclaredField(klass, name, true);
FieldUtils.removeFinalModifier(field);
try {
FieldUtils.writeStaticField(field, value, true);
} catch (IllegalAccessException ex) {
throw new AssertionError(ex);
}
}
示例10: assertFieldMatchType
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Assert Field type match
*
* @param object
* Object
* @param fieldName
* field name
* @param expectedType
* expected type
* @throws IllegalArgumentException
* if type is not matched
*/
public static void assertFieldMatchType(Object object, String fieldName, Class<?> expectedType) throws IllegalArgumentException {
Class<?> type = object.getClass();
Field field = FieldUtils.getDeclaredField(type, fieldName, true);
Class<?> fieldType = field.getType();
if (!expectedType.isAssignableFrom(fieldType)) {
String message = String.format("The type[%s] of field[%s] in Class[%s] can't match expected type[%s]", fieldType.getName(), fieldName, type.getName(), expectedType.getName());
throw new IllegalArgumentException(message);
}
}