Hi Javier -
Thank you for sending me the example of polymorphism in EJB. I have a comment,
however. It has to do with casting after you get the bean object back. Let's say I
have a Customer bean that I want to do a lookup for. Customer bean has a method
getShoppingCart() that I want to invoke. The example you sent would do this:
EJBeanManager bm = null;
InitialContext ctx = null;
EJBHome home = null;
Object obj = null;
bm = EJBeanManager(JNDI_FACTORY,JNDI_URL);
ctx = bm.createNamingContext();
home = bm.getHome("CustomerHome", ctx);
(Customer)customer = (Customer)bm.create("CustomerHome", new Object[] {custid});
result = customer.getShoppingCart();
I would need to cast the bean to Customer, which I don't have the information. Can I
do the following?
...
home = bm.getHome("CustomerHome", ctx);
Object obj = bm.create("CustomerHome", new Object[]{custid});
String result = obj.getClass().getMethod("getShoppingCart", arglist);
Looking forward to your comment.
Regards,
Thong Le
P.S. In the previous mail I stated that we are using XML. The reason we opt
to do this we are implementing a 3-tier arch. The presentation layer is using ADO,
ActiveX component that talks to a COM-CORBA bridge that talks to the Server EJB. The
EJB has a CORBA wrapper to the bridge and any CORBA client. The client sends XML so
that we don't have to keep on changing the IDL for every time a client change. Going
with XML will allow us to be independent of the client interface. This is what we're
trying to achieve:
I have a singleton session bean (call it ServerBean) that handles all the different
clients. The only thing my client passes to the ServerBean is an XML string that
contains the application home name, method name and its invoke parameters. The
ServerBean will do a look up to obtain the correct bean instance. However, it can't
cast to the bean's class name because it doesn't have the information. What I like to
do is the following and please tell me if it can be done (using your example) this way:
Client XML:
<QUERY>
<HOME>CustomerHome</HOME>
<METHOD>getShoppingCart</METHOD>
<USERINPUT>
<userid> 1002 </userid>
</USERINPUT>
</QUERY>
Inside the ServerBean class it does the following (assuming Customer has a method
called
getShoppingCart and it returns a string):
public interface ServerBean implement SessionBean {
public void execute(String XMLString) {
EJBeanManager bm = null;
InitialContext ctx = null;
Object obj = null;
try {
// parse xml string
jndihome = parser("HOME");
methodname = parser("METHOD");
arglist = parser("USERINPUT")
bm = new EJBeanManager(jndiclass, jndiurl);
ctx = bm.createNamingContext();
home = bm.getHome(jndihome,ctx);
obj = bm.create(jndihome);
String result = obj.getClass().getMethod(methodname, arglist);
}
}
So you can see why casting would not work well in the above example.
===========================================================================
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".