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

📄 corbaprovider.java

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

/*
	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 org.omg.CosNaming.*;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.Any;
import net.sourceforge.gjtapi.raw.remote.corba.*;
import java.io.*;
import javax.telephony.media.*;
import net.sourceforge.gjtapi.media.*;
import javax.telephony.*;
import net.sourceforge.gjtapi.*;
import java.util.*;
/**
 * This is a pluggable provider that provides access to a remote provider through CORBA
 * Creation date: (2000-08-18 10:53:56)
 * @author: Richard Deadman
 */
public class CorbaProvider implements TelephonyProvider {
	private net.sourceforge.gjtapi.raw.remote.corba.CorbaProvider remote;
	private org.omg.CORBA.ORB orb;
	private CorbaListener listener;
/**
 * Forward to remote provider.
 * Should only be called once.
 */
public synchronized void addListener(TelephonyListener rl) {
	CorbaListener cl = new CorbaListener(rl);
	//this.getOrb().connect(cl);
	this.getRemote().addListener(cl);
	this.setListener(cl);
}
/**
 * Forward to a remote stub
 */
public boolean allocateMedia(String terminal, int type, Dictionary params) {
	return this.getRemote().allocateMedia(terminal, type, this.toLongEntryArray(params));
}
/**
 * Forward answerCall to remote provider
 */
public void answerCall(CallId call, String address, String terminal) throws PrivilegeViolationException, ResourceUnavailableException,
	  MethodNotSupportedException, RawStateException {
	try {
		this.getRemote().answerCall((int)((SerializableCallId)call).getId(), address, terminal);
	} catch (PrivilegeViolationEx pve) {
		throw new PrivilegeViolationException(pve.type, pve.reason);
	} catch (ResourceUnavailableEx rue) {
		throw new ResourceUnavailableException(rue.type, rue.reason);
	} catch (MethodNotSupportedEx mnse) {
		throw new MethodNotSupportedException(mnse.reason);
	} catch (RawStateEx rse) {
		throw new RawStateException(new SerializableCallId(rse.callId), rse.address, rse.terminal,
			rse.type, rse.state, rse.info);
	}
}
/**
 * attachMedia method comment.
 */
public boolean attachMedia(CallId call, String address, boolean onFlag) {
	return this.getRemote().attachMedia((int)((SerializableCallId)call).getId(), address, onFlag);
}
/**
 * beep method comment.
 */
public void beep(net.sourceforge.gjtapi.CallId call) {
	this.getRemote().beep((int)((SerializableCallId)call).getId());
}
/**
 * Turn an Object to a CORBA ANY object
 * Creation date: (2000-08-24 10:14:47)
 * @author: Richard Deadman
 * @return org.omg.CORBA.Any
 * @param any java.lang.Object
 */
private Any convertAny(Object o) throws NotSerializableException {
	return convertToAny(this.getOrb(), o);
}
/**
 * Turn a CORBA ANY object into a Java object
 * Creation date: (2000-08-24 10:14:47)
 * @author: Richard Deadman
 * @return java.lang.Object
 * @param any org.omg.CORBA.Any
 */
static Object convertAny(Any any) {
	TypeCode type = any.type();
	switch (type.kind().value()) {
		case TCKind._tk_boolean: {
			return new Boolean(any.extract_boolean());
		} 
		case TCKind._tk_char: {
			return new Character(any.extract_char());
		} 
		case TCKind._tk_octet: {
			return new Byte(any.extract_octet());
		} 
		case TCKind._tk_double: {
			return new Double(any.extract_double());
		} 
		case TCKind._tk_float: {
			return new Float(any.extract_float());
		} 
		case TCKind._tk_long: {
			return new Integer(any.extract_long());
		} 
		case TCKind._tk_longlong: {
			return new Long(any.extract_longlong());
		} 
		case TCKind._tk_short: {
			return new Short(any.extract_short());
		} 
		case TCKind._tk_string: {
			return any.extract_string();
		} 
		case TCKind._tk_ulong: {
			return new Integer(any.extract_ulong());
		} 
		case TCKind._tk_ulonglong: {
			return new Long(any.extract_ulonglong());
		} 
		case TCKind._tk_ushort: {
			return new Short(any.extract_ushort());
		} 
		case TCKind._tk_wchar: {
			return new Character(any.extract_wchar());
		} 
		case TCKind._tk_wstring: {
			return any.extract_wstring();
		} 
		default: {
			return null;
		}
	}
}
/**
 * Convert a CORBA CallData array to a Generic JTAPI CallData array.
 * Creation date: (2000-08-23 16:14:19)
 * @author: Richard Deadman
 * @return net.sourceforge.gjtapi.CallData[]
 * @param ca net.sourceforge.gjtapi.raw.remote.corba.CallData[]
 */
private net.sourceforge.gjtapi.CallData[] convertCallArray(net.sourceforge.gjtapi.raw.remote.corba.CallData[] ca) {
	int size = ca.length;
	net.sourceforge.gjtapi.CallData[] cda = new net.sourceforge.gjtapi.CallData[size];
	for (int i = 0; i < size; i++) {
		cda[i] = this.toCallData(ca[i]);
	}
	return cda;
}
/**
 * Convert a CORBA TermData array to a Generic JTAPI TermData array.
 * Creation date: (2000-08-23 16:14:19)
 * @author: Richard Deadman
 * @return net.sourceforge.gjtapi.TermData[]
 * @param ca net.sourceforge.gjtapi.raw.remote.corba.TermData[]
 */
private net.sourceforge.gjtapi.TermData[] convertTermDataArray(net.sourceforge.gjtapi.raw.remote.corba.TermData[] td) {
	int size = td.length;
	net.sourceforge.gjtapi.TermData[] tda = new net.sourceforge.gjtapi.TermData[size];
	for (int i = 0; i < size; i++) {
		tda[i] = this.toTermData(td[i]);
	}
	return tda;
}
/**
 * Turn an Object to a CORBA ANY object
 * Creation date: (2000-08-24 10:14:47)
 * @author: Richard Deadman
 * @return org.omg.CORBA.Any
 * @param any java.lang.Object
 */
static Any convertToAny(ORB orb, Object o) throws NotSerializableException {
	Any any = orb.create_any();
	if (o instanceof Boolean) {
		any.insert_boolean(((Boolean)o).booleanValue());
	} else if (o instanceof Character) {
		any.insert_char(((Character)o).charValue());
	} else if (o instanceof Double) {
		any.insert_double(((Double)o).doubleValue());
	} else if (o instanceof Float) {
		any.insert_float(((Float)o).floatValue());
	} else if (o instanceof Integer) {
		any.insert_long(((Integer)o).intValue());
	} else if (o instanceof Long) {
		any.insert_longlong(((Long)o).longValue());
	} else if (o instanceof Byte) {
		any.insert_octet(((Byte)o).byteValue());
	} else if (o instanceof Short) {
		any.insert_short(((Short)o).shortValue());
	} else {
		throw new NotSerializableException("No CORBA ANY correspondence for: " + o.toString());
	}
	return any;
}
/**
 * Create a call from the given address and terminal to the remote address
 */
public CallId createCall(CallId id, String address, String term, String dest) throws ResourceUnavailableException, PrivilegeViolationException,
	  InvalidPartyException, InvalidArgumentException, RawStateException,
	  MethodNotSupportedException {
	try {
		return new SerializableCallId(this.getRemote().createCall((int)((SerializableCallId)id).getId(), address, term, dest));
	} catch (PrivilegeViolationEx pve) {
		throw new PrivilegeViolationException(pve.type, pve.reason);
	} catch (ResourceUnavailableEx rue) {
		throw new ResourceUnavailableException(rue.type, rue.reason);
	} catch (MethodNotSupportedEx mnse) {
		throw new MethodNotSupportedException(mnse.reason);
	} catch (RawStateEx rse) {
		throw new RawStateException(new SerializableCallId(rse.callId), rse.address, rse.terminal,
			rse.type, rse.state, rse.info);
	} catch (InvalidPartyEx ipe) {
		throw new InvalidPartyException(ipe.type, ipe.reason);
	} catch (InvalidArgumentEx iae) {
		throw new InvalidArgumentException(iae.reason);
	}
}
/**
 * Factory to create the appropriate ResourceEvent based on the CORBA resource event enumeration
 */
private GenericResourceEvent createEvent(String terminal, net.sourceforge.gjtapi.raw.remote.corba.ResourceEvent re) {
	net.sourceforge.gjtapi.raw.remote.corba.ResourceUnion ru = re.resUnion;
	switch (ru.discriminator().value()) {
		case ResourceType._player: {
			net.sourceforge.gjtapi.raw.remote.corba.PlayerEvent pe = ru.playEv();
			return new GenericPlayerEvent(CorbaProvider.createSymbol(re.eventId),
				terminal,
				CorbaProvider.createSymbol(re.error),
				CorbaProvider.createSymbol(re.qualifier),
				CorbaProvider.createSymbol(re.trigger),
				CorbaProvider.createSymbol(pe.change),
				pe.index,
				pe.offset);
		}
		case ResourceType._recorder: {
			net.sourceforge.gjtapi.raw.remote.corba.RecorderEvent rec = ru.recEv();
			return new GenericRecorderEvent(CorbaProvider.createSymbol(re.eventId),
				terminal,
				CorbaProvider.createSymbol(re.error),
				CorbaProvider.createSymbol(re.qualifier),
				CorbaProvider.createSymbol(re.trigger),
				rec.duration);
		}
		case ResourceType._sigDetector: {
			net.sourceforge.gjtapi.raw.remote.corba.SigDetectorEvent sde = ru.sdEv();
			return new GenericSignalDetectorEvent(CorbaProvider.createSymbol(re.eventId),
				terminal,
				CorbaProvider.createSymbol(re.error),
				CorbaProvider.createSymbol(re.qualifier),
				CorbaProvider.createSymbol(re.trigger),
				sde.index,
				CorbaProvider.toSymbolArray(sde.buffer));
		}
		case ResourceType._sigGenerator: {
			return new GenericSignalGeneratorEvent(CorbaProvider.createSymbol(re.eventId),
				terminal,
				CorbaProvider.createSymbol(re.error),
				CorbaProvider.createSymbol(re.qualifier),
				CorbaProvider.createSymbol(re.trigger));
		}
	}
	// should never get here
	return null;
}
/**
 * Helper method to create Symbols from their ids
 * Creation date: (2000-08-24 0:13:51)

⌨️ 快捷键说明

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