Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
KualiDocumentEventBase |
|
| 1.6;1.6 |
1 | /* | |
2 | * Copyright 2005-2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.kns.rule.event; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import java.util.List; | |
20 | ||
21 | import org.apache.commons.lang.StringUtils; | |
22 | import org.apache.log4j.Logger; | |
23 | import org.kuali.rice.kns.document.Document; | |
24 | import org.kuali.rice.kns.util.KNSPropertyConstants; | |
25 | ||
26 | /** | |
27 | * Abstract superclass for document-related events. | |
28 | */ | |
29 | abstract public class KualiDocumentEventBase implements KualiDocumentEvent { | |
30 | 0 | private static final Logger LOG = Logger.getLogger(KualiDocumentEventBase.class); |
31 | ||
32 | private final String description; | |
33 | private final String errorPathPrefix; | |
34 | protected Document document; | |
35 | ||
36 | /** | |
37 | * | |
38 | * As a general rule, business rule classes should not change the original object. This constructor was created so that | |
39 | * PreRulesCheckEvent, a UI level rule checker, can make changes. | |
40 | * | |
41 | * @param description | |
42 | * @param errorPathPrefix | |
43 | */ | |
44 | 0 | protected KualiDocumentEventBase(String description, String errorPathPrefix) { |
45 | ||
46 | 0 | if (!(this instanceof PromptBeforeValidationEvent)) { |
47 | 0 | throw new Error("THIS CONSTRUCTOR SHOULD ONLY BE USED AT THE UI LAYER"); |
48 | } | |
49 | ||
50 | 0 | this.description = description; |
51 | 0 | this.errorPathPrefix = errorPathPrefix; |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * Constructs a KualiEvent with the given description and errorPathPrefix for the given document. | |
56 | * | |
57 | * @param errorPathPrefix | |
58 | * @param document | |
59 | * @param description | |
60 | */ | |
61 | 0 | public KualiDocumentEventBase(String description, String errorPathPrefix, Document document) { |
62 | 0 | this.description = description; |
63 | 0 | this.errorPathPrefix = errorPathPrefix; |
64 | 0 | this.document = document; |
65 | ||
66 | 0 | LOG.debug(description); |
67 | 0 | } |
68 | ||
69 | ||
70 | /** | |
71 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getDocument() | |
72 | */ | |
73 | public final Document getDocument() { | |
74 | 0 | return document; |
75 | } | |
76 | ||
77 | /** | |
78 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getName() | |
79 | */ | |
80 | public final String getName() { | |
81 | 0 | return this.getClass().getName(); |
82 | } | |
83 | ||
84 | /** | |
85 | * @return a description of this event | |
86 | */ | |
87 | public final String getDescription() { | |
88 | 0 | return description; |
89 | } | |
90 | ||
91 | /** | |
92 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#getErrorPathPrefix() | |
93 | */ | |
94 | public String getErrorPathPrefix() { | |
95 | 0 | return errorPathPrefix; |
96 | } | |
97 | ||
98 | ||
99 | /** | |
100 | * @see java.lang.Object#toString() | |
101 | */ | |
102 | public String toString() { | |
103 | 0 | return getName(); |
104 | } | |
105 | ||
106 | /** | |
107 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#validate() | |
108 | */ | |
109 | public void validate() { | |
110 | 0 | if (getDocument() == null) { |
111 | 0 | throw new IllegalArgumentException("invalid (null) event document"); |
112 | } | |
113 | 0 | } |
114 | ||
115 | /** | |
116 | * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#generateEvents() | |
117 | */ | |
118 | public List generateEvents() { | |
119 | 0 | return new ArrayList(); |
120 | } | |
121 | ||
122 | /** | |
123 | * Provides null-safe access to the documentNumber of the given document. | |
124 | * | |
125 | * @param document | |
126 | * @return String containing the documentNumber of the given document, or some indication of why the documentNumber isn't | |
127 | * accessible | |
128 | */ | |
129 | protected static String getDocumentId(Document document) { | |
130 | 0 | String docId = "(null document)"; |
131 | ||
132 | 0 | if (document != null) { |
133 | 0 | String documentNumber = document.getDocumentNumber(); |
134 | 0 | if (StringUtils.isBlank(documentNumber)) { |
135 | 0 | docId = "(blank " + KNSPropertyConstants.DOCUMENT_NUMBER + ")"; |
136 | } | |
137 | else { | |
138 | 0 | docId = documentNumber; |
139 | } | |
140 | } | |
141 | ||
142 | 0 | return docId; |
143 | } | |
144 | } |