• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 Network New Technologies Inc.
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 
17 package com.networknt.schema;
18 
19 import java.util.Collections;
20 import java.util.Set;
21 
22 public class JsonSchemaException extends RuntimeException {
23     private static final long serialVersionUID = -7805792737596582110L;
24     private ValidationMessage validationMessage;
25 
JsonSchemaException(ValidationMessage validationMessage)26     public JsonSchemaException(ValidationMessage validationMessage) {
27         this.validationMessage = validationMessage;
28     }
29 
JsonSchemaException(String message)30     public JsonSchemaException(String message) {
31         super(message);
32     }
33 
JsonSchemaException(Throwable throwable)34     public JsonSchemaException(Throwable throwable) {
35         super(throwable);
36     }
37 
38     @Override
getMessage()39     public String getMessage() {
40         return this.validationMessage != null ? this.validationMessage.getMessage() : super.getMessage();
41     }
42 
getValidationMessage()43     public ValidationMessage getValidationMessage() {
44         return this.validationMessage;
45     }
46 
getValidationMessages()47     public Set<ValidationMessage> getValidationMessages() {
48         if (validationMessage == null) {
49             return Collections.emptySet();
50         }
51         return Collections.singleton(validationMessage);
52     }
53 }
54