1 package rero.bridges.event; 2 3 import sleep.runtime.*; 4 import sleep.interfaces.*; 5 import sleep.engine.*; 6 7 import rero.script.*; 8 9 import java.util.HashMap ; 10 11 public class CodeSnippet 12 { 13 protected ScriptEnvironment environment; 14 protected ScriptInstance si; 15 protected Block code; 16 17 public CodeSnippet(Block c, ScriptEnvironment e) 18 { 19 code = c; 20 environment = e; 21 22 si = environment.getScriptInstance(); 23 } 24 25 public int getLineNumber() 26 { 27 return code.getApproximateLineNumber(); 28 } 29 30 public boolean isValid() 31 { 32 return si.isLoaded(); 33 } 34 35 public int execute(HashMap eventData) 36 { 37 if (!isValid()) 41 { 42 return rero.ircfw.interfaces.ChatListener.REMOVE_LISTENER; 43 } 44 45 Scalar rv; 46 47 synchronized (environment.getScriptVariables()) 48 { 49 environment.getScriptVariables().pushLocalLevel(); 50 51 LocalVariables locals = (LocalVariables)environment.getScriptVariables().getLocalVariables(); 52 locals.setDataSource(eventData); 53 54 rv = SleepUtils.runCode(code, environment); 55 56 environment.getScriptVariables().popLocalLevel(); 57 } 58 59 if (rv == null) 60 { 61 return 0; 62 } 63 64 return rv.getValue().intValue(); 65 } 66 } 67 | Popular Tags |