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.Variant;
15 * {@link CanonicalValue} validator interface. Implementations of this interface can perform further validation of
16 * representation state such that it conforms to a YANG type derived from a type with a {@link CanonicalValue}
20 * Note: this interface should not be directly implemented. Use {@link AbstractCanonicalValueValidator} instead.
22 * @param <T> canonical value type
23 * @param <V> validated canonical value type
24 * @author Robert Varga
28 public interface CanonicalValueValidator<T extends CanonicalValue<T>, V extends T> {
30 * Returns the instantiated representation class. The representation class is a {@link CanonicalValue} which
31 * understands the semantics of modeled data and has some internal representation of it. All {@link CanonicalValue}s
32 * which share the same representation class are considered equal if their internal state would result in the
33 * same canonical string representation as defined by the YANG data model.
35 * @return Representation {@link CanonicalValue} class.
37 Class<T> getRepresentationClass();
40 * Return the class which captures the fact it was validated by this validator.
42 * @return Validated capture of the representation class.
44 Class<V> getValidatedRepresentationClass();
47 * Validate a {@link CanonicalValue} representation. Implementations should override this method if they can
48 * provide a validation algorithm which does not rely on canonical strings but works on representation state only.
50 * @param value Representation value
51 * @return Validated representation or a {@link CanonicalValueViolation}
52 * @throws NullPointerException if {@code value} is null
54 default Variant<T, CanonicalValueViolation> validateRepresentation(final T value) {
55 return validateRepresentation(value, value.toCanonicalString());
59 * Validate a {@link CanonicalValue} representation. Implementations can chose whether they operate on
60 * representation state or canonical string -- both are considered equivalent. Users should call this method if they
61 * have a representation readily available.
63 * @param value Representation value
64 * @param canonicalString Canonical string matching the representation value
65 * @return Validated representation or a {@link CanonicalValueViolation}
66 * @throws NullPointerException if {@code value} or {@code canonicalString} is null.
68 Variant<T, CanonicalValueViolation> validateRepresentation(T value, String canonicalString);