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.purap.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.purap.bo.PurApItem;
24:
25: /**
26: * Event Base class for Purchasing Accounts Payable Item
27: *
28: * contains the base methods for item events
29: */
30: public abstract class PurchasingAccountsPayableItemEventBase extends
31: KualiDocumentEventBase implements
32: PurchasingAccountsPayableItemEvent {
33: private static final Logger LOG = Logger
34: .getLogger(PurchasingAccountsPayableItemEventBase.class);
35:
36: private final PurApItem item;
37:
38: /**
39: * Copies the item and calls the super constructor
40: *
41: * @param description the description of the event
42: * @param errorPathPrefix the error path
43: * @param document the document the event is being called on
44: * @param item the item that is having the event called on
45: */
46: public PurchasingAccountsPayableItemEventBase(String description,
47: String errorPathPrefix, Document document, PurApItem item) {
48: super (description, errorPathPrefix, document);
49:
50: // by doing a deep copy, we are ensuring that the business rule class can't update
51: // the original object by reference
52: this .item = (PurApItem) ObjectUtils.deepCopy(item);
53:
54: logEvent();
55: }
56:
57: /**
58: *
59: * @see org.kuali.module.purap.rule.event.PurchasingAccountsPayableItemEvent#getItem()
60: */
61: public PurApItem getItem() {
62: return item;
63: }
64:
65: /**
66: * @see org.kuali.core.rule.event.KualiDocumentEvent#validate()
67: */
68: public void validate() {
69: super .validate();
70: if (getItem() == null) {
71: throw new IllegalArgumentException("invalid (null) item");
72: }
73: }
74:
75: /**
76: * Logs the event type and some information about the associated item
77: */
78: private void logEvent() {
79: StringBuffer logMessage = new StringBuffer(StringUtils
80: .substringAfterLast(this .getClass().getName(), "."));
81: logMessage.append(" with ");
82:
83: // vary logging detail as needed
84: if (item == null) {
85: logMessage.append("null item");
86: } else {
87: logMessage.append(" item# ");
88: logMessage.append(item.getItemIdentifier());
89: }
90:
91: LOG.debug(logMessage);
92: }
93: }
|