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.kfs.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.kfs.bo.AccountingLine;
24:
25: /**
26: * Defines methods common to all AccountingLineEvents.
27: */
28: public abstract class AccountingLineEventBase extends
29: KualiDocumentEventBase implements AccountingLineEvent {
30: private static final Logger LOG = Logger
31: .getLogger(AccountingLineEventBase.class);
32:
33: private final AccountingLine accountingLine;
34:
35: /**
36: * Initializes fields common to all subclasses
37: *
38: * @param description
39: * @param errorPathPrefix
40: * @param document
41: * @param accountingLine
42: */
43: public AccountingLineEventBase(String description,
44: String errorPathPrefix, Document document,
45: AccountingLine accountingLine) {
46: super (description, errorPathPrefix, document);
47:
48: // by doing a deep copy, we are ensuring that the business rule class can't update
49: // the original object by reference
50: this .accountingLine = (AccountingLine) ObjectUtils
51: .deepCopy(accountingLine);
52:
53: logEvent();
54: }
55:
56: /**
57: * @see org.kuali.core.rule.event.AccountingLineEvent#getAccountingLine()
58: */
59: public AccountingLine getAccountingLine() {
60: return accountingLine;
61: }
62:
63: /**
64: * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
65: */
66: public void validate() {
67: super .validate();
68: if (getAccountingLine() == null) {
69: throw new IllegalArgumentException(
70: "invalid (null) accounting line");
71: }
72: }
73:
74: /**
75: * Logs the event type and some information about the associated accountingLine
76: */
77: private void logEvent() {
78: StringBuffer logMessage = new StringBuffer(StringUtils
79: .substringAfterLast(this .getClass().getName(), "."));
80: logMessage.append(" with ");
81:
82: // vary logging detail as needed
83: if (accountingLine == null) {
84: logMessage.append("null accountingLine");
85: } else {
86: String accountingLineType = accountingLine
87: .getFinancialDocumentLineTypeCode();
88:
89: logMessage.append(accountingLineType);
90: logMessage.append(" seq# ");
91: logMessage.append(accountingLine.getSequenceNumber());
92: }
93:
94: LOG.debug(logMessage);
95: }
96: }
|