Binding generator v2 - namespace fix #4
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / RpcActionGenHelper.java
index c9b98f7f1a91768106306c7db7abb39897331a01..0d3ad6979c96260475e12511ab5135d7856aee39 100644 (file)
@@ -16,6 +16,7 @@ import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil
 import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.addRawInterfaceDefinition;
 import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.moduleTypeBuilder;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.ACTION;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INPUT;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INSTANCE_IDENTIFIER;
@@ -109,7 +110,8 @@ final class RpcActionGenHelper {
                 final Set<ActionDefinition> actions = ((ActionNodeContainer) potential).getActions();
                 for (ActionDefinition action: actions) {
                     genCtx.get(module).addTopLevelNodeType(resolveOperation(potential, action, module,
-                            schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+                            schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+                            BindingNamespaceType.Data));
                 }
             }
         }
@@ -167,17 +169,20 @@ final class RpcActionGenHelper {
             //routedRPC?
             if (isAction) {
                 genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
-                        verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+                        verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+                        BindingNamespaceType.Data));
             } else {
                 //global RPC only
                 genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
-                        verboseClassComments, genTypeBuilders, genCtx, typeProvider, false));
+                        verboseClassComments, genTypeBuilders, genCtx, typeProvider, false,
+                        BindingNamespaceType.Data));
 
             }
         }
         return genCtx;
     }
 
+    //TODO: This method should be reusable for convertion of action that is in grouping.
     /**
      * Converts RPC, Action or routed RPC into generated type
      * @return generated type
@@ -185,7 +190,7 @@ final class RpcActionGenHelper {
     private static GeneratedTypeBuilder resolveOperation(final DataSchemaNode parent, final OperationDefinition operation,
             final Module module, final SchemaContext schemaContext, final boolean verboseClassComments,
             Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx,
-            TypeProvider typeProvider, final boolean isAction) {
+            TypeProvider typeProvider, final boolean isAction, final BindingNamespaceType namespaceType) {
 
         //operation name
         final String operationName = operation.getQName().getLocalName();
@@ -202,14 +207,15 @@ final class RpcActionGenHelper {
         final String basePackageName = interfaceBuilder.getPackageName();
 
         interfaceBuilder.setDescription(createDescription(operation, interfaceBuilder.getFullyQualifiedName(),
-                schemaContext, verboseClassComments));
+                schemaContext, verboseClassComments, namespaceType));
         final String operationComment = encodeAngleBrackets(operation.getDescription());
         final MethodSignatureBuilder operationMethod = interfaceBuilder.addMethod("invoke");
 
         //input
         final ContainerSchemaNode input = operation.getInput();
         final GeneratedTypeBuilder inType = resolveOperationNode(interfaceBuilder, module, operation.getInput(),
-                basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, true);
+                basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+                genCtx, true, namespaceType);
         annotateDeprecatedIfNecessary(operation.getStatus(), inType);
         inType.setParentTypeForBuilder(interfaceBuilder);
         genCtx.get(module).addChildNodeType(input, inType);
@@ -217,7 +223,8 @@ final class RpcActionGenHelper {
         //output
         final ContainerSchemaNode output = operation.getOutput();
         final GeneratedTypeBuilder outType = resolveOperationNode(interfaceBuilder, module, operation.getOutput(),
-                basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, false);
+                basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+                genCtx, false, namespaceType);
         annotateDeprecatedIfNecessary(operation.getStatus(), outType);
         outType.setParentTypeForBuilder(interfaceBuilder);
         genCtx.get(module).addChildNodeType(output, outType);
@@ -249,7 +256,7 @@ final class RpcActionGenHelper {
                 //Action
                 GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, parentType, parentType,
                         ((ContainerSchemaNode) parent).getChildNodes(), genCtx, schemaContext, verboseClassComments,
-                        genTypeBuilders, typeProvider, BindingNamespaceType.Data);
+                        genTypeBuilders, typeProvider, namespaceType);
                 operationMethod.addParameter(parameterizedTypeFor(INSTANCE_IDENTIFIER, parentType), "ii");
                 interfaceBuilder.addImplementsType(parameterizedTypeFor(ACTION, parentType, inType, outType));
             }
@@ -270,10 +277,10 @@ final class RpcActionGenHelper {
     private static GeneratedTypeBuilder resolveOperationNode(GeneratedTypeBuilder parent, final Module module, final
             ContainerSchemaNode operationNode, final String basePackageName, final SchemaContext schemaContext, final String
             operationName, final boolean verboseClassComments, TypeProvider typeProvider, Map<String, Map<String,
-            GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput) {
-
+            GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput,
+            final BindingNamespaceType namespaceType) {
         final GeneratedTypeBuilder nodeType = addRawInterfaceDefinition(basePackageName, operationNode, schemaContext,
-                operationName, "", verboseClassComments, genTypeBuilders);
+                operationName, "", verboseClassComments, genTypeBuilders, namespaceType);
         addImplementedInterfaceFromUses(operationNode, nodeType, genCtx);
         nodeType.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
                 (BindingTypes.ITEM, parent)));
@@ -285,7 +292,7 @@ final class RpcActionGenHelper {
         nodeType.addImplementsType(parameterizedTypeFor(INSTANTIABLE, nodeType));
         nodeType.addImplementsType(augmentable(nodeType));
         GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, nodeType, nodeType, operationNode.getChildNodes(), genCtx,
-                schemaContext, verboseClassComments, genTypeBuilders, typeProvider, BindingNamespaceType.Data);
+                schemaContext, verboseClassComments, genTypeBuilders, typeProvider, namespaceType);
 
         final MethodSignatureBuilder nodeMethod = nodeType.addMethod("implementedInterface");
         nodeMethod.setReturnType(parameterizedTypeFor(CLASS, nodeType));