1 /*
2  * Copyright (C) 2018 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 import com.android.tradefed.result.error.ErrorIdentifier;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 
23 /** {@link ConfigurationException} for when the class of an object is not found. */
24 public class ClassNotFoundConfigurationException extends ConfigurationException {
25 
26     private static final long serialVersionUID = 7742154448569011969L;
27     private Map<String, String> mRejectedObjects;
28 
29     /**
30      * Creates a {@link ClassNotFoundConfigurationException}.
31      *
32      * @param msg a meaningful error message
33      * @param cause the {@link Throwable} that represents the original cause of the error
34      * @param error The {@link ErrorIdentifier} associated with the exception
35      * @param className the class of the object that was not found
36      * @param objectType the Tradefed object type of the object that was not found
37      */
ClassNotFoundConfigurationException( String msg, Throwable cause, ErrorIdentifier error, String className, String objectType)38     public ClassNotFoundConfigurationException(
39             String msg,
40             Throwable cause,
41             ErrorIdentifier error,
42             String className,
43             String objectType) {
44         super(msg, cause, error);
45         mRejectedObjects = new HashMap<>();
46         mRejectedObjects.put(className, objectType);
47     }
48 
49     /**
50      * Creates a {@link ClassNotFoundConfigurationException}.
51      *
52      * @param msg a meaningful error message
53      * @param cause the {@link Throwable} that represents the original cause of the error
54      * @param error The {@link ErrorIdentifier} associated with the exception
55      * @param rejectedObjects The map of objects that failed loading.
56      */
ClassNotFoundConfigurationException( String msg, Throwable cause, ErrorIdentifier error, Map<String, String> rejectedObjects)57     public ClassNotFoundConfigurationException(
58             String msg,
59             Throwable cause,
60             ErrorIdentifier error,
61             Map<String, String> rejectedObjects) {
62         super(msg, cause, error);
63         mRejectedObjects = rejectedObjects;
64     }
65 
66     /** Returns the map of object class that was rejected. */
getRejectedObjects()67     public Map<String, String> getRejectedObjects() {
68         return mRejectedObjects;
69     }
70 }
71