📄 gencall.java
字号:
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 javax.csapi.cc.jcc.*;
import javax.jcat.JcatAddress;
import javax.jcat.JcatCall;
import javax.jcat.JcatConnection;
import javax.jcat.JcatTerminal;
import javax.jcat.JcatTerminalConnection;
import javax.jcat.JcatTerminalConnectionListener;
import javax.telephony.Connection;
import java.util.*;
/**
* Wrapper for a Generic JTAPI Framework Call object to make it Jain Jcc compliant.
*
* <P>Note that the current implementation of release(int) is
* not properly implemented due to an insufficient service provider SPI not providing sufficient information.
*
* Creation date: (2000-10-10 12:42:59)
* @author: Richard Deadman
*/
public class GenCall implements JccCall, JcatCall {
/**
* Supervisor alarm.
* This is a thread that times when a supervisor ends on a call and executes a treatment.
**/
public class Supervisor implements Runnable {
private GenCall call;
private JccCallListener listener;
private double duration;
private int treatment;
public Supervisor(GenCall c, JccCallListener cl, double dur, int treat) {
super();
this.call = c;
this.listener = cl;
this.duration = dur;
this.treatment = treat;
}
/**
* The thread is run when the call becomes active
**/
public void run() {
try {
Thread.sleep((long)this.duration);
} catch (InterruptedException ie) {
// carry on
}
// Now do my treatment
int treat = this.treatment;
if ((treat & 4) > 0) {
// send warning tone
FreeCall fc = this.call.getFrameCall();
((GenericProvider)fc.getProvider()).getRaw().beep(fc.getCallID());
}
if ((treat & 1) > 0) {
try {
call.release();
} catch (Exception ex) {
// ignore
}
}
if ((treat & 2) > 0) {
this.listener.callSuperviseEnd(new SuperviseEvent(this.call,
JccCallEvent.CALL_SUPERVISE_END));
}
// now remove the listener
this.call.removeCallListener(this.listener);
}
}
public class SuperviseEvent implements JccCallEvent {
private GenCall call;
private int id;
public SuperviseEvent(GenCall call, int eId) {
super();
this.call = call;
this.id = eId;
}
public int getID() {
return this.id;
}
public JccCall getCall() {
return this.call;
}
public Object getSource() {
return this.getCall();
}
public int getCause() {
// must use JcpCallEvent constant to avoid Jcc 1.0b error
return JccCallEvent.CAUSE_NORMAL;
}
}
private Provider provider;
private FreeCall frameCall;
private Set pendingConns = new HashSet();
private Set waitingSupervisors = new HashSet();
/**
* GenCall constructor comment.
*/
public GenCall(Provider prov, FreeCall call) {
super();
this.setProvider(prov);
this.setFrameCall(call);
}
/**
* addCallListener method comment.
*/
public void addCallListener(JccCallListener listener) throws javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
this.getFrameCall().addCallListener(new CallListenerAdapter((Provider)this.getProvider(), listener));
}/**
* addConnectionListener method comment.
*/
public void addConnectionListener(JccConnectionListener cl, EventFilter fl) throws javax.csapi.cc.jcc.ResourceUnavailableException, javax.csapi.cc.jcc.MethodNotSupportedException {
this.getFrameCall().addCallListener(new ConnListenerAdapter((Provider)this.getProvider(), cl, fl));
}
/**
* Add a Connection to the list of those about to be routed.
* Creation date: (2000-11-09 16:27:58)
* @param conn com.uforce.jain.generic.GenConnection
*/
private void addPendingConn(GenConnection conn) {
this.getPendingConns().add(conn);
}
/**
* Here we return the single connection that is created from the originating address.
*/
public JccConnection createConnection(String targetAddress, String originatingAddress, String originalCalledAddress, String redirectingAddress) throws javax.csapi.cc.jcc.InvalidStateException, javax.csapi.cc.jcc.PrivilegeViolationException, javax.csapi.cc.jcc.MethodNotSupportedException, javax.csapi.cc.jcc.ResourceUnavailableException {
Provider prov = this.getPrivateProvider();
JccAddress target = null;
GenAddress origAddr = null;
JccAddress origCall = null;
JccAddress redirect = null;
try {
target = (JccAddress)prov.getAddress(targetAddress);
origAddr = (GenAddress)prov.getAddress(originatingAddress);
if (originalCalledAddress != null)
origCall = (JccAddress)prov.getAddress(originalCalledAddress);
if (redirectingAddress != null)
redirect = (JccAddress)prov.getAddress(redirectingAddress);
} catch (InvalidPartyException iae) {
throw new ResourceUnavailableException(
ResourceUnavailableException.ORIGINATOR_UNAVAILABLE);
}
GenConnection conn = new GenConnection(prov, this, target, origAddr, origCall, redirect);
this.addPendingConn(conn);
return conn;
}
/**
* Places a call from an originating address to a destination address string.
<p>The Call must be in the {@link JcpCall#IDLE} state (and therefore have no
existing associated JcpConnections and the Provider must be in the
{@link JcpProvider#IN_SERVICE} state. The successful effect of this method
is to place the call and create and return two JcpConnections associated with
this Call.
<h5>Method Arguments</h5>
This method has two arguments. The first argument is the originating Address
for the Call. The second argument is a destination string whose value represents
the address to which the call is placed. This destination address must be valid and
complete.
<h5>Method Post-conditions</h5>
This method returns successfully when the Provider can successfully initiate the
placing of the call. As a result, when the JccCall.connect() method returns, the JccCall
will be in the {@link JcpCall#ACTIVE} state and exactly two JccConnections will be
created and returned. The JccConnection associated with the originating endpoint is
the first JccConnection in the returned array. This JccConnection will execute the
originating JccConnection's Final State Diagram (see
<a href="package-summary.html#TOConnections">table 3</a>). The JccConnection associated
with the destination endpoint is the second JccConnection in the returned array and
will execute the terminating JccConnection's Final State Diagram. These
two JccConnections must at least be in the {@link #IDLE} state. That is, if one of
the Connections progresses beyond the IDLE state while this method is completing, this
Connection may be in a state other than the IDLE. This state must be reflected by an
event sent to the application.
<p><B>Pre-Conditions:</B> <OL>
<LI>(this.getProvider()).getState() == JcpProvider.IN_SERVICE
<LI>this.getState() == JcpCall.IDLE
</OL>
<B>Post-Conditions:</B> <OL>
<LI>(this.getProvider()).getState() == JcpProvider.IN_SERVICE
<LI>this.getState() == JcpCall.ACTIVE
<LI>Let Connection c[] = this.getConnections()
<LI>c.length == 2
<LI>c[0].getState() == JcpConnection.IDLE (at least)
<LI>c[1].getState() == JcpConnection.IDLE (at least)
</OL>
@param origaddr The originating Address for this call.
@param dialedDigits The destination address string for this call.
@return array of Connections
@throws ResourceUnavailableException An internal resource necessary for placing
the call is unavailable.
@throws PrivilegeViolationException The application does not have the proper
authority to place a call.
@throws InvalidPartyException Either the originator or the destination does not
represent a valid party required to place a call.
@throws InvalidStateException Some object required by this method is not in a valid
state as designated by the pre-conditions for this method.
@throws MethodNotSupportedException The implementation does not support this method.
@since 1.0a
*/
public JccConnection[] connect(JccAddress origaddr, String dialedDigits) throws
javax.csapi.cc.jcc.ResourceUnavailableException, javax.csapi.cc.jcc.PrivilegeViolationException, javax.csapi.cc.jcc.InvalidPartyException,
javax.csapi.cc.jcc.InvalidStateException, javax.csapi.cc.jcc.MethodNotSupportedException {
Provider prov = this.getPrivateProvider();
JccAddress target = null;
try {
target = (JccAddress)prov.getAddress(dialedDigits);
} catch (javax.csapi.cc.jcc.InvalidPartyException iae) {
throw new javax.csapi.cc.jcc.ResourceUnavailableException(
javax.csapi.cc.jcc.ResourceUnavailableException.ORIGINATOR_UNAVAILABLE);
}
GenConnection conn1 = new GenConnection(prov, this, origaddr, (GenAddress)origaddr, null, null);
GenConnection conn2 = new GenConnection(prov, this, target, (GenAddress)origaddr, null, null);
this.addPendingConn(conn1);
this.addPendingConn(conn2);
// now complete the routing
try {
conn1.routeConnection(true);
} catch (javax.csapi.cc.jcc.InvalidArgumentException iae) { // is this a spec. bug?
throw new javax.csapi.cc.jcc.InvalidStateException(conn1, javax.csapi.cc.jcc.InvalidStateException.CONNECTION_OBJECT, conn1.getState(), "trying to route connection");
}
try {
conn2.routeConnection(true);
} catch (javax.csapi.cc.jcc.InvalidArgumentException iae) { // is this a spec. bug?
throw new javax.csapi.cc.jcc.InvalidStateException(conn2, javax.csapi.cc.jcc.InvalidStateException.CONNECTION_OBJECT, conn2.getState(), "trying to route connection");
}
JccConnection jc[] = new JccConnection[2];
jc[0] = conn1;
jc[1] = conn2;
return jc;
}
/**
* Compares two objects for equality. Returns a boolean that indicates
* whether this object is equivalent to the specified object. This method
* is used when an object is stored in a hashtable.
* @param obj the Object to compare with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -