Hello, Henry:
I've done this simple Stateful Session Bean and I have no problem. Please,
read it and say me the differences between your solution and mine (I'm using
WebLogic 5.1):
/*-------------------------------------------------------------------
* Home interface
*/
import javax.ejb.*;
import java.rmi.RemoteException;
public interface StatefulHome extends EJBHome {
public Stateful create() throws RemoteException, CreateException;
}
/*-------------------------------------------------------------------
* Remote interface
*/
import javax.ejb.*;
import java.rmi.RemoteException;
import javax.naming.*;
public interface Stateful extends EJBObject {
public void setToken(String name, MyToken t) throws RemoteException;
public MyToken getToken() throws RemoteException;
}
/*-----------------------------------------------------------------
* Bean
*/
import javax.ejb.*;
import java.util.*;
public class StatefulBean implements SessionBean {
public String name;
public String value;
public void ejbCreate() {}
public void ejbPostCreate() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbStore() {}
public void ejbLoad() {}
public void ejbRemove() {}
public void setSessionContext(SessionContext ctx) {}
public void setToken(String name, MyToken t) {
this.name = name;
this.value = t.getValue(name);
}
public MyToken getToken() {
MyToken ut = new UnToken();
ut.setValue(name,value);
return ut;
}
}
/*--------------------------------------------------------
* Token class
*/
import java.util.Vector;
public class UnToken implements MyToken {
protected Vector names = new Vector();
protected Vector values = new Vector();
public String getValue(String name) {
String ret = (String) values.elementAt(names.indexOf(name));
return ret;
}
public void setValue(String name, String value) {
if(names.contains(name)) {
return; // Can't change (it's only a test)
} else {
names.addElement(name);
values.addElement(value);
}
}
}
/*----------------------------------------------------------------
* MyToken interface
*/
import java.io.Serializable;
public interface MyToken extends Serializable {
public String getValue(String name);
public void setValue(String name, String value);
}
/*----------------------------------------------------------------
* Client
*/
import javax.ejb.*;
import javax.rmi.*;
import javax.naming.*;
import java.rmi.RemoteException;
import java.util.*;
public class Client {
public static void main(String args[]) {
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory
");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context ctx = new InitialContext(p);
Object ref = ctx.lookup("StatefulBean");
StatefulHome bean_home = (StatefulHome)
PortableRemoteObject.narrow(ref,StatefulHome.class);
Stateful bean = bean_home.create();
// Put a token inside the bean
MyToken mt = new UnToken();
mt.setValue("Name","Value");
bean.setToken("Name", mt);
// Get the token of the bean
MyToken mt2 = bean.getToken();
System.out.println("Name="+mt2.getValue("Name"));
} catch(Exception e) {
System.out.println("Il y a un petit problem...");
System.out.println(e.toString());
}
}
}
Regards.
Luis F. Canals Samaniego
CEDETEL
Parque Tecnol�gico de Boecillo
Edificio Centro, Parcela 109
E-47151 Boecillo (Valladolid)
SPAIN
Tfno: +34 983 54 65 02
Fax: +34 983 54 66 96
-----Mensaje original-----
De: A mailing list for Enterprise JavaBeans development
[mailto:[EMAIL PROTECTED]]En nombre de Henry Voyer (hotmail)
Enviado el: lunes 10 de julio de 2000 16:17
Para: [EMAIL PROTECTED]
Asunto: Passing an interface to a bean ?????
> Hi everyone.
>
> for modularity, i need to pass a token interface to a method of a session
bean.
>
> as an example i have
>
> public interface aToken implements Serializable
> {
> public String getValue(String name);
> public void setValue(String name, String value);
> }
>
> i implemented my session bean to receive this interface and use the
methods.
>
> i use a class implements aToken to send messages to my session bean
> this class use a Vector to store and retrieve values.
>
> but i always have java.lang.null exception.
>
> Is it ok to pass an interface or i have to use a class and extends it to
pass my objects??
>
> Thanks a lot
> merci beaucoup
> henry
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".