📄 inverterprovider.java
字号:
package net.sourceforge.gjtapi.raw.invert;
/*
Copyright (c) 2002 8x8 Inc. (www.8x8.com)
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 javax.telephony.privatedata.PrivateData;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.capabilities.CallControlTerminalConnectionCapabilities;
import javax.telephony.capabilities.*;
import net.sourceforge.gjtapi.*;
import net.sourceforge.gjtapi.capabilities.*;
import javax.telephony.*;
import javax.telephony.media.*;
import java.util.*;
/**
* This is an Generic JTAPI "raw" Telephony Provider that wraps a JTAPI Provider and allows
* the Generic JTAPI Framework to act as a decorator to a JTAPI Provider.
* Creation date: (2000-05-31 17:42:58)
* @author: Richard Deadman
*/
public abstract class InverterProvider implements net.sourceforge.gjtapi.raw.FullJtapiTpi {
private final static String RESOURCE_NAME = "Inverter.props";
private final static String PEER_KEY = "PeerClassName";
private final static String PROV_KEY = "ProviderString";
private final static String MEDIA_FREE_RELEASE = "mediaFreeRelease";
private javax.telephony.Provider jtapiProv;
private Map provProps; // temporary map holder
private InverterListener listener = null; // an adapter to delegate JTAPI events to TelephonyEvents
private IdMapper callMap = new IdMapper(); // CallId <-> Call map.
// do we release a MediaService when media is freed from a Terminal?
private boolean mediaFreeRelease = false;
/**
* Raw constructor used by the GenericJtapiPeer factory
* Creation date: (2000-02-10 10:28:55)
* @author: Richard Deadman
*/
public InverterProvider() {
super();
// read provider details and load the resources, if available
this.setProvProps(this.loadResources(InverterProvider.RESOURCE_NAME));
this.setListener(new InverterListener(this.getCallMap()));
}
/**
* Set the raw TelephonyListener event receiver.
* <P>Note that the framework is assumed to set this before any events occur. Otherwise we will throw
* null-pointer exceptions back to JTAPI.
*/
public void addListener(TelephonyListener ro) {
this.getListener().setTListener(ro);
}
/**
* answerCall method comment.
*/
public void answerCall(CallId call, String address, String terminal) throws PrivilegeViolationException, MethodNotSupportedException, ResourceUnavailableException, RawStateException {
TerminalConnection tc = this.getTc(call, address, terminal);
if (tc != null) { // we found the connection
try {
tc.answer();
} catch (InvalidStateException ise) {
throw new RawStateException(call, address, terminal,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
} else {
throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "Could not find terminal connection");
}
}
/**
* Connect a call referenced by an id from a terminal connection to a destination address.
*
* @param id The id for the already created idle call
* @param address The name of to originating address
* @param terminal The name of the originating terminal
* @param dest The name of the destination address
* @return The call id.
*/
public CallId createCall(CallId id, String address, String terminal, String dest) throws MethodNotSupportedException, RawStateException, ResourceUnavailableException, InvalidPartyException, InvalidArgumentException, PrivilegeViolationException {
Call c = this.getCallMap().jtapiCall(id);
Provider prov = this.getJtapiProv();
Address addr = prov.getAddress(address);
Terminal term = prov.getTerminal(terminal);
try {
c.connect(term, addr, dest);
} catch (InvalidStateException ise) {
throw new RawStateException(id, address, terminal,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
return id;
}
/**
* Code to perform when this object is garbage collected.
*
* Any exception thrown by a finalize method causes the finalization to
* halt. But otherwise, it is ignored.
*/
protected void finalize() throws Throwable {
try {
this.getJtapiProv().shutdown();
} catch (Exception ex) {
// ignore
}
}
/**
* getAddresses method comment.
*/
public java.lang.String[] getAddresses() throws ResourceUnavailableException {
Address[] addrs = this.getJtapiProv().getAddresses();
String[] result = new String[addrs.length];
for (int i = 0; i < addrs.length; i++) {
result[i] = addrs[i].getName();
}
return result;
}
/**
* Get the Address names associated with a Terminal name.
*/
public String[] getAddresses(String terminal) throws javax.telephony.InvalidArgumentException {
Address[] addrs = this.getJtapiProv().getTerminal(terminal).getAddresses();
String[] result = new String[addrs.length];
for (int i = 0; i < addrs.length; i++) {
result[i] = addrs[i].getName();
}
return result;
}
/**
* Ask the raw TelephonyProvider to give a snapshot of the indicated Call.
* <P>This will only be called on a TelephonyProvider that "trottle"s call events.
* <P><B>Note:</B> This implies that the given Call will have events delivered on it until such time
* as a "TelephonyProvider::releaseCallId(CallId)".
* Creation date: (2000-06-20 15:22:50)
* @author: Richard Deadman
* @return net.sourceforge.gjtapi.CallData
* @param id net.sourceforge.gjtapi.CallId
*/
public CallData getCall(CallId id) {
// find the call
Call call = this.getCallMap().jtapiCall(id);
// ensure we are still listening to the call
try {
this.register(call);
} catch (MethodNotSupportedException mnse) {
// we can't monitor the call!
} catch (ResourceUnavailableException rue) {
// we can't monitor the call!
}
return this.toCallData(call);
}
/**
* Accessor for CallId to Call map.
* Creation date: (2000-06-06 13:04:17)
* @author: Richard Deadman
* @return A map of Call to CallId objects.
*/
private IdMapper getCallMap() {
return callMap;
}
/**
* Ask the raw TelephonyProvider to give a snapshot of all Calls on an Address.
* <P>This will only be called on a TelephonyProvider that "trottle"s call events.
* <P><B>Note:</B> This implies that the given Call will have events delivered on it until such time
* as a "TelephonyProvider::releaseCallId(CallId)".
* Creation date: (2000-06-20 15:22:50)
* @author: Richard Deadman
* @return A set of call data.
* @param number The Address's logical number
*/
public CallData[] getCallsOnAddress(String number) {
Address addr = null;
try {
addr = this.getJtapiProv().getAddress(number);
} catch (InvalidArgumentException iae) {
// fall though
}
if (addr != null) {
HashSet calls = new HashSet();
Connection[] conns = addr.getConnections();
if (conns != null) {
int connSize = conns.length;
for (int i = 0; i < connSize; i++) {
Call call = conns[i].getCall();
CallData cd = this.toCallData(call);
if (cd != null) {
calls.add(cd);
try {
this.register(call);
} catch (Exception ex) {
// we can't track these!
System.out.println("Failure to track changes to: " + call + "; Reason: " + ex);
}
}
}
}
return (CallData[])calls.toArray(new CallData[0]);
}
return null;
}
/**
* Ask the raw TelephonyProvider to give a snapshot of all Calls at a Terminal.
* <P>This will only be called on a TelephonyProvider that "trottle"s call events.
* <P><B>Note:</B> This implies that the given Calls will have events delivered on it until such time
* as a "TelephonyProvider::releaseCallId(CallId)".
* Creation date: (2000-06-20 15:22:50)
* @author: Richard Deadman
* @return A set of call data.
* @param name The Terminal's logical name
*/
public CallData[] getCallsOnTerminal(String name) {
Terminal term = null;
try {
term = this.getJtapiProv().getTerminal(name);
} catch (InvalidArgumentException iae) {
// fall though
}
if (term != null) {
HashSet calls = new HashSet();
TerminalConnection[] tcs = term.getTerminalConnections();
if (tcs != null) {
int tcsSize = tcs.length;
for (int i = 0; i < tcsSize; i++) {
Call call = tcs[i].getConnection().getCall();
CallData cd = this.toCallData(call);
if (cd != null) {
calls.add(cd);
try {
this.register(call);
} catch (Exception ex) {
// we can't track these!
System.out.println("Failure to track changes to: " + call + "; Reason: " + ex);
}
}
}
}
return (CallData[])calls.toArray(new CallData[0]);
}
return null;
}
/**
* Interrogate JTAPI capabilities and return a property holder for them to the Generic Framework.
*/
public Properties getCapabilities() {
Properties props = new Properties();
Provider prov = this.getJtapiProv();
// fill in the provider stuff
CallCapabilities cCap = prov.getCallCapabilities();
props.put(Capabilities.CREATE, new Boolean(cCap.canConnect()));
ConnectionCapabilities conCap = prov.getConnectionCapabilities();
props.put(Capabilities.RELEASE, new Boolean(conCap.canDisconnect()));
TerminalConnectionCapabilities tcCap = prov.getTerminalConnectionCapabilities();
props.put(Capabilities.ANSWER, new Boolean(tcCap.canAnswer()));
if (tcCap instanceof CallControlTerminalConnectionCapabilities) {
CallControlTerminalConnectionCapabilities cctcc = (CallControlTerminalConnectionCapabilities)tcCap;
props.put(Capabilities.HOLD, new Boolean(cctcc.canHold()));
props.put(Capabilities.JOIN, new Boolean(cctcc.canJoin()));
}
props.put(Capabilities.THROTTLE, Boolean.TRUE);
return props;
}
/**
* Package-protected accessor for the wrapped JTAPI Provider.
* Creation date: (2000-06-01 14:40:49)
* @author: Richard Deadman
* @return A JTAPI Provider I am a raw Generic Telephony Provider adapter for.
*/
protected javax.telephony.Provider getJtapiProv() {
return jtapiProv;
}
/**
* Package accessor for the Generic Framework listener adapter that listens to JTAPI events and
* sends Generic JTAPI Framework events.
* Creation date: (2000-06-06 13:04:17)
* @author: Richard Deadman
* @return The InverterListener
*/
InverterListener getListener() {
return listener;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -