Added support for named augmentations 10/910/1
authorTony Tkacik <ttkacik@cisco.com>
Mon, 19 Aug 2013 16:59:58 +0000 (18:59 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 19 Aug 2013 16:59:58 +0000 (18:59 +0200)
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
yang/yang-ext/src/main/yang/yang-ext.yang

index f20e01dc989f41266e3c1e228a4cf3b2e3691864..ea3b472710fbeb84b4783396ee0e73809d274b56 100644 (file)
@@ -15,6 +15,8 @@ import static org.opendaylight.yangtools.binding.generator.util.BindingGenerator
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;\r
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;\r
 \r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.Comparator;\r
@@ -66,6 +68,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
 import org.opendaylight.yangtools.yang.model.api.UsesNode;\r
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;\r
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;\r
@@ -109,6 +112,10 @@ public final class BindingGeneratorImpl implements BindingGenerator {
     /**\r
      * Only parent constructor is invoked.\r
      */\r
+    \r
+    private final static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";\r
+    private final static String AUGMENT_IDENTIFIER_NAME = "augment-identifier";\r
+    \r
     public BindingGeneratorImpl() {\r
         super();\r
     }\r
@@ -1000,8 +1007,9 @@ public final class BindingGeneratorImpl implements BindingGenerator {
             augmentBuilders = new HashMap<>();\r
             genTypeBuilders.put(augmentPackageName, augmentBuilders);\r
         }\r
-\r
-        final String augTypeName = augGenTypeName(augmentBuilders, targetTypeName);\r
+        final String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes());\r
+        \r
+        final String augTypeName =  augIdentifier != null ? parseToClassName(augIdentifier): augGenTypeName(augmentBuilders, targetTypeName);\r
         final Type targetTypeRef = new ReferencedTypeImpl(targetPackageName, targetTypeName);\r
         final Set<DataSchemaNode> augChildNodes = augSchema.getChildNodes();\r
 \r
@@ -1016,6 +1024,18 @@ public final class BindingGeneratorImpl implements BindingGenerator {
         return augTypeBuilder;\r
     }\r
 \r
+    private String getAugmentIdentifier(List<UnknownSchemaNode> unknownSchemaNodes) {\r
+        String ret = null;\r
+        for (UnknownSchemaNode unknownSchemaNode : unknownSchemaNodes) {\r
+            QName nodeType = unknownSchemaNode.getNodeType();\r
+            if(AUGMENT_IDENTIFIER_NAME.equals(nodeType.getLocalName()) &&\r
+                    YANG_EXT_NAMESPACE.equals(nodeType.getNamespace().toString())) {\r
+                return unknownSchemaNode.getNodeParameter();\r
+            }\r
+        }\r
+        return ret;\r
+    }\r
+\r
     /**\r
      * Convert a container, list and choice subnodes (and recursivelly their\r
      * subnodes) of augment to generated types\r
index 22aa48adbad1c30543b6293836cf625e82514d3c..11912966a1f07fd698448376707b3e79e33891e1 100644 (file)
@@ -1,60 +1,60 @@
-module yang-ext {
-    yang-version 1;
-    namespace "urn:opendaylight:params:ns:yang:extension:yang-ext";
-    prefix "ext";
-    
-    contact "Anton Tkacik <ttkacik@cisco.com>";
-
-    revision "2013-07-09" {
-        description "";
-    }
-
-    // Augmentation name
-
-    extension "augment-identifier" {
-        description 
-           "YANG language extension which assigns an identifier to 
-            augmentation. Augment identifier is used to identify
-            specific augment statement by name. 
-
-            The identifier syntax is defined formally defined by the rule
-            'identifier' in Section 12 of RFC 6020.
-
-            All augment identifiers defined in a namespace MUST be unique.
-            The namespace of augment identifiers is shared by module and
-            its submodules. 
-            ";
-            /*
-                Discussion:
-                This extension allows for ease of development / debug
-                of YANG modules and it is suitable for code generation,
-                where each augment statement is nicely identified by
-                unique name instead of combination of augment target
-                and when condition. 
-            */
-        argument "identifier";
-    }
-
-
-    // Context-aware RPCs
-
-    grouping rpc-context-ref {
-        description 
-           "A reference to RPC context.";
-        leaf context-instance {
-            type instance-identifier;
-            description "Pointer to the context. ";
-        }
-    }
-
-    extension "rpc-context-instance" {
-        description
-           "YANG language extension which defines enclosing (parent) 
-            schema node as referencable context for RPCs.
-
-            The argument is identity which is used to identify RPC context
-            type.";
-
-        argument "context-type";
-    }
+module yang-ext {\r
+    yang-version 1;\r
+    namespace "urn:opendaylight:yang:extension:yang-ext";\r
+    prefix "ext";\r
+    \r
+    contact "Anton Tkacik <ttkacik@cisco.com>";\r
+\r
+    revision "2013-07-09" {\r
+        description "";\r
+    }\r
+\r
+    // Augmentation name\r
+\r
+    extension "augment-identifier" {\r
+        description \r
+           "YANG language extension which assigns an identifier to \r
+            augmentation. Augment identifier is used to identify\r
+            specific augment statement by name. \r
+\r
+            The identifier syntax is defined formally defined by the rule\r
+            'identifier' in Section 12 of RFC 6020.\r
+\r
+            All augment identifiers defined in a namespace MUST be unique.\r
+            The namespace of augment identifiers is shared by module and\r
+            its submodules. \r
+            ";\r
+            /*\r
+                Discussion:\r
+                This extension allows for ease of development / debug\r
+                of YANG modules and it is suitable for code generation,\r
+                where each augment statement is nicely identified by\r
+                unique name instead of combination of augment target\r
+                and when condition. \r
+            */\r
+        argument "identifier";\r
+    }\r
+\r
+\r
+    // Context-aware RPCs\r
+\r
+    grouping rpc-context-ref {\r
+        description \r
+           "A reference to RPC context.";\r
+        leaf context-instance {\r
+            type instance-identifier;\r
+            description "Pointer to the context. ";\r
+        }\r
+    }\r
+\r
+    extension "rpc-context-instance" {\r
+        description\r
+           "YANG language extension which defines enclosing (parent) \r
+            schema node as referencable context for RPCs.\r
+\r
+            The argument is identity which is used to identify RPC context\r
+            type.";\r
+\r
+        argument "context-type";\r
+    }\r
 }
\ No newline at end of file