I faced with a problem I can't invoke a method of a bean instance once it isn't declared in the business interface.
Basically the problem came to me after I started working with a EJB 2.1 project had been developed by another team. The app server is Websphere v8
The problem is following: We have an abstract class FooAbstract where basic business functions are declared (like read, delete, update, etc.)
Each bean must extend that class and implement abstract methods of course. Beans can have their own public methods as well (and actually have).
For some reasons those methods aren't declared in business interfaces, however all bean's methods are invoked through reflection instead of direct calls (I don't know why).
In my opinion the reflection makes system much more slower than it could be, but I can't handle with the architecture because almost of all needed methods aren't visible for direct calls.
Here is an example:
public abstract class FooAbstract {
public abstract Object create();
public abstract void delete(Object x);
}
A FooBean class that does business logic (jndi name "Foo"):
public class FooBean extends FooAbstract implements SessionBean {
/** inherited method */
public Object create() {
Object x = new SomeDBMappedObject();
... // creating an object in DB and return wrapper class
return x;
}
/** inherited method */
public void delete(Object x) {
... // deleting object from DB
}
/** The method that performs some extra logic */
aMethod() {
... //do extra logic
}
}
Local business interface:
public interface FooLocal extends EJBLocalObject {
public abstract Object create();
public abstract void delete(Object x);
}
And finally Local Home interface:
public interface FooLocalHome extends EJBLocalHome {
public FooLocal create() throws CreateException;
}
According to the architecture specification if I need to invoke a method of another EJB I should use some utility class UtilityBean that uses reflection to dispatch my call.
Something like:
...
public static Object dispath(String jndi, String methodname, Object parameters) {
...
}
...
Eventually, my question:
I want to call extra method of FooBean directly within my EJB, but if I do something like this:
public void doSomething {
InitialContext ctx = new InitialContext ();
FooHome home = (FooHome) ctx.lookup("local:ejb/Foo");
Object bean = home.create();
...
}
into "bean" variable I get a reference to FooBean instance, but I cannot invoke method aMethod() because it doesn't exist in FooLocal interface.
Are there any suggestions?