X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2FRuntimeBeanEntry.java;h=22a2b13b4a3c667682cbf5bc2049b225fd5ca480;hb=refs%2Fchanges%2F14%2F2214%2F4;hp=d07e20bebba013c82e32ab0ba1b3c988550f0ecb;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntry.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntry.java index d07e20bebb..22a2b13b4a 100644 --- a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntry.java +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntry.java @@ -10,10 +10,7 @@ package org.opendaylight.controller.config.yangjmxgenerator; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.collect.Lists; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.*; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.NameConflictException; import org.opendaylight.yangtools.yang.common.QName; @@ -219,9 +216,13 @@ public class RuntimeBeanEntry { attributes.add(listAttribute); } + } else if (child instanceof LeafListSchemaNode) { + ListAttribute listAttribute = ListAttribute.create( + (LeafListSchemaNode) child, typeProviderWrapper); + attributes.add(listAttribute); } else { - throw new IllegalStateException("Unknown running-data node " - + child + " , " + "" + "expected leaf or container"); + throw new IllegalStateException("Unexpected running-data node " + + child); } } Set rpcs = new HashSet<>(); @@ -245,29 +246,15 @@ public class RuntimeBeanEntry { for (RpcDefinition rpcDefinition : rpcDefinitions) { String name = ModuleMXBeanEntry .findJavaParameter(rpcDefinition); - String returnType; + AttributeIfc returnType; if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().size() == 0) { - returnType = "void"; + returnType = VoidAttribute.getInstance(); } else if (rpcDefinition.getOutput().getChildNodes().size() == 1) { DataSchemaNode returnDSN = rpcDefinition.getOutput() .getChildNodes().iterator().next(); - checkArgument( - returnDSN instanceof LeafSchemaNode, - "Unexpected type of rpc return type. " - + "Currently only leafs and empty output nodes are supported, got " - + returnDSN); - LeafSchemaNode returnLeaf = (LeafSchemaNode) returnDSN; - // We currently expect leaf defined in output element in yang to be named result - // FIXME: value of result is fully qualified name - should be extended to accept TOs - String localName = returnLeaf.getQName().getLocalName(); - checkArgument( - localName.equals("result"), - "Unexpected name of leaf in output element, expected leaf named result, was %s at %s", - localName, currentModule.getName()); - - returnType = typeProviderWrapper.getType(returnLeaf) - .getFullyQualifiedName(); + returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper); + } else { throw new IllegalArgumentException( "More than one child node in rpc output is not supported. " @@ -297,6 +284,23 @@ public class RuntimeBeanEntry { attributes, rpcs); } + private static AttributeIfc getReturnTypeAttribute(DataSchemaNode child, TypeProviderWrapper typeProviderWrapper) { + if (child instanceof LeafSchemaNode) { + LeafSchemaNode leaf = (LeafSchemaNode) child; + return new JavaAttribute(leaf, typeProviderWrapper); + } else if (child instanceof ContainerSchemaNode) { + ContainerSchemaNode container = (ContainerSchemaNode) child; + TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper); + return toAttribute; + } else if (child instanceof ListSchemaNode) { + return ListAttribute.create((ListSchemaNode) child, typeProviderWrapper); + } else if (child instanceof LeafListSchemaNode) { + return ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper); + } else { + throw new IllegalStateException("Unknown output data node " + child + " for rpc"); + } + } + private static Collection sortAttributes(Set childNodes) { final TreeSet dataSchemaNodes = new TreeSet<>(new Comparator() { @Override @@ -438,10 +442,10 @@ public class RuntimeBeanEntry { public static class Rpc { private final String name; private final List parameters; - private final String returnType; + private final AttributeIfc returnType; private final String yangName; - Rpc(String returnType, String name, String yangName, + Rpc(AttributeIfc returnType, String name, String yangName, List parameters) { this.returnType = returnType; this.name = name; @@ -461,7 +465,7 @@ public class RuntimeBeanEntry { return parameters; } - public String getReturnType() { + public AttributeIfc getReturnType() { return returnType; } }