merge of localization branch into HEAD. mh and zap
[mir.git] / source / mir / producer / ScriptCallingProducerNode.java
1 package mir.producer;
2
3 import java.io.*;
4 import java.util.*;
5 import mir.util.*;
6
7 // ML: needs to be tested!
8
9 public class ScriptCallingProducerNode implements ProducerNode  {
10   String scriptExpression;
11
12   public ScriptCallingProducerNode(String aScriptExpression) {
13     scriptExpression = aScriptExpression;
14   }
15
16   public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
17     String script;
18     Process process;
19     int returnValue;
20
21     try {
22       script = ParameterExpander.expandExpression( aValueMap, scriptExpression );
23       aLogger.println("Executing " + script + ":");
24
25       process = Runtime.getRuntime().exec(script);
26       returnValue = process.waitFor();
27       aLogger.println("Terminated successfully, return value = " + returnValue + ".");
28     }
29     catch (Throwable e) {
30       throw new ProducerFailure("Executing script failed: " + e.getMessage(), e);
31     }
32   }
33
34   public Set buildVerbSet() {
35     return new HashSet();
36   }
37 }