affac8e51491242c518c63a4a8d050a43447f727
[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
16 /**
17  * Exception thrown when unique constraints would be violated and we cannot throw a
18  * {@link RequiredElementCountException}.
19  */
20 final class MinMaxElementsValidationFailedException extends SchemaValidationFailedException
21         implements YangNetconfErrorAware {
22     private static final long serialVersionUID = 1L;
23
24     private final int min;
25     private final int max;
26     private final int actual;
27
28     // FIXME: 8.0.0: we do not have a path here. Should we just allow DataValidationFailedException whereever our call
29     //               sites are?
30     MinMaxElementsValidationFailedException(final String message, final int min, final int max, final int actual) {
31         super(message);
32         this.min = min;
33         this.max = max;
34         this.actual = actual;
35     }
36
37     @Override
38     public List<YangNetconfError> getNetconfErrors() {
39         return new RequiredElementCountException(YangInstanceIdentifier.empty(), actual, min, max, "dummy")
40             .getNetconfErrors();
41     }
42 }