BUG 4930 & BUG 4017: Allow multiple refine statements in MXBean generation 30/32430/3
authorTomas Cere <tcere@cisco.com>
Tue, 12 Jan 2016 14:30:46 +0000 (15:30 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 14 Jan 2016 12:45:20 +0000 (12:45 +0000)
Stops enforcing a single refine statement when generating MXBean's.

Change-Id: I2f07fc23b355b1871170a00baf52db34f5e6eb66
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryBuilder.java
opendaylight/config/yang-jmx-generator/src/test/resources/config-jmx-it-impl.yang

index 04d3741..955e9b5 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static java.lang.String.format;
 import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
@@ -58,6 +59,8 @@ import org.slf4j.LoggerFactory;
 
 final class ModuleMXBeanEntryBuilder {
 
+    private static final String TYPE = "type";
+
     private Module currentModule;
     private Map<QName, ServiceInterfaceEntry> qNamesToSIEs;
     private SchemaContext schemaContext;
@@ -463,26 +466,31 @@ final class ModuleMXBeanEntryBuilder {
         if (isDependencyContainer(dataNodeContainer)) {
             // reference
             UsesNode usesNode = dataNodeContainer.getUses().iterator().next();
-            checkState(usesNode.getRefines().size() == 1, "Unexpected 'refine' child node size of " + dataNodeContainer);
-            LeafSchemaNode refine = (LeafSchemaNode) usesNode.getRefines().values().iterator().next();
-            checkState(refine.getUnknownSchemaNodes().size() == 1, "Unexpected unknown schema node size of " + refine);
-            UnknownSchemaNode requiredIdentity = refine.getUnknownSchemaNodes().iterator().next();
-            checkState(ConfigConstants.REQUIRED_IDENTITY_EXTENSION_QNAME.equals(requiredIdentity.getNodeType()),
-                    "Unexpected language extension " + requiredIdentity);
-            String prefixAndIdentityLocalName = requiredIdentity.getNodeParameter();
-            // import should point to a module
-            ServiceInterfaceEntry serviceInterfaceEntry = findSIE(prefixAndIdentityLocalName, currentModule,
-                    qNamesToSIEs, schemaContext);
-            boolean mandatory = refine.getConstraints().isMandatory();
-            AbstractDependencyAttribute reference;
-            if (dataNodeContainer instanceof ContainerSchemaNode) {
-                reference = new DependencyAttribute(attrNode, serviceInterfaceEntry, mandatory,
-                        attrNode.getDescription());
-            } else {
-                reference = new ListDependenciesAttribute(attrNode, serviceInterfaceEntry, mandatory,
-                        attrNode.getDescription());
+            for (SchemaNode refineNode : usesNode.getRefines().values()) {
+                // this will ignore name nodes, since they are not needed here
+                if (TYPE.equals(refineNode.getQName().getLocalName())){
+                    checkState(refineNode.getUnknownSchemaNodes().size() == 1, "Unexpected unknown schema node size of " + refineNode);
+                    UnknownSchemaNode requiredIdentity = refineNode.getUnknownSchemaNodes().iterator().next();
+                    checkState(ConfigConstants.REQUIRED_IDENTITY_EXTENSION_QNAME.equals(requiredIdentity.getNodeType()),
+                            "Unexpected language extension " + requiredIdentity);
+                    String prefixAndIdentityLocalName = requiredIdentity.getNodeParameter();
+                    // import should point to a module
+                    ServiceInterfaceEntry serviceInterfaceEntry = findSIE(prefixAndIdentityLocalName, currentModule,
+                            qNamesToSIEs, schemaContext);
+                    LeafSchemaNode refine = (LeafSchemaNode) usesNode.getRefines().values().iterator().next();
+
+                    boolean mandatory = refine.getConstraints().isMandatory();
+                    AbstractDependencyAttribute reference;
+                    if (dataNodeContainer instanceof ContainerSchemaNode) {
+                        reference = new DependencyAttribute(attrNode, serviceInterfaceEntry, mandatory,
+                                attrNode.getDescription());
+                    } else {
+                        reference = new ListDependenciesAttribute(attrNode, serviceInterfaceEntry, mandatory,
+                                attrNode.getDescription());
+                    }
+                    return Optional.of(reference);
+                }
             }
-            return Optional.of(reference);
         }
         return Optional.absent();
     }
index 0cd0d15..f00623e 100644 (file)
@@ -185,6 +185,9 @@ module config-jmx-it-impl {
                         mandatory false;
                         config:required-identity th:threadfactory;
                     }
+                    refine name {
+                        mandatory false;
+                    }
                 }
             }
         }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.