/*
* This example is from the book "Java Enterprise in a Nutshell".
* Copyright (c) 1999 by O'Reilly & Associates.
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained. Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
*/
package stateless;
import javax.ejb.*;
// Uncomment for use in standard EJB servers (Ejbhome, etc.)
import java.rmi.RemoteException;
// Uncomment for use in WebLogic, which has proprietary RMI packages
// import weblogic.rmi.RemoteException;
import NoSuchPersonException;
/**
* A ProfileServerBean, which provides enterprise
* profile information for a named person.
*/
public class ProfileServerBean implements SessionBean {
// Store session context
private SessionContext mContext = null;
// Session bean methods
/**
* No need for us to activate anything in this bean, but we need to
* provide an implementation.
*/
public void ejbActivate() {
System.out.println("ProfileServerBean activated.");
}
/**
* Nothing to do on a remove.
*/
public void ejbRemove() {
System.out.println("ProfileServerBean removed.");
}
/**
* No state to store on passivation.
*/
public void ejbPassivate() {
System.out.println("ProfileServerBean passivated.");
}
/**
* Get context from container.
*/
public void setSessionContext(SessionContext context) {
System.out.println("ProfileServerBean context set.");
mContext = context;
}
/**
* Create method(s) (corresponds to each create() method on the
* home interface, ProfileServerHome. Nothing to initialize in this case.
*/
public void ejbCreate() {
System.out.println("ProfileServerBean created.");
}
// Finally, the remote methods. Signatures of methods must match those
// on remote interface (ProfileServer), except that throwing
// RemoteException is not necessary.
/**
* Get a profile for a named person. Throws NoSuchPersonException if the
* named person cannot be found in the database(s) used to retrieve
* profile information.
*/
public Profile getProfile(String name) throws NoSuchPersonException {
// Here, we just create a ProfileImpl and return it. The EJB/RMI
// internals will return a remote stub for the object to the remote client,
// and the profile object will live on this end.
ProfileImpl profile = null;
try {
profile = new ProfileImpl(name);
}
catch (RemoteException re) {
System.out.println("Failed creating profile for " + name);
re.printStackTrace();
throw new NoSuchPersonException();
}
return profile;
}
}
|