hellobean.java
来自「最新的关于精通rmi这本书的源码」· Java 代码 · 共 73 行
JAVA
73 行
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.helloejb.ejb;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* This is a remote object that implements the remote interface.
* This is the Jini service we want to provide
*
* @see masteringrmi.helloejb.interfaces.HelloWorld
* @author Rickard 謆erg (rickard@dreambean.com)
* @version 1.0
*/
public class HelloBean
implements SessionBean
{
// Attributes implementation -------------------------------------
String myName;
// HelloWorld implementation -------------------------------------
/**
* Create a greeting.
*
* @param name a name
* @return a name a greeting including the name and the nr of invocations
*/
public String helloWorld(String name)
{
return "Hello "+name+"! My name is "+myName;
}
// SessionBean implementation ------------------------------------
public void ejbCreate()
throws CreateException
{
try
{
// Retrieve our name from the environment settings
myName = (String)new InitialContext().lookup("java:comp/env/myName");
} catch (NamingException e)
{
throw new CreateException("Could not get name for component");
}
}
public void setSessionContext(SessionContext ctx)
{
// Don't need the context so we don't store it
}
public void ejbActivate()
{
// Only applies to stateful sessions
}
public void ejbPassivate()
{
// Only applies to stateful sessions
}
public void ejbRemove()
{
// Nothing to do here in our case
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?