Merge "Fixed add/delete/modify RPC for group/flow/remove reach the test provider"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / AttributeIfcSwitchStatement.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.netconf.confignetconfconnector.mapping.attributes;
10
11 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
12 import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute;
13 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
14 import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute;
15 import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute;
16 import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute;
17
18 import javax.management.openmbean.ArrayType;
19 import javax.management.openmbean.CompositeType;
20 import javax.management.openmbean.OpenType;
21 import javax.management.openmbean.SimpleType;
22
23 public abstract class AttributeIfcSwitchStatement<T> {
24
25     protected AttributeIfc lastAttribute;
26
27     public T switchAttribute(AttributeIfc attributeIfc) {
28
29         this.lastAttribute = attributeIfc;
30
31         if (attributeIfc instanceof JavaAttribute) {
32             try {
33                 return caseJavaAttribute(attributeIfc.getOpenType());
34             } catch (UnknownOpenTypeException e) {
35                 throw getIllegalArgumentException(attributeIfc);
36             }
37
38         } else if (attributeIfc instanceof DependencyAttribute) {
39             return caseDependencyAttribute(((DependencyAttribute) attributeIfc).getOpenType());
40         } else if (attributeIfc instanceof ListAttribute) {
41             return caseListAttribute((ArrayType<?>) attributeIfc.getOpenType());
42         } else if (attributeIfc instanceof ListDependenciesAttribute) {
43             return caseListDependeciesAttribute((ArrayType<?>) attributeIfc.getOpenType());
44         } else if (attributeIfc instanceof TOAttribute) {
45             return caseTOAttribute(((TOAttribute) attributeIfc).getOpenType());
46         }
47
48         throw getIllegalArgumentException(attributeIfc);
49     }
50
51
52     private IllegalArgumentException getIllegalArgumentException(AttributeIfc attributeIfc) {
53         return new IllegalArgumentException("Unknown attribute type " + attributeIfc.getClass() + ", " + attributeIfc
54                 + " with open type:" + attributeIfc.getOpenType());
55     }
56
57     public final T caseJavaAttribute(OpenType<?> openType) {
58         if (openType instanceof SimpleType<?>) {
59             return caseJavaSimpleAttribute((SimpleType<?>) openType);
60         } else if (openType instanceof ArrayType<?>) {
61             return caseJavaArrayAttribute((ArrayType<?>) openType);
62         } else if (openType instanceof CompositeType) {
63             return caseJavaCompositeAttribute((CompositeType) openType);
64         }
65
66         throw new UnknownOpenTypeException("Unknown attribute open type " + openType);
67     }
68
69     protected abstract T caseJavaSimpleAttribute(SimpleType<?> openType);
70
71     protected abstract T caseJavaArrayAttribute(ArrayType<?> openType);
72
73     protected abstract T caseJavaCompositeAttribute(CompositeType openType);
74
75     protected abstract T caseDependencyAttribute(SimpleType<?> attributeIfc);
76
77     protected abstract T caseTOAttribute(CompositeType openType);
78
79     protected abstract T caseListAttribute(ArrayType<?> openType);
80
81     protected abstract T caseListDependeciesAttribute(ArrayType<?> openType);
82
83     private static class UnknownOpenTypeException extends RuntimeException {
84         public UnknownOpenTypeException(String message) {
85             super(message);
86         }
87     }
88 }