/* 
	ContextSupport.java

	Author:			daassi
	Description:	Event set support class for ContextListener.
					Manages listener registration and contains fire functions.
*/

package ContextListener;


import java.util.Vector;


public class ContextSupport implements java.io.Serializable
{
	Vector contextListeners = new Vector();
	
	public synchronized void addContextListener(ContextListener l)
	{
		// add a listener if it is not already registered
		if (!contextListeners.contains(l))
		{
			contextListeners.addElement(l);
		}
	}

	public synchronized void removeContextListener(ContextListener l)
	{
		// remove it if it is registered
		if (contextListeners.contains(l))
		{
			contextListeners.removeElement(l);
		}
	}
   
   public void fireNewContextInfos()
	{
		// Make a copy of the listener object vector so that
		// it cannot be changed while we are firing events.
		Vector v;
		synchronized(this)
		{
			v = (Vector) contextListeners.clone();
		}
		
		// Fire the event to all listeners.
		int count = v.size();
		for (int i = 0; i < count; i++)
		{
			ContextListener listener = (ContextListener) v.elementAt(i);
			listener.newContextInfos();
		}
	}
	
	public void fireNewProperties()
	{
		// Make a copy of the listener object vector so that
		// it cannot be changed while we are firing events.
		Vector v;
		synchronized(this)
		{
			v = (Vector) contextListeners.clone();
		}
		
		// Fire the event to all listeners.
		int count = v.size();
		for (int i = 0; i < count; i++)
		{
			ContextListener listener = (ContextListener) v.elementAt(i);
			listener.newProperties();
		}
	}
	
	
      
 /*  public void fireGetProperty()
	{
		// Make a copy of the listener object vector so that
		// it cannot be changed while we are firing events.
		Vector v;
		synchronized(this)
		{
			v = (Vector) contextListeners.clone();
		}
		
		// Fire the event to all listeners.
		int count = v.size();
		for (int i = 0; i < count; i++)
		{
			ContextListener listener = (ContextListener) v.elementAt(i);
			listener.getProperty();
		}
	}
	*/
	/*public void fireSetPropertyValues()
	{
		// Make a copy of the listener object vector so that
		// it cannot be changed while we are firing events.
		Vector v;
		synchronized(this)
		{
			v = (Vector) contextListeners.clone();
		}
		
		// Fire the event to all listeners.
		int count = v.size();
		for (int i = 0; i < count; i++)
		{
			ContextListener listener = (ContextListener) v.elementAt(i);
			listener.setPropertyValues();
		}
	}
	*/
	
	
}

/* ContextSupport.java */
