aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/planning/QueryProcessingException.java
blob: 501ddf73ce596ef4a7101aaba1889b835cd3d438 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 * Copyright (c) 2010-2013, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package tools.refinery.viatra.runtime.matchers.planning;

import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException;

/**
 * @author Zoltan Ujhelyi
 * @since 0.9
 */
public class QueryProcessingException extends ViatraQueryRuntimeException {

    private static final long serialVersionUID = -8272290113656867086L;
    /**
     * Binding the '{n}' (n = 1..N) strings to contextual conditions in 'context'
     * 
     * @param context
     *            : array of context-sensitive Strings
     */
    protected static String bind(String message, String[] context) {
        if (context == null) 
            return message;
    
        String internal = message;
        for (int i = 0; i < context.length; i++) {
            internal = internal.replace("{" + (i + 1) + "}", context[i] != null ? context[i] : "<<null>>");
        }
        return internal;
    }
    
    private Object patternDescription;
    private String shortMessage;

    /**
     * @param message
     *            The template of the exception message
     * @param context
     *            The data elements to be used to instantiate the template. Can be null if no context parameter is
     *            defined
     * @param patternDescription
     *            the PatternDescription where the exception occurred
     * @since 2.0
     */
    public QueryProcessingException(String message, Object patternDescription) {
        super(message);
        initializeFields(message, patternDescription);
    }
    
    /**
     * @param message
     *            The template of the exception message
     * @param context
     *            The data elements to be used to instantiate the template. Can be null if no context parameter is
     *            defined
     * @param patternDescription
     *            the PatternDescription where the exception occurred
     */
    public QueryProcessingException(String message, String[] context, String shortMessage, Object patternDescription) {
        super(bind(message, context));
        initializeFields(shortMessage, patternDescription);
    }

    /**
     * @param message
     *            The template of the exception message
     * @param context
     *            The data elements to be used to instantiate the template. Can be null if no context parameter is
     *            defined
     * @param patternDescription
     *            the PatternDescription where the exception occurred
     */
    public QueryProcessingException(String message, String[] context, String shortMessage, Object patternDescription,
            Throwable cause) {
        super(bind(message, context), cause);
        initializeFields(shortMessage, patternDescription);
    }
    
    public Object getPatternDescription() {
        return patternDescription;
    }

    public String getShortMessage() {
        return shortMessage;
    }

    private void initializeFields(String shortMessage, Object patternDescription) {
        this.patternDescription = patternDescription;
        this.shortMessage = shortMessage;
    }

    
    public void setPatternDescription(Object patternDescription) {
        this.patternDescription = patternDescription;
    }

}