Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MessageBuilderImpl |
|
| 1.0;1 |
1 | /** | |
2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
3 | * Educational Community License, Version 2.0 (the "License"); you may | |
4 | * not use this file except in compliance with the License. You may | |
5 | * obtain a copy of the License at | |
6 | * | |
7 | * http://www.osedu.org/licenses/ECL-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, | |
10 | * software distributed under the License is distributed on an "AS IS" | |
11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
12 | * or implied. See the License for the specific language governing | |
13 | * permissions and limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.kuali.student.common.messagebuilder.impl; | |
17 | ||
18 | import java.util.Map; | |
19 | ||
20 | import org.kuali.student.common.messagebuilder.MessageBuilder; | |
21 | import org.kuali.student.common.messagebuilder.MessageTreeBuilder; | |
22 | import org.kuali.student.common.messagebuilder.booleanmessage.MessageContainer; | |
23 | import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanFunctionResult; | |
24 | import org.kuali.student.common.messagebuilder.impl.exceptions.MessageBuilderException; | |
25 | ||
26 | /** | |
27 | * This <code>MessageBuilder</code> class builds a summary message from | |
28 | * plain strings or templates. Summary message is built from analysing the | |
29 | * outcome of a boolean expression. | |
30 | */ | |
31 | public class MessageBuilderImpl extends AbstractMessageBuilder implements MessageBuilder { | |
32 | /** | |
33 | * Constructor. | |
34 | * | |
35 | * @param language String Boolean operators' language (English and/or) | |
36 | * @param treeNodeMessageBuilder AST tree node Message builder | |
37 | */ | |
38 | public MessageBuilderImpl(final String language, final MessageTreeBuilder treeNodeMessageBuilder) { | |
39 | 19 | super(language, treeNodeMessageBuilder); |
40 | 19 | } |
41 | ||
42 | /** | |
43 | * <p>Builds and evaluates a boolean expression and returns the message and result | |
44 | * of the expression.</p> | |
45 | * <p><b>Note:</b> Order of boolean operation: ANDs before ORs and operations | |
46 | * inside parentheses before anything else.</p> | |
47 | * Example 1: 'A AND B OR C AND D' internally evaluates to '(A AND B) OR (C AND D)' | |
48 | * <pre><code>booleanExpression</code> = "A*B+C*D"</pre> | |
49 | * Example 2: '(M1 AND M2) OR M3' | |
50 | * <pre><code>booleanExpression</code> = "(M1*M2)+M3"</pre> | |
51 | * | |
52 | * @param booleanRule Boolean expression | |
53 | * @param messageContainer Contains a list of messages | |
54 | * @return Boolean function result | |
55 | * @throws MessageBuilderException Errors building message | |
56 | */ | |
57 | public BooleanFunctionResult build(final String booleanRule, final MessageContainer messageContainer) { | |
58 | 5 | return super.build(booleanRule, messageContainer.getMessageMap()); |
59 | } | |
60 | ||
61 | /** | |
62 | * <p>Builds and evaluates a boolean expression and returns the message and result | |
63 | * of the expression.</p> | |
64 | * <p><b>Note:</b> Order of boolean operation: ANDs before ORs and operations | |
65 | * inside parentheses before anything else.</p> | |
66 | * <p>if <code>messageContainer</code> contains any velocity templates | |
67 | * with keys/tokens then <code>messageContextMap</code> must be set.</p> | |
68 | * Example 1: 'A AND B OR C AND D' internally evaluates to '(A AND B) OR (C AND D)' | |
69 | * <pre><code>booleanExpression</code> = "A*B+C*D"</pre> | |
70 | * Example 2: '(M1 AND M2) OR M3' | |
71 | * <pre><code>booleanExpression</code> = "(M1*M2)+M3"</pre> | |
72 | * | |
73 | * @param booleanRule Boolean expression | |
74 | * @param messageContainer Contains a list of messages | |
75 | * @param messageContextMap Message context template map | |
76 | * @return Boolean function result | |
77 | * @throws MessageBuilderException Errors building message | |
78 | */ | |
79 | public BooleanFunctionResult build( | |
80 | final String booleanRule, | |
81 | final MessageContainer messageContainer, | |
82 | final Map<String, Object> messageContextMap) { | |
83 | 5 | return super.build(booleanRule, messageContainer.getMessageMap(), messageContextMap); |
84 | } | |
85 | ||
86 | /** | |
87 | * Builds a message from a list of messages using a boolean expression. | |
88 | * Example: (M1 AND M2) OR M3 -> (M1*M2)+M3 | |
89 | * | |
90 | * @param booleanRule Boolean expression | |
91 | * @param messageContainer Contains a list of messages | |
92 | * @return A message | |
93 | * @throws MessageBuilderException Errors building message | |
94 | */ | |
95 | public String buildMessage(final String booleanRule, final MessageContainer messageContainer) { | |
96 | 11 | return super.build(booleanRule, messageContainer.getMessageMap()).getMessage(); |
97 | } | |
98 | } |