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 java.io.Serializable; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
import java.util.Set; |
22 | |
|
23 | |
import org.apache.struts.action.ActionMessage; |
24 | |
import org.apache.struts.action.ActionMessages; |
25 | |
import org.kuali.rice.kns.util.ErrorMessage; |
26 | |
import org.kuali.rice.kns.util.MessageMap; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public abstract class MessageContainer implements Serializable { |
35 | |
private MessageMap errorMap; |
36 | |
|
37 | 0 | protected MessageContainer(MessageMap errorMap) { |
38 | 0 | this.errorMap = errorMap; |
39 | 0 | } |
40 | |
|
41 | |
protected MessageMap getMessageMap() { |
42 | 0 | return errorMap; |
43 | |
} |
44 | |
|
45 | |
public ActionMessages getRequestMessages() { |
46 | 0 | ActionMessages requestErrors = new ActionMessages(); |
47 | 0 | for (Iterator<String> iter = getMessagePropertyNames().iterator(); iter.hasNext();) { |
48 | 0 | String property = iter.next(); |
49 | 0 | List errorList = (List) getMessagesForProperty(property); |
50 | |
|
51 | 0 | for (Iterator iterator = errorList.iterator(); iterator.hasNext();) { |
52 | 0 | ErrorMessage errorMessage = (ErrorMessage) iterator.next(); |
53 | |
|
54 | |
|
55 | 0 | requestErrors.add(property, new ActionMessage(errorMessage.getErrorKey(), errorMessage.getMessageParameters())); |
56 | 0 | } |
57 | 0 | } |
58 | 0 | 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 | |
} |