| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.commons.scxml.env; |
| 18 |
|
|
| 19 |
|
import java.io.Serializable; |
| 20 |
|
import java.util.HashSet; |
| 21 |
|
import java.util.Iterator; |
| 22 |
|
import java.util.Map; |
| 23 |
|
import java.util.Set; |
| 24 |
|
|
| 25 |
|
import org.apache.commons.logging.Log; |
| 26 |
|
import org.apache.commons.logging.LogFactory; |
| 27 |
|
import org.apache.commons.scxml.ErrorReporter; |
| 28 |
|
import org.apache.commons.scxml.model.SCXML; |
| 29 |
|
import org.apache.commons.scxml.model.State; |
| 30 |
|
import org.apache.commons.scxml.model.Transition; |
| 31 |
|
import org.apache.commons.scxml.model.TransitionTarget; |
| 32 |
|
import org.apache.commons.scxml.semantics.ErrorConstants; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
public class SimpleErrorReporter implements ErrorReporter, Serializable { |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
private static final long serialVersionUID = 1L; |
| 41 |
|
|
| 42 |
49 |
private Log log = LogFactory.getLog(getClass()); |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
public SimpleErrorReporter() { |
| 48 |
49 |
super(); |
| 49 |
49 |
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
public void onError(final String errorCode, final String errDetail, |
| 55 |
|
final Object errCtx) { |
| 56 |
|
|
| 57 |
|
|
| 58 |
0 |
String errCode = errorCode.intern(); |
| 59 |
0 |
StringBuffer msg = new StringBuffer(); |
| 60 |
0 |
msg.append(errCode).append(" ("); |
| 61 |
0 |
msg.append(errDetail).append("): "); |
| 62 |
0 |
if (errCode == ErrorConstants.NO_INITIAL) { |
| 63 |
0 |
if (errCtx instanceof SCXML) { |
| 64 |
|
|
| 65 |
0 |
msg.append("<SCXML>"); |
| 66 |
0 |
} else if (errCtx instanceof State) { |
| 67 |
|
|
| 68 |
|
|
| 69 |
0 |
msg.append("State " + LogUtils.getTTPath((State) errCtx)); |
| 70 |
|
} |
| 71 |
0 |
} else if (errCode == ErrorConstants.UNKNOWN_ACTION) { |
| 72 |
|
|
| 73 |
0 |
msg.append("Action: " + errCtx.getClass().getName()); |
| 74 |
0 |
} else if (errCode == ErrorConstants.NON_DETERMINISTIC) { |
| 75 |
|
|
| 76 |
0 |
msg.append(" ["); |
| 77 |
0 |
if (errCtx instanceof HashSet) { |
| 78 |
0 |
for (Iterator i = ((Set) errCtx).iterator(); i.hasNext();) { |
| 79 |
0 |
Transition t = (Transition) i.next(); |
| 80 |
0 |
msg.append(LogUtils.transToString(t.getParent(), |
| 81 |
|
t.getTarget(), t)); |
| 82 |
0 |
if (i.hasNext()) { |
| 83 |
0 |
msg.append(", "); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
0 |
msg.append(']'); |
| 88 |
0 |
} else if (errCode == ErrorConstants.ILLEGAL_CONFIG) { |
| 89 |
|
|
| 90 |
0 |
if (errCtx instanceof Map.Entry) { |
| 91 |
0 |
TransitionTarget tt = (TransitionTarget) |
| 92 |
|
(((Map.Entry) errCtx).getKey()); |
| 93 |
0 |
Set vals = (Set) (((Map.Entry) errCtx).getValue()); |
| 94 |
0 |
msg.append(LogUtils.getTTPath(tt) + " : ["); |
| 95 |
0 |
for (Iterator i = vals.iterator(); i.hasNext();) { |
| 96 |
0 |
TransitionTarget tx = (TransitionTarget) i.next(); |
| 97 |
0 |
msg.append(LogUtils.getTTPath(tx)); |
| 98 |
0 |
if (i.hasNext()) { |
| 99 |
0 |
msg.append(", "); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
0 |
msg.append(']'); |
| 103 |
0 |
} else if (errCtx instanceof Set) { |
| 104 |
0 |
Set vals = (Set) errCtx; |
| 105 |
0 |
msg.append("<SCXML> : ["); |
| 106 |
0 |
for (Iterator i = vals.iterator(); i.hasNext();) { |
| 107 |
0 |
TransitionTarget tx = (TransitionTarget) i.next(); |
| 108 |
0 |
msg.append(LogUtils.getTTPath(tx)); |
| 109 |
0 |
if (i.hasNext()) { |
| 110 |
0 |
msg.append(", "); |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
0 |
msg.append(']'); |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
0 |
if (log.isWarnEnabled()) { |
| 117 |
0 |
log.warn(msg.toString()); |
| 118 |
|
} |
| 119 |
0 |
} |
| 120 |
|
|
| 121 |
|
} |
| 122 |
|
|