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

📄 genconnection.java

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

/*
	Copyright (c) 2002 Richard Deadman, 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 java.util.HashSet;
import java.util.Set;

import net.sourceforge.gjtapi.*;
import javax.csapi.cc.jcc.*;
import javax.jcat.JcatConnection;
import javax.telephony.Address;
import javax.telephony.Connection;
import javax.telephony.Terminal;
import javax.telephony.TerminalConnection;
/**
 * Jain Jcc Connection adapter for a Generic JTAPI Connection.
 *
 * <P>Note that current implementations of release(int) and getRedirectedAddress() are
 * not properly implemented due to an insufficient service provider SPI not providing sufficient information.
 *
 * Creation date: (2000-10-10 13:48:56)
 * @author: Richard Deadman
 */
public class GenConnection implements JccConnection, JcatConnection {
	private Provider prov = null;
	private Connection frameConn;
	/**
	 * Call
	 * This is the lazily instantiated handle to the JccCall I am connected to.
	 **/
	private JccCall call = null;
	/**
	 * Address
	 * This is the JcpAddress that I am associated with.  This is used to figure out where
	 * to route the call later.
	 **/
	private JccAddress address = null;
	/**
	 * Blocking flag
	 * <P>This indicates whether the Connection is currently blocked from further processing.
	 * This is generally set by a EventFilter returning EVENT_BLOCK for an event.
	 * Once blocked, actions on the Connection cannot take place until a "continueProcessing()"
	 * message is sent.  Currently we do not support blocking time-outs.
	 **/
	private boolean blocked = false;
	/**
	 * LastAddr
	 * <P>This is the last redirected address for this part of the call before it was redirected.
	 * It's not clear why this isn't a Call property, but we assume that when the documentation
	 * states "the last redirected JcpAddress associated with the JcpCall" it really means the
	 * series of redirected call legs.
	 **/
	private JccAddress lastAddr = null;
	/**
	 * OriginalAddress
	 * <P>This is the original address for this part of the call before it was transferred.
	 * It's not clear why this isn't a Call property, but we assume that when the documentation
	 * states "the original JcpAddress associated with the JcpCall" it really means the series
	 * of routed call legs.
	 **/
	private JccAddress origAddr = null;
	/**
	 * CallingAddr
	 * This is the source address for the connection, if one exists.
	 **/
	private GenAddress callingAddr = null;
	/**
	 * routeAddreses
	 * This is a  route addresses that is appended to the Connection address
	 * when trying to route a call.
	 **/
	private String routeAddress = null;

