📄 inverterprovider.java
字号:
}
/**
* Forward the getPrivateData off to the appropriate object, or return null if the object does not support PrivateData.
*/
public Object getPrivateData(CallId call, String address, String terminal) {
Object target = this.resolveTarget(call, address, terminal);
if ((target != null) && (target instanceof PrivateData)) {
return ((PrivateData)target).getPrivateData();
} else
return null;
}
/**
* Internal accessor for the properties map
* Creation date: (2000-02-22 14:20:52)
* @author: Richard Deadman
* @return The map that lists the provider properties
*/
private Map getProvProps() {
return provProps;
}
/**
* Find the TerminalConnection.
* @param call A call holding the TerminalConnection
* @param terminal The address of the TerminalConnection
* @param terminal The terminal of the TerminalConnection
* @return The TerminalConnection, or null.
*/
private TerminalConnection getTc(CallId call, String address, String terminal) {
Call c = this.getCallMap().jtapiCall(call);
Connection con = null;
TerminalConnection tc = null;
Connection[] conns = c.getConnections();
for (int i = 0; i < conns.length && con == null; i++) {
if (conns[i].getAddress().getName().equals(address)) {
con = conns[i];
TerminalConnection[] tcs = con.getTerminalConnections();
for (int j = 0; j < tcs.length && tc == null; i++) {
if (tcs[j].getTerminal().getName().equals(terminal)) {
tc = tcs[j];
}
}
}
}
return tc;
}
/**
* Get a list of available terminals.
* This may be null if the Telephony (raw) Provider does not support Terminals.
* If the Terminal set it too large, this will throw a ResourceUnavailableException
* <P>Since we went to lazy connecting between Addresses and Terminals, this is called so
* we don't have to follow all Address->Terminal associations to get the full set of Terminals.
* Creation date: (2000-02-11 12:29:00)
* @author: Richard Deadman
* @return An array of terminal names, media type containers.
* @exception ResourceUnavailableException if the set it too large to be returned dynamically.
*/
public TermData[] getTerminals() throws ResourceUnavailableException {
Terminal[] terms = this.getJtapiProv().getTerminals();
TermData[] result = new TermData[terms.length];
for (int i = 0; i < terms.length; i++) {
Terminal t = terms[i];
result[i] = new TermData(t.getName(), t instanceof MediaTerminal);
}
return result;
}
/**
* getTerminals method comment.
*/
public TermData[] getTerminals(String address) throws InvalidArgumentException {
Terminal[] terms = this.getJtapiProv().getAddress(address).getTerminals();
TermData[] result = new TermData[terms.length];
for (int i = 0; i < terms.length; i++) {
Terminal t = terms[i];
result[i] = new TermData(t.getName(), t instanceof MediaTerminal);
}
return result;
}
/**
* hold method comment.
*/
public void hold(CallId call, String address, String terminal) throws MethodNotSupportedException, RawStateException, PrivilegeViolationException, ResourceUnavailableException {
TerminalConnection tc = this.getTc(call, address, terminal);
if (tc != null) { // we found the connection
if (tc instanceof CallControlTerminalConnection) {
try {
((CallControlTerminalConnection)tc).hold();
} catch (InvalidStateException ise) {
throw new RawStateException(call, address, terminal,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
} else {
throw new MethodNotSupportedException("Not a CallControl Terminal Connection. Can't hold");
}
} else {
throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "Could not find terminal connection");
}
}
/**
* Initialize the Inverter Provider with a Map that defines which real JTAPI implementation to load beneath me.
* This consists of two properties:
* <ul>
* <li><B>PeerClassName</B> That defines the PeerClass name passed into the JtapiPeerFactory
* <li><B>ProviderString</B> That defines the provider service string passed into the JtapiPeer to create the provider.
* </ul>
* If "replace" is a map property, then the passed in map replaces instead of augmenting the default
* properties map.
*/
public void initialize(java.util.Map props) throws ProviderUnavailableException {
Map m = null;
Object value = null;
// determine if we need to totally replace the current properties
boolean replace = false;
if (props != null) {
value = props.get("replace");
if (value instanceof String && value != null) {
String override = (String)value;
if (override.length() > 0 && Character.toLowerCase(override.charAt(0)) == 't')
replace = true;
}
}
if (replace)
m = props;
else {
m = this.getProvProps();
m.putAll(props);
}
// create an instance of the Jtapi Provider
JtapiPeer peer = null;
try {
peer = JtapiPeerFactory.getJtapiPeer((String)m.get(InverterProvider.PEER_KEY));
} catch (JtapiPeerUnavailableException jpue) {
throw new ProviderUnavailableException(jpue.getMessage());
}
Provider prov = peer.getProvider((String)m.get(InverterProvider.PROV_KEY));
this.setJtapiProv(prov);
// set the release property
String releaseMedia = (String)m.get(InverterProvider.MEDIA_FREE_RELEASE);
if ((releaseMedia != null) && (releaseMedia.length() > 0) && (releaseMedia.toLowerCase().charAt(0) == 't'))
this.setMediaFreeRelease(true);
// free the map object
this.setProvProps(null);
}
/**
* isMediaTerminal method comment.
*/
public boolean isMediaTerminal(String terminal) {
Terminal term = null;
try {
term = this.getJtapiProv().getTerminal(terminal);
} catch (InvalidArgumentException iae) {
return false;
}
if (term instanceof MediaTerminal)
return true;
else
return false;
}
/**
* join method comment.
*/
public CallId join(CallId call1, CallId call2, String address, String terminal) throws MethodNotSupportedException, RawStateException, PrivilegeViolationException, InvalidArgumentException, ResourceUnavailableException {
IdMapper map = this.getCallMap();
Call c1 = map.jtapiCall(call1);
Call c2 = map.jtapiCall(call2);
if (c1 instanceof CallControlCall) {
try {
this.setConferenceController((CallControlCall)c1, address, terminal);
((CallControlCall)c1).conference(c2);
} catch (InvalidStateException ise) {
throw new RawStateException(call1, null, null,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
return call1;
} else if (c2 instanceof CallControlCall) {
try {
this.setConferenceController((CallControlCall)c2, address, terminal);
((CallControlCall)c2).conference(c1);
} catch (InvalidStateException ise) {
throw new RawStateException(call2, null, null,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
return call2;
} else {
throw new MethodNotSupportedException("Neither Call supports CallControl");
}
}
/**
* This method loads the Provider's initial values.
* Creation date: (2000-02-10 10:11:41)
* @author: Richard Deadman
*/
private Properties loadResources(String resName) {
// We must be able to load the properties file
Properties props = new Properties();
try {
props.load(this.getClass().getResourceAsStream("/" + InverterProvider.RESOURCE_NAME));
} catch (java.io.IOException ioe) {
// eat and hope that the initialize method sets my required properties
} catch (NullPointerException npe) {
// no resource file -- eat as well
}
// delay initialization until initialize() called -- allow property replacement
// return
return props;
}
/**
* Ensure that this call is registered with our Listener so that we get all state-change events.
* <P>Note: We require JTAPI providers under us to report accept Listeners and Observers since we use
* both to track state. As of JTAPI 1.2, not all packages supported Listeners, and so we need Observers
* to track call control state.
* Creation date: (2000-06-27 9:28:13)
* @author: Richard Deadman
* @param call The call to track the state of.
* @exception javax.telephony.MethodNotSupportedException The JTAPI inverter provider does not support both Observers and Listeners.
* @exception javax.telephony.ResourceUnavailableException The JTAPI inverter provider has run out of internal resources to track the object's state.
*/
private void register(Call call) throws MethodNotSupportedException, ResourceUnavailableException {
InverterListener il = this.getListener();
call.addCallListener(il);
call.addObserver(il);
}
/**
* release method comment.
*/
public void release(String address, CallId call) throws PrivilegeViolationException, MethodNotSupportedException, ResourceUnavailableException, RawStateException {
Call c = this.getCallMap().jtapiCall(call);
Connection con = null;
Connection[] conns = c.getConnections();
for (int i = 0; i < conns.length && con == null; i++) {
if (conns[i].getAddress().getName().equals(address)) {
con = conns[i];
}
}
if (con != null) {
try {
con.disconnect();
} catch (InvalidStateException ise) {
throw new RawStateException(call, address, null,
ise.getObjectType(),
ise.getState(),
ise.getMessage());
}
} else {
throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "Connection not found");
}
}
/**
* Release the Framework call id.
*/
public void releaseCallId(CallId id) {
this.getCallMap().freeId(id);
}
/**
* We should only get this prior to shutdown.
*/
public void removeListener(TelephonyListener ro) {
this.getListener().setTListener(null);
// tell InvertorListener to disconnect from all JTAPI objects.
// this.getListener().disconnect();
}
/**
* Tell the JTAPI provider to report events on Calls that visit this address.
*/
public void reportCallsOnAddress(String address, boolean flag)
throws InvalidArgumentException, ResourceUnavailableException {
Address addr = this.getJtapiProv().getAddress(address);
InverterListener list = this.getListener();
if (flag)
try {
addr.addCallListener(list);
addr.addCallObserver(list);
} catch (MethodNotSupportedException mnse) {
throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "Inverter Observer not supported");
}
else {
addr.removeCallListener(list);
addr.removeCallObserver(list);
}
}
/**
* reportCallsOnTerminal method comment.
*/
public void reportCallsOnTerminal(String terminal, boolean flag)
throws InvalidArgumentException, ResourceUnavailableException {
Terminal term = this.getJtapiProv().getTerminal(terminal);
InverterListener list = this.getListener();
if (flag)
try {
term.addCallListener(list);
term.addCallObserver(list);
} catch (MethodNotSupportedException mnse) {
throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "Inverter Observers not supported");
}
else {
term.removeCallListener(list);
term.removeCallObserver(list);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -