View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: RawDataMonitorable.java
13   * Created: 2008-10-09
14   * Author: kpietak
15   * $Id: AbstractRawDataMonitorable.java 2331 2009-01-13 12:56:25Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.rawdata.logging;
19  
20  import java.util.LinkedList;
21  import java.util.List;
22  
23  import org.apache.log4j.Logger;
24  import org.eclipse.core.runtime.Assert;
25  
26  import pl.edu.agh.cast.model.base.BasePlugin;
27  
28  /**
29   * Abstract class for monitorable raw data classes.
30   * 
31   * @author AGH CAST Team
32   */
33  public abstract class AbstractRawDataMonitorable implements IRawDataMonitorable {
34  
35  	private static Logger log = BasePlugin.getLogger();
36  
37  	private List<IRawDataObserver> observers;
38  
39  	/**
40  	 * Default constructor.
41  	 */
42  	public AbstractRawDataMonitorable() {
43  		observers = new LinkedList<IRawDataObserver>();
44  	}
45  
46  	/**
47  	 * 
48  	 * {@inheritDoc}
49  	 * 
50  	 * @see pl.edu.agh.cast.rawdata.logging.IRawDataMonitorable#
51  	 *      registerObserver(pl.edu.agh.cast.rawdata.logging.IRawDataObserver)
52  	 */
53  	public void registerObserver(IRawDataObserver observer) {
54  		Assert.isNotNull(observer, "Cannot register null value register"); //$NON-NLS-1$
55  		if (!observers.contains(observer)) {
56  			observers.add(observer);
57  			log.debug("The following observer has been registered: " //$NON-NLS-1$
58  			        + observer.toString());
59  		}
60  
61  	}
62  
63  	/**
64  	 * 
65  	 * {@inheritDoc}
66  	 * 
67  	 * @see pl.edu.agh.cast.rawdata.logging.IRawDataMonitorable#
68  	 *      unregisterObserver(pl.edu.agh.cast.rawdata.logging.IRawDataObserver)
69  	 */
70  	public void unregisterObserver(IRawDataObserver observer) {
71  		Assert.isNotNull(observer, "Cannot unregister null value register"); //$NON-NLS-1$
72  		observers.remove(observer);
73  		log.debug("The following observer has been unregistered: " //$NON-NLS-1$
74  		        + observer.toString());
75  
76  	}
77  
78  	protected List<IRawDataObserver> getObservers() {
79  		return observers;
80  	}
81  
82  }