Java Code Examples for org.apache.commons.beanutils.BeanUtils.describe()

The following are Jave code examples for showing how to use describe() of the org.apache.commons.beanutils.BeanUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jambo2   File: SQLHelper.java   View Source Code Vote up 6 votes
protected Map getConditions(Object param) throws IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {

    // 静态条件部分
    Map props = BeanUtils.describe(param);

    // new 动态条件部分 add by hekun
    if (param instanceof DBQueryParam) {
        DBQueryParam listVO = (DBQueryParam) param;
        Map queryConditions = listVO.getQueryConditions();

        if (queryConditions != null && queryConditions.size() > 0) {
            // 将静态条件加入动态条件中,重复的动态条件及其值将被覆盖。
            for (Iterator keys = props.keySet().iterator(); keys.hasNext(); ) {
                String key = (String) keys.next();
                Object value = props.get(key);
                if (key.startsWith("_") && value != null)
                    queryConditions.put(key, value);
            }
            props = queryConditions;
        }
    }
    return props;
}
 
Example 2
Project: sistra   File: ResultadoRegistro.java   View Source Code Vote up 6 votes
public String toString()
{
	try
	{
		StringBuffer sb = new StringBuffer( "{" );
		Map properties = BeanUtils.describe( this );
		for ( Iterator it = properties.keySet().iterator(); it.hasNext(); )
		{
			Object key = it.next();
			Object value = properties.get( key );
			sb.append( key.toString() ).append( "=" ).append( value != null ? value.toString() : null ).append( it.hasNext() ? ", " : "") ; 
		}
		sb.append( "}" );
		return sb.toString();
	}
	catch( Exception exc )
	{
		exc.printStackTrace();
		return super.toString();
	}
}
 
Example 3
Project: meazza   File: URLUtils.java   View Source Code Vote up 6 votes
/**
 * 拼接URL,参数从obj中通过反射取得。
 *
 * @param url
 *            URL
 * @param obj
 *            对象
 * @return 拼接后的URL
 */
public static String addInnerQueryString(String url, Object obj) {
    List<String> names = new ArrayList<>();
    List<Object> values = new ArrayList<>();

    try {
        Map<String, String> properties = BeanUtils.describe(obj);
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            String name = entry.getKey();
            if ("class".equals(name)) {
                continue;
            }

            names.add(name);
            values.add(entry.getValue());
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    }

    return addQueryString(url, names.toArray(new String[names.size()]), values.toArray(new Object[values.size()]));
}
 
Example 4
Project: training_storefront   File: SkuEntityTestRig.java   View Source Code Vote up 5 votes
@Override
protected Map<String, Object> initailizeTestValuesToInsert(List<String> testColumns, Object entityToInsert) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    logger.info("Starting method: initailizeTestValuesToInsert");

    for(String testColumn : testColumns){
        logger.info("Testing columns: " + testColumn);
    }

    Map<String, Object> valuesToInsert = new HashMap<String, Object>();

    Map<String, String> fieldValues = BeanUtils.describe(entityToInsert);

    for(Map.Entry<String, String> entry : fieldValues.entrySet()){
        logger.info("Preparing entry set entry of: " + entry.getKey() + " : " + entry.getValue());
    }

    for (String testColumnName : testColumns){
        String propertyName = transformSqlColumnNamesToJavaPropertyName(testColumnName);
        String fieldValue = fieldValues.get(propertyName);
        logger.info("Setting field value: " + fieldValue + " from field: " + propertyName + " for column: " + testColumnName);
        if( fieldValues.get(propertyName) != null) {
            valuesToInsert.put(testColumnName, fieldValues.get(propertyName));
        }else{
            valuesToInsert.put(testColumnName, ((SkuEntity) entityToInsert).getSkuVendor().getVendorKey());
        }
    }
    return valuesToInsert;
}
 
Example 5
Project: training_storefront   File: VendorEntityTestRig.java   View Source Code Vote up 5 votes
@Override
protected Map<String, Object> initailizeTestValuesToInsert(List<String> testColumns, Object entityToInsert) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    Map<String, Object> valuesToInsert = new HashMap<String, Object>();

    Map<String, String> fieldValues = BeanUtils.describe(entityToInsert);

    for (String testColumnName : testColumns){
        valuesToInsert.put(testColumnName, fieldValues.get(transformSqlColumnNamesToJavaPropertyName(testColumnName)));
    }
    return valuesToInsert;
}
 
Example 6
Project: pub-service   File: ReflectionUtil.java   View Source Code Vote up 5 votes
/**
 * 将po对象中有属性和值转换成map
 * 
 * @param po
 * @return
 */
