9
9
import org .xml .sax .SAXException ;
10
10
11
11
import com .sdiawara .voicextt .exception .GotoException ;
12
- import com .sdiawara .voicextt .exception .VoiceXTTException ;
13
- import com .sdiawara .voicextt .node .VoiceXmlNode ;
14
12
import com .sdiawara .voicextt .node .Vxml ;
15
13
16
14
public class Interpreter {
@@ -24,62 +22,53 @@ public class Interpreter {
24
22
public Interpreter (String startFileName ) throws ParserConfigurationException , IOException , SAXException {
25
23
this .interpreterContext = new InterpreterContext (startFileName ); // session
26
24
this .speaker = new Speaker (userInput );
27
- this .vxml = new Vxml (interpreterContext .getDocumentAcces ().get (startFileName , null )
28
- .getDocumentElement ());
29
- resetFia (vxml .getFirstDialog ());
30
- }
31
-
32
- private void resetFia (VoiceXmlNode dialog ) throws IOException , SAXException {
33
- this .fia = new FormInterpretationAlgorithm (dialog , interpreterContext .getScripting (), outPut , userInput );
34
- UncaughtExceptionHandler eh = new UncaughtExceptionHandler () {
35
-
36
- public void uncaughtException (Thread t , Throwable e ) {
37
- Throwable exception = e .getCause ();
38
- System .err .println (exception );
39
- if (exception instanceof GotoException ) {
40
- String next = ((GotoException ) exception ).getGoto ().getNext ();
41
- String expr = ((GotoException ) exception ).getGoto ().getExpr ();
42
- if (next == null && expr == null ) {
43
- throw new RuntimeException ("Semantic error" );
44
- }
45
- System .err .println (next );
46
- next = ((next == null ) ? ((String ) interpreterContext .getScripting ().eval (expr )) : next );
47
- if (next .startsWith ("#" )) {
48
- System .err .println ("next " + next .replace ("#" , "" ) + " fia is a live= " + fia .isAlive ()
49
- + "test isinterrupt " + t .isInterrupted ());
50
- fia .setCurrentDialog (vxml .getDialogById (next .replace ("#" , "" )));
51
- System .err .println ("next " + next .replace ("#" , "" ) + " fia is a live= " + fia .isAlive ()
52
- + "test isinterrupt " + t .isInterrupted ());
53
- fia .run ();
54
- System .err .println ("after fia is a live= " + fia .isAlive ()
55
- + "test isinterrupt " + t .isInterrupted ());
56
- fia .setUncaughtExceptionHandler (this );
57
- }
58
- }
59
- }
60
-
61
- };
62
- fia .setUncaughtExceptionHandler (eh );
25
+ this .vxml = new Vxml (interpreterContext .getDocumentAcces ().get (startFileName , null ).getDocumentElement ());
26
+ this .fia = new FormInterpretationAlgorithm (vxml .getFirstDialog (), interpreterContext .getScripting (), outPut , userInput );
27
+ FormInterpretationAlgorithm .setDefaultUncaughtExceptionHandler (getDefaultUncaughtExceptionHandler ());
63
28
}
64
29
65
30
public void start () throws IOException , SAXException {
66
- // if (!fia.isAlive()) {
67
31
this .fia .start ();
68
32
waitSpeaker ();
69
- System .err .println ("fin" );
70
- // }
71
33
}
72
34
73
35
private void waitSpeaker () {
74
36
try {
75
37
fia .join ();
76
38
speaker .join ();
77
39
} catch (InterruptedException e ) {
78
- // System.err.println(e);
40
+ System .err .println (e );
79
41
}
80
42
}
81
43
82
44
public List <String > getPrompts () {
83
45
return outPut .getTTS ();
84
46
}
47
+
48
+ private UncaughtExceptionHandler getDefaultUncaughtExceptionHandler () {
49
+ return new UncaughtExceptionHandler () {
50
+ public void uncaughtException (Thread t , Throwable e ) {
51
+ Throwable exception = e .getCause ();
52
+ if (exception instanceof GotoException ) {
53
+ String next = ((GotoException ) exception ).getGoto ().getNext ();
54
+ String expr = ((GotoException ) exception ).getGoto ().getExpr ();
55
+ if (next == null && expr == null ) {
56
+ throw new RuntimeException ("Semantic error" );
57
+ }
58
+ next = ((next == null ) ? ((String ) interpreterContext .getScripting ().eval (expr )) : next );
59
+ if (next .contains ("#" )) {
60
+ fia = new FormInterpretationAlgorithm (vxml .getDialogById (next .replace ("#" , "" )), interpreterContext .getScripting (), outPut ,
61
+ userInput );
62
+ try {
63
+ fia .start ();
64
+ Interpreter .this .waitSpeaker ();
65
+ } catch (Exception e1 ) {
66
+ System .err .println (e1 );
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ };
73
+ }
85
74
}
0 commit comments