本文整理匯總了Java中java.lang.reflect.Field.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getName方法的具體用法?Java Field.getName怎麽用?Java Field.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.reflect.Field
的用法示例。
在下文中一共展示了Field.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convert
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public Object convert(Object obj, Field field, Map<String, Object> excelRecordMap) {
logger.trace("field: " + field.getName() +
", obj: " + obj +
" run ValueConvertConvertor");
try {
Class<? extends Convertor>[] convertorClazzes = field.getAnnotation(ValueConvert.class).value();
for (Class<? extends Convertor> convertorClazz : convertorClazzes) {
Convertor convertor = convertorClazz.newInstance();
obj = convertor.convert(obj, field, excelRecordMap);
}
return obj;
} catch (Exception e) {
throw new RuntimeException("field注解ValueConvert轉換錯誤,filed:" + field.getName(), e);
}
}
示例2: setFieldValue
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static void setFieldValue(
Object obj, Field field, Asn1Type type, BerDataValue dataValue)
throws Asn1DecodingException {
try {
switch (type) {
case SET_OF:
case SEQUENCE_OF:
if (Asn1OpaqueObject.class.equals(field.getType())) {
field.set(obj, convert(type, dataValue, field.getType()));
} else {
field.set(obj, parseSetOf(dataValue, getElementType(field)));
}
return;
default:
field.set(obj, convert(type, dataValue, field.getType()));
break;
}
} catch (ReflectiveOperationException e) {
throw new Asn1DecodingException(
"Failed to set value of " + obj.getClass().getName()
+ "." + field.getName(),
e);
}
}
示例3: injectFields
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static Object injectFields(Object bean,
IServiceConfiguration config,
IPropertyResolver propertyresolver) throws Exception {
if (config.getInjectionStrategy() == InjectionStrategy.Default) {
for (Field f : bean.getClass().getDeclaredFields()) {
String propertyUri = f.getName() + ":undefined";
String value = propertyresolver.lookupProperty(propertyUri);
if (!"undefined".equals(value)) {
Object convertedValue = propertyresolver.lookupProperty(f.getType(),propertyUri);
f.setAccessible(true);
f.set(bean, convertedValue);
}
}
}
return bean;
}
示例4: convert
import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public Object convert(Object obj, Field field, Map<String, Object> excelRecordMap) {
logger.trace("field: " + field.getName() +
", obj: " + obj +
" run DateFormatConvertor");
if (obj == null) return null;
if (obj instanceof Date) return obj;
Date date;
try {
String dateFormat = field.getAnnotation(DateFormat.class).value();
if (StringUtils.isBlank(dateFormat))
throw new RuntimeException("field注解DateFormat值為空,filed:" + field.getName());
logger.debug(dateFormat);
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
date = sdf.parse(obj.toString());
return date;
} catch (Exception e) {
throw new RuntimeException("field注解DateFormat轉換錯誤,filed:" + field.getName(), e);
}
}
示例5: getBackLinkFieldName
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static final <O extends Model, T extends Model> String getBackLinkFieldName(
Class<O> originClass,
Class<T> targetClass
) {
Field fk = null;
try {
fk = getForeignKeyField(targetClass, originClass, getInstace(originClass));
} catch (IllegalAccessException e) {
Log.e(TAG, "an exception has been thrown trying to gather the foreign key field pointing to "
+ targetClass.getSimpleName()
+ " from origin class "
+ originClass.getSimpleName(), e);
}
if(fk != null) {
return fk.getName();
}
return null;
}
示例6: validateField
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void validateField(Field field, Object target) throws IllegalArgumentException, IllegalAccessException {
field.setAccessible(true);
Object value = field.get(target);
if (field.isAnnotationPresent(NetoNotNull.class)) {
if (value == null) {
throw new ValidationException(Constants.StatusCode.PARAMETER_NULL, field.getName() + " is null");
}
} else if (field.isAnnotationPresent(NetoNotNullOrNotEmpty.class)) {
if (value == null) {
throw new ValidationException(Constants.StatusCode.PARAMETER_NULL, field.getName() + " is null");
}
if (value instanceof String && (value == null || ((String) value).isEmpty())) {
throw new ValidationException(Constants.StatusCode.PARAMETER_NULL_OR_EMPTY, field.getName() + " is null or empty");
}
}
}
示例7: getFieldMap
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Map getFieldMap(Class cls) {
Map map = new HashMap();
Field[] fields = cls.getDeclaredFields();
int size = fields.length;
for (int i = 0; i < size; i++) {
Field field = fields[i];
MicroMappingAnno anno = field.getAnnotation(MicroMappingAnno.class);
if (anno == null) {
continue;
}
String keyName = anno.name();
String fieldName = field.getName();
map.put(fieldName, keyName);
}
return map;
}
示例8: logDeserializeError
import java.lang.reflect.Field; //導入方法依賴的package包/類
static void logDeserializeError(Field field, Object obj, Object value,
Throwable e)
throws IOException
{
String fieldName = (field.getDeclaringClass().getName()
+ "." + field.getName());
if (e instanceof HessianFieldException)
throw (HessianFieldException) e;
else if (e instanceof IOException)
throw new HessianFieldException(fieldName + ": " + e.getMessage(), e);
if (value != null)
throw new HessianFieldException(fieldName + ": " + value.getClass().getName() + " (" + value + ")"
+ " cannot be assigned to '" + field.getType().getName() + "'", e);
else
throw new HessianFieldException(fieldName + ": " + field.getType().getName() + " cannot be assigned from null", e);
}
示例9: getConstantName
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Gets user-friendly name of the public static final constant defined in a
* class or an interface for display purpose.
*
* @param value the constant value
* @param c type of class or interface
* @return name
*/
public static String getConstantName(Object value, Class c) {
for (Field f : c.getDeclaredFields()) {
int mod = f.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && Modifier.isFinal(mod)) {
try {
if (f.get(null).equals(value)) {
return f.getName();
}
} catch (IllegalAccessException e) {
return String.valueOf(value);
}
}
}
return String.valueOf(value);
}
示例10: validateConstants
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* Implements 1.2.3 #6
*/
private void validateConstants(final Class c)
throws IDLTypeException {
Field[] fields = null;
try {
fields = (Field[])
java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
return c.getFields();
}
});
} catch(java.security.PrivilegedActionException pae) {
IDLTypeException ite = new IDLTypeException();
ite.initCause(pae);
throw ite;
}
for(int i = 0; i < fields.length; i++) {
Field next = fields[i];
Class fieldType = next.getType();
if( (fieldType != java.lang.String.class) &&
!isPrimitive(fieldType) ) {
String msg = "Constant field '" + next.getName() +
"' in class '" + next.getDeclaringClass().getName() +
"' has invalid type' " + next.getType() + "'. Constants" +
" in RMI/IIOP interfaces can only have primitive" +
" types and java.lang.String types.";
throw new IDLTypeException(msg);
}
}
return;
}
示例11: MemberName
import java.lang.reflect.Field; //導入方法依賴的package包/類
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Field fld, boolean makeSetter) {
Objects.requireNonNull(fld);
// fill in vmtarget, vmindex while we have fld in hand:
MethodHandleNatives.init(this, fld);
assert(isResolved() && this.clazz != null);
this.name = fld.getName();
this.type = fld.getType();
assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField));
byte refKind = this.getReferenceKind();
assert(refKind == (isStatic() ? REF_getStatic : REF_getField));
if (makeSetter) {
changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind);
}
}
示例12: calOptionName
import java.lang.reflect.Field; //導入方法依賴的package包/類
private static String calOptionName(Option option, Field field) {
if (option.option().length() == 0) {
return field.getName();
} else {
return option.option();
}
}
示例13: printObjectProperties
import java.lang.reflect.Field; //導入方法依賴的package包/類
public static void printObjectProperties(final Logger log, final Object object, final boolean onlyImportantField) {
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
String name = field.getName();
if (!name.startsWith("this")) {
Object value = null;
try {
field.setAccessible(true);
value = field.get(object);
if (null == value) {
value = "";
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (onlyImportantField) {
Annotation annotation = field.getAnnotation(ImportantField.class);
if (null == annotation) {
continue;
}
}
if (log != null) {
log.info(name + "=" + value);
}
}
}
}
}
示例14: setFieldValue
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* 設置bean 屬性值
*
* @param map
* @param bean
* @throws Exception
*/
public static void setFieldValue(Map<Object, Object> map, Object bean) throws Exception {
Class<?> cls = bean.getClass();
Method methods[] = cls.getDeclaredMethods();
Field fields[] = cls.getDeclaredFields();
for (Field field : fields) {
String fldtype = field.getType().getSimpleName();
String fldSetName = field.getName();
String setMethod = pareSetName(fldSetName);
if (!checkMethod(methods, setMethod)) {
continue;
}
if (!map.containsKey(fldSetName)) {
continue;
}
Object value = map.get(fldSetName);
System.out.println(value.toString());
Method method = cls.getMethod(setMethod, field.getType());
System.out.println(method.getName());
if (null != value) {
if ("String".equals(fldtype)) {
method.invoke(bean, (String) value);
} else if ("Double".equals(fldtype)) {
method.invoke(bean, (Double) value);
} else if ("int".equals(fldtype)) {
int val = Integer.valueOf((String) value);
method.invoke(bean, val);
} else {
method.invoke(bean, value);
}
}
}
}
示例15: makeCustomHeaderToNet
import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
* 編碼過程
*/
public void makeCustomHeaderToNet() {
if (this.customHeader != null) {
Field[] fields = getClazzFields(customHeader.getClass());
if (null == this.extFields) {
this.extFields = new HashMap<String, String>();
}
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers())) {
String name = field.getName();
if (!name.startsWith("this")) {
Object value = null;
try {
field.setAccessible(true);
value = field.get(this.customHeader);
} catch (Exception e) {
log.error("Failed to access field [{}]", name, e);
}
if (value != null) {
this.extFields.put(name, value.toString());
}
}
}
}
}
}