I think this is very strange. I opened a new
EJB project in WebLogic server and named it AdviceEJB. Then I opened a new session bean and typed in the following code:
package headfirst;
import javax.ejb.*;
import weblogic.ejb.*;
/**
* @ejbgen:session type="Stateless" default-transaction="Supports"
* ejb-name = "Advice"
*
* @ejbgen:jndi-name local="ejb.AdviceLocalHome"
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "Advice" remote-home = "true" remote-home-name = "AdviceHome" local-class="true" local-class-name = "AdviceLocal" local-home="true" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean
implements SessionBean
{
private
String[] adviceStrings = {"One
Word: Inappropriate", "You might want to rethink that hair cut",
"Your boss will respect him if you tell him the truth."};
public void ejbActivate() {
System.out.println("ejbActivate");
}
public void ejbPassivate() {
System.out.println("ejbPassivate");
}
public void ejbRemove() {
System.out.println("ejbRemove");
}
public void setSessionContext(SessionContext ctx) {
System.out.println("SessionContext");
}
public void ejbCreate() {
// Your code here
System.out.println("In ejbCreate");
}
public String getAdvice(){
System.out.println("In getAdvice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}
}
Then using the tool I did a "Build the project". Then I clicked the plus sign on adviceEJB.jar. AdviceBean.java is created and it is as follows:
package headfirst;
import javax.ejb.*;
import weblogic.ejb.*;
/**
* @ejbgen:session type="Stateless" default-transaction="Supports"
* ejb-name = "Advice"
*
* @ejbgen:jndi-name local="ejb.AdviceLocalHome"
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "Advice" remote-home = "true" remote-home-name = "AdviceHome" local-class="true" local-class-name = "AdviceLocal" local-home="true" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean
implements SessionBean
{
private String[] adviceStrings = {"One Word: Inappropriate", "You might want to rethink that hair cut",
"Your boss will respect him if you tell him the truth."};
public void ejbActivate() {
System.out.println("ejbActivate");
}
public void ejbPassivate() {
System.out.println("ejbPassivate");
}
public void ejbRemove() {
System.out.println("ejbRemove");
}
public void setSessionContext(SessionContext ctx) {
System.out.println("SessionContext");
}
public void ejbCreate() {
// Your code here
System.out.println("In ejbCreate");
}
public String getAdvice(){
System.out.println("In getAdvice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}
}
Home interface is also created and it is as follows:
package headfirst;
/*
** This file was automatically generated by EJBGen 2.16
** Build: 20031001-1049
*/
import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;
import javax.ejb.FinderException;
import java.rmi.RemoteException;
import java.util.Collection;
// BEGIN imports from bean class
import javax.ejb.*;
import weblogic.ejb.*;
// END imports from bean class
public interface AdviceLocalHome extends EJBLocalHome {
public AdviceLocal create() throws CreateException;
}
Component interface is also created and it is as follows:
package headfirst;
/*
** This file was automatically generated by EJBGen 2.16
** Build: 20031001-1049
*/
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
// BEGIN imports from bean class
import javax.ejb.*;
import weblogic.ejb.*;
// END imports from bean class
public interface Advice extends EJBObject {
}
But in the Component interface I don't see my method. Why is this. I thought the tool will create this by itself. Okay I tried to update it. But it wouldn't let me, it is read only. Am I doing it correctly? Please help.