1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util;
17
18 import org.apache.struts.action.ActionMessage;
19 import org.apache.struts.action.ActionMessages;
20 import org.kuali.rice.krad.util.ErrorMessage;
21 import org.kuali.rice.krad.util.MessageMap;
22
23 import java.io.Serializable;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Set;
27
28
29
30
31
32
33
34 public abstract class MessageContainer implements Serializable {
35 private MessageMap errorMap;
36
37 protected MessageContainer(MessageMap errorMap) {
38 this.errorMap = errorMap;
39 }
40
41 protected MessageMap getMessageMap() {
42 return errorMap;
43 }
44
45 public ActionMessages getRequestMessages() {
46 ActionMessages requestErrors = new ActionMessages();
47 for (Iterator<String> iter = getMessagePropertyNames().iterator(); iter.hasNext();) {
48 String property = iter.next();
49 List errorList = (List) getMessagesForProperty(property);
50
51 for (Iterator iterator = errorList.iterator(); iterator.hasNext();) {
52 ErrorMessage errorMessage = (ErrorMessage) iterator.next();
53
54
55 requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters()));
56 }
57 }
58 return requestErrors;
59 }
60
61 public abstract int getMessageCount();
62
63 public abstract List<String> getMessagePropertyList();
64
65 protected abstract Set<String> getMessagePropertyNames();
66
67 protected abstract List getMessagesForProperty(String propertyName);
68 }