1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.config;
17 
18 /**
19  * Class extending {@link ConfigurationException} for template related error during configuration
20  * parsing. Allows this error to be easily detected.
21  */
22 public class TemplateResolutionError extends ConfigurationException {
23 
24     private static final long serialVersionUID = 7742154438569011969L;
25 
26     private String mTemplateKey = null;
27     private String mConfigName = null;
28 
29     /**
30      * Creates a {@link TemplateResolutionError}.
31      *
32      * @param configName the configuration name involved
33      * @param templateName the key name that is used to replace the template.
34      */
TemplateResolutionError(String configName, String templateName)35     public TemplateResolutionError(String configName, String templateName) {
36         super(String.format(
37                 "Failed to parse config xml '%s'. Reason: " +
38                 "Couldn't resolve template-include named " +
39                 "'%s': No 'default' attribute and no matching manual resolution. " +
40                 "Try using argument --template:map %s (config path)",
41                 configName, templateName, templateName));
42         mTemplateKey = templateName;
43         mConfigName = configName;
44     }
45 
46     /**
47      * Return the template key that is used to replace the template.
48      */
getTemplateKey()49     public String getTemplateKey() {
50         return mTemplateKey;
51     }
52 
53     /**
54      * Return the config name that raised the exception in the first place.
55      */
getConfigName()56     public String getConfigName() {
57         return mConfigName;
58     }
59 }
60