text:  package org.mdarad.framework.util.struts.action;24 25 import org.apache.struts.action.ActionForm;26 27 /**28 * The class FormUtils contains many util methods used29 * within the forms object and the form actions30 * 31 * @author Philippe Brouillette32 * @version 1.033 * @since 1.434 */35 public class FormUtils {36 /**37 * Method that throws <code>FormException</code> if the instance of the form is of the type38 * is not of the type passed as argument.39 * @param form <code>ActionForm</code> to be checked40 * @param type Class type needed41 * @param canBeNull flag that indicates if the form object can be null42 */43 public static void validateFormInstance(ActionForm form, Class type, boolean canBeNull) {44 if (type == null) {45 throw new IllegalArgumentException ("The type passed should not be null");46 }47 48 // the form is valid49 if (canBeNull && form == null) {50 return;51 }52 53 // check if the object is null54 if (!canBeNull && form == null) {55 throw new FormException("The form object should not be null");56 }57 58 Class formClass = form.getClass();59 60 // check if the object has the right instance61 if (!canBeNull && !type.isAssignableFrom(formClass)) {62 throw new FormException("The form object should be an instance of " + type.getName() + 63 "but is an instance of " + form.getClass().getName());64 }65 }66 }
  Java API By Example, From Geeks To Geeks. | Our Blog | Conditions of Use | About Us_ |