1 23 package org.mdarad.framework.util.struts.action; 24 25 import org.apache.struts.action.ActionForm; 26 27 35 public class FormUtils { 36 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 if (canBeNull && form == null) { 50 return; 51 } 52 53 if (!canBeNull && form == null) { 55 throw new FormException("The form object should not be null"); 56 } 57 58 Class formClass = form.getClass(); 59 60 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 } | Popular Tags |