1 /*** 2 * The contents of this file are subject to the Mozilla Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/MPL/ 6 * 7 * Software distributed under the License is distributed on an "AS 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is pow2toolkit library. 13 * 14 * The Initial Owner of the Original Code is 15 * Power Of Two S.R.L. (www.pow2.com) 16 * 17 * Portions created by Power Of Two S.R.L. are 18 * Copyright (C) Power Of Two S.R.L. 19 * All Rights Reserved. 20 * 21 * Contributor(s): 22 */ 23 package com.pow2.struts.forms; 24 25 import java.util.Map; 26 27 import org.apache.commons.beanutils.BeanUtils; 28 import org.apache.struts.action.ActionForm; 29 30 31 /*** 32 * FormUtil class 33 * 34 * @author Luca Fossato 35 * @created 29 May 2002 36 */ 37 public class FormsUtil 38 { 39 /*** 40 * Transfer data from a source ActionForm to a target value object. 41 * <br> 42 * All that is required is that the names of the public properties correspond 43 * and that the properties be native types (or arrays of native types). 44 * <br> 45 * The wrapper objects, like Integer, are supported. 46 * Optional types, like Date, are not supported. 47 * 48 * @param target the target object that will receive the data from the source ActionForm 49 * @param source the source ActionForm that will send the data to the target object 50 * @exception Exception if any error occurs 51 */ 52 public static void populate(Object target, ActionForm source) throws Exception 53 { 54 populate(target, BeanUtils.describe(source)); 55 } 56 57 58 /*** 59 * Transfer data from a source value object to a target ActionForm. 60 * <br> 61 * All that is required is that the names of the public properties correspond 62 * and that the properties be native types (or arrays of native types). 63 * <br> 64 * The wrapper objects, like Integer, are supported. 65 * Optional types, like Date, are not supported. 66 * 67 * @param target the target ActionForm that will receive the data from the source object 68 * @param source the source object that will send the data to the target ActionForm 69 * @exception Exception if any error occurs 70 */ 71 public static void populate(ActionForm target, Object source) throws Exception 72 { 73 populate((Object) target, BeanUtils.describe(source)); 74 } 75 76 77 /*** 78 * Transfer data from a source Map to a target value object. 79 * <br> 80 * All that is required is that the names of the public properties correspond 81 * and that the properties be native types (or arrays of native types). 82 * <br> 83 * The wrapper objects, like Integer, are supported. 84 * Optional types, like Date, are not supported. 85 * 86 * @param target the target object that will receive the data from the source ActionForm 87 * @param sourceMap the Map object that provides the entire set of properties for which 88 * the specified bean provides a read method 89 * @exception Exception if any error occurs 90 */ 91 public static void populate(Object target, Map sourceMap) throws Exception 92 { 93 BeanUtils.populate(target, sourceMap); 94 } 95 }