📄 hellobean.java
字号:
/*
* Created on 2005-6-29
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.nari.pmos.ejb.hello;
import javax.ejb.*;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* @author hujun
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
*/
public class helloBean implements SessionBean {
private javax.ejb.SessionContext mySessionCtx;
public void ejbActivate() {
}
public void ejbRemove() {
}
public void ejbPassivate() {
}
/**
* Sets the session context.
*
* @param SessionContext
*/
public void setSessionContext(SessionContext ctx) {
mySessionCtx = ctx;
}
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* This method corresponds to the create method in the home interface
* "interfaces.DemoHome.java". The parameter sets of the two methods are
* identical. When the client calls <code>DemoHome.create()</code>, the
* container allocates an instance of the EJBean and calls
* <code>ejbCreate()</code>.r
*/
public void ejbCreate() {
}
// ---------------------------------------------------------------------
public String echo() {
return "Hello Ejb";
}
public String echo_1(int x, int y, int z) {
return "Hello Ejb [x: " + x + "y: " + y + "z: " + z + "]";
}
public String echo_2(Integer x, Double y) {
return "Hello Ejb [x: " + x + "y: " + y + "]";
}
public Object getRemote() {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL, "jnp://10.144.98.130:1099");
try {
Context ctx = new InitialContext(p);
Object obj = ctx.lookup("pmos/ejb/hello");
helloHome home = (helloHome) javax.rmi.PortableRemoteObject.narrow(
obj, helloHome.class);
hello Hello = home.create();
return Hello;
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception:");
return null;
}
}
public Object getLocal() {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
System.out.println("@@@@@@ getLocal @@@@@@");
try {
Context ctx = new InitialContext(p);
Object obj = ctx.lookup("pmos/ejb/helloLocal");
helloLocalHome home = (helloLocalHome) obj;// (helloHome)javax.rmi.PortableRemoteObject.narrow(obj,
// helloHome.class );
helloLocal Hello = home.create();
System.out.println("getLocal ok!");
return Hello;
} catch (Exception e) {
System.out.println("getLocal fail!");
e.printStackTrace();
System.out.println("Exception:");
return null;
}
}
// ---------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -