1 13 package com.tonbeller.wcf.component; 14 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 import org.apache.log4j.Logger; 20 21 import com.tonbeller.wcf.controller.RequestContext; 22 23 30 public class FormSupport implements Form { 31 Set listeners = new HashSet (); 32 boolean fireing = false; 33 private static Logger logger = Logger.getLogger(FormSupport.class); 34 35 public FormSupport() { 36 } 37 38 41 public boolean validate(RequestContext context) { 42 logger.info("enter"); 43 if (fireing) 45 return true; 46 fireing = true; 47 try { 48 boolean valid = true; 49 for (Iterator it = listeners.iterator(); it.hasNext();) { 50 FormListener listener = (FormListener) it.next(); 51 valid = listener.validate(context) && valid; 53 } 54 return valid; 55 } finally { 56 fireing = false; 57 } 58 } 59 60 63 public void revert(RequestContext context) { 64 logger.info("enter"); 65 if (fireing) 66 return; 67 fireing = true; 68 try { 69 for (Iterator it = listeners.iterator(); it.hasNext();) { 70 FormListener listener = (FormListener) it.next(); 71 listener.revert(context); 72 } 73 } finally { 74 fireing = false; 75 } 76 } 77 78 public void addFormListener(FormListener listener) { 79 listeners.add(listener); 80 } 81 82 public void removeFormListener(FormListener listener) { 83 listeners.remove(listener); 84 } 85 86 } 87 | Popular Tags |