2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.common;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.concepts.Variant;
16 * {@link CanonicalValue} validator interface. Implementations of this interface can perform further validation of
17 * representation state such that it conforms to a YANG type derived from a type with a {@link CanonicalValue}
21 * Note: this interface should not be directly implemented. Use {@link AbstractCanonicalValueValidator} instead.
23 * @param <T> canonical value type
24 * @param <V> validated canonical value type
25 * @author Robert Varga
29 public interface CanonicalValueValidator<T extends CanonicalValue<T>, V extends T> extends Immutable {
31 * Returns the instantiated representation class. The representation class is a {@link CanonicalValue} which
32 * understands the semantics of modeled data and has some internal representation of it. All {@link CanonicalValue}s
33 * which share the same representation class are considered equal if their internal state would result in the
34 * same canonical string representation as defined by the YANG data model.
36 * @return Representation {@link CanonicalValue} class.
38 Class<T> getRepresentationClass();
41 * Return the class which captures the fact it was validated by this validator.
43 * @return Validated capture of the representation class.
45 Class<V> getValidatedRepresentationClass();
48 * Validate a {@link CanonicalValue} representation. Implementations should override this method if they can
49 * provide a validation algorithm which does not rely on canonical strings but works on representation state only.
51 * @param value Representation value
52 * @return Validated representation or a {@link CanonicalValueViolation}
53 * @throws NullPointerException if {@code value} is null
55 default Variant<T, CanonicalValueViolation> validateRepresentation(final T value) {
56 return validateRepresentation(value, value.toCanonicalString());
60 * Validate a {@link CanonicalValue} representation. Implementations can chose whether they operate on
61 * representation state or canonical string -- both are considered equivalent. Users should call this method if they
62 * have a representation readily available.
64 * @param value Representation value
65 * @param canonicalString Canonical string matching the representation value
66 * @return Validated representation or a {@link CanonicalValueViolation}
67 * @throws NullPointerException if {@code value} or {@code canonicalString} is null.
69 Variant<T, CanonicalValueViolation> validateRepresentation(T value, String canonicalString);