package com.app.ejb;import java.rmi.RemoteException;
import java.util.Properties;import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;/***************************************************************************************************
*
*
* @author: Li Tianqiu sinocom
* @version: v1.0.1 2004/01/05
**************************************************************************************************/
public class Client { private static final String JNDI_NAME = "DeitelShop"; private DeitelShopHome home; public Client()
throws NamingException
{
home = lookupHome();
} /**
* Runs the example.
*/
public void example()
throws CreateException, RemoteException
{
String customerName = "Matt"; // Create a Trader
log("Creating DeitelShopRemote\n");
DeitelShop deitel = (DeitelShop)
narrow(home.create(), DeitelShop.class);
// Get change in Cash Account from EJBean
log("The name is $: " + deitel.getName() + "\n");
log("Removing DeitelShopRemote\n");
} /**
* RMI/IIOP clients should use this narrow function
*/
private Object narrow(Object ref, Class c) { return PortableRemoteObject.narrow(ref, c);
} /**
* Lookup the EJBs home in the JNDI tree
*/
private DeitelShopHome lookupHome()
throws NamingException
{
// Lookup the beans home using JNDI
Context ctx = getInitialContext(); try {
Object home = ctx.lookup(JNDI_NAME); return (DeitelShopHome) narrow(home, DeitelShopHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
throw ne;
}
} /**
* Using a Properties object will work on JDK 1.1.x and Java2
* clients
*/
private Context getInitialContext() throws NamingException { try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory"); return new InitialContext(h);
} catch (NamingException ne) {
log("Please make sure that the server is running.");
throw ne;
}
} /**
* This is the Java2 version to get an InitialContext.
* This version relies on the existence of a jndi.properties file in
* the application's classpath.
*
*/
// private static Context getInitialContext()
// throws NamingException
// {
// return new InitialContext();
// } private static void log(String s) {
System.out.println(s);
}}
import java.util.Properties;import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;/***************************************************************************************************
*
*
* @author: Li Tianqiu sinocom
* @version: v1.0.1 2004/01/05
**************************************************************************************************/
public class Client { private static final String JNDI_NAME = "DeitelShop"; private DeitelShopHome home; public Client()
throws NamingException
{
home = lookupHome();
} /**
* Runs the example.
*/
public void example()
throws CreateException, RemoteException
{
String customerName = "Matt"; // Create a Trader
log("Creating DeitelShopRemote\n");
DeitelShop deitel = (DeitelShop)
narrow(home.create(), DeitelShop.class);
// Get change in Cash Account from EJBean
log("The name is $: " + deitel.getName() + "\n");
log("Removing DeitelShopRemote\n");
} /**
* RMI/IIOP clients should use this narrow function
*/
private Object narrow(Object ref, Class c) { return PortableRemoteObject.narrow(ref, c);
} /**
* Lookup the EJBs home in the JNDI tree
*/
private DeitelShopHome lookupHome()
throws NamingException
{
// Lookup the beans home using JNDI
Context ctx = getInitialContext(); try {
Object home = ctx.lookup(JNDI_NAME); return (DeitelShopHome) narrow(home, DeitelShopHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
throw ne;
}
} /**
* Using a Properties object will work on JDK 1.1.x and Java2
* clients
*/
private Context getInitialContext() throws NamingException { try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory"); return new InitialContext(h);
} catch (NamingException ne) {
log("Please make sure that the server is running.");
throw ne;
}
} /**
* This is the Java2 version to get an InitialContext.
* This version relies on the existence of a jndi.properties file in
* the application's classpath.
*
*/
// private static Context getInitialContext()
// throws NamingException
// {
// return new InitialContext();
// } private static void log(String s) {
System.out.println(s);
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货