1 19 20 package org.openide.execution; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.util.Collections ; 24 import org.openide.ServiceType; 25 import org.openide.filesystems.FileObject; 26 import org.openide.util.Lookup; 27 28 33 public abstract class ScriptType extends org.openide.ServiceType { 34 35 36 private static final long serialVersionUID = 4893207884933024341L; 37 38 44 public abstract boolean acceptFileObject(FileObject fo); 45 46 52 public abstract Object eval(java.io.Reader r, Context context) throws InvocationTargetException ; 53 54 57 public final Object eval(java.io.Reader r) throws InvocationTargetException { 58 return eval(r, getDefaultContext()); 59 } 60 61 67 public abstract Object eval(String script, Context context) throws InvocationTargetException ; 68 69 72 public final Object eval(String script) throws InvocationTargetException { 73 return eval(script, getDefaultContext()); 74 } 75 76 81 public abstract void exec(java.io.Reader r, Context context) throws InvocationTargetException ; 82 83 86 public final void exec(java.io.Reader r) throws InvocationTargetException { 87 exec(r, getDefaultContext()); 88 } 89 90 96 public abstract void exec(String script, Context context) throws InvocationTargetException ; 97 98 101 public final void exec(String script) throws InvocationTargetException { 102 exec(script, getDefaultContext()); 103 } 104 105 110 public abstract void addVariable(String name, Object value); 111 112 116 public static java.util.Enumeration scriptTypes () { 117 return Collections.enumeration(Lookup.getDefault().lookup(new Lookup.Template(ScriptType.class)).allInstances()); 118 } 119 120 126 public static ScriptType find (Class clazz) { 127 return (ScriptType)Lookup.getDefault().lookup(clazz); 128 } 129 130 135 public static ScriptType find (String name) { 136 ServiceType t = ((ServiceType.Registry)Lookup.getDefault().lookup(ServiceType.Registry.class)).find (name); 137 if (t instanceof ScriptType) { 138 return (ScriptType)t; 139 } else { 140 return null; 141 } 142 } 143 144 148 public static ScriptType getDefault () { 149 java.util.Enumeration en = scriptTypes (); 150 if (en.hasMoreElements()) { 151 return (ScriptType)en.nextElement (); 152 } else { 153 throw new RuntimeException ("No script type registered."); } 155 } 156 157 static Context getDefaultContext() { 158 return new Context(); 159 } 160 161 165 public static class Context { 166 } 167 } 168 | Popular Tags |