List of usage examples for java.lang.reflect Field getName
public String getName()
From source file:com.stratio.deep.commons.utils.AnnotationUtils.java
/** * Returns the value of the fields <i>deepField</i> in the instance <i>entity</i> of type T. * * @param entity the entity to process. * @param deepField the Field to process belonging to <i>entity</i> * @return the property value./*www .j a v a2 s . c o m*/ */ public static Serializable getBeanFieldValue(IDeepType entity, Field deepField) { try { return (Serializable) PropertyUtils.getProperty(entity, deepField.getName()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) { throw new DeepIOException(e1); } }
From source file:com.edmunds.autotest.ClassUtil.java
public static Map<String, Field> getAllDeclaredFieldsMap(Class originalCls, boolean lowercase, AutoTestConfig config) {/* w ww .ja v a 2 s .co m*/ Map<String, Field> fields = new HashMap<String, Field>(); Class cls = originalCls; do { for (Field field : cls.getDeclaredFields()) { String fieldName = field.getName(); if (lowercase) { fieldName = fieldName.toLowerCase(); } if (fields.containsKey(fieldName)) { if (isDeclaredUnderRootPackage(config, field) && !config.getFieldOverrideExceptions().contains(field.getName())) { String msg = "Instance variable (" + field.getName() + ") has been overridden: " + originalCls.getName(); log.warn(msg); if (config.isFailOnFieldOverride()) { fail(msg); } } } else { fields.put(fieldName, field); } } cls = cls.getSuperclass(); } while (cls != null); return fields; }
From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java
public static Map generateMapFromConfig(Class toResolve) { Map valuesMap = new HashMap(); List<Field> fields = getOnlyFields(toResolve); for (Field field : fields) { String val = getConfig().getString(field.getName()); if (val != null && val.length() > 0) { valuesMap.put(field.getName(), val); }// w w w. j av a 2 s. co m } return valuesMap; }
From source file:com.hand.hap.mybatis.util.OGNL.java
/** * FOR INTERNAL USE ONLY/* w w w .j a v a 2 s . c o m*/ * * @param parameter * @return */ public static String getOrderByClause_TL(Object parameter) { if (parameter == null) { return null; } StringBuilder sb = new StringBuilder(64); if (parameter instanceof BaseDTO) { String sortName = ((BaseDTO) parameter).getSortname(); Field[] ids = DTOClassInfo.getIdFields(parameter.getClass()); if (StringUtil.isNotEmpty(sortName)) { if (!COL_PATTERN.matcher(sortName).matches()) { throw new RuntimeException("Invalid sortname:" + sortName); } String order = ((BaseDTO) parameter).getSortorder(); if (!("ASC".equalsIgnoreCase(order) || "DESC".equalsIgnoreCase(order) || order == null)) { throw new RuntimeException("Invalid sortorder:" + order); } String columnName = unCamel(sortName); Field[] mlfs = DTOClassInfo.getMultiLanguageFields(parameter.getClass()); for (Field f : mlfs) { if (f.getName().equals(columnName)) { if (f.getAnnotation(MultiLanguageField.class) == null) { sb.append("b."); } else { sb.append("t."); } break; } } sb.append(columnName).append(" "); sb.append(StringUtils.defaultIfEmpty(order, "ASC")); if (ids.length > 0 && !ids[0].getName().equals(sortName)) { sb.append(",b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC"); } } else { if (ids.length > 0) { sb.append("b.").append(DTOClassInfo.getColumnName(ids[0])).append(" ASC"); } } } return StringUtils.trimToNull(sb.toString()); }
From source file:com.pmarlen.model.controller.EntityJPAToPlainPojoTransformer.java
public static void copyPlainValues(Entity entity, Object plain) { final Class entityClass; entityClass = entity.getClass();//from w w w . java 2s . c o m final String entityClassName = entityClass.getName(); Hashtable<String, Object> propertiesToCopy = new Hashtable<String, Object>(); Hashtable<String, Object> propertiesM2MToCopy = new Hashtable<String, Object>(); List<String> propertiesWithNULLValueToCopy = new ArrayList<String>(); List<String> propertiesKey = new ArrayList<String>(); try { final Field[] declaredFields = entityClass.getDeclaredFields(); for (Field f : declaredFields) { logger.trace("->create: \tcopy: " + entityClassName + "." + f.getName() + " accesible ? " + (f.isAccessible())); if (!f.isAccessible()) { if (f.isAnnotationPresent(javax.persistence.Id.class)) { propertiesKey.add(f.getName()); } if (f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.GeneratedValue.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t ID elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && !f.isAnnotationPresent(javax.persistence.OneToMany.class) && !f.isAnnotationPresent(javax.persistence.ManyToMany.class) && !Modifier.isStatic(f.getModifiers())) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } else if (!f.isAnnotationPresent(javax.persistence.Id.class) && f.isAnnotationPresent(javax.persistence.ManyToMany.class)) { Object valueCopyed = PropertyUtils.getProperty(entity, f.getName()); if (valueCopyed != null) { propertiesM2MToCopy.put(f.getName(), valueCopyed); } else { propertiesWithNULLValueToCopy.add(f.getName()); } logger.trace("->create:\t\t M2M elegible 2 be copied, added to copy list: " + f.getName() + " = " + valueCopyed + ", is really null?" + (valueCopyed == null)); } } } logger.trace("->create:copy values ?"); for (String p2c : propertiesToCopy.keySet()) { Object valueCopyed = propertiesToCopy.get(p2c); logger.trace("->create:\t\t copy value with SpringUtils: " + p2c + " = " + valueCopyed + ", is null?" + (valueCopyed == null)); BeanUtils.copyProperty(plain, p2c, valueCopyed); } for (String p2c : propertiesWithNULLValueToCopy) { logger.trace("->create:\t\t copy null with SpringUtils"); BeanUtils.copyProperty(plain, p2c, null); } } catch (Exception e) { logger.error("..in copy", e); } }
From source file:com.softfeeder.rules.core.Utils.java
/** * //from ww w .j a va 2 s . c o m * @param context * @param target */ public static void fieldsInjection(RuleContext context, Object target) { if (context != null) { for (Field field : target.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(Inject.class)) { try { BeanUtils.setProperty(target, field.getName(), context.getValue(field.getName())); } catch (InvocationTargetException | IllegalAccessException ex) { LOG.info(String.format("Invalid field injection %s", ex.getMessage())); } } } } }
From source file:com.antsdb.saltedfish.sql.ExternalTable.java
public static <T> ExternalTable wrap(Orca orca, String namespace, Class<T> klass, Iterable<T> iterable) { ClassBasedTable<T> table = new ClassBasedTable<>(); table.source = iterable;/*from w ww. j a v a 2 s .c om*/ table.meta.setNamespace(namespace).setTableName(iterable.getClass().getSimpleName()); List<ColumnMeta> columns = new ArrayList<>(); for (Field i : klass.getFields()) { ColumnMeta column = new ColumnMeta(orca.getTypeFactory(), new SlowRow(0)); column.setColumnName(i.getName()).setId(table.meta.getColumns().size()); if (i.getType() == String.class) { column.setType(DataType.varchar()); } else if (i.getType() == int.class) { column.setType(DataType.integer()); } else if (i.getType() == long.class) { column.setType(DataType.longtype()); } else { throw new NotImplementedException(); } columns.add(column); table.fields.add(i); } table.meta.setColumns(columns); return table; }
From source file:com.mmj.app.common.file.ExcelUtils.java
/** * ?BeanMAP//from w w w . j av a 2 s . c o m */ public static Map<String, String> getFieldValueMap(Object bean) { Class<?> cls = bean.getClass(); Map<String, String> valueMap = new LinkedHashMap<String, String>(); Field[] fields = getAllFields(new ArrayList<Field>(), cls); for (Field field : fields) { try { if (field == null || field.getName() == null) { continue; } if (StringUtils.equals("serialVersionUID", field.getName())) { continue; } Object fieldVal = PropertyUtils.getProperty(bean, field.getName()); String result = null; if (null != fieldVal) { if (StringUtils.equals("Date", field.getType().getSimpleName())) { result = DateViewTools.format((Date) fieldVal, "yyyy-MM-dd HH:mm:ss"); } else { result = String.valueOf(fieldVal); } } valueMap.put(field.getName(), result == null ? StringUtils.EMPTY : result); } catch (Exception e) { log.error(e.getMessage(), e); continue; } } return valueMap; }
From source file:com.google.api.ads.dfp.lib.utils.v201208.PqlUtils.java
/** * Gets the underlying value of the {@link Value} object. * * @param value the {@code Value} object to get the value from * @return the underlying value/* w w w . j a v a 2 s.c om*/ * @throws IllegalArgumentException if {@code value == null} * @throws IllegalAccessException if the value field cannot be accessed */ public static Object getValue(Value value) throws IllegalAccessException { if (value == null) { throw new IllegalArgumentException("Value object cannot be null."); } Field[] fields = value.getClass().getDeclaredFields(); for (Field field : fields) { if (field.getName().equals("value")) { field.setAccessible(true); return field.get(value); } } throw new IllegalArgumentException("No value field found in value object."); }
From source file:net.minder.config.impl.DefaultConfigurationInjector.java
private static String getConfigName(Field field, Alias tag) { return pickName(field.getName(), tag); }