Fixed resolution problems in Code Generator 85/1085/1
authorTony Tkacik <ttkacik@cisco.com>
Tue, 3 Sep 2013 22:05:38 +0000 (15:05 -0700)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 3 Sep 2013 22:05:55 +0000 (15:05 -0700)
Added sorting of modules by dependencies for code generator
Fixed search for parent modules

Change-Id: I9017e03937050487476eed73dafc72376b8bc4e5
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BitAndUnionTOEnclosingTest.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/ChoiceCaseGenTypesTest.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GenEnumResolvingTest.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/UsesTest.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java

index 5b3bbb28e25fb971575aeddee9e52f593a291d20..0e9e944eec79041e96180caa4af8f3bd23649118 100644 (file)
@@ -62,7 +62,7 @@ import static extension org.opendaylight.yangtools.binding.generator.util.Types.
 import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*;
 import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*;
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*;
-
+import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort\r
 \r
 public class BindingGeneratorImpl implements BindingGenerator {\r
 \r
@@ -134,27 +134,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         schemaContext = context;\r
         typeProvider = new TypeProviderImpl(context);\r
         val Set<Module> modules = context.modules;\r
-        genTypeBuilders = new HashMap();\r
-        for (module : modules) {\r
-\r
-            generatedTypes.addAll(allGroupingsToGenTypes(module));\r
-\r
-            if (false == module.childNodes.isEmpty()) {\r
-                generatedTypes.add(moduleToDataType(module));\r
-            }\r
-            generatedTypes.addAll(allTypeDefinitionsToGenTypes(module));\r
-            generatedTypes.addAll(allContainersToGenTypes(module));\r
-            generatedTypes.addAll(allListsToGenTypes(module));\r
-            generatedTypes.addAll(allChoicesToGenTypes(module));\r
-            generatedTypes.addAll(allRPCMethodsToGenType(module));\r
-            generatedTypes.addAll(allNotificationsToGenType(module));\r
-            generatedTypes.addAll(allIdentitiesToGenTypes(module, context));\r
-        }\r
-        for (module : modules) {\r
-            generatedTypes.addAll(allAugmentsToGenTypes(module));\r
-            \r
-        }\r
-        return generatedTypes;\r
+        return generateTypes(context,modules);
     }\r
 \r
     /**\r
@@ -190,20 +170,20 @@ public class BindingGeneratorImpl implements BindingGenerator {
         checkState(context.modules !== null,"Schema Context does not contain defined modules.");\r
         checkArgument(modules !== null,"Set of Modules cannot be NULL.");\r
 \r
-        val List<Type> filteredGenTypes = new ArrayList();\r
+        val List<Type> filteredGenTypes = new ArrayList();
+        \r
         schemaContext = context;\r
         typeProvider = new TypeProviderImpl(context);\r
-        val Set<Module> contextModules = context.modules;\r
+        val contextModules = ModuleDependencySort.sort(context.modules);\r
         genTypeBuilders = new HashMap();\r
         \r
         for (contextModule : contextModules) {\r
             val List<Type> generatedTypes = new ArrayList();\r
-\r
+            generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));\r
             generatedTypes.addAll(allGroupingsToGenTypes(contextModule));\r
             if (false == contextModule.childNodes.isEmpty()) {\r
                 generatedTypes.add(moduleToDataType(contextModule));\r
             }\r
-            generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));\r
             generatedTypes.addAll(allContainersToGenTypes(contextModule));\r
             generatedTypes.addAll(allListsToGenTypes(contextModule));\r
             generatedTypes.addAll(allChoicesToGenTypes(contextModule));\r
@@ -246,7 +226,6 @@ public class BindingGeneratorImpl implements BindingGenerator {
         checkArgument(module.name !== null,"Module name cannot be NULL.");\r
         val Set<TypeDefinition<?>> typeDefinitions = module.typeDefinitions;\r
         checkState(typeDefinitions !== null,'''Type Definitions for module «module.name» cannot be NULL.''');\r
-\r
         \r
         val List<Type> generatedTypes = new ArrayList();\r
         for ( TypeDefinition<?> typedef : typeDefinitions) {\r
@@ -881,18 +860,18 @@ public class BindingGeneratorImpl implements BindingGenerator {
         // and DataObject interface!!!\r
         val targetPath = augSchema.targetPath;\r
         val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);\r
-        var targetType = yangToJavaMapping.get(targetSchemaNode.path);\r
-        if(targetType == null) {\r
-            // FIXME: augmentation should be added as last, all types should already be generated\r
-            // and have assigned Java Types,\r
-            val targetModule = findParentModule(schemaContext, targetSchemaNode);\r
-            val targetBasePackage = moduleNamespaceToPackageName(targetModule);\r
-            val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());\r
-            val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();\r
-            val typeName = parseToClassName(targetSchemaNodeName);\r
-            targetType = new ReferencedTypeImpl(typePackage,typeName);\r
-        }\r
         if (targetSchemaNode !== null) {\r
+            var targetType = yangToJavaMapping.get(targetSchemaNode.path);
+            if(targetType == null) {
+                // FIXME: augmentation should be added as last, all types should already be generated
+                // and have assigned Java Types,
+                val targetModule = findParentModule(schemaContext, targetSchemaNode);
+                val targetBasePackage = moduleNamespaceToPackageName(targetModule);
+                val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());
+                val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();
+                val typeName = parseToClassName(targetSchemaNodeName);
+                targetType = new ReferencedTypeImpl(typePackage,typeName);
+            }
             val augChildNodes = augSchema.childNodes;\r
             if (!(targetSchemaNode instanceof ChoiceNode)) {\r
                 val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName,\r
index 50b637b538520c81db9c0312adac4948f42c0a3e..8bd0c51e64ecf001b81e23efffbdf05dfea0f0ef 100644 (file)
@@ -255,7 +255,7 @@ public final class TypeProviderImpl implements TypeProvider {
      */
     private Type provideTypeForIdentityref(IdentityrefTypeDefinition idref) {
         QName baseIdQName = idref.getIdentity();
-        Module module = schemaContext.findModuleByNamespace(baseIdQName.getNamespace());
+        Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),baseIdQName.getRevision());
         IdentitySchemaNode identity = null;
         for (IdentitySchemaNode id : module.getIdentities()) {
             if (id.getQName().equals(baseIdQName)) {
index c815934efd95e965b904f30c557d440b27e489c4..83eb4155c9283f50cf96c410c17a1f1ec50a9db3 100644 (file)
@@ -90,7 +90,7 @@ public class BitAndUnionTOEnclosingTest {
         assertNotNull("Lf TO wasn't found.", lfLeaf);
         assertEquals("Lf TO has incorrect number of occurences.", 1, lfLeafCounter);
         assertEquals("Lf has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
                 lfLeaf.getPackageName());
 
         assertEquals("Lf generated TO has incorrect number of properties", 2, lfLeaf.getProperties().size());
@@ -101,7 +101,7 @@ public class BitAndUnionTOEnclosingTest {
         assertNotNull("Lf1 TO wasn't found.", lf1Leaf);
         assertEquals("Lf1 TO has incorrect number of occurences.", 1, lf1LeafCounter);
         assertEquals("Lf1 has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
                 lf1Leaf.getPackageName());
 
         assertEquals("Lf generated TO has incorrect number of properties", 4, lf1Leaf.getProperties().size());
@@ -114,7 +114,7 @@ public class BitAndUnionTOEnclosingTest {
         assertNotNull("Lf2 TO wasn't found.", lf2Leaf);
         assertEquals("Lf2 TO has incorrect number of occurences.", 1, lf2LeafCounter);
         assertEquals("Lf2 has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
                 lf2Leaf.getPackageName());
 
         assertEquals("Lf generated TO has incorrect number of properties", 2, lf2Leaf.getProperties().size());
@@ -144,7 +144,7 @@ public class BitAndUnionTOEnclosingTest {
         assertNotNull("TypeUnion TO wasn't found.", typeUnionTypedef);
         assertEquals("TypeUnion TO has incorrect number of occurences.", 1, typeUnionTypedefCounter);
         assertEquals("TypeUnion has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnionTypedef.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnionTypedef.getPackageName());
 
         assertEquals("TypeUnion generated TO has incorrect number of properties", 2, typeUnionTypedef.getProperties()
                 .size());
@@ -174,7 +174,7 @@ public class BitAndUnionTOEnclosingTest {
         assertEquals("TypeUnion1 TO has incorrect number of occurences.", 1, typeUnion1Counter);
 
         assertEquals("TypeUnion1 has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnion1.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion1.getPackageName());
 
         assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4, typeUnion1.getProperties().size());
        
@@ -187,7 +187,7 @@ public class BitAndUnionTOEnclosingTest {
         assertEquals("TypeUnion2 TO has incorrect number of occurences.", 1, typeUnion2Counter);
 
         assertEquals("TypeUnion2 has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626", typeUnion2.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion2.getPackageName());
 
         assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2, typeUnion2.getProperties().size());
         containsAttributes(typeUnion2, true, true, true, new NameTypePattern("string", "String"));
@@ -218,10 +218,10 @@ public class BitAndUnionTOEnclosingTest {
         assertNotNull("UnionLeaf TO wasn't found.", unionLeaf);
 
         assertEquals("BitLeaf has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
                 bitLeaf.getPackageName());
         assertEquals("UnionLeaf has incorrect package name.",
-                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev2013626.ParentContainer",
+                "org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
                 bitLeaf.getPackageName());
 
         List<GeneratedProperty> propertiesBitLeaf = bitLeaf.getProperties();
index 28d818f89e7d033fd0eb218a361e314abefbea76..3068f46fe6939d5403f14a22beaf86f00d97799b 100644 (file)
@@ -80,7 +80,7 @@ public class ChoiceCaseGenTypesTest {
         assertFalse("genTypes is empty", genTypes.isEmpty());
 
         // test for file choice-monitoring
-        String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev201371.netconf.state.datastores.datastore.locks";
+        String pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.choice.monitoring.rev130701.netconf.state.datastores.datastore.locks";
         GeneratedType genType = null;
 
         checkGeneratedType(genTypes, "LockType", pcgPref); // choice
@@ -126,7 +126,7 @@ public class ChoiceCaseGenTypesTest {
         // test for file augment-monitoring
         // augment
         // "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type"
-        pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev201371";
+        pcgPref = "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.augment.monitoring.rev130701";
         genType = null;
 
         genType = checkGeneratedType(genTypes, "AutonomousLock", pcgPref
index e9ed3a982f0b9ad682c9a7679778ee4a65a37078..b4e0b0484d97c582c28154aa3dfca95c8a333e07 100644 (file)
@@ -169,7 +169,7 @@ public class GenEnumResolvingTest {
         GeneratedType genInterface = null;\r
         for (final Type type : genTypes) {\r
             if (type instanceof GeneratedType) {\r
-                if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev201328.topology.interfaces")\r
+                if (type.getPackageName().equals("org.opendaylight.yang.gen.v1.urn.model._abstract.topology.rev130208.topology.interfaces")\r
                         && type.getName().equals("Interface")) {\r
                     genInterface = (GeneratedType) type;\r
                 }\r
@@ -198,13 +198,13 @@ public class GenEnumResolvingTest {
         assertTrue("Expected LinkUpDownTrapEnable of type ReferencedTypeImpl",\r
                 linkUpDownTrapEnable instanceof ReferencedTypeImpl);\r
         assertEquals(linkUpDownTrapEnable.getPackageName(),\r
-                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");\r
+                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface");\r
 \r
         assertNotNull("Expected Referenced Enum OperStatus, but was NULL!",\r
                 operStatus);\r
         assertTrue("Expected OperStatus of type ReferencedTypeImpl",\r
                 operStatus instanceof  ReferencedTypeImpl);\r
         assertEquals(operStatus.getPackageName(),\r
-                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev20121115.interfaces.Interface");\r
+                "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface");\r
     }\r
 }\r
index 0c57435d3ede3ca3f9fd885936737af8f0a8fdfe..ca67d8054be31079da30dce771ea002834f3b9c1 100644 (file)
@@ -71,17 +71,17 @@ public class UsesTest {
         assertNotNull("Generated type for grouping-U wasn't generated.", groupingU);
         assertEquals("GroupingU interface generated more than one time.", 1, groupingUCounter);
         assertEquals("GroupingU is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingU.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingU.getPackageName());
 
         assertNotNull("Generated type for grouping-V wasn't generated.", groupingV);
         assertEquals("GroupingV interface generated more than one time.", 1, groupingVCounter);
         assertEquals("GroupingV is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingV.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingV.getPackageName());
 
         assertNotNull("Generated type for grouping-X wasn't generated.", groupingX);
         assertEquals("GroupingX interface generated more than one time.", 1, groupingXCounter);
         assertEquals("GroupingX is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev2013718", groupingX.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.dependencies.rev130718", groupingX.getPackageName());
 
         containsInterface("GroupingV", groupingU);
         containsInterface("GroupingX", groupingU);
@@ -122,13 +122,13 @@ public class UsesTest {
         assertEquals("Case C interface generated more than one time.", 1, caseCCounter);
         assertEquals(
                 "Case C is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev2013718.container.with.choicetest.choice.test",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718.container.with.choicetest.choice.test",
                 caseC.getPackageName());
 
         assertNotNull("Generated type for grouping-case-test wasn't generated.", groupingCaseTest);
         assertEquals("GroupingCaseTest interface generated more than one time.", 1, groupingCaseTestCounter);
         assertEquals("GroupingCaseTest is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev2013718", groupingCaseTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses._case.rev130718", groupingCaseTest.getPackageName());
 
         containsInterface("GroupingCaseTest", caseC);
         assertTrue("Case C shouldn't contain any method.", caseC.getMethodDefinitions().isEmpty());
@@ -172,13 +172,13 @@ public class UsesTest {
         assertEquals("GroupingContainerTest interface - incorrect number of occurences", 1,
                 groupingContainerTestCounter);
         assertEquals("GroupingContainerTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718",
                 groupingContainerTest.getPackageName());
 
         assertNotNull("Generated type for container-test wasn't generated", containerTest);
         assertEquals("ContainerTest interface - incorrect number of occurences", 1, containerTestCount);
         assertEquals("ContainerTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev2013718", containerTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.container.rev130718", containerTest.getPackageName());
 
         containsInterface("GroupingContainerTest", containerTest);
 
@@ -225,13 +225,13 @@ public class UsesTest {
         assertNotNull("Generated type for grouping-grouping-test wasn't generated", groupingGroupingTest);
         assertEquals("GroupingGroupingTest interface - incorrect number of occurences", 1, groupingGroupingTestCounter);
         assertEquals("GroupingGroupingTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718",
                 groupingGroupingTest.getPackageName());
 
         assertNotNull("Generated type for grouping-test wasn't generated", groupingTest);
         assertEquals("GroupingTest interface - incorrect number of occurences", 1, groupingTestCount);
         assertEquals("GroupingTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev2013718", groupingTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.grouping.rev130718", groupingTest.getPackageName());
 
         containsInterface("GroupingGroupingTest", groupingTest);
 
@@ -287,24 +287,24 @@ public class UsesTest {
         assertNotNull("Generated type for grouping-list-test wasn't generated", groupingListTest);
         assertEquals("GroupingListTest interface - incorrect number of occurences", 1, groupingListTestCounter);
         assertEquals("GroupingListTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718", groupingListTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", groupingListTest.getPackageName());
 
         assertNotNull("Generated type for list-test wasn't generated", listTest);
         assertEquals("ListTest interface - incorrect number of occurences", 1, listTestCounter);
         assertEquals("ListTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718", listTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718", listTest.getPackageName());
 
         assertNotNull("Generated type for container-grouping-list-test wasn't generated", containerGroupingListTest);
         assertEquals("ContainerGroupingListTest interface - incorrect number of occurences", 1,
                 containerGroupingListTestCounter);
         assertEquals("ContainerGroupingListTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718.grouping.list.test",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test",
                 containerGroupingListTest.getPackageName());
 
         assertNotNull("Generated type for list-grouping-list-test wasn't generated", listGroupingListTest);
         assertEquals("ListGroupingListTest interface - incorrect number of occurences", 1, listGroupingListTestCounter);
         assertEquals("ListGroupingListTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev2013718.grouping.list.test",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.list.rev130718.grouping.list.test",
                 listGroupingListTest.getPackageName());
 
         containsInterface("GroupingListTest", listTest);
@@ -360,13 +360,13 @@ public class UsesTest {
         assertNotNull("Generated type for grouping-list-test wasn't generated", groupingModulTest);
         assertEquals("GroupingModulTest interface - incorrect number of occurences", 1, groupingModulTestCounter);
         assertEquals("GroupingModulTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev2013718", groupingModulTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718", groupingModulTest.getPackageName());
 
         assertNotNull("Generated type for modul wasn't generated", groupingUsesModulData);
         assertEquals("GroupingUsesModulData interface - incorrect number of occurences", 1,
                 groupingUsesModulDataCounter);
         assertEquals("GroupingUsesModulData isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.modul.rev130718",
                 groupingUsesModulData.getPackageName());
 
         containsInterface("GroupingModulTest", groupingUsesModulData);
@@ -428,29 +428,29 @@ public class UsesTest {
         assertNotNull("Generated type for RPC test input wasn't generated", rpcTestInput);
         assertEquals("RpcTestInput interface - incorrect number of occurences", 1, rpcTestInputCounter);
         assertEquals("RpcTestInput isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", rpcTestInput.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestInput.getPackageName());
 
         assertNotNull("Generated type for RPC test output wasn't generated", rpcTestOutput);
         assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, rpcTestOutputCounter);
         assertEquals("RpcTestOutput isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", rpcTestOutput.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", rpcTestOutput.getPackageName());
 
         assertNotNull("Generated type for grouping-rpc-input-test wasn't generated", groupingRpcInputTest);
         assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcInputTestCounter);
         assertEquals("GroupingRpcInputTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", groupingRpcInputTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcInputTest.getPackageName());
 
         assertNotNull("Generated type for grouping-rpc-output-test wasn't generated", groupingRpcOutputTest);
         assertEquals("RpcTestOutput interface - incorrect number of occurences", 1, groupingRpcOutputTestCounter);
         assertEquals("GroupingRpcOutputTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718", groupingRpcOutputTest.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718", groupingRpcOutputTest.getPackageName());
 
         assertNotNull("Generated type for container-grouping-rpc-input-test wasn't generated",
                 containerGroupingRpcInputTest);
         assertEquals("ContainerGroupingRpcInputTest interface - incorrect number of occurences", 1,
                 containerGroupingRpcInputTestCounter);
         assertEquals("ContainerGroupingRpcInputTest isn't in correct package",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev2013718.grouping.rpc.input.test",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.rpc.rev130718.grouping.rpc.input.test",
                 containerGroupingRpcInputTest.getPackageName());
 
         containsInterface("GroupingRpcInputTest", rpcTestInput);
@@ -506,12 +506,12 @@ public class UsesTest {
         assertNotNull("Generated type for augment /container-augment wasn't generated.", containerAugment1);
         assertEquals("ContainerAugment1 interface generated more than one time.", 1, containerAugment1Counter);
         assertEquals("ContainerAugment1 is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev2013718", containerAugment1.getPackageName());
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718", containerAugment1.getPackageName());
 
         assertNotNull("Generated type for grouping-augment-test wasn't generated.", groupingAugmentTest);
         assertEquals("GroupingAugmentTest interface generated more than one time.", 1, groupingAugmentTestCounter);
         assertEquals("groupingAugmentTest is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.augment.rev130718",
                 groupingAugmentTest.getPackageName());
 
         containsInterface("GroupingAugmentTest", containerAugment1);
@@ -565,14 +565,14 @@ public class UsesTest {
         assertNotNull("Generated type for notification-test wasn't generated.", notificationTest);
         assertEquals("NotificationTest interface generated more than one time.", 1, notificationTestCounter);
         assertEquals("NotificationTest is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718",
                 notificationTest.getPackageName());
 
         assertNotNull("Generated type for grouping-notification-test wasn't generated.", groupingNotificationTest);
         assertEquals("GroupingNotificationTest interface generated more than one time.", 1,
                 groupingNotificationTestCounter);
         assertEquals("groupingNotificationTest is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718",
                 groupingNotificationTest.getPackageName());
 
         assertNotNull("Generated type for container-grouping-notification-test wasn't generated.",
@@ -580,7 +580,7 @@ public class UsesTest {
         assertEquals("ContainerGroupingNotificationTest interface generated more than one time.", 1,
                 containerGroupingNotificationTestCounter);
         assertEquals("ContainerGroupingNotificationTest is in wrong package.",
-                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev2013718.grouping.notification.test",
+                "org.opendaylight.yang.gen.v1.urn.grouping.uses.notification.rev130718.grouping.notification.test",
                 containerGroupingNotificationTest.getPackageName());
 
         containsInterface("GroupingNotificationTest", notificationTest);
index 3a0d74c8c4d3887f8a7ce62736d791d2cbe9bec8..77259cabce5ad3d206e8599ba042cce0b34886d5 100644 (file)
@@ -1,5 +1,7 @@
 package org.opendaylight.yangtools.binding.generator.util;\r
 \r
+import java.text.DateFormat;\r
+import java.text.SimpleDateFormat;\r
 import java.util.Arrays;\r
 import java.util.Calendar;\r
 import java.util.HashSet;\r
@@ -21,6 +23,8 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
  */\r
 public final class BindingGeneratorUtil {\r
 \r
+    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");\r
+    \r
     /**\r
      * Array of strings values which represents JAVA reserved words.\r
      */\r
@@ -143,7 +147,6 @@ public final class BindingGeneratorUtil {
     public static String moduleNamespaceToPackageName(final Module module) {\r
         final StringBuilder packageNameBuilder = new StringBuilder();\r
 \r
-        final Calendar calendar = Calendar.getInstance();\r
         if (module.getRevision() == null) {\r
             throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");\r
         }\r
@@ -167,12 +170,9 @@ public final class BindingGeneratorUtil {
         namespace = namespace.replace("=", ".");\r
 \r
         packageNameBuilder.append(namespace);\r
-        calendar.setTime(module.getRevision());\r
         packageNameBuilder.append(".rev");\r
-        packageNameBuilder.append(calendar.get(Calendar.YEAR));\r
-        packageNameBuilder.append((calendar.get(Calendar.MONTH) + 1));\r
-        packageNameBuilder.append(calendar.get(Calendar.DAY_OF_MONTH));\r
-\r
+        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));\r
+        \r
         return validateJavaPackage(packageNameBuilder.toString());\r
     }\r
 \r
index 1555bbb38ff5b12cf149cea73310d63bc87fcd85..b273c760815cc146057e73a81feb864fcc88008b 100644 (file)
@@ -88,5 +88,7 @@ public interface SchemaContext {
      * @return module instance which has namespace equal to the
      *         <code>namespace</code> or <code>null</code> in other cases
      */
-    Module findModuleByNamespace(final URI namespace);
+    Set<Module> findModuleByNamespace(final URI namespace);
+    
+    Module findModuleByNamespaceAndRevision(final URI namespace,final Date revision);
 }
index 67374b354e7e36799ebd298fa65f1cd941db6499..765cef8b9f2513c729bebf2cf1749c469655078b 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
 import java.io.ObjectOutputStream.PutField
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
+import java.util.Date
 
 /**
  * The Schema Context Util contains support methods for searching through Schema Context modules for specified schema
@@ -60,10 +61,10 @@ public  class SchemaContextUtil {
      *         <code>null</code> if the Node is not present.
      */
     public static def SchemaNode findDataSchemaNode( SchemaContext context,  SchemaPath schemaPath) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (schemaPath == null) {
+        if (schemaPath === null) {
             throw new IllegalArgumentException("Schema Path reference cannot be NULL");
         }
         val prefixedPath = (schemaPath.getPath());
@@ -99,13 +100,13 @@ public  class SchemaContextUtil {
      */
     public static def SchemaNode findDataSchemaNode( SchemaContext context,  Module module,
              RevisionAwareXPath nonCondXPath) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (module == null) {
+        if (module === null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
-        if (nonCondXPath == null) {
+        if (nonCondXPath === null) {
             throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!");
         }
 
@@ -159,16 +160,16 @@ public  class SchemaContextUtil {
      */
     public static def SchemaNode findDataSchemaNodeForRelativeXPath( SchemaContext context,  Module module,
              SchemaNode actualSchemaNode,  RevisionAwareXPath relativeXPath) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (module == null) {
+        if (module === null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
-        if (actualSchemaNode == null) {
+        if (actualSchemaNode === null) {
             throw new IllegalArgumentException("Actual Schema Node reference cannot be NULL!");
         }
-        if (relativeXPath == null) {
+        if (relativeXPath === null) {
             throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!");
         }
         if (relativeXPath.isAbsolute()) {
@@ -201,26 +202,26 @@ public  class SchemaContextUtil {
      * the method will returns <code>null</code>
      */
     public static def Module findParentModule( SchemaContext context,  SchemaNode schemaNode) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (schemaNode == null) {
+        if (schemaNode === null) {
             throw new IllegalArgumentException("Schema Node cannot be NULL!");
         }
 
         val schemaPath = schemaNode.getPath();
-        if (schemaPath == null) {
+        if (schemaPath === null) {
             throw new IllegalStateException("Schema Path for Schema Node is not "
                     + "set properly (Schema Path is NULL)");
         }
-        val qnamedPath = schemaPath.getPath();
-        if (qnamedPath == null || qnamedPath.isEmpty()) {
+        val qnamedPath = schemaPath.path;
+        if (qnamedPath === null || qnamedPath.empty) {
             throw new IllegalStateException("Schema Path contains invalid state of path parts."
                     + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name"
                     + "of path.");
         }
         val qname = qnamedPath.get(qnamedPath.size() - 1);
-        return context.findModuleByNamespace(qname.getNamespace());
+        return context.findModuleByNamespaceAndRevision(qname.namespace,qname.revision);
     }
 
     /**
@@ -242,16 +243,16 @@ public  class SchemaContextUtil {
      */
     private static def SchemaNode findSchemaNodeForGivenPath( SchemaContext context,  Module module,
              Queue<QName> qnamedPath) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (module == null) {
+        if (module === null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
-        if (module.getNamespace() == null) {
+        if (module.getNamespace() === null) {
             throw new IllegalArgumentException("Namespace for Module cannot contains NULL reference!");
         }
-        if (qnamedPath == null || qnamedPath.isEmpty()) {
+        if (qnamedPath === null || qnamedPath.isEmpty()) {
             throw new IllegalStateException("Schema Path contains invalid state of path parts."
                     + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name"
                     + "of path.");
@@ -265,15 +266,16 @@ public  class SchemaContextUtil {
         while ((nextNode != null) && !qnamedPath.isEmpty()) {
             childNodeQName = qnamedPath.peek();
             if (childNodeQName != null) {
-                val URI childNodeNamespace = childNodeQName.getNamespace();
-
                 schemaNode = nextNode.getDataChildByName(childNodeQName.getLocalName());
-                if(schemaNode == null && nextNode instanceof Module) {
+                if(schemaNode === null && nextNode instanceof Module) {
                     schemaNode = (nextNode as Module).getNotificationByName(childNodeQName);
                 }
-                if(schemaNode == null && nextNode instanceof Module) {
+                if(schemaNode === null && nextNode instanceof Module) {
                     
                 }
+                val URI childNamespace = childNodeQName.getNamespace();
+                val Date childRevision = childNodeQName.getRevision();
+                
                 if (schemaNode != null) {
                     if (schemaNode instanceof ContainerSchemaNode) {
                         nextNode = schemaNode as ContainerSchemaNode;
@@ -290,8 +292,8 @@ public  class SchemaContextUtil {
                     } else {
                         nextNode = null;
                     }
-                } else if (!childNodeNamespace.equals(moduleNamespace)) {
-                    val Module nextModule = context.findModuleByNamespace(childNodeNamespace);
+                } else if (!childNamespace.equals(moduleNamespace)) {
+                    val Module nextModule = context.findModuleByNamespaceAndRevision(childNamespace,childRevision);
                     schemaNode = findSchemaNodeForGivenPath(context, nextModule, qnamedPath);
                     return schemaNode;
                 }
@@ -304,8 +306,8 @@ public  class SchemaContextUtil {
     
     private static def SchemaNode findNodeInSchemaContext(SchemaContext context, List<QName> path) {
         val current = path.get(0);
-        val module = context.findModuleByNamespace(current.namespace);
-        if(module == null) return null;
+        val module = context.findModuleByNamespaceAndRevision(current.namespace,current.revision);
+        if(module === null) return null;
         return findNodeInModule(module,path);
     }
     
@@ -418,13 +420,13 @@ public  class SchemaContextUtil {
      */
     private static def xpathToQNamePath( SchemaContext context,  Module parentModule,
              String xpath) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (parentModule == null) {
+        if (parentModule === null) {
             throw new IllegalArgumentException("Parent Module reference cannot be NULL!");
         }
-        if (xpath == null) {
+        if (xpath === null) {
             throw new IllegalArgumentException("XPath string reference cannot be NULL!");
         }
 
@@ -460,13 +462,13 @@ public  class SchemaContextUtil {
      */
     private static def QName stringPathPartToQName( SchemaContext context,  Module parentModule,
              String prefixedPathPart) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (parentModule == null) {
+        if (parentModule === null) {
             throw new IllegalArgumentException("Parent Module reference cannot be NULL!");
         }
-        if (prefixedPathPart == null) {
+        if (prefixedPathPart === null) {
             throw new IllegalArgumentException("Prefixed Path Part cannot be NULL!");
         }
 
@@ -502,13 +504,13 @@ public  class SchemaContextUtil {
      * @return Module for given prefix in specified Schema Context if is present, otherwise returns <code>null</code>
      */
     private static def Module resolveModuleForPrefix( SchemaContext context,  Module module,  String prefix) {
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (module == null) {
+        if (module === null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
-        if (prefix == null) {
+        if (prefix === null) {
             throw new IllegalArgumentException("Prefix string cannot be NULL!");
         }
 
@@ -537,20 +539,20 @@ public  class SchemaContextUtil {
     private static def resolveRelativeXPath( SchemaContext context,  Module module,
              RevisionAwareXPath relativeXPath,  SchemaNode leafrefParentNode) {
 
-        if (context == null) {
+        if (context === null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
         }
-        if (module == null) {
+        if (module === null) {
             throw new IllegalArgumentException("Module reference cannot be NULL!");
         }
-        if (relativeXPath == null) {
+        if (relativeXPath === null) {
             throw new IllegalArgumentException("Non Conditional Revision Aware XPath cannot be NULL!");
         }
         if (relativeXPath.isAbsolute()) {
             throw new IllegalArgumentException("Revision Aware XPath MUST be relative i.e. MUST contains ../, "
                     + "for non relative Revision Aware XPath use findDataSchemaNode method!");
         }
-        if (leafrefParentNode.getPath() == null) {
+        if (leafrefParentNode.getPath() === null) {
             throw new IllegalArgumentException("Schema Path reference for Leafref cannot be NULL!");
         }
         val absolutePath = new LinkedList<QName>();
index 3eb87a9214e24bd84b7e51061f6e29e82aba4a87..2d1da1f8336f7eaff5caf95b6cb8076f8c4ea7aa 100644 (file)
@@ -84,11 +84,24 @@ final class SchemaContextImpl implements SchemaContext {
     }
 
     @Override
-    public Module findModuleByNamespace(final URI namespace) {
+    public Set<Module> findModuleByNamespace(final URI namespace) {
+        final Set<Module> ret = new HashSet<Module>();
         if (namespace != null) {
             for (final Module module : modules) {
                 if (module.getNamespace().equals(namespace)) {
-                    return module;
+                    ret.add(module);
+                }
+            }
+        }
+        return ret;
+    }
+
+    @Override
+    public Module findModuleByNamespaceAndRevision(URI namespace, Date revision) {
+        if (namespace != null) {
+            for (final Module module : modules) {
+                if (module.getNamespace().equals(namespace) && module.getRevision().equals(revision)) {
+                    return(module);
                 }
             }
         }
index 4cab8d8da6a005bd02a3c556164317c821464a85..c2088ce2718c4e89f609ddecab69965edeb6b4e8 100644 (file)
@@ -105,7 +105,7 @@ public class YangParserWithContextTest {
         // suffix _g = defined in grouping from context
 
         // get grouping
-        Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test"));
+        Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test")).iterator().next();
         assertNotNull(contextModule);
         Set<GroupingDefinition> groupings = contextModule.getGroupings();
         assertEquals(1, groupings.size());