01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.financial.rule.event;
17:
18: import org.apache.commons.lang.StringUtils;
19: import org.apache.log4j.Logger;
20: import org.kuali.core.document.Document;
21: import org.kuali.core.rule.event.KualiDocumentEventBase;
22: import org.kuali.core.util.ObjectUtils;
23: import org.kuali.module.financial.bo.Check;
24:
25: /**
26: * Defines methods common to all AccountingLineEvents.
27: */
28: public abstract class CheckEventBase extends KualiDocumentEventBase
29: implements CheckEvent {
30: private static final Logger LOG = Logger
31: .getLogger(CheckEventBase.class);
32:
33: private final Check check;
34:
35: /**
36: * Initializes fields common to all subclasses
37: *
38: * @param description
39: * @param errorPathPrefix
40: * @param document
41: * @param check
42: */
43: public CheckEventBase(String description, String errorPathPrefix,
44: Document document, Check check) {
45: super (description, errorPathPrefix, document);
46:
47: // by doing a deep copy, we are ensuring that the business rule class can't update
48: // the original object by reference
49: this .check = (Check) ObjectUtils.deepCopy(check);
50:
51: logEvent();
52: }
53:
54: /**
55: * @see org.kuali.core.rule.event.CheckEvent#getCheck()
56: */
57: public Check getCheck() {
58: return check;
59: }
60:
61: /**
62: * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
63: */
64: public void validate() {
65: super .validate();
66: if (getCheck() == null) {
67: throw new IllegalArgumentException("invalid (null) check");
68: }
69: }
70:
71: /**
72: * Logs the event type and some information about the associated accountingLine
73: */
74: private void logEvent() {
75: StringBuffer logMessage = new StringBuffer(StringUtils
76: .substringAfterLast(this .getClass().getName(), "."));
77: logMessage.append(" with ");
78:
79: // vary logging detail as needed
80: if (check == null) {
81: logMessage.append("null check");
82: } else {
83: logMessage.append(" check# ");
84: logMessage.append(check.getCheckNumber());
85: }
86:
87: LOG.debug(logMessage);
88: }
89: }
|