Added response data to operational datastore, refactored data validation
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / ValidatorProvider.java
1 /*
2  * Copyright (c) 2015 CableLabs 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
9 package org.opendaylight.controller.packetcable.provider.validation;
10
11 import java.util.NoSuchElementException;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14
15 /**
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.
18  *
19  * @author rvail
20  */
21 public interface ValidatorProvider {
22
23     /**
24      * Add a new validator or replace an old validator to this provider.
25      *
26      * @param tClass
27      *         The Class of T
28      * @param validator
29      *         The validator for the Class T
30      * @param <T>
31      *         The type being validated
32      */
33     <T extends DataObject> void put(@Nonnull final Class<T> tClass, @Nonnull final Validator<T> validator);
34
35     /**
36      * Gets the validator for a particular type
37      *
38      * @param tClass
39      *         The Class of T
40      * @param <T>
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.
45      */
46     <T extends DataObject> Validator<T> validatorFor(@Nonnull final Class<T> tClass);
47
48     /**
49      * Helper method to get a validator and then call validate with the supplied DataObject.
50      *
51      * @param tClass
52      *         The class type to validate
53      * @param data
54      *         The DataObject instance to validate
55      * @param extent
56      *         The extend to validate with
57      * @param <T>
58      *         The type of tClass
59      * @throws ValidationException
60      *         if validation fails
61      * @throws IllegalArgumentException
62      *         if data is not assignable from tClass
63      */
64     <T extends DataObject> void validate(@Nonnull final Class<T> tClass, @Nonnull final DataObject data,
65             @Nonnull final Validator.Extent extent) throws ValidationException;
66 }