⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 provider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package net.sourceforge.gjtapi.jcc;

/*
	Copyright (c) 2002 Deadman Consulting (www.deadman.ca) 

	All rights reserved. 

	Permission is hereby granted, free of charge, to any person obtaining a 
	copy of this software and associated documentation files (the 
	"Software"), to deal in the Software without restriction, including 
	without limitation the rights to use, copy, modify, merge, publish, 
	distribute, and/or sell copies of the Software, and to permit persons 
	to whom the Software is furnished to do so, provided that the above 
	copyright notice(s) and this permission notice appear in all copies of 
	the Software and that both the above copyright notice(s) and this 
	permission notice appear in supporting documentation. 

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
	OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 
	OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
	HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 
	INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 
	FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 
	NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 
	WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 

	Except as contained in this notice, the name of a copyright holder 
	shall not be used in advertising or otherwise to promote the sale, use 
	or other dealings in this Software without prior written authorization 
	of the copyright holder.
*/
import net.sourceforge.gjtapi.*;
import net.sourceforge.gjtapi.jcc.filter.*;
import javax.csapi.cc.jcc.*;
import javax.jcat.JcatAddress;
import javax.jcat.JcatProvider;
import javax.telephony.Call;
import javax.telephony.CallListener;
import javax.telephony.Connection;
import javax.telephony.Terminal;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.ref.WeakReference;
/**
 * Provider of JAIN Call Control services as a layer on the Generic JTAPI Framework.
 * Creation date: (2000-10-10 12:33:24)
 * @author: Richard Deadman
 */
public class Provider implements JccProvider, JcatProvider {

	/**
	 * Support class for tracking Generic JTAPI object associations back to
	 * the Jcc wrappers.
	 * <P>We have to make this a double-weak map so that the values (which hold handles
	 * to the keys) don't keep the keys from being garbage-collected.
	 **/
	private class DoubleWeakMap extends WeakHashMap {
		public Object put(Object key, Object value) {
			WeakReference wValue = (value instanceof WeakReference) ?
				(WeakReference)value :
				new WeakReference(value);
			Object prev = super.put(key, wValue);
			if (prev instanceof WeakReference)
				return ((WeakReference)prev).get();
			else
				return prev;
		}

		public Object get(Object key) {
			Object value = super.get(key);
			if (value instanceof WeakReference)
				return ((WeakReference)value).get();
			else
				return value;
		}
	}
	private GenericProvider genProv = null;
	private Map callListeners = new HashMap();	// JcpCallListener -> CallListenerAdapter
	private Map loadListeners = new HashMap();	//  CallLoadControlListener -> CallLoadControlEventFilter
	private DoubleWeakMap addrMap = new DoubleWeakMap();
	private DoubleWeakMap callMap = new DoubleWeakMap();
	private DoubleWeakMap connMap = new DoubleWeakMap();
	private DoubleWeakMap termMap = new DoubleWeakMap();
	private DoubleWeakMap termConnMap = new DoubleWeakMap();
/**
 * Provider constructor comment.
 */
public Provider(GenericProvider prov) {
	super();

	this.setGenProv(prov);
	
	// tell the GJTAPI provider about me
	prov.hookupJainCallback(this);
}
/**
 * addCallListener method comment.
 */
/*public void addCallListener(JccCallListener cl, EventFilter filter)
	//throws jain.application.services.jcp.MethodNotSupportedException, jain.application.services.jcp.ResourceUnavailableException
	{
	Map listMap = this.getCallListeners();
	
		// first see if we already have the listener registered.
	CallListenerAdapter cla = (CallListenerAdapter)listMap.get(cl);
	if (cla == null) {
		if (cl instanceof JccConnectionListener)
			cla = new ConnListenerAdapter(this,
					(JccConnectionListener)cl,
					filter);
		else
			cla = new CallListenerAdapter(this, cl, filter);

			// now add the new adapter
		listMap.put(cl, cla);
	} else {
		cla.setFilter(filter);
	}
}*/
/**
 * addCallListener method comment.
 */
public void addCallListener(JccCallListener cl) throws javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
	Map listMap = this.getCallListeners();
	
		// first see if we already have the listener registered.
	CallListenerAdapter cla = (CallListenerAdapter)listMap.get(cl);
	if (cla == null) {
		if (cl instanceof JccConnectionListener)
			cla = new ConnListenerAdapter(this,
					(JccConnectionListener)cl,
					null);
		else
			cla = new CallListenerAdapter(this, cl);

			// now add the new adapter to my list of JccCallListeners to add to later calls
		listMap.put(cl, cla);
		
		// ask any current calls to add the adapter
		this.addToAllCalls(cla);
	}
}

/**
 * Add a CallListenerAdapter to all existing calls on the GJTAPI domain, causing them to send
 * snapshot messages.
 * @param CallListener listener The CallListener to register against all calls.
 * @author Richard Deadman
 */
