001: /*
002: * <copyright>
003: *
004: * Copyright 2003-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026: package org.cougaar.lib.aggagent.query;
027:
028: import java.io.Serializable;
029: import java.util.Vector;
030:
031: /**
032: * Used by objects to provide an implementation of an update observable.
033: * Assists in managment of update listeners. Objects can either extend or
034: * delegate to this class.
035: */
036: public class UpdateObservable implements Serializable {
037: private Vector updateListeners = null;
038:
039: /**
040: * Default constructor
041: */
042: public UpdateObservable() {
043: updateListeners = new Vector();
044: }
045:
046: /**
047: * Add an update listener to observe this object
048: */
049: public void addUpdateListener(UpdateListener ul) {
050: updateListeners.add(ul);
051: }
052:
053: /**
054: * Remove an update listener such that it no longer gets notified of changes
055: * to this object
056: */
057: public void removeUpdateListener(UpdateListener ul) {
058: updateListeners.remove(ul);
059: }
060:
061: /**
062: * Send event to all update listeners indicating that object has been added
063: * to the log plan.
064: *
065: * @param sourceObject object that has been added
066: */
067: public void fireObjectAdded(Object sourceObject) {
068: for (int i = 0; i < updateListeners.size(); i++) {
069: UpdateListener updateListener = (UpdateListener) updateListeners
070: .elementAt(i);
071: updateListener.objectAdded(sourceObject);
072: }
073: }
074:
075: /**
076: * Send event to all update listeners indicating that object has been changed
077: * on the log plan.
078: *
079: * @param sourceObject object that has been changed
080: */
081: public void fireObjectChanged(Object sourceObject) {
082: for (int i = 0; i < updateListeners.size(); i++) {
083: UpdateListener updateListener = (UpdateListener) updateListeners
084: .elementAt(i);
085: updateListener.objectChanged(sourceObject);
086: }
087: }
088:
089: /**
090: * Send event to all update listeners indicating that object has been removed
091: * from the log plan.
092: *
093: * @param sourceObject object that has been removed
094: */
095: public void fireObjectRemoved(Object sourceObject) {
096: for (int i = 0; i < updateListeners.size(); i++) {
097: UpdateListener updateListener = (UpdateListener) updateListeners
098: .elementAt(i);
099: updateListener.objectRemoved(sourceObject);
100: }
101: }
102: }
|