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

The following are Jave code examples for showing how to use populate() 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: spring-boot   File: MyBeanUtils.java   View Source Code Vote up 10 votes
/**
 * map to bean
 * 转换过程中,由于属性的类型不同,需要分别转换。
 * java 反射机制,转换过程中属性的类型默认都是 String 类型,否则会抛出异常,而 BeanUtils 项目,做了大量转换工作,比 java 反射机制好用
 * BeanUtils 的 populate 方法,对 Date 属性转换,支持不好,需要自己编写转换器
 *
 * @param map  待转换的 map
 * @param bean 满足 bean 格式,且需要有无参的构造方法; bean 属性的名字应该和 map 的 key 相同
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
private static void mapToBean(Map<String, Object> map, Object bean) throws IllegalAccessException, InvocationTargetException {

    //注册几个转换器
    ConvertUtils.register(new SqlDateConverter(null), java.sql.Date.class);
    ConvertUtils.register(new SqlTimestampConverter(null), java.sql.Timestamp.class);
    //注册一个类型转换器  解决 common-beanutils 为 Date 类型赋值问题
    ConvertUtils.register(new Converter() {
        //  @Override
        public Object convert(Class type, Object value) { // type : 目前所遇到的数据类型。  value :目前参数的值。
            // System.out.println(String.format("value = %s", value));

            if (value == null || value.equals("") || value.equals("null"))
                return null;
            Date date = null;
            try {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                date = dateFormat.parse((String) value);
            } catch (Exception e) {

                e.printStackTrace();
            }

            return date;
        }

    }, Date.class);

    BeanUtils.populate(bean, map);
}
 
Example 2
Project: Android_Code_Arbiter   File: BeanInjection.java   View Source Code Vote up 8 votes
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
    User user = new User();
    HashMap map = new HashMap();
    Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        map.put(name, request.getParameterValues(name));
    }
    try{
        BeanUtils.populate(user, map); //BAD

        BeanUtilsBean beanUtl = BeanUtilsBean.getInstance();
        beanUtl.populate(user, map); //BAD
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
Example 3
Project: tasfe-framework   File: MysqlTemplate.java   View Source Code Vote up 6 votes
/********************************** get *************************************/

    @Override
    public <T> T _get(Class<T> clazz, Long pv) throws Exception {
        Map<String, Object> param = new HashMap<>();

        String tableName = GeneralMapperReflectUtil.getTableName(clazz);
        String primaryKey = GeneralMapperReflectUtil.getPrimaryKey(clazz);
        List<String> queryColumn = GeneralMapperReflectUtil.getAllColumns(clazz, false);

        param.put("_table_", tableName);
        param.put("_pk_", primaryKey);
        param.put("_pv_", pv);
        param.put("_query_column_", queryColumn);
        Map map = sqlSession.selectOne(Crudable.GET, param);
        T t = clazz.newInstance();
        BeanUtils.populate(t, map);
        return t;
    }
 
Example 4
Project: FCat   File: ObjectUtil.java   View Source Code Vote up 6 votes
/**
* 类实现 Maps --> Bean  
* @param objClass
* @param objMaps
*/
  public static  <T> List<T> map2BeanList(List<Map<String, Object>> objMaps, Class<T> objClass) {  
      if (objMaps == null || objClass == null) {  
          return Collections.emptyList();  
      }  
      List<T> objList = new ArrayList<T>();
      try { 
      	for(Map<String, Object> mapObj : objMaps) {
       	T obj = objClass.newInstance();
           BeanUtils.populate(obj, mapObj);
           objList.add(obj);
      	}
      } catch (Exception e) {  
      	logger.error(e.getMessage());
      } 
      return objList;
  }
 
Example 5
Project: wechat-core   File: BeanTest.java   View Source Code Vote up 6 votes
@Test
public void testMap2Bean() throws Exception {
    Map<String, Object> map = Maps.newHashMap();
    map.put("Username", "jonnyliu");
    map.put("Age", 39);
    User user = new User();
    Map map1 = Maps.newHashMap();
    map.forEach((x, y) -> {
        char[] charArray = x.toCharArray();
        charArray[0] = Character.toLowerCase(charArray[0]);
        map1.put(new String(charArray), y);
    });
    BeanUtils.populate(user, map1);

    System.out.println(user);
}
 
