本文整理汇总了Java中javax.rmi.PortableRemoteObject.narrow方法的典型用法代码示例。如果您正苦于以下问题:Java PortableRemoteObject.narrow方法的具体用法?Java PortableRemoteObject.narrow怎么用?Java PortableRemoteObject.narrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.rmi.PortableRemoteObject
的用法示例。
在下文中一共展示了PortableRemoteObject.narrow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupBMXABean
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
private static BMXATest lookupBMXABean(InitialContext ictx, String jndiName) {
try {
Object home = ictx.lookup(jndiName);
BMXATestHome rhome = (BMXATestHome) PortableRemoteObject.narrow(
home, BMXATestHome.class);
BMXATest bean = (BMXATest) PortableRemoteObject.narrow(
rhome.create(), BMXATest.class);
return bean;
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name " + jndiName
+ " on the WebLogic server at " + url);
} catch (CreateException ce) {
log("Creation failed: " + ce);
} catch (RemoteException ex) {
log("Creation failed: " + ex);
}
return null;
}
示例2: lookupCMXABean
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
private static CMXATest lookupCMXABean(InitialContext ictx, String jndiName) {
try {
Object home = ictx.lookup(jndiName);
CMXATestHome rhome = (CMXATestHome) PortableRemoteObject.narrow(
home, CMXATestHome.class);
CMXATest bean = (CMXATest) PortableRemoteObject.narrow(
rhome.create(), CMXATest.class);
return bean;
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name " + jndiName
+ " on the WebLogic server at " + url);
} catch (CreateException ce) {
log("Creation failed: " + ce);
} catch (RemoteException ex) {
log("Creation failed: " + ex);
}
return null;
}
示例3: acquire
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
private Remote acquire(RunningInfo info) throws Exception {
Remote result;
Registry registry = LocateRegistry.getRegistry("localhost", info.port);
java.rmi.Remote lookup = registry.lookup(info.name);
if (java.rmi.Remote.class.isAssignableFrom(remoteClass)) {
Remote entry =
remoteClass.isInstance(lookup)
? (Remote) lookup
: (Remote) PortableRemoteObject.narrow(lookup, remoteClass);
if (entry == null) {
result = null;
} else {
// TODO add proxy for remote object
result = (Remote) lookup;
}
} else {
result = (Remote) lookup;
}
info.remoteRef = result;
return result;
}
示例4: createEJB3
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Obtiene un EJB a partir de su nombre JNDI
* @param jndiContextProps propiedades para obtener una referencia al contexto jndi del LDAP
* @param jndiName nombre JNDI
* @param local true si se trata de una referencia al EJB local
* @param type tipo del objeto
* @return la referencia al EJB
*/
@SuppressWarnings("unchecked")
public static <T> T createEJB3(Properties jndiContextProps,
String jndiName,boolean local,Class<T> type) {
T outEJB = null;
try {
Context initialContext = JNDIContextLocator.getInstance().getInitialContext(jndiContextProps);
String theJNDIName = jndiName + (local ? "Local" : ""); // Por "convenio" el nombre JNDI del EJB local tiene el sufijo "Local"
Object obj = initialContext.lookup(theJNDIName);
if (local) {
outEJB = (T)obj;
} else {
outEJB = (T)PortableRemoteObject.narrow(obj,type);
}
} catch(NamingException namEx) {
// TODO log
String err = Strings.of("NO se ha podido obtener un contexto jndi contra el LDAP")
.asString();
System.out.println(err);
}
return outEJB;
}
示例5: createEJB2
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Obtiene un EJB a partir de su nombre JNDI
* @param jndiContextProps propiedades para obtener una referencia al contexto jndi del LDAP
* @param jndiName nombre JNDI
* @param local true si se trata de una referencia al EJB local
* @param homeType tipo del interfaz home
* @return la referencia al EJB
*/
public static <T> T createEJB2(Properties jndiContextProps,
String jndiName,boolean local,Class<?> homeType) {
T outEJB = null;
try {
Context initialContext = JNDIContextLocator.getInstance().getInitialContext(jndiContextProps);
String theJNDIName = jndiName + (local ? "Local" : ""); // Por "convenio" el nombre JNDI del EJB local tiene el sufijo "Local"
Object home = initialContext.lookup(theJNDIName);
Object homeNarrowed = PortableRemoteObject.narrow(home,homeType);
outEJB = Reflection.of(homeNarrowed).method("create").<T>invoke(); // llamar al m�todo create en el objeto home
} catch(NamingException namEx) {
// TODO log
String err = Strings.of("NO se ha podido obtener un contexto jndi contra el LDAP")
.asString();
System.out.println(err);
}
return outEJB;
}
示例6: testNarrowedRemoteAccess
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testNarrowedRemoteAccess() throws Exception
{
InitialContext iniCtx = null;
try {
iniCtx = getServerInitialContext();
Object obj = iniCtx.lookup("jaxws-jbws944//FooBean01!" + EJB3RemoteHome.class.getName());
EJB3RemoteHome ejb3Home = (EJB3RemoteHome)PortableRemoteObject.narrow(obj, EJB3RemoteHome.class);
EJB3RemoteInterface ejb3Remote = ejb3Home.create();
String helloWorld = "Hello world!";
Object retObj = ejb3Remote.echo(helloWorld);
assertEquals(helloWorld, retObj);
}
finally
{
if (iniCtx != null)
{
iniCtx.close();
}
}
}
示例7: newEJBHome
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* 得到urlName下的EJB.
*
* @param urlName
* String
* @return Object
*/
private Object newEJBHome(String urlName) {
try {
Context ctx = ServiceLocator.getInstance().getContext(urlName);
if (ctx == null) {
log.info("can't find the context by specified url " + urlName);
return null;
}
Object jndiRef = ctx.lookup(name);
Class cl = Class.forName(homeClassName);
Object homeObj = PortableRemoteObject.narrow(jndiRef, cl);
return homeObj;
} catch (Exception e) {
log.debug("create home obj fail", e);
}
return null;
}
示例8: init
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Setting up the test fixture.
*/
private void init() throws Exception
{
Context ctx = ContextHelper.getContext();
times = new long[4];
try
{
Object object = PortableRemoteObject.narrow(ctx.lookup(PBSessionHome.JNDI_NAME), EJBHome.class);
bean = ((PBSessionHome) object).create();
}
catch(Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
示例9: init
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Setting up the test fixture.
*/
private void init() throws Exception
{
Context ctx = ContextHelper.getContext();
times = new long[4];
try
{
Object object = PortableRemoteObject.narrow(ctx.lookup(ODMGSessionHome.JNDI_NAME), EJBHome.class);
bean = ((ODMGSessionHome) object).create();
}
catch(Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
示例10: lookup
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* This overridden lookup implementation performs a narrow operation
* after the JNDI lookup, provided that a home interface is specified.
* @see #setHomeInterface
* @see javax.rmi.PortableRemoteObject#narrow
*/
@Override
protected Object lookup() throws NamingException {
Object homeObject = super.lookup();
if (this.homeInterface != null) {
try {
homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
}
catch (ClassCastException ex) {
throw new RemoteLookupFailureException(
"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
}
}
return homeObject;
}
示例11: readObjectAndNarrow
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Read an object reference from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readObjectAndNarrow(InputStream in,
Class narrowTo)
throws ClassCastException
{
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
示例12: readAbstractAndNarrow
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
/**
* Read an abstract interface type from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readAbstractAndNarrow(
org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
throws ClassCastException
{
Object result = in.read_abstract_interface();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
示例13: getRemoteHome
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
private static synchronized EJBHome getRemoteHome(
String ejbContainerTagName, String jndiName, Class<?> className,
String key) throws java.rmi.RemoteException, ClassNotFoundException {
Context ctx;
if (logger.isDebugEnabled()) {
logger.debug("--getRemoteHome--");
logger.debug("ejbContainerTagName:" + ejbContainerTagName);
logger.debug("jndiName:" + jndiName);
logger.debug("className:" + className);
logger.debug("key:" + key);
}
try {
if (ejbContainerTagName == null || ejbContainerTagName.equals("")) {
ctx = ContainerUtil.getRemoteEJBContainerContext();
if (logger.isDebugEnabled()) {
logger.debug("call:getRemoteEJBContainerContext()");
}
} else {
ctx = ContainerUtil
.getRemoteEJBContainerContext(ejbContainerTagName);
if (logger.isDebugEnabled()) {
logger.debug("call:getRemoteEJBContainerContext("
+ ejbContainerTagName + ")");
}
}
Object ref = ctx.lookup(jndiName.trim());
EJBHome ejbHome = (EJBHome) PortableRemoteObject.narrow(ref,
className);
HOME_INTERFACES_REMOTE.put(key, ejbHome);
return ejbHome;
} catch (NamingException e) {
throw new RemoteException("getRemoteHome err", e);
}
}
示例14: main
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
if(args.length < 1) {
System.err.println("Usage: <file>");
System.exit(1);
}
// grab the file name from the commandline
String fileName = args[0];
TestServer.CorbaExporter ce = new TestServer.CorbaExporter();
// get a handle to the remote service to which we want to send the file
Context ctx = new InitialContext();
RemoteFileServer stub = (RemoteFileServer)
PortableRemoteObject.narrow(
ctx.lookup("RemoteFileServer"), RemoteFileServer.class);
System.out.println("Sending file " + fileName);
// setup the remote input stream. note, the client here is actually
// acting as an RMI server (very confusing, i know). this code sets up an
// RMI server in the client, which the RemoteFileServer will then
// interact with to get the file data.
SimpleRemoteInputStream istream = new SimpleRemoteInputStream(
new FileInputStream(fileName));
try {
// call the remote method on the server. the server will actually
// interact with the RMI "server" we started above to retrieve the
// file data
stub.sendFile(ce.export(istream));
} finally {
// always make a best attempt to shutdown RemoteInputStream
istream.close();
}
System.out.println("Finished sending file " + fileName);
}
示例15: export
import javax.rmi.PortableRemoteObject; //导入方法依赖的package包/类
public Object export(Remote server, Class<?> remoteClass)
throws RemoteException
{
try {
PortableRemoteObject.exportObject(server);
POA poa = getPOA();
Object servant = Util.getTie(server);
Object ref = poa.servant_to_reference((Servant)servant);
return PortableRemoteObject.narrow(ref, remoteClass);
} catch(UserException e) {
throw new ExportException("could not export corba stream servant", e);
}
}