diff options
Diffstat (limited to 'subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/planning/QueryProcessingException.java')
-rw-r--r-- | subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/planning/QueryProcessingException.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/planning/QueryProcessingException.java b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/planning/QueryProcessingException.java new file mode 100644 index 00000000..3efa32a2 --- /dev/null +++ b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/planning/QueryProcessingException.java | |||
@@ -0,0 +1,102 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.interpreter.matchers.planning; | ||
10 | |||
11 | import tools.refinery.interpreter.matchers.InterpreterRuntimeException; | ||
12 | |||
13 | /** | ||
14 | * @author Zoltan Ujhelyi | ||
15 | * @since 0.9 | ||
16 | */ | ||
17 | public class QueryProcessingException extends InterpreterRuntimeException { | ||
18 | |||
19 | private static final long serialVersionUID = -8272290113656867086L; | ||
20 | /** | ||
21 | * Binding the '{n}' (n = 1..N) strings to contextual conditions in 'context' | ||
22 | * | ||
23 | * @param context | ||
24 | * : array of context-sensitive Strings | ||
25 | */ | ||
26 | protected static String bind(String message, String[] context) { | ||
27 | if (context == null) | ||
28 | return message; | ||
29 | |||
30 | String internal = message; | ||
31 | for (int i = 0; i < context.length; i++) { | ||
32 | internal = internal.replace("{" + (i + 1) + "}", context[i] != null ? context[i] : "<<null>>"); | ||
33 | } | ||
34 | return internal; | ||
35 | } | ||
36 | |||
37 | private Object patternDescription; | ||
38 | private String shortMessage; | ||
39 | |||
40 | /** | ||
41 | * @param message | ||
42 | * The template of the exception message | ||
43 | * @param context | ||
44 | * The data elements to be used to instantiate the template. Can be null if no context parameter is | ||
45 | * defined | ||
46 | * @param patternDescription | ||
47 | * the PatternDescription where the exception occurred | ||
48 | * @since 2.0 | ||
49 | */ | ||
50 | public QueryProcessingException(String message, Object patternDescription) { | ||
51 | super(message); | ||
52 | initializeFields(message, patternDescription); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @param message | ||
57 | * The template of the exception message | ||
58 | * @param context | ||
59 | * The data elements to be used to instantiate the template. Can be null if no context parameter is | ||
60 | * defined | ||
61 | * @param patternDescription | ||
62 | * the PatternDescription where the exception occurred | ||
63 | */ | ||
64 | public QueryProcessingException(String message, String[] context, String shortMessage, Object patternDescription) { | ||
65 | super(bind(message, context)); | ||
66 | initializeFields(shortMessage, patternDescription); | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * @param message | ||
71 | * The template of the exception message | ||
72 | * @param context | ||
73 | * The data elements to be used to instantiate the template. Can be null if no context parameter is | ||
74 | * defined | ||
75 | * @param patternDescription | ||
76 | * the PatternDescription where the exception occurred | ||
77 | */ | ||
78 | public QueryProcessingException(String message, String[] context, String shortMessage, Object patternDescription, | ||
79 | Throwable cause) { | ||
80 | super(bind(message, context), cause); | ||
81 | initializeFields(shortMessage, patternDescription); | ||
82 | } | ||
83 | |||
84 | public Object getPatternDescription() { | ||
85 | return patternDescription; | ||
86 | } | ||
87 | |||
88 | public String getShortMessage() { | ||
89 | return shortMessage; | ||
90 | } | ||
91 | |||
92 | private void initializeFields(String shortMessage, Object patternDescription) { | ||
93 | this.patternDescription = patternDescription; | ||
94 | this.shortMessage = shortMessage; | ||
95 | } | ||
96 | |||
97 | |||
98 | public void setPatternDescription(Object patternDescription) { | ||
99 | this.patternDescription = patternDescription; | ||
100 | } | ||
101 | |||
102 | } | ||