X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fmapping%2Fattributes%2FAttributeIfcSwitchStatement.java;h=697b811d51c90c9b7cab4f05f266292d25d2a260;hp=5e3f54221470906fc86df848efe60673e887975b;hb=43b37a609662f705d2dd701cb8b7c479144d2ef1;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributeIfcSwitchStatement.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributeIfcSwitchStatement.java index 5e3f542214..697b811d51 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributeIfcSwitchStatement.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributeIfcSwitchStatement.java @@ -8,30 +8,88 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.*; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; +import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; + +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.OpenType; +import javax.management.openmbean.SimpleType; public abstract class AttributeIfcSwitchStatement { + protected AttributeIfc lastAttribute; + public T switchAttribute(AttributeIfc attributeIfc) { + this.lastAttribute = attributeIfc; + if (attributeIfc instanceof JavaAttribute) { - return caseJavaAttribute((JavaAttribute) attributeIfc); + try { + if(((JavaAttribute)attributeIfc).getTypeDefinition() instanceof BinaryTypeDefinition) { + return caseJavaBinaryAttribute(attributeIfc.getOpenType()); + } else + return caseJavaAttribute(attributeIfc.getOpenType()); + } catch (UnknownOpenTypeException e) { + throw getIllegalArgumentException(attributeIfc); + } + } else if (attributeIfc instanceof DependencyAttribute) { - return caseDependencyAttribute((DependencyAttribute) attributeIfc); + return caseDependencyAttribute(((DependencyAttribute) attributeIfc).getOpenType()); } else if (attributeIfc instanceof ListAttribute) { - return caseListAttribute((ListAttribute) attributeIfc); + return caseListAttribute((ArrayType) attributeIfc.getOpenType()); + } else if (attributeIfc instanceof ListDependenciesAttribute) { + return caseListDependeciesAttribute((ArrayType) attributeIfc.getOpenType()); } else if (attributeIfc instanceof TOAttribute) { - return caseTOAttribute((TOAttribute) attributeIfc); + return caseTOAttribute(((TOAttribute) attributeIfc).getOpenType()); + } + + throw getIllegalArgumentException(attributeIfc); + } + + protected T caseJavaBinaryAttribute(OpenType openType) { + return caseJavaAttribute(openType); + } + + private IllegalArgumentException getIllegalArgumentException(AttributeIfc attributeIfc) { + return new IllegalArgumentException("Unknown attribute type " + attributeIfc.getClass() + ", " + attributeIfc + + " with open type:" + attributeIfc.getOpenType()); + } + + public final T caseJavaAttribute(OpenType openType) { + if (openType instanceof SimpleType) { + return caseJavaSimpleAttribute((SimpleType) openType); + } else if (openType instanceof ArrayType) { + return caseJavaArrayAttribute((ArrayType) openType); + } else if (openType instanceof CompositeType) { + return caseJavaCompositeAttribute((CompositeType) openType); } - throw new IllegalArgumentException("Unknown attribute type " + attributeIfc.getClass() + ", " + attributeIfc); + throw new UnknownOpenTypeException("Unknown attribute open type " + openType); } - protected abstract T caseJavaAttribute(JavaAttribute attributeIfc); + protected abstract T caseJavaSimpleAttribute(SimpleType openType); + + protected abstract T caseJavaArrayAttribute(ArrayType openType); + + protected abstract T caseJavaCompositeAttribute(CompositeType openType); - protected abstract T caseDependencyAttribute(DependencyAttribute attributeIfc); + protected abstract T caseDependencyAttribute(SimpleType attributeIfc); - protected abstract T caseTOAttribute(TOAttribute attributeIfc); + protected abstract T caseTOAttribute(CompositeType openType); - protected abstract T caseListAttribute(ListAttribute attributeIfc); + protected abstract T caseListAttribute(ArrayType openType); + + protected abstract T caseListDependeciesAttribute(ArrayType openType); + + private static class UnknownOpenTypeException extends RuntimeException { + public UnknownOpenTypeException(String message) { + super(message); + } + } }