private void addToAllCalls(CallListener cl) {
	try {
		Call[] gCalls = this.getGenProv().getCalls();
		if (gCalls != null)
			for (int i = 0; i < gCalls.length; i++)
			    try {
					gCalls[i].addCallListener(cl);
			    } catch (javax.telephony.MethodNotSupportedException mnse) {
			    	// can't register with existing calls -- fail silently
			    }
	} catch (javax.telephony.ResourceUnavailableException rue) {
		// can't find existing calls -- fail silently
	}

}
/**
 * addCallLoadControlListener method comment.
 */
/*public void addCallLoadControlListener(CallLoadControlListener clcl, EventFilter filter) throws javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
	this.getLoadListeners().put(clcl, filter);
}*/
/**
 * Add a CallLoadControlListener with no filter
 */
public void addCallLoadControlListener(CallLoadControlListener clcl) throws javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
	this.getLoadListeners().put(clcl, null);
}
/**
 * addConnectionListener method comment.
 */
public void addConnectionListener(JccConnectionListener cl, EventFilter filter) {
	Map listMap = this.getCallListeners();
	
		// first see if we already have the listener registered.
	CallListenerAdapter cla = (CallListenerAdapter)listMap.get(cl);
	if (cla == null) {
		cla = new ConnListenerAdapter(this,
					(JccConnectionListener)cl,
					filter);
			// now add the new adapter
		listMap.put(cl, cla);
		
			// and add it to all existing calls
		this.addToAllCalls(cla);

	} else {
		if (cla instanceof ConnListenerAdapter)
			((ConnListenerAdapter)cla).setFilter(filter);
	}
}

/**
 * addProviderListener method comment.
 */
public void addProviderListener(JccProviderListener pl) throws javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
	try {
		this.getGenProv().addProviderListener(new ProviderListenerAdapter(
			this,
			pl));
	} catch (javax.telephony.ResourceUnavailableException rue) {
		throw new javax.csapi.cc.jcc.ResourceUnavailableException(rue.getType());
	} catch (javax.telephony.MethodNotSupportedException mnse) {
		throw new javax.csapi.cc.jcc.MethodNotSupportedException(mnse.getMessage());
	}
}
/**
 * Dispatch CallLoad cease events to all listeners
 * Creation date: (2000-11-14 16:07:15)
 * @param addr javax.telephony.Address
 */
public void callOverloadCeased(FreeAddress addr) {
	GenAddress ga = this.findAddress(addr);
	if (ga != null) {
		Iterator it = this.getLoadListeners().entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry)it.next();
			CallLoadControlListener listener = (CallLoadControlListener)entry.getKey();
			EventFilter filter = (EventFilter)entry.getValue();
			CallLoadControlEvent event = new CallOverloadEvent(this.findAddress(addr),
						CallLoadControlEvent.PROVIDER_CALL_OVERLOAD_CEASED);
			if ((filter == null) || (filter.getEventDisposition(event) != EventFilter.EVENT_DISCARD))
				listener.providerCallOverloadCeased(event);
		}
	}
}
/**
 * Insert the method's description here.
 * Creation date: (2000-11-14 16:07:15)
 * @param addr javax.telephony.Address
 */
public void callOverloadEncountered(FreeAddress addr) {
	GenAddress ga = this.findAddress(addr);
	if (ga != null) {
		Iterator it = this.getLoadListeners().entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry)it.next();
			CallLoadControlListener listener = (CallLoadControlListener)entry.getKey();
			EventFilter filter = (EventFilter)entry.getValue();
			CallLoadControlEvent event = new CallOverloadEvent(this.findAddress(addr),
						CallLoadControlEvent.PROVIDER_CALL_OVERLOAD_ENCOUNTERED);
			if ((filter == null) || (filter.getEventDisposition(event) != EventFilter.EVENT_DISCARD))
				listener.providerCallOverloadEncountered(event);
		}
	}
}
/**
 * createCall method comment.
 */
public JccCall createCall() throws javax.csapi.cc.jcc.InvalidStateException, javax.csapi.cc.jcc.PrivilegeViolationException, javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
	GenCall call = null;
	try {
		call = this.findCall((FreeCall)this.getGenProv().createCall());
	} catch (javax.telephony.InvalidStateException ise) {
		throw new javax.csapi.cc.jcc.InvalidStateException(ise.getObject(),
								ise.getObjectType(),
								ise.getState(),
								ise.getMessage());
	} catch (javax.telephony.PrivilegeViolationException pve) {
		throw new javax.csapi.cc.jcc.PrivilegeViolationException(pve.getType(), pve.getMessage());
	} catch (javax.telephony.MethodNotSupportedException mnse) {
		throw new javax.csapi.cc.jcc.MethodNotSupportedException(mnse.getMessage());
	} catch (javax.telephony.ResourceUnavailableException rue) {
		throw new javax.csapi.cc.jcc.ResourceUnavailableException(rue.getType());
	}

		// now add any listeners
	Map callListeners = this.getCallListeners();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -