1 28 29 package org.objectweb.util.explorer.core.code.lib; 30 31 import org.objectweb.util.explorer.ExplorerUtils; 32 import org.objectweb.util.explorer.core.code.api.Code; 33 import org.objectweb.util.explorer.core.code.api.CodeConfiguration; 34 import org.objectweb.util.explorer.core.common.lib.ClassResolver; 35 import org.objectweb.util.trace.TraceSystem; 36 37 import bsh.Interpreter; 38 import bsh.EvalError; 39 40 47 public class BeanShellCode 48 implements CodeConfiguration, Code 49 { 50 51 57 58 protected String theCode_ = null; 59 60 protected Class theClass_ = null; 61 62 68 74 protected boolean equals(BeanShellCode code){ 75 if(code!=null){ 76 String theCode = code.theCode_; 77 if(theCode_!=null && theCode!=null){ 78 return theCode_.equals(theCode); 79 } 80 } 81 return false; 82 } 83 84 90 public void setCode(String code) { 91 theCode_ = code; 92 } 93 94 100 103 public boolean isInstanceOf(Class c) { 104 theClass_ = c; 105 return true; 106 } 107 108 111 public Object createInstance() { 112 Interpreter interpreter = new Interpreter(); 113 114 String code = theCode_ 115 + "\nreturn (" 116 + theClass_.getName() 117 + ")this;"; 118 try 119 { 120 return interpreter.eval(code); 121 } 122 catch(EvalError exc) 123 { 124 TraceSystem.get("explorer").info(exc.getMessage()); 125 } 126 return null; 127 } 128 129 135 139 public boolean equals(Object o){ 140 if(o!=null && o instanceof BeanShellCode){ 141 return equals((BeanShellCode)o); 142 } 143 return false; 144 } 145 146 150 public String toString(){ 151 return "BeanShellCode[class=" + 152 ExplorerUtils.toString(theClass_) + "]"; 153 } 154 155 } 156 | Popular Tags |