2 * Copyright (c) 2013 Cisco Systems, Inc. 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.netconf.confignetconfconnector.mapping.attributes;
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 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
19 import javax.management.openmbean.ArrayType;
20 import javax.management.openmbean.CompositeType;
21 import javax.management.openmbean.OpenType;
22 import javax.management.openmbean.SimpleType;
24 public abstract class AttributeIfcSwitchStatement<T> {
26 protected AttributeIfc lastAttribute;
28 public T switchAttribute(AttributeIfc attributeIfc) {
30 this.lastAttribute = attributeIfc;
32 if (attributeIfc instanceof JavaAttribute) {
34 if(((JavaAttribute)attributeIfc).getTypeDefinition() instanceof BinaryTypeDefinition) {
35 return caseJavaBinaryAttribute(attributeIfc.getOpenType());
37 return caseJavaAttribute(attributeIfc.getOpenType());
38 } catch (UnknownOpenTypeException e) {
39 throw getIllegalArgumentException(attributeIfc);
42 } else if (attributeIfc instanceof DependencyAttribute) {
43 return caseDependencyAttribute(((DependencyAttribute) attributeIfc).getOpenType());
44 } else if (attributeIfc instanceof ListAttribute) {
45 return caseListAttribute((ArrayType<?>) attributeIfc.getOpenType());
46 } else if (attributeIfc instanceof ListDependenciesAttribute) {
47 return caseListDependeciesAttribute((ArrayType<?>) attributeIfc.getOpenType());
48 } else if (attributeIfc instanceof TOAttribute) {
49 return caseTOAttribute(((TOAttribute) attributeIfc).getOpenType());
52 throw getIllegalArgumentException(attributeIfc);
55 protected T caseJavaBinaryAttribute(OpenType<?> openType) {
56 return caseJavaAttribute(openType);
59 private IllegalArgumentException getIllegalArgumentException(AttributeIfc attributeIfc) {
60 return new IllegalArgumentException("Unknown attribute type " + attributeIfc.getClass() + ", " + attributeIfc
61 + " with open type:" + attributeIfc.getOpenType());
64 public final T caseJavaAttribute(OpenType<?> openType) {
65 if (openType instanceof SimpleType<?>) {
66 return caseJavaSimpleAttribute((SimpleType<?>) openType);
67 } else if (openType instanceof ArrayType<?>) {
68 return caseJavaArrayAttribute((ArrayType<?>) openType);
69 } else if (openType instanceof CompositeType) {
70 return caseJavaCompositeAttribute((CompositeType) openType);
73 throw new UnknownOpenTypeException("Unknown attribute open type " + openType);
76 protected abstract T caseJavaSimpleAttribute(SimpleType<?> openType);
78 protected abstract T caseJavaArrayAttribute(ArrayType<?> openType);
80 protected abstract T caseJavaCompositeAttribute(CompositeType openType);
82 protected abstract T caseDependencyAttribute(SimpleType<?> attributeIfc);
84 protected abstract T caseTOAttribute(CompositeType openType);
86 protected abstract T caseListAttribute(ArrayType<?> openType);
88 protected abstract T caseListDependeciesAttribute(ArrayType<?> openType);
90 private static class UnknownOpenTypeException extends RuntimeException {
91 public UnknownOpenTypeException(String message) {