2 * Copyright (c) 2015 CableLabs 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
9 package org.opendaylight.controller.packetcable.provider.validation;
11 import java.util.NoSuchElementException;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
16 * Helper class to hide the casting needed to store all the validators in one collection.
17 * Types remain consistent by using generics on the put method.
21 public interface ValidatorProvider {
24 * Add a new validator or replace an old validator to this provider.
29 * The validator for the Class T
31 * The type being validated
33 <T extends DataObject> void put(@Nonnull final Class<T> tClass, @Nonnull final Validator<T> validator);
36 * Gets the validator for a particular type
41 * The type to be validated
42 * @return a Validator instance
43 * @throws NoSuchElementException
44 * if a Validator for the passed in type does not exist on this provider.
46 <T extends DataObject> Validator<T> validatorFor(@Nonnull final Class<T> tClass);
49 * Helper method to get a validator and then call validate with the supplied DataObject.
52 * The class type to validate
54 * The DataObject instance to validate
56 * The extend to validate with
59 * @throws ValidationException
61 * @throws IllegalArgumentException
62 * if data is not assignable from tClass
64 <T extends DataObject> void validate(@Nonnull final Class<T> tClass, @Nonnull final DataObject data,
65 @Nonnull final Validator.Extent extent) throws ValidationException;