828532fe1ce91f4109f6e576532c809aa638291c
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / classifier / ClassifierChoiceValidator.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.impl.validators.qos.classifier;
10
11 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
12 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.classifier.container.ClassifierChoice;
13 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.classifier.container.classifier.choice.ExtClassifierChoice;
14 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.classifier.container.classifier.choice.Ipv6ClassifierChoice;
15 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.classifier.attributes.classifiers.classifier.container.classifier.choice.QosClassifierChoice;
16
17 /**
18  * @author rvail
19  */
20 public class ClassifierChoiceValidator extends AbstractValidator<ClassifierChoice> {
21
22     private final ClassifierValidator classifierValidator = new ClassifierValidator();
23     private final ExtClassifierValidator extClassifierValidator = new ExtClassifierValidator();
24     private final Ipv6ClassifierValidator ipv6ClassifierValidator = new Ipv6ClassifierValidator();
25
26     @Override
27     protected void doValidate(final ClassifierChoice choice, final Extent extent) {
28         if (choice == null) {
29             getErrorMessages().add("classifier-choice must exist");
30             return;
31         }
32
33         // Determine what type this choice is then validate it
34         if (choice instanceof QosClassifierChoice) {
35             validateChild(classifierValidator, ((QosClassifierChoice) choice).getClassifier());
36         }
37         else if (choice instanceof ExtClassifierChoice) {
38             validateChild(extClassifierValidator, ((ExtClassifierChoice) choice).getExtClassifier());
39         }
40         else if (choice instanceof Ipv6ClassifierChoice) {
41             validateChild(ipv6ClassifierValidator, ((Ipv6ClassifierChoice) choice).getIpv6Classifier());
42         }
43         else {
44             throw new IllegalStateException("Unknown ClassifierChoice Type: " + choice.getClass().getName());
45         }
46     }
47
48 }