Expose SchemaValidationFailedException
[yangtools.git] / data / yang-data-tree-ri / src / main / java / org / opendaylight / yangtools / yang / data / tree / impl / MinMaxElementsValidationFailedException.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.tree.impl;
9
10 import java.util.List;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
13 import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
14 import org.opendaylight.yangtools.yang.data.tree.api.RequiredElementCountException;
15 import org.opendaylight.yangtools.yang.data.tree.api.SchemaValidationFailedException;
16
17 /**
18  * Exception thrown when unique constraints would be violated and we cannot throw a
19  * {@link RequiredElementCountException}.
20  */
21 final class MinMaxElementsValidationFailedException extends SchemaValidationFailedException
22         implements YangNetconfErrorAware {
23     private static final long serialVersionUID = 1L;
24
25     private final int min;
26     private final int max;
27     private final int actual;
28
29     // FIXME: 8.0.0: we do not have a path here. Should we just allow DataValidationFailedException whereever our call
30     //               sites are?
31     MinMaxElementsValidationFailedException(final String message, final int min, final int max, final int actual) {
32         super(message);
33         this.min = min;
34         this.max = max;
35         this.actual = actual;
36     }
37
38     @Override
39     public List<YangNetconfError> getNetconfErrors() {
40         return new RequiredElementCountException(YangInstanceIdentifier.empty(), actual, min, max, "dummy")
41             .getNetconfErrors();
42     }
43 }