001    package com.hammurapi.eventbus.tests;
002    
003    import com.hammurapi.common.Condition;
004    import com.hammurapi.eventbus.Handler;
005    import com.hammurapi.eventbus.EventHandlerBase.Mode;
006    import com.hammurapi.eventbus.local.LocalEventDispatchJoinContext;
007    
008    public class JoinHandler {
009            
010            private int helloCounter;
011            private boolean helloOk;
012            
013            public int getHelloCounter() {
014                    return helloCounter;
015            }
016    
017            public boolean isHelloOk() {
018                    return helloOk;
019            }
020            
021            private int joinCounter;
022            private boolean joinOk; 
023            
024            public boolean isJoinOk() {
025                    return joinOk;
026            }
027            
028            public int getJoinCounter() {
029                    return joinCounter;
030            }
031    
032            @Handler("java(str)://str.equals(\"Hello\")")
033            public String handleHello(String str) {
034                    ++helloCounter;
035                    helloOk = "Hello".equals(str);
036                    return "World";
037            }
038            
039            @Handler({
040                            "java(,world,)://world.equals(\"World\")",
041                            "java(hello,world,i)://AND(i+((int) 'A')> (int) hello.charAt(0),i+((int) 'A')< (int) world.charAt(0))"
042                    })
043            public void join(
044                            LocalEventDispatchJoinContext<Object, Integer, Object> context, 
045                            @Condition("\"Hello\".equals(hello)") String hello, 
046                            String world, 
047                            int i) {
048                    ++joinCounter;
049                    joinOk = "Hello".equals(hello) && "World".equals(world) && i>'H'-'A' && i<'W'-'A' && Mode.POST.equals(context.getMode());
050                    
051                    context.post(hello+" "+world+" "+i);
052            }
053    }