01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript;
18:
19: import java.io.BufferedReader;
20: import java.io.IOException;
21: import java.io.PrintWriter;
22: import java.io.StringReader;
23: import java.io.StringWriter;
24: import java.util.ArrayList;
25: import java.util.List;
26: import java.util.regex.Matcher;
27: import java.util.regex.Pattern;
28:
29: import org.mozilla.javascript.RhinoException;
30:
31: /**
32: at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2460)
33: at script.pause(classpath:/org/bpmscript/jbi/bpmscriptlibrary.js:2)
34: at script(classpath:/org/bpmscript/jbi/bpmscriptlibrary.js:86)
35: at script.main(main.js:129)
36: at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2250)
37: at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:149)
38: at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
39: at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
40: at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:147)
41: at org.bpmscript.jbi.ProcessExecutor.send(ProcessExecutor.java:91)
42: at org.bpmscript.jbi.BpmScriptComponent.onMessageExchange(BpmScriptComponent.java:77)
43: at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:671)
44: at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:176)
45: at org.apache.servicemix.jbi.nmr.flow.jms.JMSFlow.access$001(JMSFlow.java:68)
46: at org.apache.servicemix.jbi.nmr.flow.jms.JMSFlow$1.run(JMSFlow.java:411)
47: at org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291)
48: at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source)
49: at java.lang.Thread.run(Unknown Source)
50: */
51: public class StackTraceParser {
52:
53: Pattern pattern = Pattern
54: .compile("at script(?:\\.(.*?))?\\((.*):(.*?)\\)");
55:
56: public StackTraceElement[] getScriptStackTrace(RhinoException ex) {
57: StringWriter st = new StringWriter();
58: ex.printStackTrace(new PrintWriter(st));
59: String trace = st.toString();
60: return getScriptStackTrace(trace);
61: }
62:
63: public StackTraceElement[] getScriptStackTrace(String trace) {
64: List<StackTraceElement> elements = new ArrayList<StackTraceElement>();
65: BufferedReader reader = new BufferedReader(new StringReader(
66: trace));
67: String line = null;
68: try {
69: while ((line = reader.readLine()) != null) {
70: Matcher matcher = pattern.matcher(line);
71: if (matcher.find()) {
72: String method = matcher.group(1);
73: String name = matcher.group(2);
74: int lineNumber = Integer.parseInt(matcher.group(3));
75: StackTraceElement element = new StackTraceElement(
76: "script", method != null ? method : "",
77: name, lineNumber);
78: elements.add(element);
79: }
80: }
81: } catch (IOException e) {
82: // this should really not happen
83: throw new RuntimeException(e);
84: }
85: return (StackTraceElement[]) elements
86: .toArray(new StackTraceElement[elements.size()]);
87: }
88: }
|