Example 6
Project: garlicts   File: BeanUtil.java   View Source Code Vote up 5 votes
public static <T> T mapToBean(Map<String, Object> map, Class<T> cls){
	
	T bean = null;
	
	try {
		bean = cls.newInstance();
		// 将map中的数据封装到javabean
		BeanUtils.populate(bean, map);
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return bean;
	
}
 
Example 7
Project: AdvancedDataProfilingSeminar   File: ConfigurationMapper.java   View Source Code Vote up 5 votes
static void applyFrom(final String value, final Object object) {
  if (value == null) {
    return;
  }

  final Map<String, String> kv = Splitter.on(",").trimResults().omitEmptyStrings()
      .withKeyValueSeparator("=").split(value);

  try {
    BeanUtils.populate(object, kv);
  } catch (final IllegalAccessException | InvocationTargetException e) {
    throw new RuntimeException(e);
  }
}
 
Example 8
Project: iBase4J-Common   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 * 
 * @param cls
 *            实体类
 * @param list
 *            实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
    E object = null;
    try {
        object = cls.newInstance();
        BeanUtils.populate(object, map);
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return object;
}
 
Example 9
Project: automat   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 * 
 * @param cls
 *            实体类
 * @param list
 *            实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
    E object = null;
    try {
        object = cls.newInstance();
        BeanUtils.populate(object, map);
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return object;
}
 
Example 10
Project: tasfe-framework   File: MysqlTemplate.java   View Source Code Vote up 5 votes
@Override
public <T> List<T> _gets(Class<T> clazz, CrudParam crudParam) throws Exception {
    Map<String, Object> param = new HashMap<>();
    String tableName = GeneralMapperReflectUtil.getTableName(clazz);

    param.put("_table_", tableName);
    param.put("_query_column_", null == crudParam.getQueryColumn() ? GeneralMapperReflectUtil.getAllColumns(clazz, false) : crudParam.getQueryColumn());
    Object entity = crudParam.getEntity();
    if (entity != null) {
        param.put("_condition_param_", null == crudParam.getConditionParam() ? GeneralMapperReflectUtil.getFieldValueMappingExceptNull(entity, false) : crudParam.getConditionParam());
    }

    param.put("_where_exp_", crudParam.getConditionExp());
    param.put("_order_exp_", crudParam.getOrderExp());
    param.put("_pks_", crudParam.getPks());
    //param.put("",);

    if (crudParam.getPageSize() != null && crudParam.getPageNo() != null) {
        Map<String, Integer> page = new HashMap<>();
        page.put("pageSize", crudParam.getPageSize());
        page.put("startRowNo", (crudParam.getPageNo() - 1) * crudParam.getPageSize());
        param.put("page", page);
    }

    List<Map> maps = sqlSession.selectList(Crudable.GETS, param);
    List<T> ts = new ArrayList<>();
    for (Map map : maps) {
        T t = clazz.newInstance();
        BeanUtils.populate(t, map);
        ts.add(t);
    }
    return ts;
}
 
Example 11
Project: mumu   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 * 
 * @param cls 实体类
 * @param list 实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
	E object = null;
	try {
		object = cls.newInstance();
		BeanUtils.populate(object, map);
	} catch (Exception e) {
		throw new InstanceException(e);
	}
	return object;
}
 
Example 12
Project: iBase4J   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 * 
 * @param cls
 *            实体类
 * @param list
 *            实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
	E object = null;
	try {
		object = cls.newInstance();
		BeanUtils.populate(object, map);
	} catch (Exception e) {
		throw new InstanceException(e);
	}
	return object;
}
 
Example 13
Project: dubbo-mock   File: BaseController.java   View Source Code Vote up 5 votes
protected <T> T assembleRequestParamForBean(HttpServletRequest request, Class<T> clazz, Page<?> page) {
    Map<String, String> paraMap = assembleRequestParamForMap(request, page);
    T t = null;
    try {
        t = clazz.newInstance();
        BeanUtils.populate(t, paraMap);
    } catch (Exception e) {
        throw new RuntimeException("MAP转换BEAN时出错。");
    }
    return t;
}
 
