1 20 package org.enhydra.barracuda.contrib.sam.models; 21 22 import java.util.*; 23 import org.enhydra.barracuda.core.comp.*; 24 import org.enhydra.barracuda.core.event.*; 25 import org.enhydra.barracuda.core.forms.*; 26 import org.enhydra.barracuda.contrib.dbroggisch.display.*; 27 import org.apache.log4j.*; 28 29 35 public class ErrorModel extends IterativeCollectionModel { 36 37 protected static Logger logger = Logger.getLogger(ErrorModel.class.getName()); 38 39 public static final String DEFAULT_ERRORMODEL = "Error"; 40 public static final String DIRECTIVE_VISIBLE = "Has_Errors"; 41 42 public ErrorModel(ViewContext vc) { 43 this(DEFAULT_ERRORMODEL, vc); 44 } 45 46 public ErrorModel(String name, ViewContext vc) { 47 super(name); 48 List errorList = (List)vc.getEventContext().getState(name); 49 if (logger.isDebugEnabled()) logger.debug("retrieving exception list from event context: " + errorList); 50 if (errorList == null) errorList = new Vector(); 51 if (logger.isDebugEnabled()) logger.debug("errorlist has " + errorList.size() + " items."); 52 setModels(errorList); 53 } 54 55 public Object getItem(String key) { 56 if (logger.isDebugEnabled()) { 57 if (_current== null) { 58 logger.error("_current is null"); 59 } else { 60 logger.debug("_current: " + _current + _current.getClass().getName()); 61 } 62 } 63 return ((Exception )_current).getMessage(); 64 } 65 66 public boolean processDirective(TemplateDirective td) { 67 if (td.getCommand().equals(DIRECTIVE_VISIBLE) && (getModels().size()==0)) return false; 68 return true; 69 } 70 71 80 81 public static void create(EventContext context, Exception ex) { 82 create(DEFAULT_ERRORMODEL, context, ex); 83 } 84 85 public static void create(String name, EventContext context, Exception ex) { 86 if (logger.isDebugEnabled()) logger.debug("Storing single exception to event context"); 87 List l; 88 if (ex instanceof ValidationException) { 89 l = ((ValidationException)ex).getExceptionList(); 90 } else { 91 l = (List)context.getState(name); 92 if (l==null) l = new Vector(); 93 l.add(ex); 94 } 95 context.putState(name, l); 96 } 97 98 public static void remove(EventContext context) { 99 remove(DEFAULT_ERRORMODEL, context); 100 } 101 102 public static void remove(String name, EventContext context) { 103 context.removeState(name); 104 } 105 106 public static boolean exists(EventContext context) { 107 return exists(DEFAULT_ERRORMODEL, context); 108 } 109 110 public static boolean exists(String name, EventContext context) { 111 return (context.getState(name) != null); 112 } 113 } 114 115 116 | Popular Tags |