Merge "Bug 1029: Remove dead code: sal-dom-it"
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / RuntimeBeanEntry.java
index 22a2b13b4a3c667682cbf5bc2049b225fd5ca480..c941d1504ddae409a9fdfa0c14ec4da957d1038e 100644 (file)
@@ -7,19 +7,44 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
 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.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+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.VoidAttribute;
 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;
-import org.opendaylight.yangtools.yang.model.api.*;
-
-import java.util.*;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkState;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
 /**
  * Holds information about runtime bean to be generated. There are two kinds of
@@ -40,8 +65,8 @@ public class RuntimeBeanEntry {
     private final Set<Rpc> rpcs;
 
     @VisibleForTesting
-    public RuntimeBeanEntry(String packageName,
-            DataSchemaNode nodeForReporting, String yangName,
+    RuntimeBeanEntry(String packageName,
+            DataNodeContainer nodeForReporting, String yangName,
             String javaNamePrefix, boolean isRoot,
             Optional<String> keyYangName, List<AttributeIfc> attributes,
             List<RuntimeBeanEntry> children, Set<Rpc> rpcs) {
@@ -85,7 +110,7 @@ public class RuntimeBeanEntry {
      *         not contain special configuration for it.
      */
     public static Map<String, RuntimeBeanEntry> extractClassNameToRuntimeBeanMap(
-            String packageName, ChoiceCaseNode container,
+            String packageName, DataNodeContainer container,
             String moduleYangName, TypeProviderWrapper typeProviderWrapper,
             String javaNamePrefix, Module currentModule) {
 
@@ -136,41 +161,42 @@ public class RuntimeBeanEntry {
 
         for (RpcDefinition rpc : currentModule.getRpcs()) {
             ContainerSchemaNode input = rpc.getInput();
-            for (UsesNode uses : input.getUses()) {
-
-                if (uses.getGroupingPath().getPath().size() != 1)
-                    continue;
-
-                // check grouping path
-                QName qname = uses.getGroupingPath().getPath().get(0);
-                if (false == qname
-                        .equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME))
-                    continue;
-
-                for (SchemaNode refinedNode : uses.getRefines().values()) {
-
-                    for (UnknownSchemaNode unknownSchemaNode : refinedNode
-                            .getUnknownSchemaNodes()) {
-                        if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME
-                                .equals(unknownSchemaNode.getNodeType())) {
-                            String localIdentityName = unknownSchemaNode
-                                    .getNodeParameter();
-                            QName identityQName = new QName(
-                                    currentModule.getNamespace(),
-                                    currentModule.getRevision(),
-                                    localIdentityName);
-                            Set<RpcDefinition> rpcDefinitions = result
-                                    .get(identityQName);
-                            if (rpcDefinitions == null) {
-                                throw new IllegalArgumentException(
-                                        "Identity referenced by rpc not found. Identity:"
-                                                + localIdentityName + " , rpc "
-                                                + rpc);
+            if (input != null) {
+                for (UsesNode uses : input.getUses()) {
+
+                    if (uses.getGroupingPath().getPath().size() != 1)
+                        continue;
+
+                    // check grouping path
+                    QName qname = uses.getGroupingPath().getPath().get(0);
+                    if (false == qname
+                            .equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME))
+                        continue;
+
+                    for (SchemaNode refinedNode : uses.getRefines().values()) {
+
+                        for (UnknownSchemaNode unknownSchemaNode : refinedNode
+                                .getUnknownSchemaNodes()) {
+                            if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME
+                                    .equals(unknownSchemaNode.getNodeType())) {
+                                String localIdentityName = unknownSchemaNode
+                                        .getNodeParameter();
+                                QName identityQName = new QName(
+                                        currentModule.getNamespace(),
+                                        currentModule.getRevision(),
+                                        localIdentityName);
+                                Set<RpcDefinition> rpcDefinitions = result
+                                        .get(identityQName);
+                                if (rpcDefinitions == null) {
+                                    throw new IllegalArgumentException(
+                                            "Identity referenced by rpc not found. Identity:"
+                                                    + localIdentityName + " , rpc "
+                                                    + rpc);
+                                }
+                                rpcDefinitions.add(rpc);
                             }
-                            rpcDefinitions.add(rpc);
                         }
                     }
-
                 }
             }
         }
@@ -201,7 +227,7 @@ public class RuntimeBeanEntry {
                 ContainerSchemaNode container = (ContainerSchemaNode) child;
                 // this can be either TO or hierarchical RB
                 TOAttribute toAttribute = TOAttribute.create(container,
-                        typeProviderWrapper);
+                        typeProviderWrapper, packageName);
                 attributes.add(toAttribute);
             } else if (child instanceof ListSchemaNode) {
                 if (isInnerStateBean(child)) {
@@ -212,7 +238,7 @@ public class RuntimeBeanEntry {
                     runtimeBeanEntries.add(hierarchicalChild);
                 } else /* ordinary list attribute */{
                     ListAttribute listAttribute = ListAttribute.create(
-                            (ListSchemaNode) child, typeProviderWrapper);
+                            (ListSchemaNode) child, typeProviderWrapper, packageName);
                     attributes.add(listAttribute);
                 }
 
@@ -244,7 +270,7 @@ public class RuntimeBeanEntry {
                 }
                 // convert RpcDefinition to Rpc
                 for (RpcDefinition rpcDefinition : rpcDefinitions) {
-                    String name = ModuleMXBeanEntry
+                    String name = TypeProviderWrapper
                             .findJavaParameter(rpcDefinition);
                     AttributeIfc returnType;
                     if (rpcDefinition.getOutput() == null
@@ -253,7 +279,7 @@ public class RuntimeBeanEntry {
                     } else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
                         DataSchemaNode returnDSN = rpcDefinition.getOutput()
                                 .getChildNodes().iterator().next();
-                        returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper);
+                        returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
 
                     } else {
                         throw new IllegalArgumentException(
@@ -284,16 +310,17 @@ public class RuntimeBeanEntry {
                 attributes, rpcs);
     }
 
-    private static AttributeIfc getReturnTypeAttribute(DataSchemaNode child, TypeProviderWrapper typeProviderWrapper) {
+    private static AttributeIfc getReturnTypeAttribute(DataSchemaNode child, TypeProviderWrapper typeProviderWrapper,
+                                                       String packageName) {
         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);
+            TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
             return toAttribute;
         } else if (child instanceof ListSchemaNode) {
-            return ListAttribute.create((ListSchemaNode) child, typeProviderWrapper);
+            return ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
         } else if (child instanceof LeafListSchemaNode) {
             return ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
         } else {
@@ -347,7 +374,7 @@ public class RuntimeBeanEntry {
                     "More than one key is not supported in " + listSchemaNode);
         }
 
-        String javaNamePrefix = ModuleMXBeanEntry
+        String javaNamePrefix = TypeProviderWrapper
                 .findJavaNamePrefix(listSchemaNode);
 
         RuntimeBeanEntry rbFromAttributes = new RuntimeBeanEntry(packageName,
@@ -361,7 +388,7 @@ public class RuntimeBeanEntry {
     }
 
     private static RuntimeBeanEntry createRoot(String packageName,
-            DataSchemaNode nodeForReporting, String attributeYangName,
+            DataNodeContainer nodeForReporting, String attributeYangName,
             List<AttributeIfc> attributes, String javaNamePrefix,
             List<RuntimeBeanEntry> children, Set<Rpc> rpcs) {
         return new RuntimeBeanEntry(packageName, nodeForReporting,