Example 14
Project: dubbo-mock   File: BaseController.java   View Source Code Vote up 5 votes
protected <T> T assembleRequestParamForBean(Map<String, String> paraMap, Class<T> clazz) {
    T t = null;
    try {
        t = clazz.newInstance();
        BeanUtils.populate(t, paraMap);
        if (StringUtils.isNotBlank(paraMap.get("selectid"))) {
            ReflectUtil.setFieldValue(t, "id", Integer.valueOf(paraMap.get("selectid")));
        } else {
            ReflectUtil.setFieldValue(t, "id", null);
        }
    } catch (Exception e) {
        throw new RuntimeException("MAP转换BEAN时出错。");
    }
    return t;
}
 
Example 15
Project: UtilsMaven   File: CommonUtils.java   View Source Code Vote up 5 votes
/**
 * 将Bean的属性值修改为Map中对应的值
 *
 * @param property 一个Map对象,封装了相应的Bean类中的属性
 * @param bean     需要修改的Bean类
 * @return 返回一个属性已修改的Bean类实例
 */
public static <T extends Object> T modifyBean(Map<String, ? extends Object> property, T bean) {
    try {
        BeanUtils.populate(bean, property);
        return bean;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 16
Project: UtilsMaven   File: CommonUtils.java   View Source Code Vote up 5 votes
/**
 * 将一个Map对象转换成一个Bean对象
 *
 * @param property 一个Map对象,封装了相应的Bean中的属性
 * @param clazz    需要转换成的Bean
 * @return 返回一个封装好的Bean类实例,封装失败返回null
 */
public static <T extends Object> T toBean(Map<String, ? extends Object> property, Class<T> clazz) {
    T bean = null;
    try {
        bean = clazz.newInstance();
        BeanUtils.populate(bean, property);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return bean;
}
 
Example 17
Project: JAVA-   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 * 
 * @param cls
 *            实体类
 * @param list
 *            实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
    E object = null;
    try {
        object = cls.newInstance();
        BeanUtils.populate(object, map);
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return object;
}
 
Example 18
Project: FCat   File: ObjectUtil.java   View Source Code Vote up 5 votes
/**
* 类实现 Map --> Bean  
* @param map
* @param clazz
*/
  public static <T> T map2Bean(Map<String, Object> map, Class<T> clazz) {  
      if (map == null || clazz == null) {  
          return null;  
      }  
      try {  
      	T obj = clazz.newInstance();
          BeanUtils.populate(obj, map);
          return obj;
      } catch (Exception e) {  
      	logger.error(e.getMessage());
      }
      return null;
  }
 
Example 19
Project: EasyController   File: BeanUtil.java   View Source Code Vote up 5 votes
public static void mapToBean(Map<String, ?> map, Object target) {
    try {
        BeanUtils.populate(target, map);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 20
Project: telco-anomaly-detection-spark   File: CDR.java   View Source Code Vote up 5 votes
public static CDR stringToCDR(String jsonStr) {
    CDR cdr = new CDR();
    try {
        Map<String, Object> jsonMap = new ObjectMapper().readValue(jsonStr, new TypeReference<Map<String, String>>(){});
        jsonMap.put("state", State.valueOf((String) jsonMap.get("state")));

        BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0);
        BeanUtils.populate(cdr, jsonMap);
    } catch (IllegalAccessException | InvocationTargetException | IOException e) {
        throw new IllegalArgumentException("Can not convert record document");
    }
    return cdr;
}
 
Example 21
Project: melon   File: InstanceUtil.java   View Source Code Vote up 5 votes
/**
 * 新建实例
 *
 * @param cls  实体类
 * @param list 实体属性Map
 * @return
 */
public static final <E> E newInstance(Class<E> cls, Map<String, ?> map) {
    E object = null;
    try {
        object = cls.newInstance();
        BeanUtils.populate(object, map);
    } catch (Exception e) {
        throw new InstanceException(e);
    }
    return object;
}
 
Example 22
Project: venus   File: CommonsBeanUtilConverter.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public Object convert(Object value, Type type) throws ConvertException {
    Object object = null;
    try {
        if (type instanceof Class) {
            Class clazz = (Class) type;
            if (value instanceof Map && !clazz.isPrimitive()) {
                object = new HashMap();
                BeanUtils.populate(object, (Map) (value));
            }
            return BeanUtilsBean.getInstance().getConvertUtils().convert(value, clazz);
        } else if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Class rawType = ((Class) parameterizedType.getRawType());
            if (Map.class.isAssignableFrom(rawType)) {
                object = new HashMap();
            } else if (List.class.isAssignableFrom(rawType)) {
                object = new LinkedList();
            } else if (rawType.isAssignableFrom(value.getClass()) && rawType.isInterface()) {
                return value;
            } else {
                object = reflectionProvider.newInstance(rawType);
            }
            if (value instanceof Map) {
                BeanUtils.populate(object, (Map) (value));
            } else {
                BeanUtils.copyProperties(object, value);
            }
        }
        return object;
    } catch (Exception e) {
        throw new ConvertException(value + " can not convert to " + type);
    }
}
 
Example 23
Project: incubator-omid   File: YAMLUtils.java   View Source Code Vote up 5 votes
public void loadSettings(String resourcePath, String defaultResourcePath, Object bean) {
    try {
        Map properties = loadSettings(resourcePath, defaultResourcePath);
        BeanUtils.populate(bean, properties);
    } catch (IllegalAccessException | InvocationTargetException | IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 24
Project: incubator-omid   File: YAMLUtils.java   View Source Code Vote up 5 votes
public void loadSettings(String resourcePath, Object bean) {
    try {
        Map properties = loadSettings(null, resourcePath);
        BeanUtils.populate(bean, properties);
    } catch (IllegalAccessException | InvocationTargetException | IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 25
Project: storm   File: MapBeanUtil.java   View Source Code Vote up 5 votes
public static void transMap2Bean2(Map<String, Object> map, Object obj) {
	if (map == null || obj == null) {
		return;
	}
	try {
		BeanUtils.populate(obj, map);
	} catch (Exception e) {
		L.i("transMap2Bean2 Error ", e + "");
	}
}
 
Example 26
Project: common   File: MapBeanUtil.java   View Source Code Vote up 5 votes
/**
 * @desc Map 转为Bean对象
 * @date 2016年1月27日-下午5:19:17
 * @param map
 * @param obj 需要先new
 */
public static void mapToBean(Map<String, Object> map, Object obj) {
    if (map == null || obj == null) {
        return;
    }
    try {
        BeanUtils.populate(obj, map);
    } catch (Exception e) {
        return;
    }
}
 
Example 27
Project: redant   File: ProxyInvocation.java   View Source Code Vote up 4 votes
/**
 * 获得方法调用的参数
 * @param method
 * @param parameterTypes
 * @return
 * @throws Exception
 */
private Object[] getParameters(Method method,Class<?>[] parameterTypes) throws Exception{
	//用于存放调用参数的对象数组
	Object[] parameters = new Object[parameterTypes.length];

	//获得所调用方法的参数的Annotation数组
	Annotation[][] annotationArray = method.getParameterAnnotations();

	//获取参数列表
	Map<String, List<String>> paramMap = HttpRequestUtil.getParameterMap(DataHolder.getHttpRequest());

	//构造调用所需要的参数数组
	for (int i = 0; i < parameterTypes.length; i++) {
		Object parameter;
		Class<?> type = parameterTypes[i];
		Annotation[] annotation = annotationArray[i];
		// 如果该参数没有RouterParam注解
		if (annotation == null || annotation.length == 0) {
			// 如果该参数类型是基础类型,则需要加RouterParam注解
			if(PrimitiveTypeUtil.isPriType(type)){
				logger.warn("Must specify a @RouterParam annotation for primitive type parameter in method={}", method.getName());
				continue;
			}
			// 封装对象类型的parameter
			parameter = type.newInstance();
			BeanUtils.populate(parameter,paramMap);
			parameters[i] = parameter;
		}else{
			RouterParam param = (RouterParam) annotation[0];
			try{
				//生成当前的调用参数
				parameter = parseParameter(paramMap, type, param, method, i);
				if(param.checkNull()){
					GenericsUtil.checkNull(param.key(), parameter);
				}
				parameters[i] = parameter;
			}catch(Exception e){
				throw new IllegalArgumentException("参数" + param.key()+"不合法,类型应该为:"+type.toString(), e);
			}
		}
	}
	return parameters;
}
 
Example 28
Project: Equella   File: MainAction.java   View Source Code Vote up 4 votes
@Override
public ActionForward unspecified(ActionMapping mapping, ActionForm formData, HttpServletRequest request,
	HttpServletResponse response) throws Exception
{
	MainForm form = (MainForm) formData;
	setupCollections(form);
	Properties properties = new Properties();
	properties.load(getClass().getResourceAsStream("/defaults.properties"));
	BeanUtils.populate(form, properties);

	InputStream xml = null;
	try
	{
		xml = getClass().getResourceAsStream("/defaults.xml");
		if( xml != null )
		{
			Map<String, String> xmlProps = new HashMap<String, String>();
			PropBagEx pbag = new PropBagEx(xml);
			for( PropBagEx value : pbag.iterateAll("*") )
			{
				xmlProps.put(value.getNodeName(), value.getSubtree("*").toString());
			}
			BeanUtils.populate(form, xmlProps);
		}
	}
	finally
	{
		if( xml != null )
		{
			xml.close();
		}
	}

	InputStream json = null;
	try
	{
		json = getClass().getResourceAsStream("/defaults.json");
		if( json != null )
		{
			Map<String, String> jsonProps = new HashMap<String, String>();

			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.enable(SerializationFeature.INDENT_OUTPUT);

			ObjectNode obj = (ObjectNode) objectMapper.readTree(json);
			Iterator<String> fields = obj.fieldNames();
			while( fields.hasNext() )
			{
				String field = fields.next();
				JsonNode node = obj.get(field);

				jsonProps.put(field, objectMapper.writeValueAsString(node));
			}
			BeanUtils.populate(form, jsonProps);
		}
	}
	finally
	{
		if( json != null )
		{
			json.close();
		}
	}

	form.setMethod("submit");
	return mapping.findForward("main");
}
 
Example 29
Project: sistra   File: VerAction.java   View Source Code Vote up 4 votes
public ActionForward execute(ActionMapping       mapping,
                             ActionForm          form,
                             HttpServletRequest  request,
                             HttpServletResponse response) throws Exception {
    
    InstanciaDelegate delegate = RegistroManager.recuperarInstancia(request);
    if (delegate == null) {
        ActionErrors errors = new ActionErrors();
        errors.add(null, new ActionError("errors.session"));
        saveErrors(request, errors);
        return mapping.findForward("fail");
    }

    Pantalla p = delegate.obtenerPantalla();
    if (p == null) {
    	
    	// En caso de ser telematico comprobamos si debemos ir a la penultima pantalla o bien devolver el control
    	boolean telematic = (delegate instanceof InstanciaTelematicaDelegate);
    	if (telematic) {
            InstanciaTelematicaDelegate itd = (InstanciaTelematicaDelegate) delegate;
            Map propiedadesForm = itd.obtenerPropiedadesFormulario();
            boolean mostrarPantallaFin = false;
        	try{
        		mostrarPantallaFin = (propiedadesForm.get("pantallaFin.mostrar")!=null?Boolean.parseBoolean((String)propiedadesForm.get("pantallaFin.mostrar")):false);
        	}catch (Exception ex){
        		log.error("La propiedad pantallaFin.mostrar no tiene un valor v�lido (true/false): " + propiedadesForm.get("pantallaFin.mostrar"));
        		mostrarPantallaFin = false;
        	}
        	if (!mostrarPantallaFin){
        		response.sendRedirect("finalitzarTelematic.do?ID_INSTANCIA=" + (String) request.getAttribute(RegistroManager.ID_INSTANCIA));
        		return null;
        	}
        }
    	
    	// Vamos a penultima pantalla
        return mapping.findForward("end");
        
    } else {
        ModuleConfig config = mapping.getModuleConfig();
        ActionMapping nextMapping = (ActionMapping) config.findActionConfig("/procesar");
        PantallaForm pantallaForm = (PantallaForm) RequestUtils.createActionForm(request, nextMapping, config, getServlet());
        request.setAttribute(nextMapping.getAttribute(), pantallaForm);
        pantallaForm.reset(nextMapping, request);
        // Alimentamos con datos pantalla actual
    	BeanUtils.populate(pantallaForm, delegate.obtenerDatosPantalla());
        return mapping.findForward("view");
    }
}
 
Example 30
Project: haven-platform   File: ConfigsTest.java   View Source Code Vote up 4 votes
@Test
public void testMap() throws InvocationTargetException, IllegalAccessException {
    ContainerSource createContainerArg = new ContainerSource();

    BeanUtils.populate(createContainerArg, Collections.singletonMap("cpuShares", "23"));

    createContainerArg.getCpuShares();
    Assert.assertNotNull(createContainerArg.getCpuShares());

    ContainerSource createContainerArg2 = new ContainerSource();
    BeanUtils.populate(createContainerArg2, Collections.singletonMap("blkioWeight", "15"));

    BeanUtils.copyProperties(createContainerArg, createContainerArg2);

    Assert.assertNotNull(createContainerArg.getBlkioWeight());

}
 
Example 31
Project: lams   File: DefinitionsFactoryConfig.java   View Source Code Vote up 3 votes
/**
 * Populate this config object from properties map, based on
 * the specified name/value pairs.  This method uses the populate() method from
 * org.apache.commons.beanutils.BeanUtil.
 * <p>
 * Properties keys are scanned for old property names, and linked to the new name
 * if necessary. This modifies the properties map.
 * <p>
 * The particular setter method to be called for each property is
 * determined using the usual JavaBeans introspection mechanisms.  Thus,
 * you may identify custom setter methods using a BeanInfo class that is
 * associated with the class of the bean itself.  If no such BeanInfo
 * class is available, the standard method name conversion ("set" plus
 * the capitalized name of the property in question) is used.
 * <p>
 * <strong>NOTE</strong>:  It is contrary to the JavaBeans Specification
 * to have more than one setter method (with different argument
 * signatures) for the same property.
 *
 * @param properties Map keyed by property name, with the
 *  corresponding (String or String[]) value(s) to be set.
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method.
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception.
 * @see org.apache.commons.beanutils.BeanUtils
 */
public void populate(Map properties)
    throws IllegalAccessException, InvocationTargetException {

    // link old parameter names for backward compatibility
    linkOldPropertyNames(properties);
    BeanUtils.populate(this, properties);
}
 
Example 32
Project: sonar-scanner-maven   File: DefinitionsFactoryConfig.java   View Source Code Vote up 3 votes
/**
 * Populate this config object from properties map, based on
 * the specified name/value pairs.  This method uses the populate() method from
 * org.apache.commons.beanutils.BeanUtil.
 * <p>
 * Properties keys are scanned for old property names, and linked to the new name
 * if necessary. This modifies the properties map.
 * <p>
 * The particular setter method to be called for each property is
 * determined using the usual JavaBeans introspection mechanisms.  Thus,
 * you may identify custom setter methods using a BeanInfo class that is
 * associated with the class of the bean itself.  If no such BeanInfo
 * class is available, the standard method name conversion ("set" plus
 * the capitalized name of the property in question) is used.
 * <p>
 * <strong>NOTE</strong>:  It is contrary to the JavaBeans Specification
 * to have more than one setter method (with different argument
 * signatures) for the same property.
 *
 * @param properties Map keyed by property name, with the
 *  corresponding (String or String[]) value(s) to be set.
 *
 * @exception IllegalAccessException if the caller does not have
 *  access to the property accessor method.
 * @exception InvocationTargetException if the property accessor method
 *  throws an exception.
 * @see org.apache.commons.beanutils.BeanUtils
 */
public void populate(Map properties)
    throws IllegalAccessException, InvocationTargetException {

    // link old parameter names for backward compatibility
    linkOldPropertyNames(properties);
    BeanUtils.populate(this, properties);
}