public static Map po2Map(Object po) {
	Map poMap = new HashMap();
	Map map = new HashMap();
	try {
		map = BeanUtils.describe(po);
	} catch (Exception ex) {
	}
	Object[] keyArray = map.keySet().toArray();
	for (int i = 0; i < keyArray.length; i++) {
		String str = keyArray[i].toString();
		if (str != null && !str.equals("class")) {
			if (map.get(str) != null) {
				poMap.put(str, map.get(str));
			}
		}
	}

	Method[] ms =po.getClass().getMethods();
	for(Method m:ms){
		String name = m.getName();
		
		if(name.startsWith("get")||name.startsWith("is")){
			if(m.getAnnotation(NotDbField.class)!=null||m.getAnnotation(PrimaryKeyField.class)!=null){
				poMap.remove(getFieldName(name)); 
			} 
		}

	}
	
	/**
	 * 如果此实体为动态字段实体,将动态字段加入
	 */
	if(po instanceof DynamicField){
		DynamicField dynamicField = (DynamicField) po;
		Map fields = dynamicField.getFields();
		poMap.putAll(fields);
	}
	return poMap;
}
 
Example 7
Project: pub-service   File: ReflectionUtil.java   View Source Code Vote up 5 votes
/**
 * 将po对象中有属性和值转换成map
 * 
 * @param po
 * @return
 */
public static Map po2Map(Object po) {
	Map poMap = new HashMap();
	Map map = new HashMap();
	try {
		map = BeanUtils.describe(po);
	} catch (Exception ex) {
	}
	Object[] keyArray = map.keySet().toArray();
	for (int i = 0; i < keyArray.length; i++) {
		String str = keyArray[i].toString();
		if (str != null && !str.equals("class")) {
			if (map.get(str) != null) {
				poMap.put(str, map.get(str));
			}
		}
	}

	Method[] ms =po.getClass().getMethods();
	for(Method m:ms){
		String name = m.getName();
		
		if(name.startsWith("get")||name.startsWith("is")){
			if(m.getAnnotation(NotDbField.class)!=null||m.getAnnotation(PrimaryKeyField.class)!=null){
				poMap.remove(getFieldName(name)); 
			} 
		}

	}
	
	/**
	 * 如果此实体为动态字段实体,将动态字段加入
	 */
	if(po instanceof DynamicField){
		DynamicField dynamicField = (DynamicField) po;
		Map fields = dynamicField.getFields();
		poMap.putAll(fields);
	}
	return poMap;
}
 
Example 8
Project: infoarchive-sip-sdk   File: JavaBean.java   View Source Code Vote up 5 votes
@Override
public String toString() {
  try {
    Map<String, String> properties = BeanUtils.describe(this);
    properties.remove("class");
    return properties.toString();
  } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    return super.toString();
  }
}
 
Example 9
Project: abina-common-util   File: ReflectionUtils.java   View Source Code Vote up 5 votes
/**
 * 将po对象中有属性和值转换成map
 * 
 * @param po
 * @return
 */
public static Map po2Map(Object po) {
	Map poMap = new HashMap();
	Map map = new HashMap();
	try {
		map = BeanUtils.describe(po);
	} catch (Exception ex) {
	}
	Object[] keyArray = map.keySet().toArray();
	for (int i = 0; i < keyArray.length; i++) {
		String str = keyArray[i].toString();
		if (str != null && !str.equals("class")) {
			if (map.get(str) != null) {
				poMap.put(str, map.get(str));
			}
		}
	}

	Method[] ms =po.getClass().getMethods();
	/*for(Method m:ms){
		String name = m.getName();
		
	/*	if(name.startsWith("get")||name.startsWith("is")){
			if(m.getAnnotation(NotDbField.class)!=null||m.getAnnotation(PrimaryKeyField.class)!=null){
				poMap.remove(getFieldName(name)); 
			} 
		}

	}
	
	/**
	 * 如果此实体为动态字段实体,将动态字段加入
	 */
	/*if(po instanceof DynamicField){
		DynamicField dynamicField = (DynamicField) po;
		Map fields = dynamicField.getFields();
		poMap.putAll(fields);
	}*/
	return poMap;
}
 
Example 10
Project: jfinal-plus   File: DefaultLogProccesor.java   View Source Code Vote up 5 votes
@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public void process(SysLog sysLog) {
        Map map = null;
        try {
            map = BeanUtils.describe(sysLog);
            map.remove("class");
        } catch (Exception e) {
            e.printStackTrace();
        }
        Record record = new Record();
        record.setColumns(map);
        System.out.println(record);
//        Db.save("syslog", record);
    }