01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/chat/tags/sakai_2-4-1/chat-tool/tool/src/java/org/sakaiproject/chat/tool/ChatObservingCourier.java $
03: * $Id: ChatObservingCourier.java 8206 2006-04-24 19:40:15Z ggolden@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.chat.tool;
21:
22: import java.util.Observable;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.sakaiproject.courier.cover.CourierService;
27: import org.sakaiproject.event.api.Event;
28: import org.sakaiproject.util.EventObservingCourier;
29:
30: /**
31: * <p>
32: * ChatObservingCourier is an ObservingCourier that watches chat events and delivers them with extra information, specifically the reference to the message referenced by the event.
33: * </p>
34: */
35: public class ChatObservingCourier extends EventObservingCourier {
36: /** Our logger. */
37: private static Log M_log = LogFactory
38: .getLog(ChatObservingCourier.class);
39:
40: protected boolean m_alertEnabled;
41:
42: /**
43: * Construct.
44: *
45: * @param deliveryId
46: * The key identifying the Portal Page Instance.
47: * @param elementId
48: * The key identifying the element on the Portal Page that would need a courier delivered message when things change.
49: * @param The
50: * event resource pattern - we watch for only events whose ref start with this.
51: */
52: public ChatObservingCourier(String deliveryId, String elementId,
53: String resourcePattern, boolean wantsBeeps) {
54: super (deliveryId, elementId, resourcePattern);
55: m_alertEnabled = wantsBeeps;
56:
57: } // ChatObservingCourier
58:
59: /**
60: * This method is called whenever the observed object is changed. An application calls an <tt>Observable</tt> object's <code>notifyObservers</code> method to have all the object's observers notified of the change. default implementation is to
61: * cause the courier service to deliver to the interface controlled by my controller. Extensions can override.
62: *
63: * @param o
64: * the observable object.
65: * @param arg
66: * an argument passed to the <code>notifyObservers</code> method.
67: */
68: public void update(Observable o, Object arg) {
69: // ignore changes when not enabled
70: if (!getEnabled()) {
71: if (M_log.isDebugEnabled())
72: M_log.debug("update [DISABLED]: "
73: + ((arg == null) ? "null" : arg.toString()));
74: return;
75: }
76:
77: if (!check(arg))
78: return;
79:
80: CourierService.deliver(new ChatDelivery(getDeliveryId(),
81: getElementId(), ((Event) arg).getResource(),
82: m_alertEnabled));
83:
84: } // update
85:
86: public void alertEnabled(boolean newVal) {
87: m_alertEnabled = newVal;
88:
89: } // alertEnabled
90: }
|