1 19 package org.netbeans.mdrshell; 20 21 import java.util.*; 22 import java.io.*; 23 24 import koala.dynamicjava.interpreter.*; 25 import koala.dynamicjava.parser.wrapper.*; 26 27 import org.netbeans.api.mdr.MDRManager; 28 import org.netbeans.mdr.handlers.*; 29 import org.netbeans.mdr.persistence.StorageException; 30 import org.netbeans.mdr.persistence.memoryimpl.StorageFactoryImpl; 31 import org.openide.ErrorManager; 32 33 38 public class DJava extends Object { 39 40 41 public DJava() { 42 } 43 44 static koala.dynamicjava.interpreter.Interpreter interpreter; 45 48 public static void initialize ( ) { 49 interpreter = new TreeInterpreter(new JavaCCParserFactory()); 51 BaseObjectHandler.setClassLoaderProvider(new CLProviderImpl()); 52 53 MDRManager.getDefault().getDefaultRepository().getExtentNames(); 55 56 String storageName = System.getProperty("MDRStorageProperty." + StorageFactoryImpl.STORAGE_ID); 57 if (storageName != null) { 58 try { 59 StorageFactoryImpl.serialize(storageName); 60 } catch (StorageException e) { 61 } 62 } 63 } 64 65 public static Object eval ( String line ) throws Exception { 66 try { 67 Reader r = new StringReader(line + ";"); 68 return interpreter.interpret(r, line ); 69 } catch (Exception e) { 70 ErrorManager.getDefault().notify(e); 71 throw e; 72 } 73 } 74 75 78 public static void declareVariable ( String name, Object object ) { 79 interpreter.defineVariable( name, object ); 80 } 81 82 private static class CLProviderImpl implements ClassLoaderProvider { 83 public ClassLoader getClassLoader() { 84 return interpreter.getClassLoader(); 85 } 86 87 96 public Class defineClass(String className, byte[] classFile) { 97 return interpreter.defineClass(className, classFile); 98 } 99 } 100 } 101 | Popular Tags |