package examples.ejb.subclass.child;
import javax.ejb.*;
import javax.naming.*;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.*;
import examples.ejb.subclass.parent.*;
/**
* ChildBean is a stateless SessionBean. This bean illustrates:
*
* - Child class to the ParentBean class
*
- Using subclassing to simplify related bean classes
*
- Contains only methods that are either unique to the Child class
* or overload methods in the Parent Bean
*
- Using JNDI to look up and call another bean from
* within a bean (callParentBean)
*
*
* @author Copyright (c) 1998 by WebLogic, Inc. All Rights Reserved.
* @author Copyright (c) 1998-1999 by BEA Systems, Inc. All Rights Reserved.
*/
public class ChildBean extends examples.ejb.subclass.parent.ParentBean
implements SessionBean {
/**
* Returns a message identifying the method.
* This method is unique to the Child bean.
*
* @return String Message
*/
public String childSaysHello() {
return "Hello from the ChildBean.";
}
/**
* Returns a message identifying the method.
* This method is inherited and overloaded by the Child bean.
*
* @return String Message
*/
public String parentSaysHello() {
return "Hello from the ChildBean overload of the \"parentSaysHello()\" method.";
}
/**
* Looks up a parent bean and calls its
* parentMethodOnly(). Returns a message identifying the method.
*
* - Demonstrates calling one bean from another bean
*
- Uses SessionContext ctx to generate a new Context
*
- Uses that Context to find the ParentHome
*
* @return String Message
* @exception RemoteException if there is
* a communications or systems failure
*/
public String callParentBean() throws RemoteException {
String message = "ChildBean calling a ParentBean method:\n";
try {
Context context = new InitialContext(ctx.getEnvironment());
ParentHome parentHome = (ParentHome) context.lookup("parent.ParentHome");
Parent parent = parentHome.create();
message = message + parent.parentMethodOnly();
return message;
}
catch (Exception e) {
throw new RemoteException(e.getMessage());
}
}
}