	private int state = 0;
/**
 * This is created by a Call.createConnection, and leaves the Connection ready to be routed.
 * Creation date: (2000-11-09 15:11:29)
 * @param targetAddress java.lang.String
 * @param originatingAddress java.lang.String
 * @param redirectingAddress java.lang.String
 */
public GenConnection(Provider prov, JccCall call, JccAddress addr, GenAddress originatingAddress, JccAddress originalCalledAddress, JccAddress redirectingAddress) {
	super();

	this.setProv(prov);
	this.setCall(call);
	this.setAddress(addr);
	this.setCallingAddr(originatingAddress);
	this.setOrigAddr(originalCalledAddress);
	this.setLastAddr(redirectingAddress);
}
/**
 * GenConnection constructor comment.
 */
public GenConnection(Provider prov, Connection conn) {
	super();

	this.setProv(prov);
	this.setFrameConn(conn);
}
/**
 * answer method comment.
 */
public void answer() {
	// unblock
	this.continueProcessing();

	TerminalConnection[] tcs = this.getFrameConn().getTerminalConnections();
	if (tcs.length > 0)
		try {
			tcs[0].answer();
		} catch (Exception e) {
			throw new RuntimeException("Could not answer due to " + e);
		}
}
/**
 * attachMedia method comment.
 */
public void attachMedia() {
	// unblock
	this.continueProcessing();

	this.attachMedia(true);
}
/**
 * attachMedia method comment.
 */
private void attachMedia(boolean flag) {
	this.getProv().getGenProv().getRaw().attachMedia(((GenCall)this.getCall()).getFrameCall().getCallID(),
		this.getAddress().getName(),
		flag);
}
/**
 * Enable call processing to continue on this connection.
 */
public void continueProcessing() {
	this.setBlocked(false);
}
/**
 * detachMedia method comment.
 */
public void detachMedia() {
	// unblock
	this.continueProcessing();

	this.attachMedia(false);
}
/**
 * Am I sematically equal to the other object.
 * Creation date: (2000-10-10 13:51:57)
 * @return boolean
 * @param other java.lang.Object
 */
public boolean equals(Object other) {
	if (other instanceof GenConnection) {
		GenConnection gc = (GenConnection)other;
		return ((this.getCall().equals(gc.getCall())) &&
			(this.getAddress().equals(gc.getAddress())));
	}
	return false;
}
/**
 * getAddress method comment.
 */
public synchronized JccAddress getAddress() {
	if (this.address == null) {
		this.address = this.getProv().findAddress((FreeAddress)this.getFrameConn().getAddress());
	}
	return this.address;
}
/**
 * getCall method comment.
 */
public synchronized JccCall getCall() {
	if (this.call == null) {
		this.call = this.getProv().findCall((FreeCall)this.getFrameConn().getCall());
	}
	return this.call;
}
/**
 * Internal accessor.
 * Creation date: (2000-11-09 15:23:18)
 * @return java.lang.String
 */
private GenAddress getCallingAddr() {
	return callingAddr;
}
/**
 * getDestinationAddress method comment.
 */
public String getDestinationAddress() {
	int state = this.getJccState();
	if ((state == ADDRESS_COLLECT) ||
		(state == ADDRESS_ANALYZE) ||
		(state == CALL_DELIVERY)) {
			if (this.getRouteAddress() != null)
				return this.getRouteAddress();
			else
				return this.getAddress().getName();
		}
	return null;
}
/**
 * Insert the method's description here.
 * Creation date: (2000-10-10 13:54:27)
 * @return javax.telephony.Connection
 */
private javax.telephony.Connection getFrameConn() {
	return frameConn;
}
/**
 * This is an artifact of earlier Jcc version. Since it is no longer part of the
 * API, but is used by another method, it is now private.
 */
private int getJccState() {
	int jtapiState = this.getFrameConn().getState();
	switch (jtapiState) {
		case Connection.ALERTING: {
			return JccConnection.ALERTING;
		}
		case Connection.CONNECTED: {
			return JccConnection.CONNECTED;
		}
		case Connection.DISCONNECTED: {
			return JccConnection.DISCONNECTED;
		}
		case Connection.FAILED: {
			return JccConnection.FAILED;
		}
		case Connection.IDLE: {
			return JccConnection.IDLE;
		}
		case Connection.INPROGRESS: {
			int jccState = this.state;
			/* if ((jccState == JccConnection.ADDRESS_ANALYZE) ||
				(jccState == JccConnection.ADDRESS_COLLECT) ||
				(jccState == JccConnection.AUTHORIZE_CALL_ATTEMPT) ||
				(jccState == JccConnection.CALL_DELIVERY)) */
			return jccState;
		}
		default: {
			return JccConnection.FAILED;	// should never be here -- but no UNKNOWN in Jcc anymore
		}
	}
}
/**
 * Internal accessor for the address that I will be routed to.
 * Creation date: (2000-11-09 15:23:18)
 * @return java.lang.String
 */
private JccAddress getJccAddress() {
	return address;
}
/**
 * getLastAddr method comment.
 */
public String getLastAddress() {
	return this.lastAddr.getName();
}
/**
 * getMoreDialledDigits method comment.
 */
public java.lang.String getMoreDialedDigits() {
	return this.getProv().getGenProv().getRaw().getDialledDigits(((GenCall)this.getCall()).getFrameCall().getCallID(),
		this.getAddress().getName());
}
/**
 * getOriginalAddress method comment.
 */
public String getOriginalAddress() {
	return this.origAddr.getName();
}
/**
 * getOriginalAddress method comment.
 */
public JccAddress getOriginatingAddress() {
	return this.getCallingAddr();
}

/**
		Returns the redirected address.
		Only after the event with id. {@link JcpConnectionEvent#CONNECTION_DISCONNECTED
		CONNECTION_DISCONNECTED} with cause code {@link JccCallEvent#CAUSE_REDIRECTED
		CAUSE_REDIRECTED} occured and the connection returned by
		{@link JcpConnectionEvent#getConnection()} is <code>this</code> and it is a
		terminating connection, this method will return the address of the party to
		which this connection is redirected.  In all other cases this method returns
		<code>null</code>.

		<P>Note: Currently the TelephonyListener does not receive redirecting information
		for connection disconnects, and so this information is not available.

		@return the address to which the call is redirected or <code>null</code> if
		the call is not redirected.
		@since 1.0a
    */
    public String getRedirectedAddress() {
    	return null;
    }

/**
 * Internal accessor for the Call I am a part of
 * Creation date: (2000-11-09 15:32:29)
 * @return jain.application.services.jcc.JccCall
 */
private JccCall getPrivateCall() {
	return call;
}
/**
 * Insert the method's description here.
 * Creation date: (2000-10-30 12:55:56)
 * @return com.uforce.jain.generic.Provider
 */
private Provider getProv() {
	return prov;
}
/**
 * Internal accessor for the route address.
 * Creation date: (2001-01-24 10:39:17)
 * @return java.lang.String
 */
private java.lang.String getRouteAddress() {
	return routeAddress;
}
/**
 * getState method comment.
 */
public int getState() {
	return this.getJccState();
}
/**
 * Combination of Provider, call and address hashcodes
 * Creation date: (2000-10-10 13:50:25)
 * @return int
 */
public int hashCode() {
	return this.getCall().hashCode() + this.getAddress().hashCode();
}
/**
 * Am I blocked from futher processing?
 */
public boolean isBlocked() {
	return this.blocked;
}
/**
 * release method comment.
 */
public void release() throws javax.csapi.cc.jcc.InvalidStateException, javax.csapi.cc.jcc.PrivilegeViolationException, javax.csapi.cc.jcc.ResourceUnavailableException {
	// unblock
	this.continueProcessing();

	try {
		this.getFrameConn().disconnect();
	} catch (javax.telephony.InvalidStateException ise) {

⌨️ 快捷键说明

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