1 19 20 package org.openide.execution; 21 22 import java.security.AllPermission ; 23 import java.security.CodeSource ; 24 import java.security.PermissionCollection ; 25 import java.security.Permissions ; 26 import org.openide.util.Lookup; 27 import org.openide.util.RequestProcessor; 28 import org.openide.windows.IOProvider; 29 import org.openide.windows.InputOutput; 30 31 37 public abstract class ExecutionEngine extends Object { 38 39 47 public abstract ExecutorTask execute(String name, Runnable run, InputOutput io); 48 49 61 protected abstract PermissionCollection createPermissions(CodeSource cs, InputOutput io); 62 63 71 protected abstract NbClassPath createLibraryPath (); 72 73 89 public static ExecutionEngine getDefault() { 90 ExecutionEngine ee = (ExecutionEngine) Lookup.getDefault().lookup(ExecutionEngine.class); 91 if (ee == null) { 92 ee = new Trivial(); 93 } 94 return ee; 95 } 96 97 100 static final class Trivial extends ExecutionEngine { 101 102 public Trivial() {} 103 104 protected NbClassPath createLibraryPath() { 105 return new NbClassPath(new String [0]); 106 } 107 108 protected PermissionCollection createPermissions(CodeSource cs, InputOutput io) { 109 PermissionCollection allPerms = new Permissions (); 110 allPerms.add(new AllPermission ()); 111 allPerms.setReadOnly(); 112 return allPerms; 113 } 114 115 public ExecutorTask execute(String name, Runnable run, InputOutput io) { 116 return new ET(run, name, io); 117 } 118 119 private static final class ET extends ExecutorTask { 120 private RequestProcessor.Task task; 121 private int resultValue; 122 private final String name; 123 private InputOutput io; 124 125 public ET(Runnable run, String name, InputOutput io) { 126 super(run); 127 this.resultValue = resultValue; 128 this.name = name; 129 task = RequestProcessor.getDefault().post(this); 130 } 131 132 public void stop() { 133 task.cancel(); 134 } 135 136 public int result() { 137 waitFinished(); 138 return resultValue; 139 } 140 141 public InputOutput getInputOutput() { 142 return io; 143 } 144 145 public void run() { 146 try { 147 super.run(); 148 } catch (RuntimeException x) { 149 x.printStackTrace(); 150 resultValue = 1; 151 } 152 } 153 154 } 155 156 } 157 158 } 159 | Popular Tags |