I was having this crazy idea on adding injection support to applets too.
Okay, so applets are created and inited in a remote VM, but we could still
allow the applet author to use annotations, example follows

public class MyCrazyApplet extends Applet {
      @EJB(name="CalculatorImplLocal") Calculator calculator;

      public void paint(Graphics g){
         double result = calc.add(10,20);
         g.drawString(result,10,10);
      }
}

On our end what we could do is enhance the class and add the following in
the init method/constructor/setter (we could introduce a concept called
init-injection for applets -- and maybe even servlets)
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.openejb.client.RemoteInitialContextFactory");
        props.put(Context.PROVIDER_URL,"http://127.0.0.1:8080/applet/ejb";);
        try {
            ctx = new InitialContext(props);
            final Object ref = ctx.lookup("CalculatorImplRemote");
                    Calculator calc = (Calculator)
PortableRemoteObject.narrow(
                            ref, Calculator.class);
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }

So, behind the scenes this is not pure injection, but we can always make it
easier for users to work with applets and EJB's . There could possibly be a
better way to simulate injection.

Thoughts?

-- 
Karan Singh Malhi

Reply via email to