Ink Context Dependency Injection

Basic usage

Simple Context Dependency Injection example
                @ManagedBean(name="mybean")
                public class MyBean {
                    public String getMyProp(){...}
                    public void setMyProp(String val){...}
                }


                public class Test {
                    public static void main(String[] args) {
                        InkELContext ctx = new InkElContext();
                        ctx.defineBean(MyBean.class);

                        String prop = ctx.getValue("#{mybean.myProp}",String.class);
                        .....
                        ctx.setValue("#{mybean.myProp}","this is a value...");
                    }
                }
            

Full example

Simple Context Dependency Injection example
                    @ManagedBean(name="mybean")
                    public class MyBeanImpl implements MyBean {
                        @InjectValue("#{CallContext}")
                        CallContext clientSideContext;
                        public String hello() {
                            return "hello "+clientSideContext;
                        }
                    }
                    /* client side view of our bean */
                    public interface MyBean extends java.rmi.Remote {
                        public String hello() throws RemoteException;
                    }

                    public class ServerRunner {
                        public static void main(String[] args) {
                            CurrentContext.setContextFactory(new CurrentContext.CurrentContextFactory() {
                                @Override
                                public InkELContext createCurrentContext() {
                                    InkELContext context = new InkELContext();
                                    context.defineSimpleBean(MyBean.class);
                                    context.defineSimpleBean(CallContext.class);
                                    return context;
                                }
                            });

                            RMIServer server = new RMIServer("tcp://localhost:5432");
                            server.defineBean("clientsidename", new RMIContextualBeanFactory("#{mybean}", MyBean.class));

                            // ... waiting calls...
                            Thread.sleep(Integer.MAX_VALUE);
                            server.stop();
                    }

                    public class ClientRunner {
                        public static void main(String[] args) {

                            RMIClient client = new RMIClient("tcp://localhost:5432");
                            CallContext cc = new CallContext();
                            cc.setValue("name", "you");
                            MyBean proxy = client.getBean("clientsidename", MyBean.class, cc);
                            String result = proxy.hello("me");

                            server.stop();
                    }
                }