From ca85a6f3a39b406ab122fe985ee010a41489f658 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Mon, 25 Mar 2013 14:25:07 +0100 Subject: [PATCH] Merge from development repository. See commit log bellow for more details. commit d3f7ff74377f55c106ca28a43c936ef4d3bcb5e2 Author: mvitez Date: Mon Mar 25 10:15:36 2013 +0100 improve some code commit a0bec74e277e7afcc0f6867ba2d7527d4e25db60 Author: mvitez Date: Mon Mar 25 09:26:59 2013 +0100 added typedef and augment resolving, added tests commit 32fff33187321463bb27b5c11b63a71d8dbc104e Merge: 562dbeb e6b3057 Author: lsedlak Date: Fri Mar 22 15:27:59 2013 +0100 Merge branch 'binding-api' commit e6b30574b2598c289ea90be6588151dc7cb7b0fa Author: lsedlak Date: Fri Mar 22 15:16:12 2013 +0100 Added Implementation of getPathStatement into Identityref.java; commit ef70678b2127fd56d062d99a20a02de401262b29 Author: lsedlak Date: Fri Mar 22 15:14:28 2013 +0100 Added RevisionAwareXPath into interface definition; commit 78cb3c64716f7cf2788dfaf61906a07481bcd9df Author: mvitez Date: Fri Mar 22 13:40:05 2013 +0100 added implementation of SchemaContext commit 45769c7721eb9832cd43c04a020f1ca7f52172ef Author: lsedlak Date: Fri Mar 22 13:55:26 2013 +0100 Changed parameter in generateTypes from Module to SchemaContext; Implemented changes in generatedTypes in BindingGeneratorImpl.java; Implemented changes in GeneratedTypesTest.java; commit 562dbebbbbfec341c98885ad80b87f3d8d05c3f7 Author: mvitez Date: Fri Mar 22 13:40:05 2013 +0100 added implementation of SchemaContext commit c4ea91257946fa1f3cd44a148af7a44e254b661f Author: lsedlak Date: Fri Mar 22 11:09:50 2013 +0100 Added definition: getExtensions into SchemaContext.java; commit 8b239e3fb4a322baa36867d4ce41f2c142a8ef76 Author: mvitez Date: Fri Mar 22 10:46:27 2013 +0100 fix Demo, GeneratedTypesTest commit 6564270ea304905ccb91718066c7aa65b5430ecb Author: mvitez Date: Fri Mar 22 10:33:26 2013 +0100 rename packages commit f3326c65f7de3ce77137b0c972aff32aa5d6f6c6 Author: mvitez Date: Thu Mar 21 17:45:24 2013 +0100 renamed YangModelParserImpl-> YangModelParserListenerImpl commit 26fa647a676f9c466a010536e9d972486adbb904 Author: Anton Tkacik Date: Thu Mar 21 15:49:55 2013 +0100 Added SAL Binding SPI commit e60fb750ef193d8456cb1196b4d13f12f44ad276 Author: lsedlak Date: Thu Mar 21 17:27:05 2013 +0100 Added yang-model-parser-api module into pom definition; commit c7023e3f2ae7defeadba319c40011ed4f90bfb4f Author: Anton Tkacik Date: Thu Mar 21 11:22:50 2013 +0100 Renamed Controller architecture to OpenDayLightController SAL commit 985d3e66977876be83db6cba92753ef3ade3edf2 Merge: 9c9c027 39c8c01 Author: mvitez Date: Thu Mar 21 15:31:53 2013 +0100 more progress on yang java model commit 9c9c0271a4b7b35177164e94e1677dabecd88ca8 Author: mvitez Date: Thu Mar 21 13:58:59 2013 +0100 more progress on yang java model commit 5609186d6b22a89f8d0568962bb8d0657818cee4 Merge: c26cf1d 5adfb70 Author: mvitez Date: Wed Mar 20 18:14:34 2013 +0100 getExtensionSchemaNodes changed to getUnknownSchemaNodes; Whole package org.opendaylight.controller.model.parser.builder refactored accordingly; commit 820716ed377f4a7878a1f6373095053eb4ababd0 Author: mvitez Date: Thu Mar 21 10:04:44 2013 +0100 added equals, hashCode commit c26cf1d917811ab0d5473342d253314f62d6e0a1 Author: mvitez Date: Wed Mar 20 18:13:56 2013 +0100 more progress on yang java model commit 32e3b9dbef20ab6d8e40d9eded3c452a7f23fdc2 Author: mvitez Date: Wed Mar 20 15:44:10 2013 +0100 Changed getLengthConstraint to getLengthConstraints and changed return value from LengthConstraint to Set of LengthConstraints; Updated BinaryType implementation accordingly; commit e8419305c2b7b3197734c8d89d77be25f2d78440 Author: mvitez Date: Wed Mar 20 15:44:10 2013 +0100 more progress on yang java model commit 6b0283f178366831306456d59431b5747f6c038b Author: mvitez Date: Wed Mar 20 12:08:31 2013 +0100 Added method definitions for RevisionAwareXPath interface; commit 463884e9e9e21ff03a3b89b590d0b08d9dd2d9b7 Author: mvitez Date: Wed Mar 20 12:08:31 2013 +0100 rework augment parsing commit b2fe0c91d7cf184252e2516ad15cdd50e01130a7 Author: mvitez Date: Tue Mar 19 18:18:28 2013 +0100 fix test commit cd388c2f7fd0460ca068270035ab0acdaa9e5e79 Author: mvitez Date: Tue Mar 19 18:16:33 2013 +0100 more progress on yang java model commit 638c43548ca83c739131118a404c7b1d454055db Merge: 2b0fb2c 36f2f95 Author: mvitez Date: Tue Mar 19 15:21:27 2013 +0100 GeneratedType changed to Type in return value of generateTypes method; Implemented composite key resolving through GeneratedTOBuilder; Added test cases for composite key generation; Added list-composite-key.yang file for testing purposes; Change-Id: I9145a87945cc4638ff454f268eb37dd1bf8b3142 Signed-off-by: Tony Tkacik --- .../generator/api/BindingGenerator.java | 6 +- .../generator/impl/BindingGeneratorImpl.java | 176 ++- .../yang/types/test/GeneratedTypesTest.java | 262 +++- .../test/resources/list-composite-key.yang | 63 + .../generator/test/GeneratorJavaFileTest.java | 3 +- .../type/builder/MethodSignatureBuilder.java | 12 +- .../model/api/type/builder/package-info.java | 12 +- .../code-generator-demo/pom.xml | 5 - .../org/opendaylight/controller/Demo.java | 70 +- .../yang-model-parser-api/pom.xml | 17 + .../model/parser/api/YangModelParser.java | 58 + .../yang/model/parser/api/package-info.java | 8 + .../yang-model-parser-impl/pom.xml | 9 +- .../antlrv4/code/gen/YangLexer.java | 693 +++++---- .../antlrv4/code/gen/YangParser.java | 47 +- .../AugmentationSchemaBuilderImpl.java | 306 ---- .../builder/ContainerSchemaNodeBuilder.java | 468 ------ .../parser/builder/DeviationBuilder.java | 108 -- .../model/parser/builder/FeatureBuilder.java | 190 --- .../parser/builder/GroupingBuilderImpl.java | 245 --- .../builder/LeafListSchemaNodeBuilder.java | 221 --- .../parser/builder/LeafSchemaNodeBuilder.java | 232 --- .../parser/builder/ListSchemaNodeBuilder.java | 463 ------ .../model/parser/builder/ModuleBuilder.java | 824 ---------- .../parser/builder/MustDefinitionBuilder.java | 86 -- .../parser/builder/NotificationBuilder.java | 229 --- .../model/parser/builder/TypedefBuilder.java | 196 --- .../parser/builder/UsesNodeBuilderImpl.java | 78 - .../parser/builder/YangModelBuilder.java | 198 --- .../parser/util/YangModelBuilderHelper.java | 659 -------- .../api/AbstractChildNodeBuilder.java | 80 +- .../api/AugmentationSchemaBuilder.java | 57 +- .../api/AugmentationTargetBuilder.java | 46 +- .../model/parser/builder}/api/Builder.java | 2 +- .../parser/builder}/api/ChildNodeBuilder.java | 45 +- .../builder}/api/DataSchemaNodeBuilder.java | 48 +- .../parser/builder}/api/GroupingBuilder.java | 38 +- .../builder}/api/SchemaNodeBuilder.java | 52 +- .../parser/builder}/api/TypeAwareBuilder.java | 42 +- .../api/TypeDefinitionAwareBuilder.java | 2 +- .../builder}/api/TypeDefinitionBuilder.java | 47 +- .../parser/builder}/api/UsesNodeBuilder.java | 42 +- .../impl/AugmentationSchemaBuilderImpl.java | 324 ++++ .../builder/impl/ConstraintsBuilder.java | 317 ++++ .../impl/ContainerSchemaNodeBuilder.java | 362 +++++ .../parser/builder/impl/DeviationBuilder.java | 144 ++ .../parser/builder/impl/ExtensionBuilder.java | 257 ++++ .../parser/builder/impl/FeatureBuilder.java | 198 +++ .../builder/impl/GroupingBuilderImpl.java | 350 +++++ .../impl/LeafListSchemaNodeBuilder.java | 323 ++++ .../builder/impl/LeafSchemaNodeBuilder.java | 307 ++++ .../builder/impl/ListSchemaNodeBuilder.java | 508 +++++++ .../parser/builder/impl/ModuleBuilder.java | 1098 ++++++++++++++ .../builder/impl/NotificationBuilder.java | 343 +++++ .../builder/impl}/RpcDefinitionBuilder.java | 628 ++++---- .../parser/builder/impl/TypedefBuilder.java | 297 ++++ .../impl/UnknownSchemaNodeBuilder.java | 126 ++ .../builder/impl/UsesNodeBuilderImpl.java | 161 ++ .../parser/impl/YangModelParserImpl.java | 321 ++++ .../impl/YangModelParserListenerImpl.java} | 1332 ++++++++--------- .../parser/util/YangModelBuilderUtil.java | 1094 ++++++++++++++ .../ContainerSchemaNodeBuilderTest.java | 118 -- .../LeafListSchemaNodeBuilderTest.java | 99 -- .../builder/ListSchemaNodeBuilderTest.java | 121 -- .../parser/impl/YangModelParserTest.java | 97 -- .../impl/ContainerSchemaNodeBuilderTest.java | 111 ++ .../impl/LeafListSchemaNodeBuilderTest.java | 91 ++ .../impl/LeafSchemaNodeBuilderTest.java | 90 ++ .../impl/ListSchemaNodeBuilderTest.java | 118 ++ .../model/parser/builder/impl}/TestUtils.java | 66 +- .../builder/impl/YangModelBuilderTest.java | 73 + .../impl/YangModelParserListenerTest.java | 212 +++ .../parser/impl/YangModelParserTest.java | 93 ++ .../src/test/resources/model/testfile1.yang | 39 + .../src/test/resources/model/testfile2.yang | 43 + .../src/test/resources/test-model.yang | 164 ++ opendaylight/sal/yang-prototype/sal/pom.xml | 2 + .../sal/binding/api/BindingAwareBroker.java | 5 +- .../sal/binding/api/BindingAwareProvider.java | 4 + .../sal/sal-binding-broker-impl/pom.xml | 6 +- .../sal/binding/impl/BindingBrokerImpl.java | 188 +++ .../sal/binding/impl/NotificationInvoker.java | 9 + .../sal/binding/impl/NotificationModule.java | 230 +++ .../sal/binding/impl/package-info.java | 8 + .../sal/sal-binding-spi/pom.xml | 22 + .../controller/sal/binding/spi/Mapper.java | 35 + .../sal/binding/spi/MappingProvider.java | 28 + .../sal/binding/spi/SALBindingModule.java | 31 + .../sal/core/impl/ConsumerSessionImpl.java | 10 +- .../sal/core/impl/rpc/RpcModule.java | 8 - .../controller/sal/core/api/Broker.java | 5 + .../yang-prototype/sal/sal-core-demo/pom.xml | 33 +- .../controller/yang/binding/DataObject.java | 5 + .../controller/yang/binding/Notification.java | 3 +- .../model/api/type/BinaryTypeDefinition.java | 14 +- .../api/type/IdentityrefTypeDefinition.java | 5 +- .../yang/model/api/ContainerSchemaNode.java | 2 - .../controller/yang/model/api/Deviation.java | 2 - .../yang/model/api/LeafListSchemaNode.java | 2 - .../yang/model/api/LeafSchemaNode.java | 4 +- .../controller/yang/model/api/Module.java | 3 + .../yang/model/api/RevisionAwareXPath.java | 18 +- .../yang/model}/api/SchemaContext.java | 58 +- .../controller/yang/model/api/SchemaNode.java | 2 +- .../controller/yang/model/api/Status.java | 2 +- .../yang/model/api/UnknownSchemaNode.java} | 9 +- .../controller/yang/model/api/UsesNode.java | 5 + .../model/util/AbstractInteger.java | 4 +- .../controller/model/util/BinaryType.java | 47 +- .../controller/model/util/BitsType.java | 4 +- .../controller/model/util/BooleanType.java | 4 +- .../controller/model/util/Decimal64.java | 4 +- .../model/util/EnumerationType.java | 4 +- .../controller/model/util/ExtendedType.java | 28 +- .../controller/model/util/IdentityType.java | 4 +- .../controller/model/util/Identityref.java | 110 +- .../model/util/InstanceIdentifier.java | 4 +- .../controller/model/util/Leafref.java | 4 +- .../model/util/RevisionAwareXPathImpl.java | 66 + .../controller/model/util/StringType.java | 4 +- .../controller/model/util/UnknownType.java | 9 +- .../model/util/YangTypesConverter.java | 5 + 122 files changed, 10592 insertions(+), 6937 deletions(-) create mode 100644 opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/list-composite-key.yang create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/pom.xml create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/YangModelParser.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/package-info.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/AugmentationSchemaBuilderImpl.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/DeviationBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/FeatureBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/GroupingBuilderImpl.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafSchemaNodeBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ModuleBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustDefinitionBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/NotificationBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/TypedefBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/UsesNodeBuilderImpl.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/YangModelBuilder.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/util/YangModelBuilderHelper.java rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/AbstractChildNodeBuilder.java (92%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/AugmentationSchemaBuilder.java (82%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/AugmentationTargetBuilder.java (89%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/Builder.java (86%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/ChildNodeBuilder.java (85%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/DataSchemaNodeBuilder.java (58%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/GroupingBuilder.java (88%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/SchemaNodeBuilder.java (90%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/TypeAwareBuilder.java (89%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/TypeDefinitionAwareBuilder.java (89%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/TypeDefinitionBuilder.java (86%) rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser => yang/model/parser/builder}/api/UsesNodeBuilder.java (75%) create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser/builder => yang/model/parser/builder/impl}/RpcDefinitionBuilder.java (61%) create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/{model/parser/impl/YangModelParserImpl.java => yang/model/parser/impl/YangModelParserListenerImpl.java} (63%) create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilderTest.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilderTest.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilderTest.java delete mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/impl/YangModelParserTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilderTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilderTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilderTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilderTest.java rename opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/{model/parser/builder => yang/model/parser/builder/impl}/TestUtils.java (53%) create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang create mode 100644 opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/test-model.yang create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/package-info.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java create mode 100644 opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java create mode 100644 opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/DataObject.java rename opendaylight/sal/yang-prototype/{sal/sal-schema-repository-api/src/main/java/org/opendaylight/controller/sal/schema => yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model}/api/SchemaContext.java (61%) rename opendaylight/sal/yang-prototype/{code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustAwareBuilder.java => yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java} (51%) create mode 100644 opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/RevisionAwareXPathImpl.java diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-api/src/main/java/org/opendaylight/controller/sal/binding/generator/api/BindingGenerator.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-api/src/main/java/org/opendaylight/controller/sal/binding/generator/api/BindingGenerator.java index 686f364132..bed7989074 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-api/src/main/java/org/opendaylight/controller/sal/binding/generator/api/BindingGenerator.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-api/src/main/java/org/opendaylight/controller/sal/binding/generator/api/BindingGenerator.java @@ -9,11 +9,11 @@ package org.opendaylight.controller.sal.binding.generator.api; import java.util.List; -import org.opendaylight.controller.sal.binding.model.api.GeneratedType; -import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.yang.model.api.SchemaContext; public interface BindingGenerator { - public List generateTypes(final Module module); + public List generateTypes(final SchemaContext context); } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java index d346352350..343d9ef0e5 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -8,8 +8,6 @@ package org.opendaylight.controller.sal.binding.generator.impl; import java.net.URI; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; @@ -22,8 +20,11 @@ import org.opendaylight.controller.binding.generator.util.CodeGeneratorHelper; import org.opendaylight.controller.binding.generator.util.Types; import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider; +import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; import org.opendaylight.controller.sal.binding.model.api.Type; +import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; +import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder; import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder; import org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl; @@ -35,15 +36,13 @@ import org.opendaylight.controller.yang.model.api.LeafListSchemaNode; import org.opendaylight.controller.yang.model.api.LeafSchemaNode; import org.opendaylight.controller.yang.model.api.ListSchemaNode; import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; public class BindingGeneratorImpl implements BindingGenerator { - private static DateFormat simpleDateFormat = new SimpleDateFormat( - "yyyy-MM-dd"); private static Calendar calendar = new GregorianCalendar(); - private final Map> genTypeBuilders; private final List schemaContainers; private final List schemaLists; @@ -63,22 +62,30 @@ public class BindingGeneratorImpl implements BindingGenerator { } @Override - public List generateTypes(final Module module) { - final List genTypes = new ArrayList(); - - basePackageName = resolveBasePackageName(module.getNamespace(), - module.getYangVersion()); - - traverseModule(module); - if (schemaContainers.size() > 0) { - for (final ContainerSchemaNode container : schemaContainers) { - genTypes.add(containerToGenType(container)); - } - } + public List generateTypes(final SchemaContext context) { + final List genTypes = new ArrayList(); + + if (context != null) { + final Set modules = context.getModules(); + + if (modules != null) { + for (final Module module : modules) { + basePackageName = resolveBasePackageName(module.getNamespace(), + module.getYangVersion()); + + traverseModule(module); + if (schemaContainers.size() > 0) { + for (final ContainerSchemaNode container : schemaContainers) { + genTypes.add(containerToGenType(container)); + } + } - if (schemaLists.size() > 0) { - for (final ListSchemaNode list : schemaLists) { - genTypes.add(listToGenType(list)); + if (schemaLists.size() > 0) { + for (final ListSchemaNode list : schemaLists) { + genTypes.addAll(listToGenType(list)); + } + } + } } } @@ -113,7 +120,8 @@ public class BindingGeneratorImpl implements BindingGenerator { for (final DataSchemaNode node : schemaNodes) { if (node instanceof LeafSchemaNode) { - resolveLeafSchemaNode(typeBuilder, (LeafSchemaNode) node); + resolveLeafSchemaNodeAsMethod(typeBuilder, + (LeafSchemaNode) node); } else if (node instanceof LeafListSchemaNode) { resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node); @@ -128,23 +136,23 @@ public class BindingGeneratorImpl implements BindingGenerator { return typeBuilder.toInstance(); } - private boolean resolveLeafSchemaNode( - final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode node) { - if ((node != null) && (typeBuilder != null)) { - final String nodeName = node.getQName().getLocalName(); - String nodeDesc = node.getDescription(); - if (nodeDesc == null) { - nodeDesc = ""; + private boolean resolveLeafSchemaNodeAsMethod( + final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) { + if ((leaf != null) && (typeBuilder != null)) { + final String leafName = leaf.getQName().getLocalName(); + String leafDesc = leaf.getDescription(); + if (leafDesc == null) { + leafDesc = ""; } - if (nodeName != null) { - final TypeDefinition typeDef = node.getType(); + if (leafName != null) { + final TypeDefinition typeDef = leaf.getType(); final Type javaType = typeProvider .javaTypeForSchemaDefinitionType(typeDef); - constructGetter(typeBuilder, nodeName, nodeDesc, javaType); - if (!node.isConfiguration()) { - constructSetter(typeBuilder, nodeName, nodeDesc, javaType); + constructGetter(typeBuilder, leafName, leafDesc, javaType); + if (!leaf.isConfiguration()) { + constructSetter(typeBuilder, leafName, leafDesc, javaType); } return true; } @@ -152,6 +160,39 @@ public class BindingGeneratorImpl implements BindingGenerator { return false; } + private boolean resolveLeafSchemaNodeAsProperty( + final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf, + boolean isReadOnly) { + if ((leaf != null) && (toBuilder != null)) { + final String leafName = leaf.getQName().getLocalName(); + String leafDesc = leaf.getDescription(); + if (leafDesc == null) { + leafDesc = ""; + } + + if (leafName != null) { + final TypeDefinition typeDef = leaf.getType(); + final Type javaType = typeProvider + .javaTypeForSchemaDefinitionType(typeDef); + + final GeneratedPropertyBuilder propBuilder = toBuilder + .addProperty(CodeGeneratorHelper + .parseToClassName(leafName)); + + propBuilder.setReadOnly(isReadOnly); + propBuilder.addReturnType(javaType); + propBuilder.addComment(leafDesc); + + toBuilder.addEqualsIdentity(propBuilder); + toBuilder.addHashIdentity(propBuilder); + toBuilder.addToStringProperty(propBuilder); + + return true; + } + } + return false; + } + private boolean resolveLeafListSchemaNode( final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node) { @@ -316,16 +357,27 @@ public class BindingGeneratorImpl implements BindingGenerator { return packageNameBuilder.toString(); } - private GeneratedType listToGenType(ListSchemaNode list) { + private List listToGenType(final ListSchemaNode list) { if (list == null) { return null; } final GeneratedTypeBuilder typeBuilder = resolveListTypeBuilder(list); + final List listKeys = listKeys(list); + GeneratedTOBuilder genTOBuilder = null; + if (listKeys.size() > 0) { + genTOBuilder = resolveListKey(list); + } final Set schemaNodes = list.getChildNodes(); for (final DataSchemaNode node : schemaNodes) { + if (node instanceof LeafSchemaNode) { - resolveLeafSchemaNode(typeBuilder, (LeafSchemaNode) node); + final LeafSchemaNode leaf = (LeafSchemaNode) node; + if (!isPartOfListKey(leaf, listKeys)) { + resolveLeafSchemaNodeAsMethod(typeBuilder, leaf); + } else { + resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true); + } } else if (node instanceof LeafListSchemaNode) { resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node); @@ -336,7 +388,59 @@ public class BindingGeneratorImpl implements BindingGenerator { resolveListSchemaNode(typeBuilder, (ListSchemaNode) node); } } - return typeBuilder.toInstance(); + + final List genTypes = new ArrayList(); + if (genTOBuilder != null) { + final GeneratedTransferObject genTO = genTOBuilder.toInstance(); + constructGetter(typeBuilder, genTO.getName(), "Returns Primary Key of Yang List Type", genTO); + genTypes.add(genTO); + } + genTypes.add(typeBuilder.toInstance()); + return genTypes; + } + + /** + * @param list + * @return + */ + private GeneratedTOBuilder resolveListKey(final ListSchemaNode list) { + final String packageName = resolveGeneratedTypePackageName(list + .getPath()); + final String listName = list.getQName().getLocalName() + "Key"; + + if ((packageName != null) && (list != null) && (listName != null)) { + final String genTOName = CodeGeneratorHelper + .parseToClassName(listName); + final GeneratedTOBuilder newType = new GeneratedTOBuilderImpl( + packageName, genTOName); + + return newType; + } + return null; + } + + private boolean isPartOfListKey(final LeafSchemaNode leaf, + final List keys) { + if ((leaf != null) && (keys != null) && (leaf.getQName() != null)) { + final String leafName = leaf.getQName().getLocalName(); + if (keys.contains(leafName)) { + return true; + } + } + return false; + } + + private List listKeys(final ListSchemaNode list) { + final List listKeys = new ArrayList(); + + if (list.getKeyDefinition() != null) { + final List keyDefinitions = list.getKeyDefinition(); + + for (final QName keyDefinition : keyDefinitions) { + listKeys.add(keyDefinition.getLocalName()); + } + } + return listKeys; } private GeneratedTypeBuilder resolveListTypeBuilder( diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java index 049f8d98a1..095208d977 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/yang/types/test/GeneratedTypesTest.java @@ -10,73 +10,51 @@ package org.opendaylight.controller.sal.binding.yang.types.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.io.InputStream; import java.util.List; +import java.util.Set; -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.ParseTreeWalker; import org.junit.Test; -import org.opendaylight.controller.antlrv4.code.gen.YangLexer; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.model.parser.builder.ModuleBuilder; -import org.opendaylight.controller.model.parser.impl.YangModelParserImpl; import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator; import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl; +import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty; +import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject; import org.opendaylight.controller.sal.binding.model.api.GeneratedType; import org.opendaylight.controller.sal.binding.model.api.MethodSignature; +import org.opendaylight.controller.sal.binding.model.api.Type; import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; +import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl; public class GeneratedTypesTest { - private Module resolveModuleFromFile(final String filePath) { - try { - final InputStream inStream = getClass().getResourceAsStream( - filePath); - if (inStream != null) { - ANTLRInputStream input = new ANTLRInputStream(inStream); - final YangLexer lexer = new YangLexer(input); - final CommonTokenStream tokens = new CommonTokenStream(lexer); - final YangParser parser = new YangParser(tokens); + private SchemaContext resolveSchemaContextFromFiles( + final String... yangFiles) { + final YangModelParser parser = new YangModelParserImpl(); + final Set modules = parser.parseYangModels(yangFiles); - final ParseTree tree = parser.yang(); - final ParseTreeWalker walker = new ParseTreeWalker(); - - final YangModelParserImpl modelParser = new YangModelParserImpl(); - walker.walk(modelParser, tree); - - final ModuleBuilder genModule = modelParser.getModuleBuilder(); - final Module module = genModule.build(); - - return module; - } - } catch (IOException e) { - e.printStackTrace(); - } - return null; + return parser.resolveSchemaContext(modules); } @Test public void testContainerResolving() { - final Module module = resolveModuleFromFile("/simple-container-demo.yang"); - assertTrue(module != null); + final String filePath = getClass().getResource("/simple-container-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(module); + final List genTypes = bindingGen.generateTypes(context); assertTrue(genTypes != null); - assertEquals(genTypes.size(), 2); - - final GeneratedType simpleContainer = genTypes.get(0); - final GeneratedType nestedContainer = genTypes.get(1); + assertEquals(2, genTypes.size()); - assertEquals(simpleContainer.getName(), "SimpleContainer"); - assertEquals(nestedContainer.getName(), "NestedContainer"); + final GeneratedType simpleContainer = (GeneratedType) genTypes.get(0); + final GeneratedType nestedContainer = (GeneratedType) genTypes.get(1); - assertEquals(simpleContainer.getMethodDefinitions().size(), 4); - assertEquals(nestedContainer.getMethodDefinitions().size(), 4); + assertEquals("SimpleContainer", simpleContainer.getName()); + assertEquals("NestedContainer", nestedContainer.getName()); + assertEquals(4, simpleContainer.getMethodDefinitions().size()); + assertEquals(4, nestedContainer.getMethodDefinitions().size()); int methodsCount = 0; for (final MethodSignature method : simpleContainer @@ -90,8 +68,8 @@ public class GeneratedTypesTest { methodsCount++; final MethodSignature.Parameter param = method.getParameters() .get(0); - assertEquals(param.getName(), "foo"); - assertEquals(param.getType().getName(), "Integer"); + assertEquals("foo", param.getName()); + assertEquals("Integer", param.getType().getName()); } if (method.getName().equals("getBar")) { @@ -104,7 +82,7 @@ public class GeneratedTypesTest { methodsCount++; } } - assertEquals(methodsCount, 4); + assertEquals(4, methodsCount); methodsCount = 0; for (final MethodSignature method : nestedContainer @@ -118,8 +96,8 @@ public class GeneratedTypesTest { methodsCount++; final MethodSignature.Parameter param = method.getParameters() .get(0); - assertEquals(param.getName(), "foo"); - assertEquals(param.getType().getName(), "Short"); + assertEquals("foo", param.getName()); + assertEquals("Short", param.getType().getName()); } if (method.getName().equals("getBar")) { @@ -132,30 +110,28 @@ public class GeneratedTypesTest { methodsCount++; } } - assertEquals(methodsCount, 4); + assertEquals(4, methodsCount); } @Test public void testLeafListResolving() { - final Module module = resolveModuleFromFile("/simple-leaf-list-demo.yang"); - assertTrue(module != null); + final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(module); + final List genTypes = bindingGen.generateTypes(context); assertTrue(genTypes != null); - assertEquals(genTypes.size(), 2); + assertEquals(2, genTypes.size()); - final GeneratedType simpleContainer = genTypes.get(0); - final GeneratedType nestedContainer = genTypes.get(1); + final GeneratedType simpleContainer = (GeneratedType) genTypes.get(0); + final GeneratedType nestedContainer = (GeneratedType) genTypes.get(1); - assertEquals(simpleContainer.getName(), "SimpleContainer"); - assertEquals(nestedContainer.getName(), "NestedContainer"); - - // FIXME: uncomment after fix in DOM tree parser - LeafSchemaNode bad - // isConfig resolving - assertEquals(simpleContainer.getMethodDefinitions().size(), 4); - assertEquals(nestedContainer.getMethodDefinitions().size(), 3); + assertEquals("SimpleContainer", simpleContainer.getName()); + assertEquals("NestedContainer", nestedContainer.getName()); + assertEquals(4, simpleContainer.getMethodDefinitions().size()); + assertEquals(3, nestedContainer.getMethodDefinitions().size()); int methodsCount = 0; for (final MethodSignature method : simpleContainer @@ -169,8 +145,8 @@ public class GeneratedTypesTest { methodsCount++; final MethodSignature.Parameter param = method.getParameters() .get(0); - assertEquals(param.getName(), "foo"); - assertEquals(param.getType().getName(), "List"); + assertEquals("foo", param.getName()); + assertEquals("List", param.getType().getName()); } if (method.getName().equals("getBar")) { @@ -183,7 +159,7 @@ public class GeneratedTypesTest { methodsCount++; } } - assertEquals(methodsCount, 4); + assertEquals(4, methodsCount); methodsCount = 0; for (final MethodSignature method : nestedContainer @@ -197,8 +173,8 @@ public class GeneratedTypesTest { methodsCount++; final MethodSignature.Parameter param = method.getParameters() .get(0); - assertEquals(param.getName(), "foo"); - assertEquals(param.getType().getName(), "Short"); + assertEquals("foo", param.getName()); + assertEquals("Short", param.getType().getName()); } if (method.getName().equals("getBar")) { @@ -206,30 +182,160 @@ public class GeneratedTypesTest { methodsCount++; } } - assertEquals(methodsCount, 3); + assertEquals(3, methodsCount); } @Test public void testListResolving() { - final Module module = resolveModuleFromFile("/simple-list-demo.yang"); - assertTrue(module != null); + final String filePath = getClass().getResource("/simple-list-demo.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(module); + final List genTypes = bindingGen.generateTypes(context); assertTrue(genTypes != null); - assertEquals(genTypes.size(), 3); + assertEquals(4, genTypes.size()); + + int genTypesCount = 0; + int genTOsCount = 0; + for (final Type type : genTypes) { + if (type instanceof GeneratedType) { + final GeneratedType genType = (GeneratedType) type; + if (genType.getName().equals("ListParentContainer")) { + assertEquals(2, genType.getMethodDefinitions().size()); + genTypesCount++; + } else if (genType.getName().equals("SimpleList")) { + assertEquals(7, genType.getMethodDefinitions().size()); + final List methods = genType + .getMethodDefinitions(); + int methodsCount = 0; + for (final MethodSignature method : methods) { + if (method.getName().equals("getSimpleListKey")) { + assertEquals("SimpleListKey", method + .getReturnType().getName()); + methodsCount++; + } else if (method.getName().equals( + "getListChildContainer")) { + assertEquals("ListChildContainer", method + .getReturnType().getName()); + methodsCount++; + } else if (method.getName().equals("getFoo")) { + methodsCount++; + } else if (method.getName().equals("setFoo")) { + methodsCount++; + } else if (method.getName().equals("getSimpleLeafList")) { + methodsCount++; + } else if (method.getName().equals("setSimpleLeafList")) { + methodsCount++; + } else if (method.getName().equals("getBar")) { + methodsCount++; + } + } + assertEquals(7, methodsCount); + genTypesCount++; + } else if (genType.getName().equals("ListChildContainer")) { + assertEquals(2, genType.getMethodDefinitions().size()); + genTypesCount++; + } + } else if (type instanceof GeneratedTransferObject) { + genTOsCount++; + final GeneratedTransferObject genTO = (GeneratedTransferObject) type; + final List properties = genTO + .getProperties(); + final List hashProps = genTO + .getHashCodeIdentifiers(); + final List equalProps = genTO + .getEqualsIdentifiers(); + + assertEquals(1, properties.size()); + assertEquals("ListKey", properties.get(0).getName()); + assertEquals("Byte", properties.get(0).getReturnType() + .getName()); + assertEquals(true, properties.get(0).isReadOnly()); + assertEquals(1, hashProps.size()); + assertEquals("ListKey", hashProps.get(0).getName()); + assertEquals("Byte", hashProps.get(0).getReturnType().getName()); + assertEquals(1, equalProps.size()); + assertEquals("ListKey", equalProps.get(0).getName()); + assertEquals("Byte", equalProps.get(0).getReturnType() + .getName()); + } + } + assertEquals(3, genTypesCount); + assertEquals(1, genTOsCount); + } + + @Test + public void testListCompositeKeyResolving() { + final String filePath = getClass().getResource("/list-composite-key.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + + assertTrue(context != null); + + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List genTypes = bindingGen.generateTypes(context); + + assertTrue(genTypes != null); + assertEquals(6, genTypes.size()); + + int genTypesCount = 0; + int genTOsCount = 0; + for (final Type type : genTypes) { + if (type instanceof GeneratedType) { + genTypesCount++; + } else if (type instanceof GeneratedTransferObject) { + final GeneratedTransferObject genTO = (GeneratedTransferObject) type; + + if (genTO.getName().equals("CompositeKeyListKey")) { + final List properties = genTO + .getProperties(); + int propertyCount = 0; + for (final GeneratedProperty prop : properties) { + if (prop.getName().equals("Key1")) { + propertyCount++; + } else if (prop.getName().equals("Key2")) { + propertyCount++; + } + } + assertEquals(2, propertyCount); + genTOsCount++; + } else if (genTO.getName().equals("InnerListKey")) { + final List properties = genTO + .getProperties(); + assertEquals(1, properties.size()); + genTOsCount++; + } + } + } + + assertEquals(4, genTypesCount); + assertEquals(2, genTOsCount); } @Test public void testGeneratedTypes() { - final Module module = resolveModuleFromFile("/demo-topology.yang"); - assertTrue(module != null); + final String filePath = getClass().getResource("/demo-topology.yang").getPath(); + final SchemaContext context = resolveSchemaContextFromFiles(filePath); + assertTrue(context != null); final BindingGenerator bindingGen = new BindingGeneratorImpl(); - final List genTypes = bindingGen.generateTypes(module); + final List genTypes = bindingGen.generateTypes(context); assertTrue(genTypes != null); - assertEquals(genTypes.size(), 10); + assertEquals(13, genTypes.size()); + + int genTypesCount = 0; + int genTOsCount = 0; + for (final Type type : genTypes) { + if (type instanceof GeneratedType) { + genTypesCount++; + } else if (type instanceof GeneratedTransferObject) { + genTOsCount++; + } + } + + assertEquals(10, genTypesCount); + assertEquals(3, genTOsCount); } } diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/list-composite-key.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/list-composite-key.yang new file mode 100644 index 0000000000..333c8bfb60 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/list-composite-key.yang @@ -0,0 +1,63 @@ +module list-composite-key { + yang-version 1; + namespace "urn:composite.key"; + prefix "scd"; + + organization "Cisco"; + + contact "WILL-BE-DEFINED-LATER"; + + description " + This module contains the definitions of elements that creates network + topology i.e. definition of network nodes and links. This module is + not designed to be used solely for network representation. This module + SHOULD be used as base module in defining the network topology. + "; + + revision "2013-02-27" { + reference " WILL BE DEFINED LATER"; + } + + container list-parent-container { + + list composite-key-list { + key "key1 key2"; + + leaf key1 { + type int8; + } + + leaf key2 { + type string; + } + + list inner-list { + key "key1"; + + leaf key1 { + type uint16; + } + + leaf foo { + type int32; + } + } + + leaf foo { + type int32; + } + } + + list no-key-list { + leaf foo { + type int32; + } + + leaf bar { + type decimal64 { + fraction-digits 2; + } + } + } + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java index 36d0fbc28c..9df281fcd3 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java @@ -57,8 +57,7 @@ public class GeneratorJavaFileTest { generator.generateToFile(PATH); // path: test-dir/com/cisco/yang - String[] files = new File(PATH + FS + "com" + FS + "cisco" + FS - + "yang").list(); + String[] files = new File(PATH + FS + "org" + FS + "opendaylight" + FS + "controller" + FS + "gen").list(); List filesList = Arrays.asList(files); assertEquals(3, files.length); diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java index 4abdc99b91..349a342710 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/MethodSignatureBuilder.java @@ -1,11 +1,11 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. +/** + + * + * March 2013 * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2013 by Cisco Systems, Inc. + * All rights reserved. */ - package org.opendaylight.controller.sal.binding.model.api.type.builder; import org.opendaylight.controller.sal.binding.model.api.MethodSignature; diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/package-info.java b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/package-info.java index 2a462a131a..ff2c06e757 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/package-info.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/package-info.java @@ -1,9 +1,9 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. +/** + + * + * March 2013 * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2013 by Cisco Systems, Inc. + * All rights reserved. */ - package org.opendaylight.controller.sal.binding.model.api.type.builder; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/pom.xml b/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/pom.xml index dfa23fae72..58608354d1 100644 --- a/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/pom.xml +++ b/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/pom.xml @@ -18,11 +18,6 @@ binding-generator-impl 1.0 - - org.opendaylight.controller - yang-model-parser-impl - 1.0 - org.opendaylight.controller binding-java-api-generator diff --git a/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/src/main/java/org/opendaylight/controller/Demo.java b/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/src/main/java/org/opendaylight/controller/Demo.java index 6628966489..2d38c7db51 100644 --- a/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/src/main/java/org/opendaylight/controller/Demo.java +++ b/opendaylight/sal/yang-prototype/code-generator/code-generator-demo/src/main/java/org/opendaylight/controller/Demo.java @@ -1,50 +1,50 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller; import java.io.File; -import java.util.Map; - -import org.opendaylight.controller.model.parser.builder.YangModelBuilder; - +import java.util.Set; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl; public class Demo { - public static void main(String[] args) throws Exception { - - String yangFilesDir; - if(args.length > 0) { - yangFilesDir = args[0]; - } else { - yangFilesDir = "src/main/resources"; - } - - File resourceDir = new File(yangFilesDir); - if(!resourceDir.exists()) { - throw new IllegalArgumentException("Specified resource directory does not exists: "+ resourceDir.getAbsolutePath()); - } - - String[] dirList = resourceDir.list(); - String[] absFiles = new String[dirList.length]; - - int i = 0; - for(String fileName : dirList) { - File f = new File(fileName); - absFiles[i] = f.getAbsolutePath(); - i++; - } - - YangModelBuilder builder = new YangModelBuilder(absFiles); - Map builtModules = builder.build(); - - System.out.println("Modules built: "+ builtModules.size()); - } + public static void main(String[] args) throws Exception { + + String yangFilesDir; + if (args.length > 0) { + yangFilesDir = args[0]; + } else { + yangFilesDir = "src/main/resources/demo"; + } + + File resourceDir = new File(yangFilesDir); + if (!resourceDir.exists()) { + throw new IllegalArgumentException( + "Specified resource directory does not exists: " + + resourceDir.getAbsolutePath()); + } + + String[] dirList = resourceDir.list(); + String[] absFiles = new String[dirList.length]; + + int i = 0; + for (String fileName : dirList) { + File abs = new File(resourceDir, fileName); + absFiles[i] = abs.getAbsolutePath(); + i++; + } + + YangModelParserImpl parser = new YangModelParserImpl(); + Set builtModules = parser.parseYangModels(absFiles); + + System.out.println("Modules built: " + builtModules.size()); + } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/pom.xml b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/pom.xml new file mode 100644 index 0000000000..5bfd19d47a --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/pom.xml @@ -0,0 +1,17 @@ + + 4.0.0 + + org.opendaylight.controller + binding-generator + 1.0 + + yang-model-parser-api + + + + org.opendaylight.controller + yang-model-api + 1.0 + + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/YangModelParser.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/YangModelParser.java new file mode 100644 index 0000000000..8faf73e3b4 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/YangModelParser.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.api; + +import java.util.Set; + +import org.opendaylight.controller.model.api.type.UnknownTypeDefinition; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.SchemaContext; + +/** + * Yang Model Parser interface is designed for parsing yang models and + * convert the information to Data Schema Tree. + * + */ +public interface YangModelParser { + + /** + * Parse single Yang model file and return the schema definition of Yang + * module defined in *.Yang file. + * + * @param yangFile + * yang file to parse + * @return the schema definition of Yang module defined in .Yang file. + */ + public Module parseYangModel(final String yangFile); + + /** + * Parse one or more Yang model files and return the definitions of Yang + * modules defined in *.Yang files; + *
+ * This method SHOULD be used if user need to parse multiple yang models + * that are referenced either through import or include statements. + * + * @param yangFiles yang files to parse + * @return Set of Yang Modules + */ + public Set parseYangModels(final String... yangFiles); + + /** + * Creates {@link SchemaContext} from specified Modules. The modules SHOULD + * not contain any unresolved Schema Nodes or Type Definitions. By + * unresolved Schema Nodes or Type Definitions we mean that the Module + * should not contain ANY Schema Nodes that contains + * {@link UnknownTypeDefinition} and all dependencies although via import or + * include definitions are resolved. + * + * @param modules + * Set of Yang Modules + * @return Schema Context instance constructed from whole Set of Modules. + */ + public SchemaContext resolveSchemaContext(final Set modules); +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/package-info.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/package-info.java new file mode 100644 index 0000000000..2e8a029f85 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-api/src/main/java/org/opendaylight/controller/yang/model/parser/api/package-info.java @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.api; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/pom.xml b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/pom.xml index 184abf03ee..e04cb701ee 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/pom.xml +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/pom.xml @@ -18,6 +18,11 @@ yang-model-api 1.0
+ + org.opendaylight.controller + yang-model-parser-api + 1.0 + org.opendaylight.controller yang-model-util @@ -50,5 +55,5 @@ 1.8.4 - - \ No newline at end of file + + diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangLexer.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangLexer.java index 0fbfc1c6bd..4f7769eaf9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangLexer.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangLexer.java @@ -7,21 +7,21 @@ */ package org.opendaylight.controller.antlrv4.code.gen; -import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.Lexer; -import org.antlr.v4.runtime.RuleContext; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNSimulator; -import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; @SuppressWarnings({ "all", "warnings", "unchecked", "unused", "cast" }) public class YangLexer extends Lexer { protected static final DFA[] _decisionToDFA; protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int SEMICOLON = 1, LEFT_BRACE = 2, RIGHT_BRACE = 3, - PLUS = 4, WS = 5, LINE_COMMENT = 6, BLOCK_COMMENT = 7, + PLUS = 4, WS = 5, LINE_COMMENT = 6, START_BLOCK_COMMENT = 7, YIN_ELEMENT_KEYWORD = 8, YANG_VERSION_KEYWORD = 9, WHEN_KEYWORD = 10, VALUE_KEYWORD = 11, USES_KEYWORD = 12, UNITS_KEYWORD = 13, UNIQUE_KEYWORD = 14, TYPEDEF_KEYWORD = 15, @@ -48,12 +48,14 @@ public class YangLexer extends Lexer { CHOICE_KEYWORD = 65, CASE_KEYWORD = 66, BIT_KEYWORD = 67, BELONGS_TO_KEYWORD = 68, BASE_KEYWORD = 69, AUGMENT_KEYWORD = 70, ARGUMENT_KEYWORD = 71, ANYXML_KEYWORD = 72, IDENTIFIER = 73, - STRING = 74, S = 75; + STRING = 74, S = 75, END_BLOCK_COMMENT = 76; public static final int VALUE_MODE = 1; - public static String[] modeNames = { "DEFAULT_MODE", "VALUE_MODE" }; + public static final int BLOCK_COMMENT_MODE = 2; + public static String[] modeNames = { "DEFAULT_MODE", "VALUE_MODE", + "BLOCK_COMMENT_MODE" }; public static final String[] tokenNames = { "", "SEMICOLON", - "LEFT_BRACE", "'}'", "'+'", "WS", "LINE_COMMENT", "BLOCK_COMMENT", + "LEFT_BRACE", "'}'", "'+'", "WS", "LINE_COMMENT", "'/*'", "'yin-element'", "'yang-version'", "'when'", "'value'", "'uses'", "'units'", "'unique'", "'typedef'", "'type'", "'submodule'", "'status'", "'rpc'", "'revision-date'", "'revision'", @@ -69,9 +71,9 @@ public class YangLexer extends Lexer { "'description'", "'default'", "'container'", "'contact'", "'config'", "'choice'", "'case'", "'bit'", "'belongs-to'", "'base'", "'augment'", "'argument'", "'anyxml'", "IDENTIFIER", - "STRING", "S" }; + "STRING", "S", "'*/'" }; public static final String[] ruleNames = { "PLUS", "WS", "LINE_COMMENT", - "BLOCK_COMMENT", "SEMICOLON", "LEFT_BRACE", "RIGHT_BRACE", + "START_BLOCK_COMMENT", "SEMICOLON", "LEFT_BRACE", "RIGHT_BRACE", "YIN_ELEMENT_KEYWORD", "YANG_VERSION_KEYWORD", "WHEN_KEYWORD", "VALUE_KEYWORD", "USES_KEYWORD", "UNITS_KEYWORD", "UNIQUE_KEYWORD", "TYPEDEF_KEYWORD", "TYPE_KEYWORD", "SUBMODULE_KEYWORD", @@ -95,7 +97,7 @@ public class YangLexer extends Lexer { "BASE_KEYWORD", "AUGMENT_KEYWORD", "ARGUMENT_KEYWORD", "ANYXML_KEYWORD", "IDENTIFIER", "ESC", "UNICODE", "HEX", "END_IDENTIFIER_SEMICOLON", "END_IDENTIFIER_LEFT_BRACE", - "SUB_STRING", "STRING", "S" }; + "SUB_STRING", "STRING", "S", "END_BLOCK_COMMENT", "BLOCK_COMMENT" }; public YangLexer(CharStream input) { super(input); @@ -144,7 +146,7 @@ public class YangLexer extends Lexer { break; case 3: - BLOCK_COMMENT_action((RuleContext) _localctx, actionIndex); + START_BLOCK_COMMENT_action((RuleContext) _localctx, actionIndex); break; case 4: @@ -433,6 +435,14 @@ public class YangLexer extends Lexer { case 80: S_action((RuleContext) _localctx, actionIndex); break; + + case 81: + END_BLOCK_COMMENT_action((RuleContext) _localctx, actionIndex); + break; + + case 82: + BLOCK_COMMENT_action((RuleContext) _localctx, actionIndex); + break; } } @@ -667,7 +677,8 @@ public class YangLexer extends Lexer { private void BLOCK_COMMENT_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { - case 3: + case 76: + more(); skip(); break; } @@ -856,6 +867,16 @@ public class YangLexer extends Lexer { } } + private void START_BLOCK_COMMENT_action(RuleContext _localctx, + int actionIndex) { + switch (actionIndex) { + case 3: + pushMode(BLOCK_COMMENT_MODE); + skip(); + break; + } + } + private void WS_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { case 1: @@ -1006,6 +1027,15 @@ public class YangLexer extends Lexer { } } + private void END_BLOCK_COMMENT_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 75: + popMode(); + skip(); + break; + } + } + private void BASE_KEYWORD_action(RuleContext _localctx, int actionIndex) { switch (actionIndex) { case 66: @@ -1055,322 +1085,323 @@ public class YangLexer extends Lexer { } } - public static final String _serializedATN = "\2\4M\u03bf\b\1\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4" - + "\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4" - + "\20\t\20\4\21\t\21\4\22\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4" - + "\27\t\27\4\30\t\30\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4" - + "\36\t\36\4\37\t\37\4 \t \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4\'\t\'" - + "\4(\t(\4)\t)\4*\t*\4+\t+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61\t\61\4" - + "\62\t\62\4\63\t\63\4\64\t\64\4\65\t\65\4\66\t\66\4\67\t\67\48\t8\49\t" - + "9\4:\t:\4;\t;\4<\t<\4=\t=\4>\t>\4?\t?\4@\t@\4A\tA\4B\tB\4C\tC\4D\tD\4" - + "E\tE\4F\tF\4G\tG\4H\tH\4I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\4O\tO\4P\t" - + "P\4Q\tQ\4R\tR\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\4\3\4\3\4\3\4\7\4\u00b3" - + "\n\4\f\4\16\4\u00b6\13\4\3\4\3\4\3\5\3\5\3\5\3\5\7\5\u00be\n\5\f\5\16" - + "\5\u00c1\13\5\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\b" - + "\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3" - + "\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3" - + "\13\3\13\3\13\3\13\3\13\3\f\3\f\3\f\3\f\3\f\3\f\3\f\3\f\3\r\3\r\3\r\3" - + "\r\3\r\3\r\3\r\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17" - + "\3\17\3\17\3\17\3\17\3\17\3\17\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20" - + "\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22" - + "\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\23\3\23\3\23\3\23\3\23\3\23\3\23" - + "\3\23\3\23\3\24\3\24\3\24\3\24\3\24\3\24\3\25\3\25\3\25\3\25\3\25\3\25" - + "\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\26\3\26\3\26\3\26" - + "\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3\27\3\27\3\27\3\27\3\27\3\27\3\27" - + "\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\30\3\30" - + "\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3\31\3\31\3\31\3\31\3\31\3\31\3\31" - + "\3\31\3\31\3\31\3\31\3\31\3\32\3\32\3\32\3\32\3\32\3\32\3\32\3\32\3\33" - + "\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3\34\3\34\3\34\3\34" - + "\3\34\3\34\3\34\3\34\3\34\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35" - + "\3\35\3\35\3\36\3\36\3\36\3\36\3\36\3\36\3\36\3\36\3\36\3\36\3\37\3\37" - + "\3\37\3\37\3\37\3\37\3\37\3 \3 \3 \3 \3 \3 \3 \3!\3!\3!\3!\3!\3!\3!\3" - + "!\3!\3!\3!\3!\3!\3!\3!\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"" - + "\3\"\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3#\3$\3$\3$\3$\3$\3$\3" - + "$\3$\3$\3$\3$\3$\3%\3%\3%\3%\3%\3%\3%\3&\3&\3&\3&\3&\3&\3&\3&\3&\3\'\3" - + "\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3(\3(\3(\3(\3(" - + "\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3*" - + "\3*\3*\3*\3*\3*\3*\3+\3+\3+\3+\3+\3+\3+\3+\3+\3,\3,\3,\3,\3,\3,\3,\3," - + "\3,\3,\3,\3,\3-\3-\3-\3-\3-\3-\3-\3.\3.\3.\3.\3.\3.\3/\3/\3/\3/\3/\3/" - + "\3\60\3\60\3\60\3\60\3\60\3\60\3\60\3\60\3\60\3\60\3\61\3\61\3\61\3\61" - + "\3\61\3\61\3\61\3\61\3\61\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62" - + "\3\62\3\62\3\62\3\62\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\63" - + "\3\63\3\64\3\64\3\64\3\64\3\64\3\64\3\64\3\64\3\64\3\64\3\64\3\65\3\65" - + "\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65" - + "\3\65\3\65\3\66\3\66\3\66\3\66\3\66\3\66\3\66\3\66\3\66\3\66\3\67\3\67" - + "\3\67\3\67\3\67\3\67\3\67\3\67\3\67\3\67\38\38\38\38\38\38\38\38\38\3" - + "8\38\38\39\39\39\39\39\39\39\39\39\39\39\39\3:\3:\3:\3:\3:\3:\3:\3:\3" - + ":\3:\3:\3:\3:\3:\3:\3:\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3" - + ";\3<\3<\3<\3<\3<\3<\3<\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3>\3" - + ">\3>\3>\3>\3>\3>\3>\3>\3>\3?\3?\3?\3?\3?\3?\3?\3?\3?\3?\3?\3?\3@\3@\3" - + "@\3@\3@\3@\3@\3@\3@\3@\3A\3A\3A\3A\3A\3A\3A\3A\3A\3B\3B\3B\3B\3B\3B\3" - + "B\3B\3B\3C\3C\3C\3C\3C\3C\3C\3D\3D\3D\3D\3D\3D\3E\3E\3E\3E\3E\3E\3E\3" - + "E\3E\3E\3E\3E\3E\3F\3F\3F\3F\3F\3F\3F\3G\3G\3G\3G\3G\3G\3G\3G\3G\3G\3" - + "H\3H\3H\3H\3H\3H\3H\3H\3H\3H\3H\3I\3I\3I\3I\3I\3I\3I\3I\3I\3J\3J\7J\u0382" - + "\nJ\fJ\16J\u0385\13J\3J\3J\3K\3K\3K\5K\u038c\nK\3L\3L\3L\3L\3L\3L\3M\3" - + "M\3N\3N\3N\3N\3O\3O\3O\3O\3P\3P\3P\7P\u03a1\nP\fP\16P\u03a4\13P\3P\3P" - + "\3P\3P\7P\u03aa\nP\fP\16P\u03ad\13P\3P\5P\u03b0\nP\3Q\3Q\6Q\u03b4\nQ\r" - + "Q\16Q\u03b5\5Q\u03b8\nQ\3Q\3Q\3R\3R\3R\3R\2S\4\6\2\6\7\3\b\b\4\n\t\5\f" - + "\3\6\16\4\7\20\5\b\22\n\t\24\13\n\26\f\13\30\r\f\32\16\r\34\17\16\36\20" - + "\17 \21\20\"\22\21$\23\22&\24\23(\25\24*\26\25,\27\26.\30\27\60\31\30" - + "\62\32\31\64\33\32\66\34\338\35\34:\36\35<\37\36> \37@!\1B\" D#!F$\"H" - + "%#J&$L\'%N(&P)\'R*(T+)V,*X-+Z.,\\/-^\60\1`\61.b\62/d\63\60f\64\61h\65" - + "\62j\66\63l\67\64n8\65p9\66r:\67t;8v<9x=:z>;|?<~@=\u0080A>\u0082B?\u0084" - + "C@\u0086DA\u0088EB\u008aFC\u008cGD\u008eHE\u0090IF\u0092JG\u0094KH\u0096" - + "\2\1\u0098\2\1\u009a\2\1\u009c\2I\u009e\2J\u00a0\2\1\u00a2LK\u00a4ML\4" - + "\2\3\r\5\13\f\17\17\"\"\4\f\f\17\17\2\6/;C\\aac|\7/\60\62\3\2\2\2\2@\3\2\2\2\2B\3\2\2\2\2D\3\2\2\2\2F\3\2\2\2\2H" - + "\3\2\2\2\2J\3\2\2\2\2L\3\2\2\2\2N\3\2\2\2\2P\3\2\2\2\2R\3\2\2\2\2T\3\2" - + "\2\2\2V\3\2\2\2\2X\3\2\2\2\2Z\3\2\2\2\2\\\3\2\2\2\2^\3\2\2\2\2`\3\2\2" - + "\2\2b\3\2\2\2\2d\3\2\2\2\2f\3\2\2\2\2h\3\2\2\2\2j\3\2\2\2\2l\3\2\2\2\2" - + "n\3\2\2\2\2p\3\2\2\2\2r\3\2\2\2\2t\3\2\2\2\2v\3\2\2\2\2x\3\2\2\2\2z\3" - + "\2\2\2\2|\3\2\2\2\2~\3\2\2\2\2\u0080\3\2\2\2\2\u0082\3\2\2\2\2\u0084\3" - + "\2\2\2\2\u0086\3\2\2\2\2\u0088\3\2\2\2\2\u008a\3\2\2\2\2\u008c\3\2\2\2" - + "\2\u008e\3\2\2\2\2\u0090\3\2\2\2\2\u0092\3\2\2\2\2\u0094\3\2\2\2\3\u009c" - + "\3\2\2\2\3\u009e\3\2\2\2\3\u00a2\3\2\2\2\3\u00a4\3\2\2\2\4\u00a6\3\2\2" - + "\2\6\u00aa\3\2\2\2\b\u00ae\3\2\2\2\n\u00b9\3\2\2\2\f\u00c7\3\2\2\2\16" - + "\u00cb\3\2\2\2\20\u00cf\3\2\2\2\22\u00d3\3\2\2\2\24\u00e1\3\2\2\2\26\u00f0" - + "\3\2\2\2\30\u00f7\3\2\2\2\32\u00ff\3\2\2\2\34\u0106\3\2\2\2\36\u010e\3" - + "\2\2\2 \u0117\3\2\2\2\"\u0121\3\2\2\2$\u0128\3\2\2\2&\u0134\3\2\2\2(\u013d" - + "\3\2\2\2*\u0143\3\2\2\2,\u0153\3\2\2\2.\u015e\3\2\2\2\60\u0171\3\2\2\2" - + "\62\u017a\3\2\2\2\64\u0186\3\2\2\2\66\u018e\3\2\2\28\u0199\3\2\2\2:\u01a2" - + "\3\2\2\2<\u01ad\3\2\2\2>\u01b7\3\2\2\2@\u01be\3\2\2\2B\u01c5\3\2\2\2D" - + "\u01d4\3\2\2\2F\u01e1\3\2\2\2H\u01f0\3\2\2\2J\u01fc\3\2\2\2L\u0203\3\2" - + "\2\2N\u020c\3\2\2\2P\u021b\3\2\2\2R\u022a\3\2\2\2T\u0236\3\2\2\2V\u023d" - + "\3\2\2\2X\u0246\3\2\2\2Z\u0252\3\2\2\2\\\u0259\3\2\2\2^\u025f\3\2\2\2" - + "`\u0265\3\2\2\2b\u026f\3\2\2\2d\u0278\3\2\2\2f\u0285\3\2\2\2h\u0290\3" - + "\2\2\2j\u029b\3\2\2\2l\u02ad\3\2\2\2n\u02b7\3\2\2\2p\u02c1\3\2\2\2r\u02cd" - + "\3\2\2\2t\u02d9\3\2\2\2v\u02e9\3\2\2\2x\u02f9\3\2\2\2z\u0300\3\2\2\2|" - + "\u030e\3\2\2\2~\u0318\3\2\2\2\u0080\u0324\3\2\2\2\u0082\u032e\3\2\2\2" - + "\u0084\u0337\3\2\2\2\u0086\u0340\3\2\2\2\u0088\u0347\3\2\2\2\u008a\u034d" - + "\3\2\2\2\u008c\u035a\3\2\2\2\u008e\u0361\3\2\2\2\u0090\u036b\3\2\2\2\u0092" - + "\u0376\3\2\2\2\u0094\u037f\3\2\2\2\u0096\u0388\3\2\2\2\u0098\u038d\3\2" - + "\2\2\u009a\u0393\3\2\2\2\u009c\u0395\3\2\2\2\u009e\u0399\3\2\2\2\u00a0" - + "\u03af\3\2\2\2\u00a2\u03b7\3\2\2\2\u00a4\u03bb\3\2\2\2\u00a6\u00a7\7-" - + "\2\2\u00a7\u00a8\3\2\2\2\u00a8\u00a9\b\2\2\2\u00a9\5\3\2\2\2\u00aa\u00ab" - + "\t\2\2\2\u00ab\u00ac\3\2\2\2\u00ac\u00ad\b\3\3\2\u00ad\7\3\2\2\2\u00ae" - + "\u00af\7\61\2\2\u00af\u00b0\7\61\2\2\u00b0\u00b4\3\2\2\2\u00b1\u00b3\n" - + "\3\2\2\u00b2\u00b1\3\2\2\2\u00b3\u00b6\3\2\2\2\u00b4\u00b2\3\2\2\2\u00b4" - + "\u00b5\3\2\2\2\u00b5\u00b7\3\2\2\2\u00b6\u00b4\3\2\2\2\u00b7\u00b8\b\4" - + "\4\2\u00b8\t\3\2\2\2\u00b9\u00ba\7\61\2\2\u00ba\u00bb\7,\2\2\u00bb\u00bf" - + "\3\2\2\2\u00bc\u00be\n\4\2\2\u00bd\u00bc\3\2\2\2\u00be\u00c1\3\2\2\2\u00bf" - + "\u00bd\3\2\2\2\u00bf\u00c0\3\2\2\2\u00c0\u00c2\3\2\2\2\u00c1\u00bf\3\2" - + "\2\2\u00c2\u00c3\7,\2\2\u00c3\u00c4\7\61\2\2\u00c4\u00c5\3\2\2\2\u00c5" - + "\u00c6\b\5\5\2\u00c6\13\3\2\2\2\u00c7\u00c8\7=\2\2\u00c8\u00c9\3\2\2\2" - + "\u00c9\u00ca\b\6\6\2\u00ca\r\3\2\2\2\u00cb\u00cc\7}\2\2\u00cc\u00cd\3" - + "\2\2\2\u00cd\u00ce\b\7\7\2\u00ce\17\3\2\2\2\u00cf\u00d0\7\177\2\2\u00d0" - + "\u00d1\3\2\2\2\u00d1\u00d2\b\b\b\2\u00d2\21\3\2\2\2\u00d3\u00d4\7{\2\2" - + "\u00d4\u00d5\7k\2\2\u00d5\u00d6\7p\2\2\u00d6\u00d7\7/\2\2\u00d7\u00d8" - + "\7g\2\2\u00d8\u00d9\7n\2\2\u00d9\u00da\7g\2\2\u00da\u00db\7o\2\2\u00db" - + "\u00dc\7g\2\2\u00dc\u00dd\7p\2\2\u00dd\u00de\7v\2\2\u00de\u00df\3\2\2" - + "\2\u00df\u00e0\b\t\t\2\u00e0\23\3\2\2\2\u00e1\u00e2\7{\2\2\u00e2\u00e3" - + "\7c\2\2\u00e3\u00e4\7p\2\2\u00e4\u00e5\7i\2\2\u00e5\u00e6\7/\2\2\u00e6" - + "\u00e7\7x\2\2\u00e7\u00e8\7g\2\2\u00e8\u00e9\7t\2\2\u00e9\u00ea\7u\2\2" - + "\u00ea\u00eb\7k\2\2\u00eb\u00ec\7q\2\2\u00ec\u00ed\7p\2\2\u00ed\u00ee" - + "\3\2\2\2\u00ee\u00ef\b\n\n\2\u00ef\25\3\2\2\2\u00f0\u00f1\7y\2\2\u00f1" - + "\u00f2\7j\2\2\u00f2\u00f3\7g\2\2\u00f3\u00f4\7p\2\2\u00f4\u00f5\3\2\2" - + "\2\u00f5\u00f6\b\13\13\2\u00f6\27\3\2\2\2\u00f7\u00f8\7x\2\2\u00f8\u00f9" - + "\7c\2\2\u00f9\u00fa\7n\2\2\u00fa\u00fb\7w\2\2\u00fb\u00fc\7g\2\2\u00fc" - + "\u00fd\3\2\2\2\u00fd\u00fe\b\f\f\2\u00fe\31\3\2\2\2\u00ff\u0100\7w\2\2" - + "\u0100\u0101\7u\2\2\u0101\u0102\7g\2\2\u0102\u0103\7u\2\2\u0103\u0104" - + "\3\2\2\2\u0104\u0105\b\r\r\2\u0105\33\3\2\2\2\u0106\u0107\7w\2\2\u0107" - + "\u0108\7p\2\2\u0108\u0109\7k\2\2\u0109\u010a\7v\2\2\u010a\u010b\7u\2\2" - + "\u010b\u010c\3\2\2\2\u010c\u010d\b\16\16\2\u010d\35\3\2\2\2\u010e\u010f" - + "\7w\2\2\u010f\u0110\7p\2\2\u0110\u0111\7k\2\2\u0111\u0112\7s\2\2\u0112" - + "\u0113\7w\2\2\u0113\u0114\7g\2\2\u0114\u0115\3\2\2\2\u0115\u0116\b\17" - + "\17\2\u0116\37\3\2\2\2\u0117\u0118\7v\2\2\u0118\u0119\7{\2\2\u0119\u011a" - + "\7r\2\2\u011a\u011b\7g\2\2\u011b\u011c\7f\2\2\u011c\u011d\7g\2\2\u011d" - + "\u011e\7h\2\2\u011e\u011f\3\2\2\2\u011f\u0120\b\20\20\2\u0120!\3\2\2\2" - + "\u0121\u0122\7v\2\2\u0122\u0123\7{\2\2\u0123\u0124\7r\2\2\u0124\u0125" - + "\7g\2\2\u0125\u0126\3\2\2\2\u0126\u0127\b\21\21\2\u0127#\3\2\2\2\u0128" - + "\u0129\7u\2\2\u0129\u012a\7w\2\2\u012a\u012b\7d\2\2\u012b\u012c\7o\2\2" - + "\u012c\u012d\7q\2\2\u012d\u012e\7f\2\2\u012e\u012f\7w\2\2\u012f\u0130" - + "\7n\2\2\u0130\u0131\7g\2\2\u0131\u0132\3\2\2\2\u0132\u0133\b\22\22\2\u0133" - + "%\3\2\2\2\u0134\u0135\7u\2\2\u0135\u0136\7v\2\2\u0136\u0137\7c\2\2\u0137" - + "\u0138\7v\2\2\u0138\u0139\7w\2\2\u0139\u013a\7u\2\2\u013a\u013b\3\2\2" - + "\2\u013b\u013c\b\23\23\2\u013c\'\3\2\2\2\u013d\u013e\7t\2\2\u013e\u013f" - + "\7r\2\2\u013f\u0140\7e\2\2\u0140\u0141\3\2\2\2\u0141\u0142\b\24\24\2\u0142" - + ")\3\2\2\2\u0143\u0144\7t\2\2\u0144\u0145\7g\2\2\u0145\u0146\7x\2\2\u0146" - + "\u0147\7k\2\2\u0147\u0148\7u\2\2\u0148\u0149\7k\2\2\u0149\u014a\7q\2\2" - + "\u014a\u014b\7p\2\2\u014b\u014c\7/\2\2\u014c\u014d\7f\2\2\u014d\u014e" - + "\7c\2\2\u014e\u014f\7v\2\2\u014f\u0150\7g\2\2\u0150\u0151\3\2\2\2\u0151" - + "\u0152\b\25\25\2\u0152+\3\2\2\2\u0153\u0154\7t\2\2\u0154\u0155\7g\2\2" - + "\u0155\u0156\7x\2\2\u0156\u0157\7k\2\2\u0157\u0158\7u\2\2\u0158\u0159" - + "\7k\2\2\u0159\u015a\7q\2\2\u015a\u015b\7p\2\2\u015b\u015c\3\2\2\2\u015c" - + "\u015d\b\26\26\2\u015d-\3\2\2\2\u015e\u015f\7t\2\2\u015f\u0160\7g\2\2" - + "\u0160\u0161\7s\2\2\u0161\u0162\7w\2\2\u0162\u0163\7k\2\2\u0163\u0164" - + "\7t\2\2\u0164\u0165\7g\2\2\u0165\u0166\7/\2\2\u0166\u0167\7k\2\2\u0167" - + "\u0168\7p\2\2\u0168\u0169\7u\2\2\u0169\u016a\7v\2\2\u016a\u016b\7c\2\2" - + "\u016b\u016c\7p\2\2\u016c\u016d\7e\2\2\u016d\u016e\7g\2\2\u016e\u016f" - + "\3\2\2\2\u016f\u0170\b\27\27\2\u0170/\3\2\2\2\u0171\u0172\7t\2\2\u0172" - + "\u0173\7g\2\2\u0173\u0174\7h\2\2\u0174\u0175\7k\2\2\u0175\u0176\7p\2\2" - + "\u0176\u0177\7g\2\2\u0177\u0178\3\2\2\2\u0178\u0179\b\30\30\2\u0179\61" - + "\3\2\2\2\u017a\u017b\7t\2\2\u017b\u017c\7g\2\2\u017c\u017d\7h\2\2\u017d" - + "\u017e\7g\2\2\u017e\u017f\7t\2\2\u017f\u0180\7g\2\2\u0180\u0181\7p\2\2" - + "\u0181\u0182\7e\2\2\u0182\u0183\7g\2\2\u0183\u0184\3\2\2\2\u0184\u0185" - + "\b\31\31\2\u0185\63\3\2\2\2\u0186\u0187\7t\2\2\u0187\u0188\7c\2\2\u0188" - + "\u0189\7p\2\2\u0189\u018a\7i\2\2\u018a\u018b\7g\2\2\u018b\u018c\3\2\2" - + "\2\u018c\u018d\b\32\32\2\u018d\65\3\2\2\2\u018e\u018f\7r\2\2\u018f\u0190" - + "\7t\2\2\u0190\u0191\7g\2\2\u0191\u0192\7u\2\2\u0192\u0193\7g\2\2\u0193" - + "\u0194\7p\2\2\u0194\u0195\7e\2\2\u0195\u0196\7g\2\2\u0196\u0197\3\2\2" - + "\2\u0197\u0198\b\33\33\2\u0198\67\3\2\2\2\u0199\u019a\7r\2\2\u019a\u019b" - + "\7t\2\2\u019b\u019c\7g\2\2\u019c\u019d\7h\2\2\u019d\u019e\7k\2\2\u019e" - + "\u019f\7z\2\2\u019f\u01a0\3\2\2\2\u01a0\u01a1\b\34\34\2\u01a19\3\2\2\2" - + "\u01a2\u01a3\7r\2\2\u01a3\u01a4\7q\2\2\u01a4\u01a5\7u\2\2\u01a5\u01a6" - + "\7k\2\2\u01a6\u01a7\7v\2\2\u01a7\u01a8\7k\2\2\u01a8\u01a9\7q\2\2\u01a9" - + "\u01aa\7p\2\2\u01aa\u01ab\3\2\2\2\u01ab\u01ac\b\35\35\2\u01ac;\3\2\2\2" - + "\u01ad\u01ae\7r\2\2\u01ae\u01af\7c\2\2\u01af\u01b0\7v\2\2\u01b0\u01b1" - + "\7v\2\2\u01b1\u01b2\7g\2\2\u01b2\u01b3\7t\2\2\u01b3\u01b4\7p\2\2\u01b4" - + "\u01b5\3\2\2\2\u01b5\u01b6\b\36\36\2\u01b6=\3\2\2\2\u01b7\u01b8\7r\2\2" - + "\u01b8\u01b9\7c\2\2\u01b9\u01ba\7v\2\2\u01ba\u01bb\7j\2\2\u01bb\u01bc" - + "\3\2\2\2\u01bc\u01bd\b\37\37\2\u01bd?\3\2\2\2\u01be\u01bf\7q\2\2\u01bf" - + "\u01c0\7w\2\2\u01c0\u01c1\7v\2\2\u01c1\u01c2\7r\2\2\u01c2\u01c3\7w\2\2" - + "\u01c3\u01c4\7v\2\2\u01c4A\3\2\2\2\u01c5\u01c6\7q\2\2\u01c6\u01c7\7t\2" - + "\2\u01c7\u01c8\7i\2\2\u01c8\u01c9\7c\2\2\u01c9\u01ca\7p\2\2\u01ca\u01cb" - + "\7k\2\2\u01cb\u01cc\7|\2\2\u01cc\u01cd\7c\2\2\u01cd\u01ce\7v\2\2\u01ce" - + "\u01cf\7k\2\2\u01cf\u01d0\7q\2\2\u01d0\u01d1\7p\2\2\u01d1\u01d2\3\2\2" - + "\2\u01d2\u01d3\b! \2\u01d3C\3\2\2\2\u01d4\u01d5\7q\2\2\u01d5\u01d6\7t" - + "\2\2\u01d6\u01d7\7f\2\2\u01d7\u01d8\7g\2\2\u01d8\u01d9\7t\2\2\u01d9\u01da" - + "\7g\2\2\u01da\u01db\7f\2\2\u01db\u01dc\7/\2\2\u01dc\u01dd\7d\2\2\u01dd" - + "\u01de\7{\2\2\u01de\u01df\3\2\2\2\u01df\u01e0\b\"!\2\u01e0E\3\2\2\2\u01e1" - + "\u01e2\7p\2\2\u01e2\u01e3\7q\2\2\u01e3\u01e4\7v\2\2\u01e4\u01e5\7k\2\2" - + "\u01e5\u01e6\7h\2\2\u01e6\u01e7\7k\2\2\u01e7\u01e8\7e\2\2\u01e8\u01e9" - + "\7c\2\2\u01e9\u01ea\7v\2\2\u01ea\u01eb\7k\2\2\u01eb\u01ec\7q\2\2\u01ec" - + "\u01ed\7p\2\2\u01ed\u01ee\3\2\2\2\u01ee\u01ef\b#\"\2\u01efG\3\2\2\2\u01f0" - + "\u01f1\7p\2\2\u01f1\u01f2\7c\2\2\u01f2\u01f3\7o\2\2\u01f3\u01f4\7g\2\2" - + "\u01f4\u01f5\7u\2\2\u01f5\u01f6\7r\2\2\u01f6\u01f7\7c\2\2\u01f7\u01f8" - + "\7e\2\2\u01f8\u01f9\7g\2\2\u01f9\u01fa\3\2\2\2\u01fa\u01fb\b$#\2\u01fb" - + "I\3\2\2\2\u01fc\u01fd\7o\2\2\u01fd\u01fe\7w\2\2\u01fe\u01ff\7u\2\2\u01ff" - + "\u0200\7v\2\2\u0200\u0201\3\2\2\2\u0201\u0202\b%$\2\u0202K\3\2\2\2\u0203" - + "\u0204\7o\2\2\u0204\u0205\7q\2\2\u0205\u0206\7f\2\2\u0206\u0207\7w\2\2" - + "\u0207\u0208\7n\2\2\u0208\u0209\7g\2\2\u0209\u020a\3\2\2\2\u020a\u020b" - + "\b&%\2\u020bM\3\2\2\2\u020c\u020d\7o\2\2\u020d\u020e\7k\2\2\u020e\u020f" - + "\7p\2\2\u020f\u0210\7/\2\2\u0210\u0211\7g\2\2\u0211\u0212\7n\2\2\u0212" - + "\u0213\7g\2\2\u0213\u0214\7o\2\2\u0214\u0215\7g\2\2\u0215\u0216\7p\2\2" - + "\u0216\u0217\7v\2\2\u0217\u0218\7u\2\2\u0218\u0219\3\2\2\2\u0219\u021a" - + "\b\'&\2\u021aO\3\2\2\2\u021b\u021c\7o\2\2\u021c\u021d\7c\2\2\u021d\u021e" - + "\7z\2\2\u021e\u021f\7/\2\2\u021f\u0220\7g\2\2\u0220\u0221\7n\2\2\u0221" - + "\u0222\7g\2\2\u0222\u0223\7o\2\2\u0223\u0224\7g\2\2\u0224\u0225\7p\2\2" - + "\u0225\u0226\7v\2\2\u0226\u0227\7u\2\2\u0227\u0228\3\2\2\2\u0228\u0229" - + "\b(\'\2\u0229Q\3\2\2\2\u022a\u022b\7o\2\2\u022b\u022c\7c\2\2\u022c\u022d" - + "\7p\2\2\u022d\u022e\7f\2\2\u022e\u022f\7c\2\2\u022f\u0230\7v\2\2\u0230" - + "\u0231\7q\2\2\u0231\u0232\7t\2\2\u0232\u0233\7{\2\2\u0233\u0234\3\2\2" - + "\2\u0234\u0235\b)(\2\u0235S\3\2\2\2\u0236\u0237\7n\2\2\u0237\u0238\7k" - + "\2\2\u0238\u0239\7u\2\2\u0239\u023a\7v\2\2\u023a\u023b\3\2\2\2\u023b\u023c" - + "\b*)\2\u023cU\3\2\2\2\u023d\u023e\7n\2\2\u023e\u023f\7g\2\2\u023f\u0240" - + "\7p\2\2\u0240\u0241\7i\2\2\u0241\u0242\7v\2\2\u0242\u0243\7j\2\2\u0243" - + "\u0244\3\2\2\2\u0244\u0245\b+*\2\u0245W\3\2\2\2\u0246\u0247\7n\2\2\u0247" - + "\u0248\7g\2\2\u0248\u0249\7c\2\2\u0249\u024a\7h\2\2\u024a\u024b\7/\2\2" - + "\u024b\u024c\7n\2\2\u024c\u024d\7k\2\2\u024d\u024e\7u\2\2\u024e\u024f" - + "\7v\2\2\u024f\u0250\3\2\2\2\u0250\u0251\b,+\2\u0251Y\3\2\2\2\u0252\u0253" - + "\7n\2\2\u0253\u0254\7g\2\2\u0254\u0255\7c\2\2\u0255\u0256\7h\2\2\u0256" - + "\u0257\3\2\2\2\u0257\u0258\b-,\2\u0258[\3\2\2\2\u0259\u025a\7m\2\2\u025a" - + "\u025b\7g\2\2\u025b\u025c\7{\2\2\u025c\u025d\3\2\2\2\u025d\u025e\b.-\2" - + "\u025e]\3\2\2\2\u025f\u0260\7k\2\2\u0260\u0261\7p\2\2\u0261\u0262\7r\2" - + "\2\u0262\u0263\7w\2\2\u0263\u0264\7v\2\2\u0264_\3\2\2\2\u0265\u0266\7" - + "k\2\2\u0266\u0267\7p\2\2\u0267\u0268\7e\2\2\u0268\u0269\7n\2\2\u0269\u026a" - + "\7w\2\2\u026a\u026b\7f\2\2\u026b\u026c\7g\2\2\u026c\u026d\3\2\2\2\u026d" - + "\u026e\b\60.\2\u026ea\3\2\2\2\u026f\u0270\7k\2\2\u0270\u0271\7o\2\2\u0271" - + "\u0272\7r\2\2\u0272\u0273\7q\2\2\u0273\u0274\7t\2\2\u0274\u0275\7v\2\2" - + "\u0275\u0276\3\2\2\2\u0276\u0277\b\61/\2\u0277c\3\2\2\2\u0278\u0279\7" - + "k\2\2\u0279\u027a\7h\2\2\u027a\u027b\7/\2\2\u027b\u027c\7h\2\2\u027c\u027d" - + "\7g\2\2\u027d\u027e\7c\2\2\u027e\u027f\7v\2\2\u027f\u0280\7w\2\2\u0280" - + "\u0281\7t\2\2\u0281\u0282\7g\2\2\u0282\u0283\3\2\2\2\u0283\u0284\b\62" - + "\60\2\u0284e\3\2\2\2\u0285\u0286\7k\2\2\u0286\u0287\7f\2\2\u0287\u0288" - + "\7g\2\2\u0288\u0289\7p\2\2\u0289\u028a\7v\2\2\u028a\u028b\7k\2\2\u028b" - + "\u028c\7v\2\2\u028c\u028d\7{\2\2\u028d\u028e\3\2\2\2\u028e\u028f\b\63" - + "\61\2\u028fg\3\2\2\2\u0290\u0291\7i\2\2\u0291\u0292\7t\2\2\u0292\u0293" - + "\7q\2\2\u0293\u0294\7w\2\2\u0294\u0295\7r\2\2\u0295\u0296\7k\2\2\u0296" - + "\u0297\7p\2\2\u0297\u0298\7i\2\2\u0298\u0299\3\2\2\2\u0299\u029a\b\64" - + "\62\2\u029ai\3\2\2\2\u029b\u029c\7h\2\2\u029c\u029d\7t\2\2\u029d\u029e" - + "\7c\2\2\u029e\u029f\7e\2\2\u029f\u02a0\7v\2\2\u02a0\u02a1\7k\2\2\u02a1" - + "\u02a2\7q\2\2\u02a2\u02a3\7p\2\2\u02a3\u02a4\7/\2\2\u02a4\u02a5\7f\2\2" - + "\u02a5\u02a6\7k\2\2\u02a6\u02a7\7i\2\2\u02a7\u02a8\7k\2\2\u02a8\u02a9" - + "\7v\2\2\u02a9\u02aa\7u\2\2\u02aa\u02ab\3\2\2\2\u02ab\u02ac\b\65\63\2\u02ac" - + "k\3\2\2\2\u02ad\u02ae\7h\2\2\u02ae\u02af\7g\2\2\u02af\u02b0\7c\2\2\u02b0" - + "\u02b1\7v\2\2\u02b1\u02b2\7w\2\2\u02b2\u02b3\7t\2\2\u02b3\u02b4\7g\2\2" - + "\u02b4\u02b5\3\2\2\2\u02b5\u02b6\b\66\64\2\u02b6m\3\2\2\2\u02b7\u02b8" - + "\7f\2\2\u02b8\u02b9\7g\2\2\u02b9\u02ba\7x\2\2\u02ba\u02bb\7k\2\2\u02bb" - + "\u02bc\7c\2\2\u02bc\u02bd\7v\2\2\u02bd\u02be\7g\2\2\u02be\u02bf\3\2\2" - + "\2\u02bf\u02c0\b\67\65\2\u02c0o\3\2\2\2\u02c1\u02c2\7f\2\2\u02c2\u02c3" - + "\7g\2\2\u02c3\u02c4\7x\2\2\u02c4\u02c5\7k\2\2\u02c5\u02c6\7c\2\2\u02c6" - + "\u02c7\7v\2\2\u02c7\u02c8\7k\2\2\u02c8\u02c9\7q\2\2\u02c9\u02ca\7p\2\2" - + "\u02ca\u02cb\3\2\2\2\u02cb\u02cc\b8\66\2\u02ccq\3\2\2\2\u02cd\u02ce\7" - + "g\2\2\u02ce\u02cf\7z\2\2\u02cf\u02d0\7v\2\2\u02d0\u02d1\7g\2\2\u02d1\u02d2" - + "\7p\2\2\u02d2\u02d3\7u\2\2\u02d3\u02d4\7k\2\2\u02d4\u02d5\7q\2\2\u02d5" - + "\u02d6\7p\2\2\u02d6\u02d7\3\2\2\2\u02d7\u02d8\b9\67\2\u02d8s\3\2\2\2\u02d9" - + "\u02da\7g\2\2\u02da\u02db\7t\2\2\u02db\u02dc\7t\2\2\u02dc\u02dd\7q\2\2" - + "\u02dd\u02de\7t\2\2\u02de\u02df\7/\2\2\u02df\u02e0\7o\2\2\u02e0\u02e1" - + "\7g\2\2\u02e1\u02e2\7u\2\2\u02e2\u02e3\7u\2\2\u02e3\u02e4\7c\2\2\u02e4" - + "\u02e5\7i\2\2\u02e5\u02e6\7g\2\2\u02e6\u02e7\3\2\2\2\u02e7\u02e8\b:8\2" - + "\u02e8u\3\2\2\2\u02e9\u02ea\7g\2\2\u02ea\u02eb\7t\2\2\u02eb\u02ec\7t\2" - + "\2\u02ec\u02ed\7q\2\2\u02ed\u02ee\7t\2\2\u02ee\u02ef\7/\2\2\u02ef\u02f0" - + "\7c\2\2\u02f0\u02f1\7r\2\2\u02f1\u02f2\7r\2\2\u02f2\u02f3\7/\2\2\u02f3" - + "\u02f4\7v\2\2\u02f4\u02f5\7c\2\2\u02f5\u02f6\7i\2\2\u02f6\u02f7\3\2\2" - + "\2\u02f7\u02f8\b;9\2\u02f8w\3\2\2\2\u02f9\u02fa\7g\2\2\u02fa\u02fb\7p" - + "\2\2\u02fb\u02fc\7w\2\2\u02fc\u02fd\7o\2\2\u02fd\u02fe\3\2\2\2\u02fe\u02ff" - + "\b<:\2\u02ffy\3\2\2\2\u0300\u0301\7f\2\2\u0301\u0302\7g\2\2\u0302\u0303" - + "\7u\2\2\u0303\u0304\7e\2\2\u0304\u0305\7t\2\2\u0305\u0306\7k\2\2\u0306" - + "\u0307\7r\2\2\u0307\u0308\7v\2\2\u0308\u0309\7k\2\2\u0309\u030a\7q\2\2" - + "\u030a\u030b\7p\2\2\u030b\u030c\3\2\2\2\u030c\u030d\b=;\2\u030d{\3\2\2" - + "\2\u030e\u030f\7f\2\2\u030f\u0310\7g\2\2\u0310\u0311\7h\2\2\u0311\u0312" - + "\7c\2\2\u0312\u0313\7w\2\2\u0313\u0314\7n\2\2\u0314\u0315\7v\2\2\u0315" - + "\u0316\3\2\2\2\u0316\u0317\b><\2\u0317}\3\2\2\2\u0318\u0319\7e\2\2\u0319" - + "\u031a\7q\2\2\u031a\u031b\7p\2\2\u031b\u031c\7v\2\2\u031c\u031d\7c\2\2" - + "\u031d\u031e\7k\2\2\u031e\u031f\7p\2\2\u031f\u0320\7g\2\2\u0320\u0321" - + "\7t\2\2\u0321\u0322\3\2\2\2\u0322\u0323\b?=\2\u0323\177\3\2\2\2\u0324" - + "\u0325\7e\2\2\u0325\u0326\7q\2\2\u0326\u0327\7p\2\2\u0327\u0328\7v\2\2" - + "\u0328\u0329\7c\2\2\u0329\u032a\7e\2\2\u032a\u032b\7v\2\2\u032b\u032c" - + "\3\2\2\2\u032c\u032d\b@>\2\u032d\u0081\3\2\2\2\u032e\u032f\7e\2\2\u032f" - + "\u0330\7q\2\2\u0330\u0331\7p\2\2\u0331\u0332\7h\2\2\u0332\u0333\7k\2\2" - + "\u0333\u0334\7i\2\2\u0334\u0335\3\2\2\2\u0335\u0336\bA?\2\u0336\u0083" - + "\3\2\2\2\u0337\u0338\7e\2\2\u0338\u0339\7j\2\2\u0339\u033a\7q\2\2\u033a" - + "\u033b\7k\2\2\u033b\u033c\7e\2\2\u033c\u033d\7g\2\2\u033d\u033e\3\2\2" - + "\2\u033e\u033f\bB@\2\u033f\u0085\3\2\2\2\u0340\u0341\7e\2\2\u0341\u0342" - + "\7c\2\2\u0342\u0343\7u\2\2\u0343\u0344\7g\2\2\u0344\u0345\3\2\2\2\u0345" - + "\u0346\bCA\2\u0346\u0087\3\2\2\2\u0347\u0348\7d\2\2\u0348\u0349\7k\2\2" - + "\u0349\u034a\7v\2\2\u034a\u034b\3\2\2\2\u034b\u034c\bDB\2\u034c\u0089" - + "\3\2\2\2\u034d\u034e\7d\2\2\u034e\u034f\7g\2\2\u034f\u0350\7n\2\2\u0350" - + "\u0351\7q\2\2\u0351\u0352\7p\2\2\u0352\u0353\7i\2\2\u0353\u0354\7u\2\2" - + "\u0354\u0355\7/\2\2\u0355\u0356\7v\2\2\u0356\u0357\7q\2\2\u0357\u0358" - + "\3\2\2\2\u0358\u0359\bEC\2\u0359\u008b\3\2\2\2\u035a\u035b\7d\2\2\u035b" - + "\u035c\7c\2\2\u035c\u035d\7u\2\2\u035d\u035e\7g\2\2\u035e\u035f\3\2\2" - + "\2\u035f\u0360\bFD\2\u0360\u008d\3\2\2\2\u0361\u0362\7c\2\2\u0362\u0363" - + "\7w\2\2\u0363\u0364\7i\2\2\u0364\u0365\7o\2\2\u0365\u0366\7g\2\2\u0366" - + "\u0367\7p\2\2\u0367\u0368\7v\2\2\u0368\u0369\3\2\2\2\u0369\u036a\bGE\2" - + "\u036a\u008f\3\2\2\2\u036b\u036c\7c\2\2\u036c\u036d\7t\2\2\u036d\u036e" - + "\7i\2\2\u036e\u036f\7w\2\2\u036f\u0370\7o\2\2\u0370\u0371\7g\2\2\u0371" - + "\u0372\7p\2\2\u0372\u0373\7v\2\2\u0373\u0374\3\2\2\2\u0374\u0375\bHF\2" - + "\u0375\u0091\3\2\2\2\u0376\u0377\7c\2\2\u0377\u0378\7p\2\2\u0378\u0379" - + "\7{\2\2\u0379\u037a\7z\2\2\u037a\u037b\7o\2\2\u037b\u037c\7n\2\2\u037c" - + "\u037d\3\2\2\2\u037d\u037e\bIG\2\u037e\u0093\3\2\2\2\u037f\u0383\t\5\2" - + "\2\u0380\u0382\t\6\2\2\u0381\u0380\3\2\2\2\u0382\u0385\3\2\2\2\u0383\u0381" - + "\3\2\2\2\u0383\u0384\3\2\2\2\u0384\u0386\3\2\2\2\u0385\u0383\3\2\2\2\u0386" - + "\u0387\bJH\2\u0387\u0095\3\2\2\2\u0388\u038b\7^\2\2\u0389\u038c\t\7\2" - + "\2\u038a\u038c\5\u0098L\2\u038b\u0389\3\2\2\2\u038b\u038a\3\2\2\2\u038c" - + "\u0097\3\2\2\2\u038d\u038e\7w\2\2\u038e\u038f\5\u009aM\2\u038f\u0390\5" - + "\u009aM\2\u0390\u0391\5\u009aM\2\u0391\u0392\5\u009aM\2\u0392\u0099\3" - + "\2\2\2\u0393\u0394\t\b\2\2\u0394\u009b\3\2\2\2\u0395\u0396\7=\2\2\u0396" - + "\u0397\3\2\2\2\u0397\u0398\bNI\2\u0398\u009d\3\2\2\2\u0399\u039a\7}\2" - + "\2\u039a\u039b\3\2\2\2\u039b\u039c\bOJ\2\u039c\u009f\3\2\2\2\u039d\u03a2" - + "\7$\2\2\u039e\u03a1\5\u0096K\2\u039f\u03a1\n\t\2\2\u03a0\u039e\3\2\2\2" - + "\u03a0\u039f\3\2\2\2\u03a1\u03a4\3\2\2\2\u03a2\u03a0\3\2\2\2\u03a2\u03a3" - + "\3\2\2\2\u03a3\u03a5\3\2\2\2\u03a4\u03a2\3\2\2\2\u03a5\u03b0\7$\2\2\u03a6" - + "\u03ab\7)\2\2\u03a7\u03aa\5\u0096K\2\u03a8\u03aa\n\n\2\2\u03a9\u03a7\3" - + "\2\2\2\u03a9\u03a8\3\2\2\2\u03aa\u03ad\3\2\2\2\u03ab\u03a9\3\2\2\2\u03ab" - + "\u03ac\3\2\2\2\u03ac\u03ae\3\2\2\2\u03ad\u03ab\3\2\2\2\u03ae\u03b0\7)" - + "\2\2\u03af\u039d\3\2\2\2\u03af\u03a6\3\2\2\2\u03b0\u00a1\3\2\2\2\u03b1" - + "\u03b8\5\u00a0P\2\u03b2\u03b4\n\13\2\2\u03b3\u03b2\3\2\2\2\u03b4\u03b5" - + "\3\2\2\2\u03b5\u03b3\3\2\2\2\u03b5\u03b6\3\2\2\2\u03b6\u03b8\3\2\2\2\u03b7" - + "\u03b1\3\2\2\2\u03b7\u03b3\3\2\2\2\u03b8\u03b9\3\2\2\2\u03b9\u03ba\bQ" - + "K\2\u03ba\u00a3\3\2\2\2\u03bb\u03bc\t\f\2\2\u03bc\u03bd\3\2\2\2\u03bd" - + "\u03be\bRL\2\u03be\u00a5\3\2\2\2\17\2\3\u00b4\u00bf\u0383\u038b\u03a0" - + "\u03a2\u03a9\u03ab\u03af\u03b5\u03b7"; + public static final String _serializedATN = "\2\4N\u03c4\b\1\b\1\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t" + + "\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t" + + "\17\4\20\t\20\4\21\t\21\4\22\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t" + + "\26\4\27\t\27\4\30\t\30\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t" + + "\35\4\36\t\36\4\37\t\37\4 \t \4!\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\4&\t&\4" + + "\'\t\'\4(\t(\4)\t)\4*\t*\4+\t+\4,\t,\4-\t-\4.\t.\4/\t/\4\60\t\60\4\61" + + "\t\61\4\62\t\62\4\63\t\63\4\64\t\64\4\65\t\65\4\66\t\66\4\67\t\67\48\t" + + "8\49\t9\4:\t:\4;\t;\4<\t<\4=\t=\4>\t>\4?\t?\4@\t@\4A\tA\4B\tB\4C\tC\4" + + "D\tD\4E\tE\4F\tF\4G\tG\4H\tH\4I\tI\4J\tJ\4K\tK\4L\tL\4M\tM\4N\tN\4O\t" + + "O\4P\tP\4Q\tQ\4R\tR\4S\tS\4T\tT\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\4\3" + + "\4\3\4\3\4\7\4\u00b8\n\4\f\4\16\4\u00bb\13\4\3\4\3\4\3\5\3\5\3\5\3\5\3" + + "\5\3\6\3\6\3\6\3\6\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t" + + "\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3" + + "\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\f\3\f" + + "\3\f\3\f\3\f\3\f\3\f\3\f\3\r\3\r\3\r\3\r\3\r\3\r\3\r\3\16\3\16\3\16\3" + + "\16\3\16\3\16\3\16\3\16\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3\17\3" + + "\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\20\3\21\3\21\3\21\3\21\3" + + "\21\3\21\3\21\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3\22\3" + + "\22\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\23\3\24\3\24\3\24\3\24\3" + + "\24\3\24\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3\25\3" + + "\25\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3" + + "\26\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3\27\3" + + "\27\3\27\3\27\3\27\3\27\3\27\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3\30\3" + + "\30\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\31\3\32\3" + + "\32\3\32\3\32\3\32\3\32\3\32\3\32\3\33\3\33\3\33\3\33\3\33\3\33\3\33\3" + + "\33\3\33\3\33\3\33\3\34\3\34\3\34\3\34\3\34\3\34\3\34\3\34\3\34\3\35\3" + + "\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\35\3\36\3\36\3\36\3\36\3" + + "\36\3\36\3\36\3\36\3\36\3\36\3\37\3\37\3\37\3\37\3\37\3\37\3\37\3 \3 " + + "\3 \3 \3 \3 \3 \3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3!\3\"\3\"\3" + + "\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3\"\3#\3#\3#\3#\3#\3#\3#\3#\3#" + + "\3#\3#\3#\3#\3#\3#\3$\3$\3$\3$\3$\3$\3$\3$\3$\3$\3$\3$\3%\3%\3%\3%\3%" + + "\3%\3%\3&\3&\3&\3&\3&\3&\3&\3&\3&\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'\3\'" + + "\3\'\3\'\3\'\3\'\3\'\3\'\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(\3(" + + "\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3)\3*\3*\3*\3*\3*\3*\3*\3+\3+\3+\3+" + + "\3+\3+\3+\3+\3+\3,\3,\3,\3,\3,\3,\3,\3,\3,\3,\3,\3,\3-\3-\3-\3-\3-\3-" + + "\3-\3.\3.\3.\3.\3.\3.\3/\3/\3/\3/\3/\3/\3\60\3\60\3\60\3\60\3\60\3\60" + + "\3\60\3\60\3\60\3\60\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\61\3\62" + + "\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\62\3\63\3\63" + + "\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\63\3\64\3\64\3\64\3\64\3\64" + + "\3\64\3\64\3\64\3\64\3\64\3\64\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65" + + "\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\65\3\66\3\66\3\66\3\66" + + "\3\66\3\66\3\66\3\66\3\66\3\66\3\67\3\67\3\67\3\67\3\67\3\67\3\67\3\67" + + "\3\67\3\67\38\38\38\38\38\38\38\38\38\38\38\38\39\39\39\39\39\39\39\3" + + "9\39\39\39\39\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3:\3;\3;\3" + + ";\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3;\3<\3<\3<\3<\3<\3<\3<\3=\3=\3" + + "=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3=\3>\3>\3>\3>\3>\3>\3>\3>\3>\3>\3?\3" + + "?\3?\3?\3?\3?\3?\3?\3?\3?\3?\3?\3@\3@\3@\3@\3@\3@\3@\3@\3@\3@\3A\3A\3" + + "A\3A\3A\3A\3A\3A\3A\3B\3B\3B\3B\3B\3B\3B\3B\3B\3C\3C\3C\3C\3C\3C\3C\3" + + "D\3D\3D\3D\3D\3D\3E\3E\3E\3E\3E\3E\3E\3E\3E\3E\3E\3E\3E\3F\3F\3F\3F\3" + + "F\3F\3F\3G\3G\3G\3G\3G\3G\3G\3G\3G\3G\3H\3H\3H\3H\3H\3H\3H\3H\3H\3H\3" + + "H\3I\3I\3I\3I\3I\3I\3I\3I\3I\3J\3J\7J\u037e\nJ\fJ\16J\u0381\13J\3J\3J" + + "\3K\3K\3K\5K\u0388\nK\3L\3L\3L\3L\3L\3L\3M\3M\3N\3N\3N\3N\3O\3O\3O\3O" + + "\3P\3P\3P\7P\u039d\nP\fP\16P\u03a0\13P\3P\3P\3P\3P\7P\u03a6\nP\fP\16P" + + "\u03a9\13P\3P\5P\u03ac\nP\3Q\3Q\6Q\u03b0\nQ\rQ\16Q\u03b1\5Q\u03b4\nQ\3" + + "Q\3Q\3R\3R\3R\3R\3S\3S\3S\3S\3S\3T\3T\3T\3T\2U\5\6\2\7\7\3\t\b\4\13\t" + + "\5\r\3\6\17\4\7\21\5\b\23\n\t\25\13\n\27\f\13\31\r\f\33\16\r\35\17\16" + + "\37\20\17!\21\20#\22\21%\23\22\'\24\23)\25\24+\26\25-\27\26/\30\27\61" + + "\31\30\63\32\31\65\33\32\67\34\339\35\34;\36\35=\37\36? \37A!\1C\" E#" + + "!G$\"I%#K&$M\'%O(&Q)\'S*(U+)W,*Y-+[.,]/-_\60\1a\61.c\62/e\63\60g\64\61" + + "i\65\62k\66\63m\67\64o8\65q9\66s:\67u;8w<9y=:{>;}?<\177@=\u0081A>\u0083" + + "B?\u0085C@\u0087DA\u0089EB\u008bFC\u008dGD\u008fHE\u0091IF\u0093JG\u0095" + + "KH\u0097\2\1\u0099\2\1\u009b\2\1\u009d\2I\u009f\2J\u00a1\2\1\u00a3LK\u00a5" + + "ML\u00a7NM\u00a9\2N\5\2\3\4\f\5\13\f\17\17\"\"\4\f\f\17\17\6/;C\\aac|" + + "\7/\60\62\3" + + "\2\2\2\u01b3\u01b4\7r\2\2\u01b4\u01b5\7c\2\2\u01b5\u01b6\7v\2\2\u01b6" + + "\u01b7\7j\2\2\u01b7\u01b8\3\2\2\2\u01b8\u01b9\b\37\37\2\u01b9@\3\2\2\2" + + "\u01ba\u01bb\7q\2\2\u01bb\u01bc\7w\2\2\u01bc\u01bd\7v\2\2\u01bd\u01be" + + "\7r\2\2\u01be\u01bf\7w\2\2\u01bf\u01c0\7v\2\2\u01c0B\3\2\2\2\u01c1\u01c2" + + "\7q\2\2\u01c2\u01c3\7t\2\2\u01c3\u01c4\7i\2\2\u01c4\u01c5\7c\2\2\u01c5" + + "\u01c6\7p\2\2\u01c6\u01c7\7k\2\2\u01c7\u01c8\7|\2\2\u01c8\u01c9\7c\2\2" + + "\u01c9\u01ca\7v\2\2\u01ca\u01cb\7k\2\2\u01cb\u01cc\7q\2\2\u01cc\u01cd" + + "\7p\2\2\u01cd\u01ce\3\2\2\2\u01ce\u01cf\b! \2\u01cfD\3\2\2\2\u01d0\u01d1" + + "\7q\2\2\u01d1\u01d2\7t\2\2\u01d2\u01d3\7f\2\2\u01d3\u01d4\7g\2\2\u01d4" + + "\u01d5\7t\2\2\u01d5\u01d6\7g\2\2\u01d6\u01d7\7f\2\2\u01d7\u01d8\7/\2\2" + + "\u01d8\u01d9\7d\2\2\u01d9\u01da\7{\2\2\u01da\u01db\3\2\2\2\u01db\u01dc" + + "\b\"!\2\u01dcF\3\2\2\2\u01dd\u01de\7p\2\2\u01de\u01df\7q\2\2\u01df\u01e0" + + "\7v\2\2\u01e0\u01e1\7k\2\2\u01e1\u01e2\7h\2\2\u01e2\u01e3\7k\2\2\u01e3" + + "\u01e4\7e\2\2\u01e4\u01e5\7c\2\2\u01e5\u01e6\7v\2\2\u01e6\u01e7\7k\2\2" + + "\u01e7\u01e8\7q\2\2\u01e8\u01e9\7p\2\2\u01e9\u01ea\3\2\2\2\u01ea\u01eb" + + "\b#\"\2\u01ebH\3\2\2\2\u01ec\u01ed\7p\2\2\u01ed\u01ee\7c\2\2\u01ee\u01ef" + + "\7o\2\2\u01ef\u01f0\7g\2\2\u01f0\u01f1\7u\2\2\u01f1\u01f2\7r\2\2\u01f2" + + "\u01f3\7c\2\2\u01f3\u01f4\7e\2\2\u01f4\u01f5\7g\2\2\u01f5\u01f6\3\2\2" + + "\2\u01f6\u01f7\b$#\2\u01f7J\3\2\2\2\u01f8\u01f9\7o\2\2\u01f9\u01fa\7w" + + "\2\2\u01fa\u01fb\7u\2\2\u01fb\u01fc\7v\2\2\u01fc\u01fd\3\2\2\2\u01fd\u01fe" + + "\b%$\2\u01feL\3\2\2\2\u01ff\u0200\7o\2\2\u0200\u0201\7q\2\2\u0201\u0202" + + "\7f\2\2\u0202\u0203\7w\2\2\u0203\u0204\7n\2\2\u0204\u0205\7g\2\2\u0205" + + "\u0206\3\2\2\2\u0206\u0207\b&%\2\u0207N\3\2\2\2\u0208\u0209\7o\2\2\u0209" + + "\u020a\7k\2\2\u020a\u020b\7p\2\2\u020b\u020c\7/\2\2\u020c\u020d\7g\2\2" + + "\u020d\u020e\7n\2\2\u020e\u020f\7g\2\2\u020f\u0210\7o\2\2\u0210\u0211" + + "\7g\2\2\u0211\u0212\7p\2\2\u0212\u0213\7v\2\2\u0213\u0214\7u\2\2\u0214" + + "\u0215\3\2\2\2\u0215\u0216\b\'&\2\u0216P\3\2\2\2\u0217\u0218\7o\2\2\u0218" + + "\u0219\7c\2\2\u0219\u021a\7z\2\2\u021a\u021b\7/\2\2\u021b\u021c\7g\2\2" + + "\u021c\u021d\7n\2\2\u021d\u021e\7g\2\2\u021e\u021f\7o\2\2\u021f\u0220" + + "\7g\2\2\u0220\u0221\7p\2\2\u0221\u0222\7v\2\2\u0222\u0223\7u\2\2\u0223" + + "\u0224\3\2\2\2\u0224\u0225\b(\'\2\u0225R\3\2\2\2\u0226\u0227\7o\2\2\u0227" + + "\u0228\7c\2\2\u0228\u0229\7p\2\2\u0229\u022a\7f\2\2\u022a\u022b\7c\2\2" + + "\u022b\u022c\7v\2\2\u022c\u022d\7q\2\2\u022d\u022e\7t\2\2\u022e\u022f" + + "\7{\2\2\u022f\u0230\3\2\2\2\u0230\u0231\b)(\2\u0231T\3\2\2\2\u0232\u0233" + + "\7n\2\2\u0233\u0234\7k\2\2\u0234\u0235\7u\2\2\u0235\u0236\7v\2\2\u0236" + + "\u0237\3\2\2\2\u0237\u0238\b*)\2\u0238V\3\2\2\2\u0239\u023a\7n\2\2\u023a" + + "\u023b\7g\2\2\u023b\u023c\7p\2\2\u023c\u023d\7i\2\2\u023d\u023e\7v\2\2" + + "\u023e\u023f\7j\2\2\u023f\u0240\3\2\2\2\u0240\u0241\b+*\2\u0241X\3\2\2" + + "\2\u0242\u0243\7n\2\2\u0243\u0244\7g\2\2\u0244\u0245\7c\2\2\u0245\u0246" + + "\7h\2\2\u0246\u0247\7/\2\2\u0247\u0248\7n\2\2\u0248\u0249\7k\2\2\u0249" + + "\u024a\7u\2\2\u024a\u024b\7v\2\2\u024b\u024c\3\2\2\2\u024c\u024d\b,+\2" + + "\u024dZ\3\2\2\2\u024e\u024f\7n\2\2\u024f\u0250\7g\2\2\u0250\u0251\7c\2" + + "\2\u0251\u0252\7h\2\2\u0252\u0253\3\2\2\2\u0253\u0254\b-,\2\u0254\\\3" + + "\2\2\2\u0255\u0256\7m\2\2\u0256\u0257\7g\2\2\u0257\u0258\7{\2\2\u0258" + + "\u0259\3\2\2\2\u0259\u025a\b.-\2\u025a^\3\2\2\2\u025b\u025c\7k\2\2\u025c" + + "\u025d\7p\2\2\u025d\u025e\7r\2\2\u025e\u025f\7w\2\2\u025f\u0260\7v\2\2" + + "\u0260`\3\2\2\2\u0261\u0262\7k\2\2\u0262\u0263\7p\2\2\u0263\u0264\7e\2" + + "\2\u0264\u0265\7n\2\2\u0265\u0266\7w\2\2\u0266\u0267\7f\2\2\u0267\u0268" + + "\7g\2\2\u0268\u0269\3\2\2\2\u0269\u026a\b\60.\2\u026ab\3\2\2\2\u026b\u026c" + + "\7k\2\2\u026c\u026d\7o\2\2\u026d\u026e\7r\2\2\u026e\u026f\7q\2\2\u026f" + + "\u0270\7t\2\2\u0270\u0271\7v\2\2\u0271\u0272\3\2\2\2\u0272\u0273\b\61" + + "/\2\u0273d\3\2\2\2\u0274\u0275\7k\2\2\u0275\u0276\7h\2\2\u0276\u0277\7" + + "/\2\2\u0277\u0278\7h\2\2\u0278\u0279\7g\2\2\u0279\u027a\7c\2\2\u027a\u027b" + + "\7v\2\2\u027b\u027c\7w\2\2\u027c\u027d\7t\2\2\u027d\u027e\7g\2\2\u027e" + + "\u027f\3\2\2\2\u027f\u0280\b\62\60\2\u0280f\3\2\2\2\u0281\u0282\7k\2\2" + + "\u0282\u0283\7f\2\2\u0283\u0284\7g\2\2\u0284\u0285\7p\2\2\u0285\u0286" + + "\7v\2\2\u0286\u0287\7k\2\2\u0287\u0288\7v\2\2\u0288\u0289\7{\2\2\u0289" + + "\u028a\3\2\2\2\u028a\u028b\b\63\61\2\u028bh\3\2\2\2\u028c\u028d\7i\2\2" + + "\u028d\u028e\7t\2\2\u028e\u028f\7q\2\2\u028f\u0290\7w\2\2\u0290\u0291" + + "\7r\2\2\u0291\u0292\7k\2\2\u0292\u0293\7p\2\2\u0293\u0294\7i\2\2\u0294" + + "\u0295\3\2\2\2\u0295\u0296\b\64\62\2\u0296j\3\2\2\2\u0297\u0298\7h\2\2" + + "\u0298\u0299\7t\2\2\u0299\u029a\7c\2\2\u029a\u029b\7e\2\2\u029b\u029c" + + "\7v\2\2\u029c\u029d\7k\2\2\u029d\u029e\7q\2\2\u029e\u029f\7p\2\2\u029f" + + "\u02a0\7/\2\2\u02a0\u02a1\7f\2\2\u02a1\u02a2\7k\2\2\u02a2\u02a3\7i\2\2" + + "\u02a3\u02a4\7k\2\2\u02a4\u02a5\7v\2\2\u02a5\u02a6\7u\2\2\u02a6\u02a7" + + "\3\2\2\2\u02a7\u02a8\b\65\63\2\u02a8l\3\2\2\2\u02a9\u02aa\7h\2\2\u02aa" + + "\u02ab\7g\2\2\u02ab\u02ac\7c\2\2\u02ac\u02ad\7v\2\2\u02ad\u02ae\7w\2\2" + + "\u02ae\u02af\7t\2\2\u02af\u02b0\7g\2\2\u02b0\u02b1\3\2\2\2\u02b1\u02b2" + + "\b\66\64\2\u02b2n\3\2\2\2\u02b3\u02b4\7f\2\2\u02b4\u02b5\7g\2\2\u02b5" + + "\u02b6\7x\2\2\u02b6\u02b7\7k\2\2\u02b7\u02b8\7c\2\2\u02b8\u02b9\7v\2\2" + + "\u02b9\u02ba\7g\2\2\u02ba\u02bb\3\2\2\2\u02bb\u02bc\b\67\65\2\u02bcp\3" + + "\2\2\2\u02bd\u02be\7f\2\2\u02be\u02bf\7g\2\2\u02bf\u02c0\7x\2\2\u02c0" + + "\u02c1\7k\2\2\u02c1\u02c2\7c\2\2\u02c2\u02c3\7v\2\2\u02c3\u02c4\7k\2\2" + + "\u02c4\u02c5\7q\2\2\u02c5\u02c6\7p\2\2\u02c6\u02c7\3\2\2\2\u02c7\u02c8" + + "\b8\66\2\u02c8r\3\2\2\2\u02c9\u02ca\7g\2\2\u02ca\u02cb\7z\2\2\u02cb\u02cc" + + "\7v\2\2\u02cc\u02cd\7g\2\2\u02cd\u02ce\7p\2\2\u02ce\u02cf\7u\2\2\u02cf" + + "\u02d0\7k\2\2\u02d0\u02d1\7q\2\2\u02d1\u02d2\7p\2\2\u02d2\u02d3\3\2\2" + + "\2\u02d3\u02d4\b9\67\2\u02d4t\3\2\2\2\u02d5\u02d6\7g\2\2\u02d6\u02d7\7" + + "t\2\2\u02d7\u02d8\7t\2\2\u02d8\u02d9\7q\2\2\u02d9\u02da\7t\2\2\u02da\u02db" + + "\7/\2\2\u02db\u02dc\7o\2\2\u02dc\u02dd\7g\2\2\u02dd\u02de\7u\2\2\u02de" + + "\u02df\7u\2\2\u02df\u02e0\7c\2\2\u02e0\u02e1\7i\2\2\u02e1\u02e2\7g\2\2" + + "\u02e2\u02e3\3\2\2\2\u02e3\u02e4\b:8\2\u02e4v\3\2\2\2\u02e5\u02e6\7g\2" + + "\2\u02e6\u02e7\7t\2\2\u02e7\u02e8\7t\2\2\u02e8\u02e9\7q\2\2\u02e9\u02ea" + + "\7t\2\2\u02ea\u02eb\7/\2\2\u02eb\u02ec\7c\2\2\u02ec\u02ed\7r\2\2\u02ed" + + "\u02ee\7r\2\2\u02ee\u02ef\7/\2\2\u02ef\u02f0\7v\2\2\u02f0\u02f1\7c\2\2" + + "\u02f1\u02f2\7i\2\2\u02f2\u02f3\3\2\2\2\u02f3\u02f4\b;9\2\u02f4x\3\2\2" + + "\2\u02f5\u02f6\7g\2\2\u02f6\u02f7\7p\2\2\u02f7\u02f8\7w\2\2\u02f8\u02f9" + + "\7o\2\2\u02f9\u02fa\3\2\2\2\u02fa\u02fb\b<:\2\u02fbz\3\2\2\2\u02fc\u02fd" + + "\7f\2\2\u02fd\u02fe\7g\2\2\u02fe\u02ff\7u\2\2\u02ff\u0300\7e\2\2\u0300" + + "\u0301\7t\2\2\u0301\u0302\7k\2\2\u0302\u0303\7r\2\2\u0303\u0304\7v\2\2" + + "\u0304\u0305\7k\2\2\u0305\u0306\7q\2\2\u0306\u0307\7p\2\2\u0307\u0308" + + "\3\2\2\2\u0308\u0309\b=;\2\u0309|\3\2\2\2\u030a\u030b\7f\2\2\u030b\u030c" + + "\7g\2\2\u030c\u030d\7h\2\2\u030d\u030e\7c\2\2\u030e\u030f\7w\2\2\u030f" + + "\u0310\7n\2\2\u0310\u0311\7v\2\2\u0311\u0312\3\2\2\2\u0312\u0313\b><\2" + + "\u0313~\3\2\2\2\u0314\u0315\7e\2\2\u0315\u0316\7q\2\2\u0316\u0317\7p\2" + + "\2\u0317\u0318\7v\2\2\u0318\u0319\7c\2\2\u0319\u031a\7k\2\2\u031a\u031b" + + "\7p\2\2\u031b\u031c\7g\2\2\u031c\u031d\7t\2\2\u031d\u031e\3\2\2\2\u031e" + + "\u031f\b?=\2\u031f\u0080\3\2\2\2\u0320\u0321\7e\2\2\u0321\u0322\7q\2\2" + + "\u0322\u0323\7p\2\2\u0323\u0324\7v\2\2\u0324\u0325\7c\2\2\u0325\u0326" + + "\7e\2\2\u0326\u0327\7v\2\2\u0327\u0328\3\2\2\2\u0328\u0329\b@>\2\u0329" + + "\u0082\3\2\2\2\u032a\u032b\7e\2\2\u032b\u032c\7q\2\2\u032c\u032d\7p\2" + + "\2\u032d\u032e\7h\2\2\u032e\u032f\7k\2\2\u032f\u0330\7i\2\2\u0330\u0331" + + "\3\2\2\2\u0331\u0332\bA?\2\u0332\u0084\3\2\2\2\u0333\u0334\7e\2\2\u0334" + + "\u0335\7j\2\2\u0335\u0336\7q\2\2\u0336\u0337\7k\2\2\u0337\u0338\7e\2\2" + + "\u0338\u0339\7g\2\2\u0339\u033a\3\2\2\2\u033a\u033b\bB@\2\u033b\u0086" + + "\3\2\2\2\u033c\u033d\7e\2\2\u033d\u033e\7c\2\2\u033e\u033f\7u\2\2\u033f" + + "\u0340\7g\2\2\u0340\u0341\3\2\2\2\u0341\u0342\bCA\2\u0342\u0088\3\2\2" + + "\2\u0343\u0344\7d\2\2\u0344\u0345\7k\2\2\u0345\u0346\7v\2\2\u0346\u0347" + + "\3\2\2\2\u0347\u0348\bDB\2\u0348\u008a\3\2\2\2\u0349\u034a\7d\2\2\u034a" + + "\u034b\7g\2\2\u034b\u034c\7n\2\2\u034c\u034d\7q\2\2\u034d\u034e\7p\2\2" + + "\u034e\u034f\7i\2\2\u034f\u0350\7u\2\2\u0350\u0351\7/\2\2\u0351\u0352" + + "\7v\2\2\u0352\u0353\7q\2\2\u0353\u0354\3\2\2\2\u0354\u0355\bEC\2\u0355" + + "\u008c\3\2\2\2\u0356\u0357\7d\2\2\u0357\u0358\7c\2\2\u0358\u0359\7u\2" + + "\2\u0359\u035a\7g\2\2\u035a\u035b\3\2\2\2\u035b\u035c\bFD\2\u035c\u008e" + + "\3\2\2\2\u035d\u035e\7c\2\2\u035e\u035f\7w\2\2\u035f\u0360\7i\2\2\u0360" + + "\u0361\7o\2\2\u0361\u0362\7g\2\2\u0362\u0363\7p\2\2\u0363\u0364\7v\2\2" + + "\u0364\u0365\3\2\2\2\u0365\u0366\bGE\2\u0366\u0090\3\2\2\2\u0367\u0368" + + "\7c\2\2\u0368\u0369\7t\2\2\u0369\u036a\7i\2\2\u036a\u036b\7w\2\2\u036b" + + "\u036c\7o\2\2\u036c\u036d\7g\2\2\u036d\u036e\7p\2\2\u036e\u036f\7v\2\2" + + "\u036f\u0370\3\2\2\2\u0370\u0371\bHF\2\u0371\u0092\3\2\2\2\u0372\u0373" + + "\7c\2\2\u0373\u0374\7p\2\2\u0374\u0375\7{\2\2\u0375\u0376\7z\2\2\u0376" + + "\u0377\7o\2\2\u0377\u0378\7n\2\2\u0378\u0379\3\2\2\2\u0379\u037a\bIG\2" + + "\u037a\u0094\3\2\2\2\u037b\u037f\t\4\2\2\u037c\u037e\t\5\2\2\u037d\u037c" + + "\3\2\2\2\u037e\u0381\3\2\2\2\u037f\u037d\3\2\2\2\u037f\u0380\3\2\2\2\u0380" + + "\u0382\3\2\2\2\u0381\u037f\3\2\2\2\u0382\u0383\bJH\2\u0383\u0096\3\2\2" + + "\2\u0384\u0387\7^\2\2\u0385\u0388\t\6\2\2\u0386\u0388\5\u0099L\2\u0387" + + "\u0385\3\2\2\2\u0387\u0386\3\2\2\2\u0388\u0098\3\2\2\2\u0389\u038a\7w" + + "\2\2\u038a\u038b\5\u009bM\2\u038b\u038c\5\u009bM\2\u038c\u038d\5\u009b" + + "M\2\u038d\u038e\5\u009bM\2\u038e\u009a\3\2\2\2\u038f\u0390\t\7\2\2\u0390" + + "\u009c\3\2\2\2\u0391\u0392\7=\2\2\u0392\u0393\3\2\2\2\u0393\u0394\bNI" + + "\2\u0394\u009e\3\2\2\2\u0395\u0396\7}\2\2\u0396\u0397\3\2\2\2\u0397\u0398" + + "\bOJ\2\u0398\u00a0\3\2\2\2\u0399\u039e\7$\2\2\u039a\u039d\5\u0097K\2\u039b" + + "\u039d\n\b\2\2\u039c\u039a\3\2\2\2\u039c\u039b\3\2\2\2\u039d\u03a0\3\2" + + "\2\2\u039e\u039c\3\2\2\2\u039e\u039f\3\2\2\2\u039f\u03a1\3\2\2\2\u03a0" + + "\u039e\3\2\2\2\u03a1\u03ac\7$\2\2\u03a2\u03a7\7)\2\2\u03a3\u03a6\5\u0097" + + "K\2\u03a4\u03a6\n\t\2\2\u03a5\u03a3\3\2\2\2\u03a5\u03a4\3\2\2\2\u03a6" + + "\u03a9\3\2\2\2\u03a7\u03a5\3\2\2\2\u03a7\u03a8\3\2\2\2\u03a8\u03aa\3\2" + + "\2\2\u03a9\u03a7\3\2\2\2\u03aa\u03ac\7)\2\2\u03ab\u0399\3\2\2\2\u03ab" + + "\u03a2\3\2\2\2\u03ac\u00a2\3\2\2\2\u03ad\u03b4\5\u00a1P\2\u03ae\u03b0" + + "\n\n\2\2\u03af\u03ae\3\2\2\2\u03b0\u03b1\3\2\2\2\u03b1\u03af\3\2\2\2\u03b1" + + "\u03b2\3\2\2\2\u03b2\u03b4\3\2\2\2\u03b3\u03ad\3\2\2\2\u03b3\u03af\3\2" + + "\2\2\u03b4\u03b5\3\2\2\2\u03b5\u03b6\bQK\2\u03b6\u00a4\3\2\2\2\u03b7\u03b8" + + "\t\13\2\2\u03b8\u03b9\3\2\2\2\u03b9\u03ba\bRL\2\u03ba\u00a6\3\2\2\2\u03bb" + + "\u03bc\7,\2\2\u03bc\u03bd\7\61\2\2\u03bd\u03be\3\2\2\2\u03be\u03bf\bS" + + "M\2\u03bf\u00a8\3\2\2\2\u03c0\u03c1\13\2\2\2\u03c1\u03c2\3\2\2\2\u03c2" + + "\u03c3\bTN\2\u03c3\u00aa\3\2\2\2\17\2\3\4\u00b9\u037f\u0387\u039c\u039e" + + "\u03a5\u03a7\u03ab\u03b1\u03b3"; public static final ATN _ATN = ATNSimulator.deserialize(_serializedATN .toCharArray()); static { diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangParser.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangParser.java index 2b22fc7396..91b0917e29 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangParser.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/antlrv4/code/gen/YangParser.java @@ -7,21 +7,14 @@ */ package org.opendaylight.controller.antlrv4.code.gen; -import java.util.List; - -import org.antlr.v4.runtime.NoViableAltException; -import org.antlr.v4.runtime.Parser; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.RecognitionException; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNSimulator; -import org.antlr.v4.runtime.atn.ParserATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; -import org.antlr.v4.runtime.tree.TerminalNode; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; @SuppressWarnings({ "all", "warnings", "unchecked", "unused", "cast" }) public class YangParser extends Parser { @@ -38,26 +31,26 @@ public class YangParser extends Parser { CONTAINER_KEYWORD = 62, DEVIATION_KEYWORD = 55, STATUS_KEYWORD = 18, IDENTITY_KEYWORD = 50, IDENTIFIER = 73, REFINE_KEYWORD = 23, USES_KEYWORD = 12, VALUE_KEYWORD = 11, - IMPORT_KEYWORD = 48, BLOCK_COMMENT = 7, INPUT_KEYWORD = 46, - IF_FEATURE_KEYWORD = 49, PLUS = 4, PATTERN_KEYWORD = 29, - LENGTH_KEYWORD = 42, FEATURE_KEYWORD = 53, - REQUIRE_INSTANCE_KEYWORD = 22, ORGANIZATION_KEYWORD = 32, - UNIQUE_KEYWORD = 14, SUBMODULE_KEYWORD = 17, TYPE_KEYWORD = 16, - RIGHT_BRACE = 3, ERROR_MESSAGE_KEYWORD = 57, LINE_COMMENT = 6, - OUTPUT_KEYWORD = 31, MIN_ELEMENTS_KEYWORD = 38, MUST_KEYWORD = 36, - SEMICOLON = 1, POSITION_KEYWORD = 28, PATH_KEYWORD = 30, S = 75, - KEY_KEYWORD = 45, EXTENSION_KEYWORD = 56, WS = 5, + IMPORT_KEYWORD = 48, INPUT_KEYWORD = 46, IF_FEATURE_KEYWORD = 49, + PLUS = 4, PATTERN_KEYWORD = 29, LENGTH_KEYWORD = 42, + FEATURE_KEYWORD = 53, REQUIRE_INSTANCE_KEYWORD = 22, + ORGANIZATION_KEYWORD = 32, UNIQUE_KEYWORD = 14, + SUBMODULE_KEYWORD = 17, TYPE_KEYWORD = 16, RIGHT_BRACE = 3, + ERROR_MESSAGE_KEYWORD = 57, LINE_COMMENT = 6, OUTPUT_KEYWORD = 31, + MIN_ELEMENTS_KEYWORD = 38, MUST_KEYWORD = 36, SEMICOLON = 1, + POSITION_KEYWORD = 28, PATH_KEYWORD = 30, S = 75, KEY_KEYWORD = 45, + EXTENSION_KEYWORD = 56, START_BLOCK_COMMENT = 7, WS = 5, MANDATORY_KEYWORD = 40, ORDERED_BY_KEYWORD = 33, ERROR_APP_TAG_KEYWORD = 58, INCLUDE_KEYWORD = 47, ANYXML_KEYWORD = 72, AUGMENT_KEYWORD = 70, DEVIATE_KEYWORD = 54, LEFT_BRACE = 2, YANG_VERSION_KEYWORD = 9, LIST_KEYWORD = 41, TYPEDEF_KEYWORD = 15, MAX_ELEMENTS_KEYWORD = 39, ENUM_KEYWORD = 59, CASE_KEYWORD = 66, UNITS_KEYWORD = 13, GROUPING_KEYWORD = 51, - BASE_KEYWORD = 69, RANGE_KEYWORD = 25, + END_BLOCK_COMMENT = 76, BASE_KEYWORD = 69, RANGE_KEYWORD = 25, FRACTION_DIGITS_KEYWORD = 52, CONFIG_KEYWORD = 64, BIT_KEYWORD = 67, STRING = 74; public static final String[] tokenNames = { "", "SEMICOLON", - "LEFT_BRACE", "'}'", "'+'", "WS", "LINE_COMMENT", "BLOCK_COMMENT", + "LEFT_BRACE", "'}'", "'+'", "WS", "LINE_COMMENT", "'/*'", "'yin-element'", "'yang-version'", "'when'", "'value'", "'uses'", "'units'", "'unique'", "'typedef'", "'type'", "'submodule'", "'status'", "'rpc'", "'revision-date'", "'revision'", @@ -73,7 +66,7 @@ public class YangParser extends Parser { "'description'", "'default'", "'container'", "'contact'", "'config'", "'choice'", "'case'", "'bit'", "'belongs-to'", "'base'", "'augment'", "'argument'", "'anyxml'", "IDENTIFIER", - "STRING", "S" }; + "STRING", "S", "'*/'" }; public static final int RULE_yang = 0, RULE_string = 1, RULE_identifier_stmt = 2, RULE_stmtend = 3, RULE_deviate_replace_stmt = 4, RULE_deviate_delete_stmt = 5, @@ -12858,7 +12851,7 @@ public class YangParser extends Parser { return _localctx; } - public static final String _serializedATN = "\2\3M\u04bd\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4" + public static final String _serializedATN = "\2\3N\u04bd\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4" + "\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20" + "\4\21\t\21\4\22\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27" + "\4\30\t\30\4\31\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36" diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/AugmentationSchemaBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/AugmentationSchemaBuilderImpl.java deleted file mode 100644 index 2ece5a0715..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/AugmentationSchemaBuilderImpl.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.model.parser.util.YangModelBuilderHelper; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder { - - private final AugmentationSchemaImpl instance; - private final SchemaPath augmentTarget; - final Set childNodes = new HashSet(); - final Set groupings = new HashSet(); - private final Set usesNodes = new HashSet(); - - AugmentationSchemaBuilderImpl(String augmentPath) { - SchemaPath targetPath = YangModelBuilderHelper.parsePath(augmentPath); - augmentTarget = targetPath; - instance = new AugmentationSchemaImpl(targetPath); - } - - @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { - childNodes.add(childNode); - } - - @Override - public void addGrouping(GroupingBuilder grouping) { - groupings.add(grouping); - } - - /** - * Always returns null. - */ - @Override - public QName getQName() { - return null; - } - - @Override - public AugmentationSchema build() { - - // CHILD NODES - Map childs = new HashMap(); - for(DataSchemaNodeBuilder node : childNodes) { - childs.put(node.getQName(), node.build()); - } - instance.setChildNodes(childs); - - // GROUPINGS - Set groupingDefinitions = new HashSet(); - for(GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); - } - instance.setGroupings(groupingDefinitions); - - // USES - Set usesNodeDefinitions = new HashSet(); - for(UsesNodeBuilder builder : usesNodes) { - usesNodeDefinitions.add(builder.build()); - } - instance.setUses(usesNodeDefinitions); - - return instance; - } - - @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - usesNodes.add(usesBuilder); - } - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - throw new UnsupportedOperationException("Augmentation can not contains type definitions"); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public SchemaPath getTargetPath() { - return augmentTarget; - } - - - private static class AugmentationSchemaImpl implements AugmentationSchema { - - private final SchemaPath targetPath; - private Map childNodes; - private Set groupings; - private Set uses; - - private String description; - private String reference; - private Status status; - - private AugmentationSchemaImpl(SchemaPath targetPath) { - this.targetPath = targetPath; - } - - - @Override - public SchemaPath getTargetPath() { - return targetPath; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public Set getUses() { - return uses; - } - private void setUses(Set uses) { - this.uses = uses; - } - - /** - * This method always returns null, because augmentation can not contains type definitions. - */ - @Override - public Set> getTypeDefinitions() { - return null; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for(Map.Entry entry : childNodes.entrySet()) { - if(entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public int hashCode() { - final int prime = 17; - int result = 1; - result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode()); - result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode()); - result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); - result = prime * result + ((uses == null) ? 0 : uses.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj; - if (targetPath == null) { - if (other.targetPath != null) { - return false; - } - } else if (!targetPath.equals(other.targetPath)) { - return false; - } - if (childNodes == null) { - if (other.childNodes != null) { - return false; - } - } else if (!childNodes.equals(other.childNodes)) { - return false; - } - if (groupings == null) { - if (other.groupings != null) { - return false; - } - } else if (!groupings.equals(other.groupings)) { - return false; - } - if (uses == null) { - if (other.uses != null) { - return false; - } - } else if (!uses.equals(other.uses)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(AugmentationSchemaImpl.class.getSimpleName()); - sb.append("["); - sb.append("targetPath="+ targetPath); - sb.append(", childNodes="+ childNodes.values()); - sb.append(", groupings="+ groupings); - sb.append(", uses="+ uses); - sb.append("]"); - return sb.toString(); - } - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java deleted file mode 100644 index 1651bfcb54..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilder.java +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.AbstractChildNodeBuilder; -import org.opendaylight.controller.model.parser.api.AugmentationTargetBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder implements TypeDefinitionAwareBuilder, MustAwareBuilder, AugmentationTargetBuilder, DataSchemaNodeBuilder { - - private final ContainerSchemaNodeImpl instance; - - private final Set addedTypedefs = new HashSet(); - private final Set augmentations = new HashSet(); - private final Set addedUsesNodes = new HashSet(); - private MustDefinitionBuilder mustDefinitionBuilder; - - ContainerSchemaNodeBuilder(QName qname) { - super(qname); - instance = new ContainerSchemaNodeImpl(qname); - } - - @Override - public ContainerSchemaNode build() { - // CHILD NODES - Map childs = new HashMap(); - for (DataSchemaNodeBuilder node : childNodes) { - childs.put(node.getQName(), node.build()); - } - instance.setChildNodes(childs); - - // GROUPINGS - Set groupingDefinitions = new HashSet(); - for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); - } - instance.setGroupings(groupingDefinitions); - - // TYPEDEFS - Set> typedefs = new HashSet>(); - for(TypeDefinitionBuilder entry : addedTypedefs) { - typedefs.add(entry.build()); - } - instance.setTypeDefinitions(typedefs); - - // USES - Set uses = new HashSet(); - for (UsesNodeBuilder builder : addedUsesNodes) { - uses.add(builder.build()); - } - instance.setUses(uses); - - // MUST definition - if(mustDefinitionBuilder != null) { - MustDefinition md = mustDefinitionBuilder.build(); - instance.setMustStatement(md); - } - - instance.setAvailableAugmentations(augmentations); - - return instance; - } - - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - addedTypedefs.add(type); - } - - @Override - public void addAugmentation(AugmentationSchema augment) { - augmentations.add(augment); - } - - @Override - public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); - } - - @Override - public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); - } - - public void setConstraints(ConstraintDefinition constraints) { - instance.setConstraints(constraints); - } - - @Override - public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { - addedUsesNodes.add(usesNodeBuilder); - } - - public void setPresenceContainer(boolean presence) { - instance.setPresenceContainer(presence); - } - - @Override - public void setMustDefinitionBuilder(MustDefinitionBuilder mustDefinitionBuilder) { - this.mustDefinitionBuilder = mustDefinitionBuilder; - } - - - private class ContainerSchemaNodeImpl implements ContainerSchemaNode { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status = Status.CURRENT; - - private boolean augmenting; - private boolean configuration; - private ConstraintDefinition constraints; - - private Set augmentations; - - private Map childNodes; - private Set groupings; - private Set> typeDefinitions; - - private Set uses; - private boolean presence; - - private MustDefinition mustDefinition; - - private ContainerSchemaNodeImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - private void setAugmenting(boolean augmenting) { - this.augmenting = augmenting; - } - - @Override - public boolean isConfiguration() { - return configuration; - } - private void setConfiguration(boolean configuration) { - this.configuration = configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraints; - } - private void setConstraints(ConstraintDefinition constraints) { - this.constraints = constraints; - } - - @Override - public Set getAvailableAugmentations() { - return augmentations; - } - private void setAvailableAugmentations( - Set augmentations) { - this.augmentations = augmentations; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for (Map.Entry entry : childNodes.entrySet()) { - if (entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public Set getUses() { - return uses; - } - - private void setUses(Set uses) { - this.uses = uses; - } - - @Override - public boolean isPresenceContainer() { - return presence; - } - - private void setPresenceContainer(boolean presence) { - this.presence = presence; - } - - @Override - public MustDefinition getMustDefinition() { - return mustDefinition; - } - private void setMustStatement(MustDefinition mustDefinition) { - this.mustDefinition = mustDefinition; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + (augmenting ? 1231 : 1237); - result = prime * result + (configuration ? 1231 : 1237); - result = prime * result + ((constraints == null) ? 0 : constraints.hashCode()); - result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); - result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode()); - result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); - result = prime * result + ((uses == null) ? 0 : uses.hashCode()); - result = prime * result + (presence ? 1231 : 1237); - result = prime * result + ((mustDefinition == null) ? 0 : mustDefinition.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ContainerSchemaNodeImpl other = (ContainerSchemaNodeImpl) obj; - if (qname == null) { - if (other.qname != null) { - return false; - } - } else if (!qname.equals(other.qname)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } - if(augmenting != other.augmenting) { - return false; - } - if(configuration != other.configuration) { - return false; - } - if (constraints == null) { - if (other.constraints != null) { - return false; - } - } else if (!constraints.equals(other.constraints)) { - return false; - } - if (augmentations == null) { - if (other.augmentations != null) { - return false; - } - } else if (!augmentations.equals(other.augmentations)) { - return false; - } - if (childNodes == null) { - if (other.childNodes != null) { - return false; - } - } else if (!childNodes.equals(other.childNodes)) { - return false; - } - if (groupings == null) { - if (other.groupings != null) { - return false; - } - } else if (!groupings.equals(other.groupings)) { - return false; - } - if (uses == null) { - if (other.uses != null) { - return false; - } - } else if (!uses.equals(other.uses)) { - return false; - } - if(presence != other.presence) { - return false; - } - if (mustDefinition == null) { - if (other.mustDefinition != null) { - return false; - } - } else if (!mustDefinition.equals(other.mustDefinition)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder( - ContainerSchemaNodeImpl.class.getSimpleName()); - sb.append("["); - sb.append("qname=" + qname); - sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); - sb.append(", augmenting=" + augmenting); - sb.append(", constraints=" + constraints); - sb.append(", augmentations=" + augmentations); - sb.append(", childNodes=" + childNodes.values()); - sb.append(", groupings=" + groupings); - sb.append(", uses=" + uses); - sb.append(", presence=" + presence); - sb.append(", mustDefinition="+ mustDefinition); - sb.append("]"); - return sb.toString(); - } - } - -} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/DeviationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/DeviationBuilder.java deleted file mode 100644 index abc6198811..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/DeviationBuilder.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import org.opendaylight.controller.model.parser.api.Builder; -import org.opendaylight.controller.model.parser.util.YangModelBuilderHelper; -import org.opendaylight.controller.yang.model.api.Deviation; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Deviation.Deviate; - - -public class DeviationBuilder implements MustAwareBuilder, Builder { - - private final DeviationImpl instance; - private MustDefinitionBuilder mustDefinitionBuilder; - - DeviationBuilder(String targetPathStr) { - SchemaPath targetPath = YangModelBuilderHelper.parsePath(targetPathStr); - instance = new DeviationImpl(targetPath); - } - - @Override - public Deviation build() { - // MUST definition - if(mustDefinitionBuilder != null) { - MustDefinition md = mustDefinitionBuilder.build(); - instance.setMustDefinition(md); - } - return instance; - } - - public void setDeviate(String deviate) { - if(deviate.equals("not-supported")) { - instance.setDeviate(Deviate.NOT_SUPPORTED); - } else if(deviate.equals("add")) { - instance.setDeviate(Deviate.ADD); - } else if(deviate.equals("replace")) { - instance.setDeviate(Deviate.REPLACE); - } else if(deviate.equals("delete")) { - instance.setDeviate(Deviate.DELETE); - } else { - throw new IllegalArgumentException("Unsupported type of 'deviate' statement: "+ deviate); - } - } - - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setMustDefinitionBuilder(MustDefinitionBuilder mustDefinitionBuilder) { - this.mustDefinitionBuilder = mustDefinitionBuilder; - } - - private static class DeviationImpl implements Deviation { - - private SchemaPath targetPath; - private Deviate deviate; - private String reference; - private MustDefinition mustDefinition; - - private DeviationImpl(SchemaPath targetPath) { - this.targetPath = targetPath; - } - - @Override - public SchemaPath getTargetPath() { - return targetPath; - } - - @Override - public Deviate getDeviate() { - return deviate; - } - private void setDeviate(Deviate deviate) { - this.deviate = deviate; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public String toString() { - return DeviationImpl.class.getSimpleName() +"[targetPath="+ targetPath +", deviate="+ deviate +", reference="+ reference +", mustDefinition="+ mustDefinition +"]"; - } - - @Override - public MustDefinition getMustDefinition() { - return mustDefinition; - } - private void setMustDefinition(MustDefinition mustDefinition) { - this.mustDefinition = mustDefinition; - } - - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/FeatureBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/FeatureBuilder.java deleted file mode 100644 index e91d2fb687..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/FeatureBuilder.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.List; - -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.FeatureDefinition; -import org.opendaylight.controller.yang.model.api.SchemaNode; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; - - -public class FeatureBuilder implements SchemaNodeBuilder { - - private final FeatureDefinitionImpl instance; - private final QName qname; - - FeatureBuilder(QName qname) { - this.qname = qname; - instance = new FeatureDefinitionImpl(qname); - } - - @Override - public SchemaNode build() { - return instance; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public void setPath(SchemaPath path) { - instance.setPath(path); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - private static class FeatureDefinitionImpl implements FeatureDefinition { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status; - - private FeatureDefinitionImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path;; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj; - if (qname == null) { - if (other.qname != null) { - return false; - } - } else if (!qname.equals(other.qname)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName()); - sb.append("[name="+ qname); - sb.append(", path="+ path); - sb.append(", description="+ description); - sb.append(", reference="+ reference); - sb.append(", status="+ status +"]"); - return sb.toString(); - } - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/GroupingBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/GroupingBuilderImpl.java deleted file mode 100644 index 5ffe307344..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/GroupingBuilderImpl.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class GroupingBuilderImpl implements GroupingBuilder { - - private final GroupingDefinitionImpl instance; - private final Set childNodes = new HashSet(); - private final Set groupings = new HashSet(); - private final Set addedTypedefs = new HashSet(); - private final Set usesNodes = new HashSet(); - - GroupingBuilderImpl(QName qname) { - this.instance = new GroupingDefinitionImpl(qname); - } - - @Override - public GroupingDefinition build() { - // CHILD NODES - Map childs = new HashMap(); - for(DataSchemaNodeBuilder node : childNodes) { - childs.put(node.getQName(), node.build()); - } - instance.setChildNodes(childs); - - // GROUPINGS - Set groupingDefinitions = new HashSet(); - for(GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); - } - instance.setGroupings(groupingDefinitions); - - // TYPEDEFS - Set> typedefs = new HashSet>(); - for (TypeDefinitionBuilder entry : addedTypedefs) { - typedefs.add(entry.build()); - } - instance.setTypeDefinitions(typedefs); - - // USES - Set usesNodeDefinitions = new HashSet(); - for(UsesNodeBuilder builder : usesNodes) { - usesNodeDefinitions.add(builder.build()); - } - instance.setUses(usesNodeDefinitions); - - return instance; - } - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - addedTypedefs.add(type); - } - @Override - public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); - } - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { - childNodes.add(childNode); - } - - @Override - public void addGrouping(GroupingBuilder grouping) { - groupings.add(grouping); - } - - @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - usesNodes.add(usesBuilder); - } - - - - private static class GroupingDefinitionImpl implements GroupingDefinition { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status; - - private Map childNodes; - private Set groupings; - private Set> typeDefinitions; - private Set uses; - - private GroupingDefinitionImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public Set getUses() { - return uses; - } - private void setUses(Set uses) { - this.uses = uses; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for(Map.Entry entry : childNodes.entrySet()) { - if(entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(GroupingDefinitionImpl.class.getSimpleName() +"[\n"); - sb.append("qname="+ qname +", \n"); - sb.append("path="+ path +", \n"); - sb.append("description="+ description +", \n"); - sb.append("reference="+ reference +", \n"); - sb.append("status="+ status +", \n"); - sb.append("childNodes="+ childNodes.values() +", \n"); - sb.append("groupings="+ groupings +"]"); - return sb.toString(); - } - } - - /** - * Always returns null. - */ - @Override - public QName getQName() { - return null; - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilder.java deleted file mode 100644 index f2ea8cadd0..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilder.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.List; - -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeAwareBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.LeafListSchemaNode; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; - - -public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder, TypeAwareBuilder, MustAwareBuilder, DataSchemaNodeBuilder { - - private final LeafListSchemaNodeImpl instance; - private final QName qname; - private TypeDefinition type; - private MustDefinitionBuilder mustDefinitionBuilder; - - LeafListSchemaNodeBuilder(QName qname) { - this.qname = qname; - instance = new LeafListSchemaNodeImpl(qname); - } - - - @Override - public DataSchemaNode build() { - if(mustDefinitionBuilder != null) { - MustDefinition mustDefinition = mustDefinitionBuilder.build(); - instance.setMustDefinition(mustDefinition); - } - return instance; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public void setPath(SchemaPath path) { - instance.setPath(path); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public TypeDefinition getType() { - return type; - } - - @Override - public void setType(TypeDefinition type) { - this.type = type; - instance.setType(type); - } - - @Override - public void setMustDefinitionBuilder(MustDefinitionBuilder mustDefinitionBuilder) { - this.mustDefinitionBuilder = mustDefinitionBuilder; - } - - public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); - } - public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); - } - public void setConstraints(ConstraintDefinition constraints) { - instance.setConstraints(constraints); - } - public void setUserOrdered(boolean userOrdered) { - instance.setUserOrdered(userOrdered); - } - - - private class LeafListSchemaNodeImpl implements LeafListSchemaNode { - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status = Status.CURRENT; - - private boolean augmenting; - private boolean configuration; - private ConstraintDefinition constraints; - - private TypeDefinition type; - private boolean userOrdered; - - private MustDefinition mustDefinition; - - private LeafListSchemaNodeImpl(QName qname) { - this.qname = qname; - } - - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path;; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - private void setAugmenting(boolean augmenting) { - this.augmenting = augmenting; - } - - @Override - public boolean isConfiguration() { - return configuration; - } - private void setConfiguration(boolean configuration) { - this.configuration = configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraints; - } - private void setConstraints(ConstraintDefinition constraints) { - this.constraints = constraints; - } - - @Override - public TypeDefinition getType() { - return type; - } - public void setType(TypeDefinition> type) { - this.type = type; - } - - @Override - public boolean isUserOrdered() { - return userOrdered; - } - private void setUserOrdered(boolean userOrdered) { - this.userOrdered = userOrdered; - } - - @Override - public MustDefinition getMustDefinition() { - return mustDefinition; - } - private void setMustDefinition(MustDefinition mustDefinition) { - this.mustDefinition = mustDefinition; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - return LeafListSchemaNodeImpl.class.getSimpleName() +"[qname="+ qname +", type="+ type +"]"; - } - } - - } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafSchemaNodeBuilder.java deleted file mode 100644 index f50ac8a665..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/LeafSchemaNodeBuilder.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.List; - -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeAwareBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.LeafSchemaNode; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; - - -public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder, - SchemaNodeBuilder, TypeAwareBuilder, MustAwareBuilder { - - private final QName qname; - private final LeafSchemaNodeImpl instance; - private TypeDefinition type; - private MustDefinitionBuilder mustDefinitionBuilder; - - LeafSchemaNodeBuilder(QName qname) { - this.qname = qname; - instance = new LeafSchemaNodeImpl(qname); - } - - @Override - public LeafSchemaNode build() { - if (mustDefinitionBuilder != null) { - MustDefinition mustDefinition = mustDefinitionBuilder.build(); - instance.setMustDefinition(mustDefinition); - } - return instance; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public void setPath(SchemaPath path) { - instance.setPath(path); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); - } - - public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); - } - - public void setConstraints(ConstraintDefinition constraints) { - instance.setConstraints(constraints); - } - - @Override - public TypeDefinition getType() { - return type; - } - - @Override - public void setType(TypeDefinition type) { - this.type = type; - instance.setType(type); - } - - @Override - public void setMustDefinitionBuilder( - MustDefinitionBuilder mustDefinitionBuilder) { - this.mustDefinitionBuilder = mustDefinitionBuilder; - } - - private class LeafSchemaNodeImpl implements LeafSchemaNode { - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status = Status.CURRENT; - - private boolean augmenting; - private boolean configuration; - private ConstraintDefinition constraints; - - private TypeDefinition type; - private MustDefinition mustDefinition; - - private LeafSchemaNodeImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - - private void setStatus(Status status) { - if (status != null) { - this.status = status; - } - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - - private void setAugmenting(boolean augmenting) { - this.augmenting = augmenting; - } - - @Override - public boolean isConfiguration() { - return configuration; - } - - private void setConfiguration(boolean configuration) { - this.configuration = configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraints; - } - - private void setConstraints(ConstraintDefinition constraints) { - this.constraints = constraints; - } - - @Override - public TypeDefinition getType() { - return type; - } - - private void setType(TypeDefinition> type) { - this.type = type; - } - - @Override - public MustDefinition getMustDefinition() { - return mustDefinition; - } - - private void setMustDefinition(MustDefinition mustDefinition) { - this.mustDefinition = mustDefinition; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder( - LeafSchemaNodeImpl.class.getSimpleName()); - sb.append("["); - sb.append("qname=" + qname); - sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); - sb.append(", augmenting=" + augmenting); - sb.append(", configuration=" + configuration); - sb.append(", constraints=" + constraints); - sb.append(", type=" + type); - sb.append(", mustDefinition=" + mustDefinition); - sb.append("]"); - return sb.toString(); - } - } -} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilder.java deleted file mode 100644 index 3059ba91db..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilder.java +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.AbstractChildNodeBuilder; -import org.opendaylight.controller.model.parser.api.AugmentationTargetBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.ListSchemaNode; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder, TypeDefinitionAwareBuilder { - - private final ListSchemaNodeImpl instance; - - private final Set addedTypedefs = new HashSet(); - private final Set augmentations = new HashSet(); - private final Set usesNodes = new HashSet(); - - ListSchemaNodeBuilder(QName qname) { - super(qname); - instance = new ListSchemaNodeImpl(qname); - } - - @Override - public ListSchemaNode build() { - // CHILD NODES - Map childs = new HashMap(); - for(DataSchemaNodeBuilder node : childNodes) { - childs.put(node.getQName(), node.build()); - } - instance.setChildNodes(childs); - - // TYPEDEFS - Set> typedefs = new HashSet>(); - for (TypeDefinitionBuilder entry : addedTypedefs) { - typedefs.add(entry.build()); - } - instance.setTypeDefinitions(typedefs); - - // USES - Set usesNodeDefinitions = new HashSet(); - for(UsesNodeBuilder builder : usesNodes) { - usesNodeDefinitions.add(builder.build()); - } - instance.setUses(usesNodeDefinitions); - - // GROUPINGS - Set groupingDefinitions = new HashSet(); - for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); - } - instance.setGroupings(groupingDefinitions); - - instance.setAvailableAugmentations(augmentations); - - return instance; - } - - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - addedTypedefs.add(type); - } - - @Override - public void setPath(SchemaPath path) { - instance.setPath(path); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - usesNodes.add(usesBuilder); - } - - @Override - public void addAugmentation(AugmentationSchema augmentationSchema) { - augmentations.add(augmentationSchema); - } - - public void setKeyDefinition(List keyDefinition) { - instance.setKeyDefinition(keyDefinition); - } - public void setAugmenting(boolean augmenting) { - instance.setAugmenting(augmenting); - } - public void setConfiguration(boolean configuration) { - instance.setConfiguration(configuration); - } - public void setConstraints(ConstraintDefinition constraints) { - instance.setConstraints(constraints); - } - public void setUserOrdered(boolean userOrdered) { - instance.setUserOrdered(userOrdered); - } - - - private class ListSchemaNodeImpl implements ListSchemaNode { - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status = Status.CURRENT; - - private List keyDefinition; - - private boolean augmenting; - private boolean configuration; - private ConstraintDefinition constraints; - - private Set augmentations; - - private Map childNodes; - private Set> typeDefinitions; - private Set groupings; - private Set uses; - - private boolean userOrdered; - - private ListSchemaNodeImpl(QName qname) { - this.qname = qname; - } - - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public List getKeyDefinition() { - return keyDefinition; - } - private void setKeyDefinition(List keyDefinition) { - this.keyDefinition = keyDefinition; - } - - @Override - public boolean isAugmenting() { - return augmenting; - } - private void setAugmenting(boolean augmenting) { - this.augmenting = augmenting; - } - - @Override - public boolean isConfiguration() { - return configuration; - } - private void setConfiguration(boolean configuration) { - this.configuration = configuration; - } - - @Override - public ConstraintDefinition getConstraints() { - return constraints; - } - private void setConstraints(ConstraintDefinition constraints) { - this.constraints = constraints; - } - - @Override - public Set getAvailableAugmentations() { - return augmentations; - } - private void setAvailableAugmentations(Set augmentations) { - this.augmentations = augmentations; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public Set getUses() { - return uses; - } - private void setUses(Set uses) { - this.uses = uses; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for(Map.Entry entry : childNodes.entrySet()) { - if(entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public boolean isUserOrdered() { - return userOrdered; - } - private void setUserOrdered(boolean userOrdered) { - this.userOrdered = userOrdered; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((keyDefinition == null) ? 0 : keyDefinition.hashCode()); - result = prime * result + (augmenting ? 1231 : 1237); - result = prime * result + (configuration ? 1231 : 1237); - result = prime * result + ((constraints == null) ? 0 : constraints.hashCode()); - result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); - result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode()); - result = prime * result + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode()); - result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); - result = prime * result + ((uses == null) ? 0 : uses.hashCode()); - result = prime * result + (userOrdered ? 1231 : 1237); - return result; - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj; - if (qname == null) { - if (other.qname != null) { - return false; - } - } else if (!qname.equals(other.qname)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (status == null) { - if (other.status != null) { - return false; - } - } else if (!status.equals(other.status)) { - return false; - } - if (keyDefinition == null) { - if (other.keyDefinition != null) { - return false; - } - } else if (!keyDefinition.equals(other.keyDefinition)) { - return false; - } - if(augmenting != other.augmenting) { - return false; - } - if(configuration != other.configuration) { - return false; - } - if (constraints == null) { - if (other.constraints != null) { - return false; - } - } else if (!constraints.equals(other.constraints)) { - return false; - } - if (augmentations == null) { - if (other.augmentations != null) { - return false; - } - } else if (!augmentations.equals(other.augmentations)) { - return false; - } - if (childNodes == null) { - if (other.childNodes != null) { - return false; - } - } else if (!childNodes.equals(other.childNodes)) { - return false; - } - if (typeDefinitions == null) { - if (other.typeDefinitions != null) { - return false; - } - } else if (!typeDefinitions.equals(other.typeDefinitions)) { - return false; - } - if (groupings == null) { - if (other.groupings != null) { - return false; - } - } else if (!groupings.equals(other.groupings)) { - return false; - } - if (uses == null) { - if (other.uses != null) { - return false; - } - } else if (!uses.equals(other.uses)) { - return false; - } - if(userOrdered != other.userOrdered) { - return false; - } - return true; - } - - - - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(ListSchemaNodeImpl.class.getSimpleName()); - sb.append("["); - sb.append("qname="+ qname); - sb.append(", path="+ path); - sb.append(", description="+ description); - sb.append(", reference="+ reference); - sb.append(", status="+ status); - sb.append(", keyDefinition="+ keyDefinition); - sb.append(", augmenting="+ augmenting); - sb.append(", configuration="+ configuration); - sb.append(", constraints="+ constraints); - sb.append(", augmentations="+ augmentations); - sb.append(", childNodes="+ childNodes.values()); - sb.append(", typedefinitions="+ typeDefinitions); - sb.append(", groupings="+ groupings); - sb.append(", uses="+ uses); - sb.append(", userOrdered="+ userOrdered); - sb.append("]"); - return sb.toString(); - } - } - - } \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ModuleBuilder.java deleted file mode 100644 index 98cfbb6e16..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/ModuleBuilder.java +++ /dev/null @@ -1,824 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - -import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.model.parser.api.Builder; -import org.opendaylight.controller.model.parser.api.ChildNodeBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.TypeAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.Deviation; -import org.opendaylight.controller.yang.model.api.FeatureDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.api.ModuleImport; -import org.opendaylight.controller.yang.model.api.NotificationDefinition; -import org.opendaylight.controller.yang.model.api.RpcDefinition; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -/** - * This builder builds Module object. If this module is dependent on external - * module/modules, these dependencies must be resolved before module is built, - * otherwise result may not be valid. - */ -public class ModuleBuilder implements Builder { - - private final ModuleImpl instance; - private final String name; - private String prefix; - - private final Set imports = new HashSet(); - private Set augmentations; - - /** - * All nodes, that can contain other nodes - */ - private final Map, Builder> moduleNodes = new HashMap, Builder>(); - - /** - * Holds all child (DataSchemaNode) nodes: anyxml, choice, container, list, leaf, leaf-list. - */ - private final Map, DataSchemaNodeBuilder> addedChilds = new HashMap, DataSchemaNodeBuilder>(); - - private final Map, GroupingBuilder> addedGroupings = new HashMap, GroupingBuilder>(); - private final Set addedAugments = new HashSet(); - private final Map, UsesNodeBuilder> addedUsesNodes = new HashMap, UsesNodeBuilder>(); - private final Map, RpcDefinitionBuilder> addedRpcs = new HashMap, RpcDefinitionBuilder>(); - private final Set addedNotifications = new HashSet(); - private final Map, FeatureBuilder> addedFeatures = new HashMap, FeatureBuilder>(); - private final Map addedDeviations = new HashMap(); - private final Map, TypeDefinitionBuilder> addedTypedefs = new HashMap, TypeDefinitionBuilder>(); - - - private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); - - - public ModuleBuilder(String name) { - this.name = name; - instance = new ModuleImpl(name); - } - - /** - * Build new Module object based on this builder. Throws IllegalStateException if builder contains unresolved nodes. - */ - public Module build() { - instance.setImports(imports); - - // TYPEDEFS - Set> typedefs = buildModuleTypedefs(addedTypedefs); - instance.setTypeDefinitions(typedefs); - - // CHILD NODES - final Map childNodes = buildModuleChildNodes(addedChilds); - instance.setChildNodes(childNodes); - - // GROUPINGS - final Set groupings = buildModuleGroupings(addedGroupings); - instance.setGroupings(groupings); - - // USES - final Set usesNodeDefinitions = buildUsesNodes(addedUsesNodes); - instance.setUses(usesNodeDefinitions); - - // FEATURES - Set features = buildModuleFeatures(addedFeatures); - instance.setFeatures(features); - - // NOTIFICATIONS - final Set notifications = new HashSet(); - for (NotificationBuilder entry : addedNotifications) { - notifications.add((NotificationDefinition) entry.build()); - } - instance.setNotifications(notifications); - - // AUGMENTATIONS -// final Set augmentations = new HashSet(); -// for(AugmentationSchemaBuilder entry : addedAugments) { -// augmentations.add(entry.build()); -// } -// instance.setAugmentations(augmentations); - instance.setAugmentations(augmentations); - - // RPCs - final Set rpcs = buildModuleRpcs(addedRpcs); - instance.setRpcs(rpcs); - - // DEVIATIONS - Set deviations = new HashSet(); - for(Map.Entry entry : addedDeviations.entrySet()) { - deviations.add(entry.getValue().build()); - } - instance.setDeviations(deviations); - - return instance; - } - - Builder getNode(List path) { - return moduleNodes.get(path); - } - - Map, TypeAwareBuilder> getDirtyNodes() { - return dirtyNodes; - } - - String getName() { - return name; - } - - String getPrefix() { - return prefix; - } - - Set getAddedAugments() { - return addedAugments; - } - - - public void addDirtyNode(Stack path) { - List dirtyNodePath = new ArrayList(path); - TypeAwareBuilder nodeBuilder = (TypeAwareBuilder)moduleNodes.get(dirtyNodePath); - dirtyNodes.put(dirtyNodePath, nodeBuilder); - } - - public void setNamespace(URI namespace) { - instance.setNamespace(namespace); - } - - public void setRevision(Date revision) { - instance.setRevision(revision); - } - - public void setPrefix(String prefix) { - this.prefix = prefix; - instance.setPrefix(prefix); - } - - public void setYangVersion(String yangVersion) { - instance.setYangVersion(yangVersion); - } - - public void setDescription(String description) { - instance.setDescription(description); - } - public void setReference(String reference) { - instance.setReference(reference); - } - public void setOrganization(String organization) { - instance.setOrganization(organization); - } - public void setContact(String contact) { - instance.setContact(contact); - } - public void setAugmentations(Set augmentations) { - this.augmentations = augmentations; - } - - public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) { - ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix); - return imports.add(moduleImport); - } - - public Set getModuleImports() { - return imports; - } - - public ContainerSchemaNodeBuilder addContainerNode(QName containerName, Stack parentPath) { - List pathToNode = new ArrayList(parentPath); - - ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(containerName); - - ChildNodeBuilder parent = (ChildNodeBuilder)moduleNodes.get(pathToNode); - if(parent != null) { - parent.addChildNode(containerBuilder); - } - - pathToNode.add(containerName.getLocalName()); - moduleNodes.put(pathToNode, containerBuilder); - addedChilds.put(pathToNode, containerBuilder); - - return containerBuilder; - } - - public ListSchemaNodeBuilder addListNode(QName listName, Stack parentPath) { - List pathToNode = new ArrayList(parentPath); - - ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName); - - ChildNodeBuilder parent = (ChildNodeBuilder)moduleNodes.get(pathToNode); - if(parent != null) { - parent.addChildNode(listBuilder); - } - - pathToNode.add(listName.getLocalName()); - moduleNodes.put(pathToNode, listBuilder); - addedChilds.put(pathToNode, listBuilder); - - return listBuilder; - } - - public LeafSchemaNodeBuilder addLeafNode(QName leafName, Stack parentPath) { - List pathToNode = new ArrayList(parentPath); - - LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName); - - ChildNodeBuilder parent = (ChildNodeBuilder)moduleNodes.get(pathToNode); - if(parent != null) { - parent.addChildNode(leafBuilder); - } - - pathToNode.add(leafName.getLocalName()); - addedChilds.put(pathToNode, leafBuilder); - moduleNodes.put(pathToNode, leafBuilder); - - return leafBuilder; - } - - public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName, Stack parentPath) { - List pathToNode = new ArrayList(parentPath); - - LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(leafListName); - ChildNodeBuilder parent = (ChildNodeBuilder)moduleNodes.get(pathToNode); - if(parent != null) { - parent.addChildNode(leafListBuilder); - } - - pathToNode.add(leafListName.getLocalName()); - addedChilds.put(pathToNode, leafListBuilder); - moduleNodes.put(pathToNode, leafListBuilder); - - return leafListBuilder; - } - - public GroupingBuilder addGrouping(QName qname, Stack parentPath) { - List pathToGroup = new ArrayList(parentPath); - - GroupingBuilder builder = new GroupingBuilderImpl(qname); - ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder)moduleNodes.get(pathToGroup); - if(parentNodeBuilder != null) { - parentNodeBuilder.addGrouping(builder); - } - - pathToGroup.add(qname.getLocalName()); - moduleNodes.put(pathToGroup, builder); - addedGroupings.put(pathToGroup, builder); - - return builder; - } - - public AugmentationSchemaBuilder addAugment(String name, Stack parentPath) { - List pathToAugment = new ArrayList(parentPath); - - AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name); - - // augment can only be in 'module' or 'uses' statement - UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); - if(parent != null) { - parent.addAugment(builder); - } - - pathToAugment.add(name); - moduleNodes.put(pathToAugment, builder); - addedAugments.add(builder); - - return builder; - } - - public UsesNodeBuilder addUsesNode(String groupingPathStr, Stack parentPath) { - List pathToUses = new ArrayList(parentPath); - - UsesNodeBuilder builder = new UsesNodeBuilderImpl(groupingPathStr); - - ChildNodeBuilder parent = (ChildNodeBuilder)moduleNodes.get(pathToUses); - if(parent != null) { - parent.addUsesNode(builder); - } - - pathToUses.add(groupingPathStr); - addedUsesNodes.put(pathToUses, builder); - - return builder; - } - - public RpcDefinitionBuilder addRpc(QName qname, Stack parentPath) { - List pathToRpc = new ArrayList(parentPath); - - RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); - - pathToRpc.add(qname.getLocalName()); - addedRpcs.put(pathToRpc, rpcBuilder); - - QName inputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "input"); - ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName); - List pathToInput = new ArrayList(pathToRpc); - pathToInput.add("input"); - moduleNodes.put(pathToInput, inputBuilder); - rpcBuilder.setInput(inputBuilder); - - QName outputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "output"); - ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName); - List pathToOutput = new ArrayList(pathToRpc); - pathToOutput.add("output"); - moduleNodes.put(pathToOutput, outputBuilder); - rpcBuilder.setOutput(outputBuilder); - - return rpcBuilder; - } - - public NotificationBuilder addNotification(QName notificationName, Stack parentPath) { - List pathToNotification = new ArrayList(parentPath); - - NotificationBuilder notificationBuilder = new NotificationBuilder(notificationName); - - pathToNotification.add(notificationName.getLocalName()); - moduleNodes.put(pathToNotification, notificationBuilder); - addedNotifications.add(notificationBuilder); - - return notificationBuilder; - } - - public FeatureBuilder addFeature(QName featureName, Stack parentPath) { - List pathToFeature = new ArrayList(parentPath); - pathToFeature.add(featureName.getLocalName()); - - FeatureBuilder builder = new FeatureBuilder(featureName); - addedFeatures.put(pathToFeature, builder); - return builder; - } - - public TypedefBuilder addTypedef(QName typeDefName, Stack parentPath) { - List pathToType = new ArrayList(parentPath); - TypedefBuilder builder = new TypedefBuilder(typeDefName); - TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder)moduleNodes.get(pathToType); - if(parent != null) { - parent.addTypedef(builder); - } - pathToType.add(typeDefName.getLocalName()); - addedTypedefs.put(pathToType, builder); - moduleNodes.put(pathToType, builder); - return builder; - } - - public Set getModuleTypedefs() { - Set typedefs = new HashSet(); - for(Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { - if(entry.getKey().size() == 2) { - typedefs.add(entry.getValue()); - } - } - return typedefs; - } - - public void setType(TypeDefinition type, Stack parentPath) { - TypeAwareBuilder parent = (TypeAwareBuilder)moduleNodes.get(parentPath); - parent.setType(type); - } - - public DeviationBuilder addDeviation(String targetPath) { - DeviationBuilder builder = new DeviationBuilder(targetPath); - addedDeviations.put(targetPath, builder); - return builder; - } - - public MustDefinitionBuilder addMustDefinition(String xpathStr, Stack parentPath) { - MustAwareBuilder parent = (MustAwareBuilder)moduleNodes.get(parentPath); - String path = parentPath.get(parentPath.size()-1); - if(parent == null) { - for(Map.Entry db : addedDeviations.entrySet()) { - String key = db.getKey(); - if(key.equals(path)) { - parent = db.getValue(); - } - } - } - MustDefinitionBuilder builder = new MustDefinitionBuilder(xpathStr); - parent.setMustDefinitionBuilder(builder); - return builder; - } - - public ModuleBuilder addSubmodule(QName qname) { - ModuleBuilder submoduleBuilder = new ModuleBuilder(qname.getLocalName()); - return submoduleBuilder; - } - - - - private class ModuleImpl implements Module { - - private URI namespace; - private final String name; - private Date revision; - private String prefix; - private String yangVersion; - private String description; - private String reference; - private String organization; - private String contact; - private Set imports; - private Set features; - private Set> typeDefinitions; - private Set notifications; - private Set augmentations; - private Set rpcs; - private Set deviations; - private Map childNodes; - private Set groupings; - private Set uses; - - private ModuleImpl(String name) { - this.name = name; - } - - - @Override - public URI getNamespace() { - return namespace; - } - private void setNamespace(URI namespace) { - this.namespace = namespace; - } - - @Override - public String getName() { - return name; - } - - @Override - public Date getRevision() { - return revision; - } - private void setRevision(Date revision) { - this.revision = revision; - } - - @Override - public String getPrefix() { - return prefix; - } - private void setPrefix(String prefix) { - this.prefix = prefix; - } - - @Override - public String getYangVersion() { - return yangVersion; - } - private void setYangVersion(String yangVersion) { - this.yangVersion = yangVersion; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public String getOrganization() { - return organization; - } - private void setOrganization(String organization) { - this.organization = organization; - } - - @Override - public String getContact() { - return contact; - } - private void setContact(String contact) { - this.contact = contact; - } - - @Override - public Set getImports() { - return imports; - } - private void setImports(Set imports) { - this.imports = imports; - } - - @Override - public Set getFeatures() { - return features; - } - private void setFeatures(Set features) { - this.features = features; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public Set getNotifications() { - return notifications; - } - private void setNotifications(Set notifications) { - this.notifications = notifications; - } - - @Override - public Set getAugmentations() { - return augmentations; - } - private void setAugmentations(Set augmentations) { - this.augmentations = augmentations; - } - - @Override - public Set getRpcs() { - return rpcs; - } - private void setRpcs(Set rpcs) { - this.rpcs = rpcs; - } - - @Override - public Set getDeviations() { - return deviations; - } - private void setDeviations(Set deviations) { - this.deviations = deviations; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public Set getUses() { - return uses; - } - private void setUses(Set uses) { - this.uses = uses; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for(Map.Entry entry : childNodes.entrySet()) { - if(entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName()); - sb.append("[\n"); - sb.append("name="+ name +",\n"); - sb.append("namespace="+ namespace +",\n"); - sb.append("revision="+ revision +",\n"); - sb.append("prefix="+ prefix +",\n"); - sb.append("yangVersion="+ yangVersion +",\n"); - sb.append("description="+ description +",\n"); - sb.append("reference="+ reference +",\n"); - sb.append("organization="+ organization +",\n"); - sb.append("contact="+ contact +",\n"); - sb.append("childNodes="+ childNodes.values() +",\n"); - sb.append("groupings="+ groupings +",\n"); - sb.append("imports="+ imports +",\n"); - sb.append("features="+ features +",\n"); - sb.append("typeDefinitions="+ typeDefinitions +",\n"); - sb.append("notifications="+ notifications +",\n"); - sb.append("augmentations="+ augmentations +",\n"); - sb.append("rpcs="+ rpcs +",\n"); - sb.append("deviations="+ deviations +"\n"); - sb.append("]"); - return sb.toString(); - } - - } - - private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) { - ModuleImport moduleImport = new ModuleImport() { - @Override - public String getModuleName() { - return moduleName; - } - @Override - public Date getRevision() { - return revision; - } - @Override - public String getPrefix() { - return prefix; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode()); - result = prime * result + ((revision == null) ? 0 : revision.hashCode()); - result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ModuleImport other = (ModuleImport) obj; - if (getModuleName() == null) { - if (other.getModuleName() != null) { - return false; - } - } else if (!getModuleName().equals(other.getModuleName())) { - return false; - } - if (getRevision() == null) { - if (other.getRevision() != null) { - return false; - } - } else if (!getRevision().equals(other.getRevision())) { - return false; - } - if (getPrefix() == null) { - if (other.getPrefix() != null) { - return false; - } - } else if (!getPrefix().equals(other.getPrefix())) { - return false; - } - return true; - } - - @Override - public String toString() { - return "ModuleImport[moduleName="+ moduleName +", revision="+ revision +", prefix="+ prefix +"]"; - } - }; - return moduleImport; - } - - /** - * Traverse through given addedChilds and add only direct module childs. Direct - * module child path size is 2 (1. module name, 2. child name). - * - * @param addedChilds - * @return map of children, where key is child QName and value is child itself - */ - private Map buildModuleChildNodes( - Map, DataSchemaNodeBuilder> addedChilds) { - final Map childNodes = new HashMap(); - for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds - .entrySet()) { - if (entry.getKey().size() == 2) { - DataSchemaNode node = entry.getValue().build(); - QName qname = entry.getValue().getQName(); - childNodes.put(qname, node); - } - } - return childNodes; - } - - /** - * Traverse through given addedGroupings and add only direct module groupings. Direct - * module grouping path size is 2 (1. module name, 2. grouping name). - * - * @param addedGroupings - * @return set of built GroupingDefinition objects - */ - private Set buildModuleGroupings(Map, GroupingBuilder> addedGroupings) { - final Set groupings = new HashSet(); - for(Map.Entry, GroupingBuilder> entry : addedGroupings.entrySet()) { - if(entry.getKey().size() == 2) { - groupings.add(entry.getValue().build()); - } - } - return groupings; - } - - /** - * Traverse through given addedRpcs and build RpcDefinition objects. - * @param addedRpcs - * @return set of built RpcDefinition objects - */ - private Set buildModuleRpcs(Map, RpcDefinitionBuilder> addedRpcs) { - final Set rpcs = new HashSet(); - RpcDefinitionBuilder builder; - for(Map.Entry, RpcDefinitionBuilder> entry : addedRpcs.entrySet()) { - builder = entry.getValue(); - RpcDefinition rpc = builder.build(); - rpcs.add(rpc); - } - return rpcs; - } - - /** - * Traverse through given addedTypedefs and add only direct module typedef statements. Direct - * module typedef path size is 2 (1. module name, 2. typedef name). - * - * @param addedTypedefs - * @return set of built module typedef statements - */ - private Set> buildModuleTypedefs(Map, TypeDefinitionBuilder> addedTypedefs) { - Set> typedefs = new HashSet>(); - for(Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { - if(entry.getKey().size() == 2) { - TypeDefinition> node = entry.getValue().build(); - typedefs.add(node); - } - } - return typedefs; - } - - /** - * Traverse through given addedUsesNodes and add only direct module uses nodes. Direct - * module uses node path size is 2 (1. module name, 2. uses name). - * - * @param addedUsesNodes - * @return set of built module uses nodes - */ - private Set buildUsesNodes(Map, UsesNodeBuilder> addedUsesNodes) { - final Set usesNodeDefinitions = new HashSet(); - for (Map.Entry, UsesNodeBuilder> entry : addedUsesNodes.entrySet()) { - if (entry.getKey().size() == 2) { - usesNodeDefinitions.add(entry.getValue().build()); - } - } - return usesNodeDefinitions; - } - - /** - * Traverse through given addedFeatures and add only direct module features. Direct - * module feature path size is 2 (1. module name, 2. feature name). - * - * @param addedFeatures - * @return set of built module features - */ - private Set buildModuleFeatures(Map, FeatureBuilder> addedFeatures) { - Set features = new HashSet(); - for(Map.Entry, FeatureBuilder> entry : addedFeatures.entrySet()) { - if(entry.getKey().size() == 2) { - features.add((FeatureDefinition)entry.getValue().build()); - } - } - return features; - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustDefinitionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustDefinitionBuilder.java deleted file mode 100644 index fecfae8020..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustDefinitionBuilder.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import org.opendaylight.controller.model.parser.api.Builder; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; - - -public class MustDefinitionBuilder implements Builder { - - private final MustDefinitionImpl instance; - - MustDefinitionBuilder(String xpathStr) { - instance = new MustDefinitionImpl(xpathStr); - } - - @Override - public MustDefinition build() { - return instance; - } - - public void setDescription(String description) { - instance.setDescription(description); - } - - public void setReference(String reference) { - instance.setReference(reference); - } - - private static class MustDefinitionImpl implements MustDefinition { - - private final String xpathStr; - private String description; - private String reference; - - private MustDefinitionImpl(String xpathStr) { - this.xpathStr = xpathStr; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getErrorAppTag() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getErrorMessage() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public RevisionAwareXPath getXpath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - return MustDefinitionImpl.class.getSimpleName() +"[xpathStr="+ xpathStr +"]"; - } - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/NotificationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/NotificationBuilder.java deleted file mode 100644 index 52decc0645..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/NotificationBuilder.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.AbstractChildNodeBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.NotificationDefinition; -import org.opendaylight.controller.yang.model.api.SchemaNode; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class NotificationBuilder extends AbstractChildNodeBuilder implements TypeDefinitionAwareBuilder, SchemaNodeBuilder { - - private final NotificationDefinitionImpl instance; - private final Set addedTypedefs = new HashSet(); - private final Set addedUsesNodes = new HashSet(); - - NotificationBuilder(QName qname) { - super(qname); - instance = new NotificationDefinitionImpl(qname); - } - - @Override - public SchemaNode build() { - // CHILD NODES - Map childs = new HashMap(); - for (DataSchemaNodeBuilder node : childNodes) { - childs.put(node.getQName(), node.build()); - } - instance.setChildNodes(childs); - - // GROUPINGS - Set groupingDefinitions = new HashSet(); - for (GroupingBuilder builder : groupings) { - groupingDefinitions.add(builder.build()); - } - instance.setGroupings(groupingDefinitions); - - // TYPEDEFS - Set> typedefs = new HashSet>(); - for (TypeDefinitionBuilder entry : addedTypedefs) { - typedefs.add(entry.build()); - } - instance.setTypeDefinitions(typedefs); - - // USES - Set uses = new HashSet(); - for (UsesNodeBuilder builder : addedUsesNodes) { - uses.add(builder.build()); - } - instance.setUses(uses); - - return instance; - } - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - addedTypedefs.add(type); - } - - @Override - public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { - addedUsesNodes.add(usesNodeBuilder); - } - - @Override - public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - - private class NotificationDefinitionImpl implements NotificationDefinition { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status; - - private Map childNodes; - private Set groupings; - private Set> typeDefinitions; - - private Set uses; - - private NotificationDefinitionImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public Set getChildNodes() { - return new HashSet(childNodes.values()); - } - private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; - } - - @Override - public Set getGroupings() { - return groupings; - } - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public Set getUses() { - return uses; - } - private void setUses(Set uses) { - this.uses = uses; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return childNodes.get(name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - DataSchemaNode result = null; - for (Map.Entry entry : childNodes.entrySet()) { - if (entry.getKey().getLocalName().equals(name)) { - result = entry.getValue(); - break; - } - } - return result; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder( - NotificationDefinitionImpl.class.getSimpleName()); - sb.append("[qname=" + qname + "]"); - return sb.toString(); - } - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/TypedefBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/TypedefBuilder.java deleted file mode 100644 index a6a3c609cf..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/TypedefBuilder.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.List; - -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.util.UnknownType; -import org.opendaylight.controller.model.util.YangTypesConverter; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; - - -public class TypedefBuilder implements TypeDefinitionBuilder, SchemaNodeBuilder, TypeAwareBuilder { - - private final QName qname; - private SchemaPath schemaPath; - private TypeDefinition baseType; - - private String description; - private String reference; - private Status status; - - TypedefBuilder(QName qname) { - this.qname = qname; - } - - @Override - public TypeDefinition> build() { - final TypeDefinition type = YangTypesConverter.javaTypeForBaseYangType(qname); - if(type != null) { - return type; - } else { - if(baseType != null) { - // typedef - TypeDefinitionImpl instance = new TypeDefinitionImpl(qname); - instance.setDescription(description); - instance.setReference(reference); - instance.setStatus(status); - instance.setPath(schemaPath); - instance.setBaseType(baseType); - return instance; - } else { - // type - final UnknownType.Builder unknownBuilder = new UnknownType.Builder(qname, description, reference); - unknownBuilder.status(status); - return unknownBuilder.build(); - } - } - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public void setPath(final SchemaPath schemaPath) { - this.schemaPath = schemaPath; - } - - @Override - public void setDescription(final String description) { - this.description = description; - } - - @Override - public void setReference(final String reference) { - this.reference = reference; - } - - @Override - public void setStatus(final Status status) { - if(status != null) { - this.status = status; - } - } - - @Override - public TypeDefinition getType() { - return baseType; - } - - @Override - public void setType(TypeDefinition baseType) { - this.baseType = baseType; - } - - @Override - public TypeDefinition getBaseType() { - return baseType; - } - - - - private static class TypeDefinitionImpl> implements TypeDefinition { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status = Status.CURRENT; - private T baseType; - - private TypeDefinitionImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - private void setStatus(Status status) { - this.status = status; - } - - @Override - public T getBaseType() { - return baseType; - } - private void setBaseType(T type) { - this.baseType = type; - } - - @Override - public String getUnits() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Object getDefaultValue() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(TypeDefinitionImpl.class.getSimpleName()); - sb.append("["); - sb.append("qname="+ qname); - sb.append(", path="+ path); - sb.append(", description="+ description); - sb.append(", reference="+ reference); - sb.append(", status="+ status); - sb.append(", baseType="+ baseType +"]"); - return sb.toString(); - } - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/UsesNodeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/UsesNodeBuilderImpl.java deleted file mode 100644 index df626f145f..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/UsesNodeBuilderImpl.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.model.parser.api.Builder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.UsesNode; - -public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { - - private final String groupingPathStr; - - UsesNodeBuilderImpl(String groupingPathStr) { - this.groupingPathStr = groupingPathStr; - } - - @Override - public UsesNode build() { - SchemaPath groupingPath = parseUsesPath(groupingPathStr); - final UsesNodeImpl instance = new UsesNodeImpl(groupingPath); - return instance; - } - - public void addAugment(AugmentationSchemaBuilder augmentBuilder) { - // TODO: - } - - private SchemaPath parseUsesPath(String augmentPath) { - String[] splittedPath = augmentPath.split("/"); - List path = new ArrayList(); - QName name; - for (String pathElement : splittedPath) { - String[] splittedElement = pathElement.split(":"); - if (splittedElement.length == 1) { - name = new QName(null, null, null, splittedElement[0]); - } else { - name = new QName(null, null, splittedElement[0], - splittedElement[1]); - } - path.add(name); - } - // TODO: absolute vs relative? - return new SchemaPath(path, false); - } - - private static class UsesNodeImpl implements UsesNode { - - private final SchemaPath groupingPath; - - private UsesNodeImpl(SchemaPath groupingPath) { - this.groupingPath = groupingPath; - } - - @Override - public SchemaPath getGroupingPath() { - return groupingPath; - } - - @Override - public String toString() { - return UsesNodeImpl.class.getSimpleName() + "[groupingPath=" - + groupingPath + "]"; - } - - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/YangModelBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/YangModelBuilder.java deleted file mode 100644 index bc0f36372b..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/YangModelBuilder.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.ParseTreeWalker; -import org.opendaylight.controller.antlrv4.code.gen.YangLexer; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.model.parser.api.AugmentationTargetBuilder; -import org.opendaylight.controller.model.parser.api.Builder; -import org.opendaylight.controller.model.parser.api.TypeAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.impl.YangModelParserImpl; -import org.opendaylight.controller.model.util.UnknownType; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.api.ModuleImport; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangModelBuilder implements Builder { - - private static final Logger logger = LoggerFactory - .getLogger(YangModelBuilder.class); - - private final Map modules = new HashMap(); - - public YangModelBuilder(String... yangFiles) { - final YangModelParserImpl yangModelParser = new YangModelParserImpl(); - final ParseTreeWalker walker = new ParseTreeWalker(); - - List trees = parseYangFiles(yangFiles); - - ModuleBuilder[] builders = new ModuleBuilder[trees.size()]; - - for (int i = 0; i < trees.size(); i++) { - walker.walk(yangModelParser, trees.get(i)); - builders[i] = yangModelParser.getModuleBuilder(); - } - - for (ModuleBuilder builder : builders) { - final String builderName = builder.getName(); - modules.put(builderName, builder); - } - } - - @Override - public Map build() { - Map builtModules = new HashMap(); - for (ModuleBuilder builder : modules.values()) { - validateBuilder(builder); - builtModules.put(builder.getName(), builder.build()); - } - return builtModules; - } - - private void validateBuilder(ModuleBuilder builder) { - resolveTypedefs(builder); - resolveAugments(builder); - } - - private void resolveTypedefs(ModuleBuilder builder) { - Map, TypeAwareBuilder> dirtyNodes = builder - .getDirtyNodes(); - if (dirtyNodes.size() == 0) { - return; - } else { - for (Map.Entry, TypeAwareBuilder> entry : dirtyNodes - .entrySet()) { - TypeAwareBuilder tab = entry.getValue(); - TypeDefinitionBuilder tdb = findTypeAwareBuilder( - entry.getValue(), builder); - tab.setType(tdb.build()); - } - } - } - - private TypeDefinitionBuilder findTypeAwareBuilder( - TypeAwareBuilder typeBuilder, ModuleBuilder builder) { - UnknownType type = (UnknownType) typeBuilder.getType(); - QName typeQName = type.getQName(); - String typeName = type.getQName().getLocalName(); - String prefix = typeQName.getPrefix(); - - ModuleBuilder dependentModuleBuilder; - if (prefix.equals(builder.getPrefix())) { - dependentModuleBuilder = builder; - } else { - String dependentModuleName = getDependentModuleName(builder, prefix); - dependentModuleBuilder = modules.get(dependentModuleName); - } - - Set typedefs = dependentModuleBuilder - .getModuleTypedefs(); - - TypeDefinitionBuilder lookedUpBuilder = null; - for (TypeDefinitionBuilder tdb : typedefs) { - QName qname = tdb.getQName(); - if (qname.getLocalName().equals(typeName)) { - lookedUpBuilder = tdb; - break; - } - } - - if (lookedUpBuilder.getBaseType() instanceof UnknownType) { - return findTypeAwareBuilder((TypeAwareBuilder) lookedUpBuilder, - dependentModuleBuilder); - } else { - return lookedUpBuilder; - } - } - - private void resolveAugments(ModuleBuilder builder) { - Set augmentBuilders = builder - .getAddedAugments(); - - Set augments = new HashSet(); - for (AugmentationSchemaBuilder augmentBuilder : augmentBuilders) { - SchemaPath augmentTargetSchemaPath = augmentBuilder.getTargetPath(); - String prefix = null; - List augmentTargetPath = new ArrayList(); - for (QName pathPart : augmentTargetSchemaPath.getPath()) { - prefix = pathPart.getPrefix(); - augmentTargetPath.add(pathPart.getLocalName()); - } - String dependentModuleName = getDependentModuleName(builder, prefix); - augmentTargetPath.add(0, dependentModuleName); - - ModuleBuilder dependentModule = modules.get(dependentModuleName); - AugmentationTargetBuilder augmentTarget = (AugmentationTargetBuilder) dependentModule - .getNode(augmentTargetPath); - AugmentationSchema result = augmentBuilder.build(); - augmentTarget.addAugmentation(result); - augments.add(result); - } - builder.setAugmentations(augments); - } - - private List parseYangFiles(String... yangFiles) { - List trees = new ArrayList(); - File yangFile; - for (String fileName : yangFiles) { - try { - yangFile = new File(fileName); - FileInputStream inStream = new FileInputStream(yangFile); - ANTLRInputStream input = new ANTLRInputStream(inStream); - final YangLexer lexer = new YangLexer(input); - final CommonTokenStream tokens = new CommonTokenStream(lexer); - final YangParser parser = new YangParser(tokens); - trees.add(parser.yang()); - } catch (IOException e) { - logger.warn("Exception while reading yang file: " + fileName, e); - } - } - return trees; - } - - /** - * Returns name of dependent module based on given prefix. - * - * @param builder - * current builder which contains import - * @param prefix - * prefix of dependent module used in current builder - * @return name of dependent module - */ - private String getDependentModuleName(ModuleBuilder builder, String prefix) { - ModuleImport moduleImport = null; - for (ModuleImport mi : builder.getModuleImports()) { - if (mi.getPrefix().equals(prefix)) { - moduleImport = mi; - break; - } - } - return moduleImport.getModuleName(); - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/util/YangModelBuilderHelper.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/util/YangModelBuilderHelper.java deleted file mode 100644 index 7d9dcf19fb..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/util/YangModelBuilderHelper.java +++ /dev/null @@ -1,659 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.util; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Stack; - -import org.antlr.v4.runtime.tree.ParseTree; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bits_specificationContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Decimal64_specificationContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_specificationContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Fraction_digits_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Length_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Numerical_restrictionsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Pattern_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Position_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Range_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_argContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; -import org.opendaylight.controller.model.api.type.BitsTypeDefinition; -import org.opendaylight.controller.model.api.type.EnumTypeDefinition; -import org.opendaylight.controller.model.api.type.LengthConstraint; -import org.opendaylight.controller.model.api.type.PatternConstraint; -import org.opendaylight.controller.model.api.type.RangeConstraint; -import org.opendaylight.controller.model.api.type.BitsTypeDefinition.Bit; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.util.BaseConstraints; -import org.opendaylight.controller.model.util.UnknownType; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangModelBuilderHelper { - - private static final Logger logger = LoggerFactory - .getLogger(YangModelBuilderHelper.class); - - /** - * Get 'description', 'reference' and 'status' statements and fill in - * builder. - * - * @param ctx - * context to parse - * @param builder - * builder to fill in with parsed statements - */ - public static void parseSchemaNodeArgs(ParseTree ctx, - SchemaNodeBuilder builder) { - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - String desc = stringFromNode(child); - builder.setDescription(desc); - } else if (child instanceof Reference_stmtContext) { - String ref = stringFromNode(child); - builder.setReference(ref); - } else if (child instanceof Status_stmtContext) { - Status status = getStatus((Status_stmtContext) child); - builder.setStatus(status); - } - } - } - - public static SchemaPath getActualSchemaPath(Stack actualPath, - URI namespace, Date revision, String prefix) { - final List path = new ArrayList(); - QName qname; - for (String pathElement : actualPath) { - qname = new QName(namespace, revision, prefix, pathElement); - path.add(qname); - } - return new SchemaPath(path, true); - } - - public static Status getStatus(Status_stmtContext ctx) { - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree statusArg = ctx.getChild(i); - if (statusArg instanceof Status_argContext) { - String statusArgStr = stringFromNode(statusArg); - if (statusArgStr.equals("current")) { - return Status.CURRENT; - } else if (statusArgStr.equals("deprecated")) { - return Status.DEPRECATED; - } else if (statusArgStr.equals("obsolete")) { - return Status.OBSOLOTE; - } else { - logger.warn("Invalid 'status' statement: " + statusArgStr); - } - } - } - return null; - } - - public static String stringFromNode(final ParseTree treeNode) { - final String result = ""; - for (int j = 0; j < treeNode.getChildCount(); ++j) { - if (treeNode.getChild(j) instanceof StringContext) { - final StringContext context = (StringContext) treeNode - .getChild(j); - - if (context != null) { - return context.getChild(0).getText().replace("\"", ""); - } - } - } - return result; - } - - public static SchemaPath parsePath(String augmentPath) { - boolean absolute = augmentPath.startsWith("/"); - String[] splittedPath = augmentPath.split("/"); - List path = new ArrayList(); - QName name; - for (String pathElement : splittedPath) { - if (pathElement.length() > 0) { - String[] splittedElement = pathElement.split(":"); - if (splittedElement.length == 1) { - name = new QName(null, null, null, splittedElement[0]); - } else { - name = new QName(null, null, splittedElement[0], - splittedElement[1]); - } - path.add(name); - } - } - return new SchemaPath(path, absolute); - } - - public static List createListKey(String keyDefinition, - URI namespace, Date revision, String prefix) { - List key = new ArrayList(); - String[] splittedKey = keyDefinition.split(" "); - - QName qname = null; - for (String keyElement : splittedKey) { - if (keyElement.length() != 0) { - qname = new QName(namespace, revision, prefix, keyElement); - key.add(qname); - } - } - return key; - } - - public static TypeDefinition parseUnknownType(QName typedefQName, - ParseTree ctx) { - UnknownType.Builder ut = new UnknownType.Builder(typedefQName); - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Type_body_stmtsContext) { - for (int j = 0; j < child.getChildCount(); j++) { - ParseTree typeBodyChild = child.getChild(j); - // NUMERICAL RESTRICTIONS - if (typeBodyChild instanceof Numerical_restrictionsContext) { - for (int k = 0; k < typeBodyChild.getChildCount(); k++) { - ParseTree numRestrictionsChild = typeBodyChild - .getChild(k); - if (numRestrictionsChild instanceof Range_stmtContext) { - List ranges = parseRangeConstraints((Range_stmtContext) numRestrictionsChild); - ut.rangeStatements(ranges); - } - } - // STRING RESTRICTIONS - } else if (typeBodyChild instanceof String_restrictionsContext) { - List patterns = new ArrayList(); - List lengths = new ArrayList(); - for (int k = 0; k < typeBodyChild.getChildCount(); k++) { - ParseTree stringRestrictionsChild = typeBodyChild - .getChild(k); - if (stringRestrictionsChild instanceof Pattern_stmtContext) { - patterns.add(parsePatternConstraint((Pattern_stmtContext) stringRestrictionsChild)); - } else if (stringRestrictionsChild instanceof Length_stmtContext) { - lengths = parseLengthConstraints((Length_stmtContext) stringRestrictionsChild); - } - } - ut.patterns(patterns); - ut.lengthStatements(lengths); - // DECIMAL64 - } else if (typeBodyChild instanceof Decimal64_specificationContext) { - for (int k = 0; k < typeBodyChild.getChildCount(); k++) { - ParseTree fdChild = typeBodyChild.getChild(k); - if (fdChild instanceof Fraction_digits_stmtContext) { - // TODO: implement fraction digits - // return - // Integer.valueOf(stringFromNode(fdChild)); - } - } - } - - } - } - } - return ut.build(); - } - - public static List getRangeConstraints( - Type_body_stmtsContext ctx) { - List rangeConstraints = new ArrayList(); - for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree numRestrChild = ctx.getChild(j); - if (numRestrChild instanceof Numerical_restrictionsContext) { - for (int k = 0; k < numRestrChild.getChildCount(); k++) { - ParseTree rangeChild = numRestrChild.getChild(k); - if (rangeChild instanceof Range_stmtContext) { - rangeConstraints - .addAll(parseRangeConstraints((Range_stmtContext) rangeChild)); - } - } - } - } - return rangeConstraints; - } - - private static List parseRangeConstraints( - Range_stmtContext ctx) { - List rangeConstraints = new ArrayList(); - String description = null; - String reference = null; - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } - } - - String rangeStr = stringFromNode(ctx); - String trimmed = rangeStr.replace(" ", ""); - String[] splittedRange = trimmed.split("\\|"); - for (String rangeDef : splittedRange) { - // TODO: this needs to be refactored, because valid range can be - // also defined as "1..max" - String[] splittedRangeDef = rangeDef.split("\\.\\."); - Long min = Long.valueOf(splittedRangeDef[0]); - Long max = Long.valueOf(splittedRangeDef[1]); - RangeConstraint range = BaseConstraints.rangeConstraint(min, max, - description, reference); - rangeConstraints.add(range); - } - - return rangeConstraints; - } - - public static Integer getFractionDigits(Type_body_stmtsContext ctx) { - for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree dec64specChild = ctx.getChild(j); - if (dec64specChild instanceof Decimal64_specificationContext) { - for (int k = 0; k < dec64specChild.getChildCount(); k++) { - ParseTree fdChild = dec64specChild.getChild(k); - if (fdChild instanceof Fraction_digits_stmtContext) { - return Integer.valueOf(stringFromNode(fdChild)); - } - } - } - } - return null; - } - - public static List getEnumConstants( - Type_body_stmtsContext ctx) { - List enumConstants = new ArrayList(); - - out: for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree enumSpecChild = ctx.getChild(j); - if (enumSpecChild instanceof Enum_specificationContext) { - for (int k = 0; k < enumSpecChild.getChildCount(); k++) { - ParseTree enumChild = enumSpecChild.getChild(k); - if (enumChild instanceof Enum_stmtContext) { - enumConstants.add(createEnumPair( - (Enum_stmtContext) enumChild, k)); - if (k == enumSpecChild.getChildCount() - 1) { - break out; - } - } - } - } - } - return enumConstants; - } - - private static EnumTypeDefinition.EnumPair createEnumPair( - Enum_stmtContext ctx, final int value) { - final String name = stringFromNode(ctx); - return new EnumTypeDefinition.EnumPair() { - - @Override - public QName getQName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public SchemaPath getPath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getReference() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Status getStatus() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getName() { - return name; - } - - @Override - public Integer getValue() { - return value; - } - - @Override - public String toString() { - return EnumTypeDefinition.EnumPair.class.getSimpleName() - + "[name=" + name + ", value=" + value + "]"; - } - }; - } - - public static List getLengthConstraints( - Type_body_stmtsContext ctx) { - List lengthConstraints = new ArrayList(); - for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree stringRestrChild = ctx.getChild(j); - if (stringRestrChild instanceof String_restrictionsContext) { - for (int k = 0; k < stringRestrChild.getChildCount(); k++) { - ParseTree lengthChild = stringRestrChild.getChild(k); - if (lengthChild instanceof Length_stmtContext) { - lengthConstraints - .addAll(parseLengthConstraints((Length_stmtContext) lengthChild)); - } - } - } - } - return lengthConstraints; - } - - private static List parseLengthConstraints( - Length_stmtContext ctx) { - List lengthConstraints = new ArrayList(); - String description = null; - String reference = null; - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } - } - - String lengthStr = stringFromNode(ctx); - String trimmed = lengthStr.replace(" ", ""); - String[] splittedRange = trimmed.split("\\|"); - for (String rangeDef : splittedRange) { - // TODO: this needs to be refactored, because valid length can be - // also defined as "1" - String[] splittedRangeDef = rangeDef.split("\\.\\."); - Long min = Long.valueOf(splittedRangeDef[0]); - Long max = Long.valueOf(splittedRangeDef[1]); - LengthConstraint range = BaseConstraints.lengthConstraint(min, max, - description, reference); - lengthConstraints.add(range); - } - - return lengthConstraints; - } - - public static List getPatternConstraint( - Type_body_stmtsContext ctx) { - List patterns = new ArrayList(); - - out: for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree stringRestrChild = ctx.getChild(j); - if (stringRestrChild instanceof String_restrictionsContext) { - for (int k = 0; k < stringRestrChild.getChildCount(); k++) { - ParseTree lengthChild = stringRestrChild.getChild(k); - if (lengthChild instanceof Pattern_stmtContext) { - patterns.add(parsePatternConstraint((Pattern_stmtContext) lengthChild)); - if (k == lengthChild.getChildCount() - 1) { - break out; - } - } - } - } - } - return patterns; - } - - /** - * Internal helper method. - * - * @param ctx - * pattern context - * @return PatternConstraint object - */ - private static PatternConstraint parsePatternConstraint( - Pattern_stmtContext ctx) { - String description = null; - String reference = null; - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } - } - String pattern = stringFromNode(ctx); - return BaseConstraints.patternConstraint(pattern, description, - reference); - } - - public static List getBits( - Type_body_stmtsContext ctx, Stack actualPath, - URI namespace, Date revision, String prefix) { - List bits = new ArrayList(); - for (int j = 0; j < ctx.getChildCount(); j++) { - ParseTree bitsSpecChild = ctx.getChild(j); - if (bitsSpecChild instanceof Bits_specificationContext) { - for (int k = 0; k < bitsSpecChild.getChildCount(); k++) { - ParseTree bitChild = bitsSpecChild.getChild(k); - if (bitChild instanceof Bit_stmtContext) { - bits.add(parseBit((Bit_stmtContext) bitChild, - actualPath, namespace, revision, prefix)); - } - } - } - } - return bits; - } - - private static BitsTypeDefinition.Bit parseBit(final Bit_stmtContext ctx, - Stack actualPath, final URI namespace, final Date revision, - final String prefix) { - String name = stringFromNode(ctx); - final QName qname = new QName(namespace, revision, prefix, name); - Long position = null; - - String description = null; - String reference = null; - Status status = Status.CURRENT; - - Stack bitPath = new Stack(); - bitPath.addAll(actualPath); - bitPath.add(name); - - SchemaPath schemaPath = getActualSchemaPath(bitPath, namespace, - revision, prefix); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Position_stmtContext) { - String positionStr = stringFromNode(child); - position = Long.valueOf(positionStr); - if (position < 0 || position > 4294967295L) { - throw new IllegalArgumentException( - "position value MUST be in the range 0 to 4294967295, but was: " - + position); - } - } else if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } else if (child instanceof Status_stmtContext) { - status = getStatus((Status_stmtContext) child); - } - } - - // TODO: extensionDefinitions - return createBit(qname, schemaPath, description, reference, status, - null, position); - } - - private static BitsTypeDefinition.Bit createBit(final QName qname, - final SchemaPath schemaPath, final String description, - final String reference, final Status status, - final List extensionDefinitions, - final Long position) { - return new BitsTypeDefinition.Bit() { - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return schemaPath; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public String getReference() { - return reference; - } - - @Override - public Status getStatus() { - return status; - } - - @Override - public List getExtensionSchemaNodes() { - return extensionDefinitions; - } - - @Override - public Long getPosition() { - return position; - } - - @Override - public String getName() { - return qname.getLocalName(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((qname == null) ? 0 : qname.hashCode()); - result = prime * result - + ((schemaPath == null) ? 0 : schemaPath.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result - + ((status == null) ? 0 : status.hashCode()); - result = prime * result - + ((position == null) ? 0 : position.hashCode()); - result = prime - * result - + ((extensionDefinitions == null) ? 0 - : extensionDefinitions.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Bit other = (Bit) obj; - if (qname == null) { - if (other.getQName() != null) { - return false; - } - } else if (!qname.equals(other.getQName())) { - return false; - } - if (schemaPath == null) { - if (other.getPath() != null) { - return false; - } - } else if (!schemaPath.equals(other.getPath())) { - return false; - } - if (description == null) { - if (other.getDescription() != null) { - return false; - } - } else if (!description.equals(other.getDescription())) { - return false; - } - if (reference == null) { - if (other.getReference() != null) { - return false; - } - } else if (!reference.equals(other.getReference())) { - return false; - } - if (status == null) { - if (other.getStatus() != null) { - return false; - } - } else if (!status.equals(other.getStatus())) { - return false; - } - if (extensionDefinitions == null) { - if (other.getExtensionSchemaNodes() != null) { - return false; - } - } else if (!extensionDefinitions.equals(other - .getExtensionSchemaNodes())) { - return false; - } - if (position == null) { - if (other.getPosition() != null) { - return false; - } - } else if (!position.equals(other.getPosition())) { - return false; - } - return true; - } - - @Override - public String toString() { - return Bit.class.getSimpleName() + "[name=" - + qname.getLocalName() + ", position=" + position + "]"; - } - }; - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AbstractChildNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java similarity index 92% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AbstractChildNodeBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java index cc950eccef..71e24bcf82 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AbstractChildNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AbstractChildNodeBuilder.java @@ -1,40 +1,40 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import java.util.HashSet; -import java.util.Set; - -import org.opendaylight.controller.yang.common.QName; - -public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder { - - private final QName qname; - protected final Set childNodes = new HashSet(); - protected final Set groupings = new HashSet(); - - protected AbstractChildNodeBuilder(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { - childNodes.add(childNode); - } - - @Override - public void addGrouping(GroupingBuilder grouping) { - groupings.add(grouping); - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import java.util.HashSet; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; + +public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder { + + private final QName qname; + protected final Set childNodes = new HashSet(); + protected final Set groupings = new HashSet(); + + protected AbstractChildNodeBuilder(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void addChildNode(DataSchemaNodeBuilder childNode) { + childNodes.add(childNode); + } + + @Override + public void addGrouping(GroupingBuilder grouping) { + groupings.add(grouping); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationSchemaBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java similarity index 82% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationSchemaBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java index fe2fc0e677..71cf7a19e9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationSchemaBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationSchemaBuilder.java @@ -1,26 +1,31 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; - -/** - * Interface for builders of 'augment' statement. - */ -public interface AugmentationSchemaBuilder extends ChildNodeBuilder, TypeDefinitionAwareBuilder { - - void setDescription(String description); - void setReference(String reference); - void setStatus(Status status); - - AugmentationSchema build(); - SchemaPath getTargetPath(); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import java.util.Set; + +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; + +/** + * Interface for builders of 'augment' statement. + */ +public interface AugmentationSchemaBuilder extends ChildNodeBuilder, TypeDefinitionAwareBuilder { + + void setDescription(String description); + void setReference(String reference); + void setStatus(Status status); + + SchemaPath getTargetPath(); + + Set getChildNodes(); + + AugmentationSchema build(); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationTargetBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java similarity index 89% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationTargetBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java index bd71a8aef8..7b4a191865 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/AugmentationTargetBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/AugmentationTargetBuilder.java @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.AugmentationSchema; - -/** - * Interface for builders of those nodes, which can be augmentation targets. - */ -public interface AugmentationTargetBuilder { - - /** - * Add augment, which points to this node. - * @param augment augment which points to this node - */ - void addAugmentation(AugmentationSchema augment); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.model.api.AugmentationSchema; + +/** + * Interface for builders of those nodes, which can be augmentation targets. + */ +public interface AugmentationTargetBuilder { + + /** + * Add augment, which points to this node. + * @param augment augment which points to this node + */ + void addAugmentation(AugmentationSchema augment); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/Builder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/Builder.java similarity index 86% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/Builder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/Builder.java index fede31fefc..4db2d365d9 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/Builder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/Builder.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.model.parser.api; +package org.opendaylight.controller.yang.model.parser.builder.api; /** * Parent interface for all builder interfaces. diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/ChildNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java similarity index 85% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/ChildNodeBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java index 0f60154714..7dc716a775 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/ChildNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/ChildNodeBuilder.java @@ -1,22 +1,23 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.common.QName; - -/** - * Interface for all yang data-node containers [augment, case, container, grouping, list, module, notification]. - */ -public interface ChildNodeBuilder extends Builder { - - QName getQName(); - void addChildNode(DataSchemaNodeBuilder childNode); - void addGrouping(GroupingBuilder groupingBuilder); - void addUsesNode(UsesNodeBuilder usesBuilder); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.common.QName; + +/** + * Interface for all yang data-node containers [augment, case, container, grouping, list, module, notification]. + */ +public interface ChildNodeBuilder extends Builder { + + QName getQName(); + void addChildNode(DataSchemaNodeBuilder childNode); + void addGrouping(GroupingBuilder groupingBuilder); + void addUsesNode(UsesNodeBuilder usesBuilder); + void addTypedef(TypeDefinitionBuilder typedefBuilder); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/DataSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java similarity index 58% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/DataSchemaNodeBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java index 1eaf1af7c2..eb17e4ee5a 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/DataSchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/DataSchemaNodeBuilder.java @@ -1,21 +1,27 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.DataSchemaNode; - -/** - * Interface for all yang data-schema nodes [anyxml, case, container, grouping, list, module, notification]. - */ -public interface DataSchemaNodeBuilder extends SchemaNodeBuilder { - - DataSchemaNode build(); - void setAugmenting(boolean augmenting); - void setConfiguration(boolean configuration); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder; + +/** + * Interface for all yang data-schema nodes [anyxml, case, container, grouping, + * list, module, notification]. + */ +public interface DataSchemaNodeBuilder extends SchemaNodeBuilder { + + DataSchemaNode build(); + + void setAugmenting(boolean augmenting); + + void setConfiguration(boolean configuration); + + ConstraintsBuilder getConstraintsBuilder(); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/GroupingBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java similarity index 88% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/GroupingBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java index 22632ab223..3db0a5ce32 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/GroupingBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/GroupingBuilder.java @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.GroupingDefinition; - -/** - * Interface for builders of 'grouping' statement. - */ -public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder { - - GroupingDefinition build(); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.model.api.GroupingDefinition; + +/** + * Interface for builders of 'grouping' statement. + */ +public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder { + + GroupingDefinition build(); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/SchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java similarity index 90% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/SchemaNodeBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java index c63104ebc4..06855cffac 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/SchemaNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/SchemaNodeBuilder.java @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; - - -/** - * Interface for all builders of SchemaNode nodes. - */ -public interface SchemaNodeBuilder extends Builder { - - QName getQName(); - void setPath(SchemaPath schemaPath); - void setDescription(String description); - void setReference(String reference); - void setStatus(Status status); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; + + +/** + * Interface for all builders of SchemaNode nodes. + */ +public interface SchemaNodeBuilder extends Builder { + + QName getQName(); + void setPath(SchemaPath schemaPath); + void setDescription(String description); + void setReference(String reference); + void setStatus(Status status); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeAwareBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeAwareBuilder.java similarity index 89% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeAwareBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeAwareBuilder.java index 64ccb119cb..ac51e5796d 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeAwareBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeAwareBuilder.java @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.TypeDefinition; - -/** - * Builders of all nodes, which can have 'type' statement must implement this interface. - * [typedef, type, leaf, leaf-list, deviate] - */ -public interface TypeAwareBuilder { - - TypeDefinition getType(); - void setType(TypeDefinition type); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.model.api.TypeDefinition; + +/** + * Builders of all nodes, which can have 'type' statement must implement this interface. + * [typedef, type, leaf, leaf-list, deviate] + */ +public interface TypeAwareBuilder { + + TypeDefinition getType(); + void setType(TypeDefinition type); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionAwareBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionAwareBuilder.java similarity index 89% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionAwareBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionAwareBuilder.java index bfa9a10b1c..8f5b3d4a82 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionAwareBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionAwareBuilder.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.model.parser.api; +package org.opendaylight.controller.yang.model.parser.builder.api; /** * Builders of all nodes, which can have 'typedef' statement must implement this interface. diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionBuilder.java similarity index 86% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionBuilder.java index 9a7b97e5c0..fc7ef22b80 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/TypeDefinitionBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/TypeDefinitionBuilder.java @@ -1,23 +1,24 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.TypeDefinition; - - -/** - * Interface for builders of 'typedef' statement. - */ -public interface TypeDefinitionBuilder { - - QName getQName(); - TypeDefinition getBaseType(); - TypeDefinition build(); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.TypeDefinition; + + +/** + * Interface for builders of 'typedef' statement. + */ +public interface TypeDefinitionBuilder { + + QName getQName(); + TypeDefinition getBaseType(); + TypeDefinition build(); + void setUnits(String units); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/UsesNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java similarity index 75% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/UsesNodeBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java index 13ecd15001..1f808eb722 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/api/UsesNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.api; - -import org.opendaylight.controller.yang.model.api.UsesNode; - -/** - * Interface for builders of 'uses' statement. - */ -public interface UsesNodeBuilder { - - void addAugment(AugmentationSchemaBuilder builder); - - UsesNode build(); - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.api; + +import org.opendaylight.controller.yang.model.api.UsesNode; + +/** + * Interface for builders of 'uses' statement. + */ +public interface UsesNodeBuilder extends Builder { + + void addAugment(AugmentationSchemaBuilder builder); + void setAugmenting(boolean augmenting); + UsesNode build(); + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java new file mode 100644 index 0000000000..1027cb1fc3 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/AugmentationSchemaBuilderImpl.java @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil; + +public class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder { + + private final AugmentationSchemaImpl instance; + private final SchemaPath augmentTarget; + final Set childNodes = new HashSet(); + final Set groupings = new HashSet(); + private final Set usesNodes = new HashSet(); + + AugmentationSchemaBuilderImpl(String augmentPath) { + SchemaPath targetPath = YangModelBuilderUtil.parseAugmentPath(augmentPath); + augmentTarget = targetPath; + instance = new AugmentationSchemaImpl(targetPath); + } + + @Override + public void addChildNode(DataSchemaNodeBuilder childNode) { + childNodes.add(childNode); + } + + @Override + public Set getChildNodes() { + return childNodes; + } + + @Override + public void addGrouping(GroupingBuilder grouping) { + groupings.add(grouping); + } + + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + usesNodes.add(usesBuilder); + } + + /** + * Always returns null. + */ + @Override + public QName getQName() { + return null; + } + + @Override + public AugmentationSchema build() { + + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + // USES + Set usesNodeDefinitions = new HashSet(); + for (UsesNodeBuilder builder : usesNodes) { + usesNodeDefinitions.add(builder.build()); + } + instance.setUses(usesNodeDefinitions); + + return instance; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + throw new UnsupportedOperationException( + "Augmentation can not contains type definitions"); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + @Override + public SchemaPath getTargetPath() { + return augmentTarget; + } + + private static class AugmentationSchemaImpl implements AugmentationSchema { + + private final SchemaPath targetPath; + private Map childNodes; + private Set groupings; + private Set uses; + + private String description; + private String reference; + private Status status; + + private AugmentationSchemaImpl(SchemaPath targetPath) { + this.targetPath = targetPath; + } + + @Override + public SchemaPath getTargetPath() { + return targetPath; + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + this.childNodes = childNodes; + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + this.groupings = groupings; + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + this.uses = uses; + } + + /** + * Always returns an empty set, because augmentation can not contains + * type definitions. + */ + @Override + public Set> getTypeDefinitions() { + return Collections.emptySet(); + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public int hashCode() { + final int prime = 17; + int result = 1; + result = prime * result + + ((targetPath == null) ? 0 : targetPath.hashCode()); + result = prime * result + + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AugmentationSchemaImpl other = (AugmentationSchemaImpl) obj; + if (targetPath == null) { + if (other.targetPath != null) { + return false; + } + } else if (!targetPath.equals(other.targetPath)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + AugmentationSchemaImpl.class.getSimpleName()); + sb.append("["); + sb.append("targetPath=" + targetPath); + sb.append(", childNodes=" + childNodes.values()); + sb.append(", groupings=" + groupings); + sb.append(", uses=" + uses); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java new file mode 100644 index 0000000000..0e338f050c --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ConstraintsBuilder.java @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.opendaylight.controller.model.util.RevisionAwareXPathImpl; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.MustDefinition; +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; + +public class ConstraintsBuilder implements Builder { + + private final ConstraintDefinitionImpl instance; + private final Set mustDefinitions; + private String whenCondition; + + ConstraintsBuilder() { + instance = new ConstraintDefinitionImpl(); + mustDefinitions = new HashSet(); + } + + @Override + public ConstraintDefinition build() { + RevisionAwareXPath whenStmt = new RevisionAwareXPathImpl(whenCondition, + false); + instance.setWhenCondition(whenStmt); + instance.setMustConstraints(mustDefinitions); + return instance; + } + + public void setMinElements(Integer minElements) { + instance.setMinElements(minElements); + } + + public void setMaxElements(Integer maxElements) { + instance.setMaxElements(maxElements); + } + + public void addMustDefinition(String mustStr, String description, + String reference) { + MustDefinition must = new MustDefinitionImpl(mustStr, description, + reference); + mustDefinitions.add(must); + } + + public void addWhenCondition(String whenCondition) { + this.whenCondition = whenCondition; + } + + public void setMandatory(boolean mandatory) { + instance.setMandatory(mandatory); + } + + private static class ConstraintDefinitionImpl implements + ConstraintDefinition { + + private DataSchemaNode parent; + private RevisionAwareXPath whenCondition; + private Set mustConstraints; + private boolean mandatory; + private Integer minElements; + private Integer maxElements; + + @Override + public DataSchemaNode getParent() { + return parent; + } + + @Override + public RevisionAwareXPath getWhenCondition() { + return whenCondition; + } + + private void setWhenCondition(RevisionAwareXPath whenCondition) { + this.whenCondition = whenCondition; + } + + @Override + public Set getMustConstraints() { + if (mustConstraints == null) { + return Collections.emptySet(); + } else { + return mustConstraints; + } + } + + private void setMustConstraints(Set mustConstraints) { + if (mustConstraints != null) { + this.mustConstraints = mustConstraints; + } + } + + @Override + public boolean isMandatory() { + return mandatory; + } + + private void setMandatory(boolean mandatory) { + this.mandatory = mandatory; + } + + @Override + public Integer getMinElements() { + return minElements; + } + + private void setMinElements(Integer minElements) { + this.minElements = minElements; + } + + @Override + public Integer getMaxElements() { + return maxElements; + } + + private void setMaxElements(Integer maxElements) { + this.maxElements = maxElements; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((parent == null) ? 0 : parent.hashCode()); + result = prime * result + + ((whenCondition == null) ? 0 : whenCondition.hashCode()); + result = prime + * result + + ((mustConstraints == null) ? 0 : mustConstraints + .hashCode()); + result = prime * result + + ((minElements == null) ? 0 : minElements.hashCode()); + result = prime * result + + ((maxElements == null) ? 0 : maxElements.hashCode()); + result = prime * result + (mandatory ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ConstraintDefinitionImpl other = (ConstraintDefinitionImpl) obj; + if (parent == null) { + if (other.parent != null) { + return false; + } + } else if (!parent.equals(other.parent)) { + return false; + } + if (whenCondition == null) { + if (other.whenCondition != null) { + return false; + } + } else if (!whenCondition.equals(other.whenCondition)) { + return false; + } + if (mustConstraints == null) { + if (other.mustConstraints != null) { + return false; + } + } else if (!mustConstraints.equals(other.mustConstraints)) { + return false; + } + if (mandatory != other.mandatory) { + return false; + } + if (minElements == null) { + if (other.minElements != null) { + return false; + } + } else if (!minElements.equals(other.minElements)) { + return false; + } + if (maxElements == null) { + if (other.maxElements != null) { + return false; + } + } else if (!maxElements.equals(other.maxElements)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ConstraintDefinitionImpl.class.getSimpleName()); + sb.append("["); + sb.append("parent=" + parent); + sb.append(", whenCondition=" + whenCondition); + sb.append(", mustConstraints=" + mustConstraints); + sb.append(", mandatory=" + mandatory); + sb.append(", minElements=" + minElements); + sb.append(", maxElements=" + maxElements); + sb.append("]"); + return sb.toString(); + } + + } + + private static class MustDefinitionImpl implements MustDefinition { + + private final String mustStr; + private final String description; + private final String reference; + + private MustDefinitionImpl(String mustStr, String description, + String reference) { + this.mustStr = mustStr; + this.description = description; + this.reference = reference; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getErrorAppTag() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getErrorMessage() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public RevisionAwareXPath getXpath() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((mustStr == null) ? 0 : mustStr.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MustDefinitionImpl other = (MustDefinitionImpl) obj; + if (mustStr == null) { + if (other.mustStr != null) { + return false; + } + } else if (!mustStr.equals(other.mustStr)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + return true; + } + + @Override + public String toString() { + return MustDefinitionImpl.class.getSimpleName() + "[mustStr=" + + mustStr + "]"; + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java new file mode 100644 index 0000000000..953b22e174 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilder.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder + implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder, + DataSchemaNodeBuilder { + + private final ContainerSchemaNodeImpl instance; + private final ConstraintsBuilder constraintsBuilder; + + private final Set addedTypedefs = new HashSet(); + private final Set augmentations = new HashSet(); + private final Set addedUsesNodes = new HashSet(); + + ContainerSchemaNodeBuilder(QName qname) { + super(qname); + instance = new ContainerSchemaNodeImpl(qname); + constraintsBuilder = new ConstraintsBuilder(); + } + + @Override + public ContainerSchemaNode build() { + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // USES + Set uses = new HashSet(); + for (UsesNodeBuilder builder : addedUsesNodes) { + uses.add(builder.build()); + } + instance.setUses(uses); + + instance.setConstraints(constraintsBuilder.build()); + instance.setAvailableAugmentations(augmentations); + + return instance; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void addAugmentation(AugmentationSchema augment) { + augmentations.add(augment); + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + @Override + public void setConfiguration(boolean configuration) { + instance.setConfiguration(configuration); + } + + @Override + public ConstraintsBuilder getConstraintsBuilder() { + return constraintsBuilder; + } + + @Override + public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { + addedUsesNodes.add(usesNodeBuilder); + } + + public void setPresenceContainer(boolean presence) { + instance.setPresenceContainer(presence); + } + + private class ContainerSchemaNodeImpl implements ContainerSchemaNode { + + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private Set augmentations = Collections.emptySet(); + private Map childNodes = Collections.emptyMap(); + private Set groupings = Collections.emptySet(); + private Set> typeDefinitions = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private boolean presence; + + private ContainerSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if(status != null) { + this.status = status; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public Set getAvailableAugmentations() { + return augmentations; + } + + private void setAvailableAugmentations( + Set augmentations) { + if (augmentations != null) { + this.augmentations = augmentations; + } + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + if (childNodes != null) { + this.childNodes = childNodes; + } + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + if (groupings != null) { + this.groupings = groupings; + } + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + if (uses != null) { + this.uses = uses; + } + } + + @Override + public boolean isPresenceContainer() { + return presence; + } + + private void setPresenceContainer(boolean presence) { + this.presence = presence; + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + if (typeDefinitions != null) { + this.typeDefinitions = typeDefinitions; + } + } + + @Override + public List getUnknownSchemaNodes() { + return Collections.emptyList(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ContainerSchemaNodeImpl other = (ContainerSchemaNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ContainerSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java new file mode 100644 index 0000000000..6e1bb6424e --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/DeviationBuilder.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import org.opendaylight.controller.yang.model.api.Deviation; +import org.opendaylight.controller.yang.model.api.Deviation.Deviate; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; +import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil; + +public class DeviationBuilder implements Builder { + + private final DeviationImpl instance; + + DeviationBuilder(String targetPathStr) { + SchemaPath targetPath = YangModelBuilderUtil + .parseAugmentPath(targetPathStr); + instance = new DeviationImpl(targetPath); + } + + @Override + public Deviation build() { + return instance; + } + + public void setDeviate(String deviate) { + if (deviate.equals("not-supported")) { + instance.setDeviate(Deviate.NOT_SUPPORTED); + } else if (deviate.equals("add")) { + instance.setDeviate(Deviate.ADD); + } else if (deviate.equals("replace")) { + instance.setDeviate(Deviate.REPLACE); + } else if (deviate.equals("delete")) { + instance.setDeviate(Deviate.DELETE); + } else { + throw new IllegalArgumentException( + "Unsupported type of 'deviate' statement: " + deviate); + } + } + + public void setReference(String reference) { + instance.setReference(reference); + } + + private static class DeviationImpl implements Deviation { + + private SchemaPath targetPath; + private Deviate deviate; + private String reference; + + private DeviationImpl(SchemaPath targetPath) { + this.targetPath = targetPath; + } + + @Override + public SchemaPath getTargetPath() { + return targetPath; + } + + @Override + public Deviate getDeviate() { + return deviate; + } + + private void setDeviate(Deviate deviate) { + this.deviate = deviate; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((targetPath == null) ? 0 : targetPath.hashCode()); + result = prime * result + + ((deviate == null) ? 0 : deviate.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + DeviationImpl other = (DeviationImpl) obj; + if (targetPath == null) { + if (other.targetPath != null) { + return false; + } + } else if (!targetPath.equals(other.targetPath)) { + return false; + } + if (deviate == null) { + if (other.deviate != null) { + return false; + } + } else if (!deviate.equals(other.deviate)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(DeviationImpl.class.getSimpleName()); + sb.append("["); + sb.append("targetPath="+ targetPath); + sb.append(", deviate="+ deviate); + sb.append(", reference="+ reference); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java new file mode 100644 index 0000000000..735feb1ab7 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ExtensionBuilder.java @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.ExtensionDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; + +public class ExtensionBuilder implements SchemaNodeBuilder { + + private final ExtensionDefinitionImpl instance; + private final QName qname; + private final List addedExtensions; + + ExtensionBuilder(QName qname) { + this.qname = qname; + instance = new ExtensionDefinitionImpl(qname); + addedExtensions = new ArrayList(); + } + + @Override + public ExtensionDefinition build() { + List extensions = new ArrayList(); + for (UnknownSchemaNodeBuilder e : addedExtensions) { + extensions.add(e.build()); + } + instance.setUnknownSchemaNodes(extensions); + return instance; + } + + public void addExtension(UnknownSchemaNodeBuilder extension) { + addedExtensions.add(extension); + } + + public void setYinElement(boolean yin) { + instance.setYinElement(yin); + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + private static class ExtensionDefinitionImpl implements ExtensionDefinition { + private final QName qname; + private SchemaPath schemaPath; + private String description; + private String reference; + private Status status = Status.CURRENT; + private List unknownSchemaNodes = Collections + .emptyList(); + private boolean yin; + + private ExtensionDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return schemaPath; + } + + private void setPath(SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + private void setUnknownSchemaNodes( + List unknownSchemaNodes) { + if(unknownSchemaNodes != null) { + this.unknownSchemaNodes = unknownSchemaNodes; + } + } + + @Override + public String getArgument() { + return qname.getLocalName(); + } + + @Override + public boolean isYinElement() { + return yin; + } + + private void setYinElement(boolean yin) { + this.yin = yin; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + + ((schemaPath == null) ? 0 : schemaPath.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime + * result + + ((unknownSchemaNodes == null) ? 0 + : unknownSchemaNodes.hashCode()); + result = prime * result + (yin ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ExtensionDefinitionImpl other = (ExtensionDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (schemaPath == null) { + if (other.schemaPath != null) { + return false; + } + } else if (!schemaPath.equals(other.schemaPath)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (unknownSchemaNodes == null) { + if (other.unknownSchemaNodes != null) { + return false; + } + } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) { + return false; + } + if (yin != other.yin) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ExtensionDefinitionImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", schemaPath=" + schemaPath); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", extensionSchemaNodes=" + unknownSchemaNodes); + sb.append(", yin=" + yin); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java new file mode 100644 index 0000000000..23c74fd0bc --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/FeatureBuilder.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.FeatureDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; + +public class FeatureBuilder implements SchemaNodeBuilder { + + private final FeatureDefinitionImpl instance; + private final QName qname; + + FeatureBuilder(QName qname) { + this.qname = qname; + instance = new FeatureDefinitionImpl(qname); + } + + @Override + public FeatureDefinitionImpl build() { + return instance; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(SchemaPath path) { + instance.setPath(path); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + private static class FeatureDefinitionImpl implements FeatureDefinition { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status; + private List unknownSchemaNodes = Collections + .emptyList(); + + private FeatureDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + ; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + FeatureDefinitionImpl.class.getSimpleName()); + sb.append("[name=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status + "]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java new file mode 100644 index 0000000000..1bacca8d5b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/GroupingBuilderImpl.java @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class GroupingBuilderImpl implements GroupingBuilder { + + private final GroupingDefinitionImpl instance; + private final Set childNodes = new HashSet(); + private final Set groupings = new HashSet(); + private final Set addedTypedefs = new HashSet(); + private final Set usesNodes = new HashSet(); + + GroupingBuilderImpl(QName qname) { + this.instance = new GroupingDefinitionImpl(qname); + } + + @Override + public GroupingDefinition build() { + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // USES + Set usesNodeDefinitions = new HashSet(); + for (UsesNodeBuilder builder : usesNodes) { + usesNodeDefinitions.add(builder.build()); + } + instance.setUses(usesNodeDefinitions); + + return instance; + } + + /** + * Always returns null. + */ + @Override + public QName getQName() { + return null; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + @Override + public void addChildNode(DataSchemaNodeBuilder childNode) { + childNodes.add(childNode); + } + + @Override + public void addGrouping(GroupingBuilder grouping) { + groupings.add(grouping); + } + + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + usesNodes.add(usesBuilder); + } + + private static class GroupingDefinitionImpl implements GroupingDefinition { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status; + private Map childNodes; + private Set groupings; + private Set> typeDefinitions; + private Set uses; + + private GroupingDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + this.childNodes = childNodes; + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + this.groupings = groupings; + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + this.uses = uses; + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + this.typeDefinitions = typeDefinitions; + } + + @Override + public List getUnknownSchemaNodes() { + return Collections.emptyList(); + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime + * result + + ((typeDefinitions == null) ? 0 : typeDefinitions + .hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GroupingDefinitionImpl other = (GroupingDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + GroupingDefinitionImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java new file mode 100644 index 0000000000..99d3e64794 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilder.java @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.LeafListSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; + +public class LeafListSchemaNodeBuilder implements SchemaNodeBuilder, + TypeAwareBuilder, DataSchemaNodeBuilder { + + private final LeafListSchemaNodeImpl instance; + private final QName qname; + private final ConstraintsBuilder constraintsBuilder; + private TypeDefinition type; + + LeafListSchemaNodeBuilder(QName qname) { + this.qname = qname; + instance = new LeafListSchemaNodeImpl(qname); + constraintsBuilder = new ConstraintsBuilder(); + } + + @Override + public LeafListSchemaNode build() { + instance.setConstraints(constraintsBuilder.build()); + return instance; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(SchemaPath path) { + instance.setPath(path); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + if(status != null) { + instance.setStatus(status); + } + } + + @Override + public TypeDefinition getType() { + return type; + } + + @Override + public void setType(TypeDefinition type) { + this.type = type; + instance.setType(type); + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + @Override + public void setConfiguration(boolean configuration) { + instance.setConfiguration(configuration); + } + + @Override + public ConstraintsBuilder getConstraintsBuilder() { + return constraintsBuilder; + } + + public void setUserOrdered(boolean userOrdered) { + instance.setUserOrdered(userOrdered); + } + + private class LeafListSchemaNodeImpl implements LeafListSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private TypeDefinition type; + private boolean userOrdered; + private List unknownSchemaNodes = Collections.emptyList(); + + private LeafListSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public TypeDefinition getType() { + return type; + } + + public void setType(TypeDefinition> type) { + this.type = type; + } + + @Override + public boolean isUserOrdered() { + return userOrdered; + } + + private void setUserOrdered(boolean userOrdered) { + this.userOrdered = userOrdered; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + (augmenting ? 1231 : 1237); + result = prime * result + (configuration ? 1231 : 1237); + result = prime * result + + ((constraints == null) ? 0 : constraints.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + (userOrdered ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LeafListSchemaNodeImpl other = (LeafListSchemaNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (augmenting != other.augmenting) { + return false; + } + if (configuration != other.configuration) { + return false; + } + if (constraints == null) { + if (other.constraints != null) { + return false; + } + } else if (!constraints.equals(other.constraints)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (userOrdered != other.userOrdered) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + LeafListSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", augmenting=" + augmenting); + sb.append(", configuration=" + configuration); + sb.append(", constraints=" + constraints); + sb.append(", type=" + type); + sb.append(", userOrdered=" + userOrdered); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java new file mode 100644 index 0000000000..5c28e1ba2c --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilder.java @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.LeafSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; + +public class LeafSchemaNodeBuilder implements DataSchemaNodeBuilder, + SchemaNodeBuilder, TypeAwareBuilder { + + private final QName qname; + private final LeafSchemaNodeImpl instance; + private final ConstraintsBuilder constraintsBuilder; + private TypeDefinition type; + + LeafSchemaNodeBuilder(QName qname) { + this.qname = qname; + instance = new LeafSchemaNodeImpl(qname); + constraintsBuilder = new ConstraintsBuilder(); + } + + @Override + public LeafSchemaNode build() { + instance.setConstraints(constraintsBuilder.build()); + return instance; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(SchemaPath path) { + instance.setPath(path); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + if(status != null) { + instance.setStatus(status); + } + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + @Override + public void setConfiguration(boolean configuration) { + instance.setConfiguration(configuration); + } + + @Override + public ConstraintsBuilder getConstraintsBuilder() { + return constraintsBuilder; + } + + @Override + public TypeDefinition getType() { + return type; + } + + @Override + public void setType(TypeDefinition type) { + this.type = type; + instance.setType(type); + } + + private class LeafSchemaNodeImpl implements LeafSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private TypeDefinition type; + private List unknownSchemaNodes = Collections.emptyList(); + + private LeafSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public TypeDefinition getType() { + return type; + } + + private void setType(TypeDefinition> type) { + this.type = type; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + (augmenting ? 1231 : 1237); + result = prime * result + (configuration ? 1231 : 1237); + result = prime * result + + ((constraints == null) ? 0 : constraints.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LeafSchemaNodeImpl other = (LeafSchemaNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (augmenting != other.augmenting) { + return false; + } + if (configuration != other.configuration) { + return false; + } + if (constraints == null) { + if (other.constraints != null) { + return false; + } + } else if (!constraints.equals(other.constraints)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + LeafSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", augmenting=" + augmenting); + sb.append(", configuration=" + configuration); + sb.append(", constraints=" + constraints); + sb.append(", type=" + type); + sb.append(", constraints=" + constraints); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java new file mode 100644 index 0000000000..2a4befe1e3 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilder.java @@ -0,0 +1,508 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ConstraintDefinition; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements + DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder, + TypeDefinitionAwareBuilder { + + private final ListSchemaNodeImpl instance; + private final ConstraintsBuilder constraintsBuilder; + + private final Set addedTypedefs = new HashSet(); + private final Set augmentations = new HashSet(); + private final Set usesNodes = new HashSet(); + + ListSchemaNodeBuilder(QName qname) { + super(qname); + instance = new ListSchemaNodeImpl(qname); + constraintsBuilder = new ConstraintsBuilder(); + } + + @Override + public ListSchemaNode build() { + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // USES + Set usesNodeDefinitions = new HashSet(); + for (UsesNodeBuilder builder : usesNodes) { + usesNodeDefinitions.add(builder.build()); + } + instance.setUses(usesNodeDefinitions); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + instance.setConstraints(constraintsBuilder.build()); + instance.setAvailableAugmentations(augmentations); + + return instance; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void setPath(SchemaPath path) { + instance.setPath(path); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + if(status != null) { + instance.setStatus(status); + } + } + + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + usesNodes.add(usesBuilder); + } + + @Override + public void addAugmentation(AugmentationSchema augmentationSchema) { + augmentations.add(augmentationSchema); + } + + public void setKeyDefinition(List keyDefinition) { + instance.setKeyDefinition(keyDefinition); + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + @Override + public void setConfiguration(boolean configuration) { + instance.setConfiguration(configuration); + } + + @Override + public ConstraintsBuilder getConstraintsBuilder() { + return constraintsBuilder; + } + + public void setUserOrdered(boolean userOrdered) { + instance.setUserOrdered(userOrdered); + } + + private class ListSchemaNodeImpl implements ListSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private List keyDefinition = Collections.emptyList(); + private boolean augmenting; + private boolean configuration; + private ConstraintDefinition constraints; + private Set augmentations = Collections.emptySet(); + private Map childNodes = Collections.emptyMap(); + private Set> typeDefinitions = Collections.emptySet(); + private Set groupings = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private boolean userOrdered; + private List unknownSchemaNodes = Collections.emptyList(); + + private ListSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public List getKeyDefinition() { + if(keyDefinition == null) { + return Collections.emptyList(); + } else { + return keyDefinition; + } + } + + private void setKeyDefinition(List keyDefinition) { + if(keyDefinition != null) { + this.keyDefinition = keyDefinition; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public boolean isConfiguration() { + return configuration; + } + + private void setConfiguration(boolean configuration) { + this.configuration = configuration; + } + + @Override + public ConstraintDefinition getConstraints() { + return constraints; + } + + private void setConstraints(ConstraintDefinition constraints) { + this.constraints = constraints; + } + + @Override + public Set getAvailableAugmentations() { + return augmentations; + } + + private void setAvailableAugmentations( + Set augmentations) { + if(augmentations != null) { + this.augmentations = augmentations; + } + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + if(childNodes != null) { + this.childNodes = childNodes; + } + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + if(groupings != null) { + this.groupings = groupings; + } + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + if(typeDefinitions != null) { + this.typeDefinitions = typeDefinitions; + } + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + if(uses != null) { + this.uses = uses; + } + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public boolean isUserOrdered() { + return userOrdered; + } + + private void setUserOrdered(boolean userOrdered) { + this.userOrdered = userOrdered; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((keyDefinition == null) ? 0 : keyDefinition.hashCode()); + result = prime * result + (augmenting ? 1231 : 1237); + result = prime * result + (configuration ? 1231 : 1237); + result = prime * result + + ((constraints == null) ? 0 : constraints.hashCode()); + result = prime * result + + ((augmentations == null) ? 0 : augmentations.hashCode()); + result = prime * result + + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime + * result + + ((typeDefinitions == null) ? 0 : typeDefinitions + .hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + result = prime * result + (userOrdered ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ListSchemaNodeImpl other = (ListSchemaNodeImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (keyDefinition == null) { + if (other.keyDefinition != null) { + return false; + } + } else if (!keyDefinition.equals(other.keyDefinition)) { + return false; + } + if (augmenting != other.augmenting) { + return false; + } + if (configuration != other.configuration) { + return false; + } + if (constraints == null) { + if (other.constraints != null) { + return false; + } + } else if (!constraints.equals(other.constraints)) { + return false; + } + if (augmentations == null) { + if (other.augmentations != null) { + return false; + } + } else if (!augmentations.equals(other.augmentations)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + if (userOrdered != other.userOrdered) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ListSchemaNodeImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", keyDefinition=" + keyDefinition); + sb.append(", augmenting=" + augmenting); + sb.append(", configuration=" + configuration); + sb.append(", constraints=" + constraints); + sb.append(", augmentations=" + augmentations); + sb.append(", childNodes=" + childNodes.values()); + sb.append(", typedefinitions=" + typeDefinitions); + sb.append(", groupings=" + groupings); + sb.append(", uses=" + uses); + sb.append(", userOrdered=" + userOrdered); + sb.append("]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java new file mode 100644 index 0000000000..5f89e86455 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java @@ -0,0 +1,1098 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.Deviation; +import org.opendaylight.controller.yang.model.api.ExtensionDefinition; +import org.opendaylight.controller.yang.model.api.FeatureDefinition; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.NotificationDefinition; +import org.opendaylight.controller.yang.model.api.RpcDefinition; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; +import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +/** + * This builder builds Module object. If this module is dependent on external + * module/modules, these dependencies must be resolved before module is built, + * otherwise result may not be valid. + */ +public class ModuleBuilder implements Builder { + + private final ModuleImpl instance; + private final String name; + private String prefix; + private Date revision; + + private final Set imports = new HashSet(); + private Set augmentations; + + /** + * All nodes, that can contain other nodes + */ + private final Map, Builder> moduleNodes = new HashMap, Builder>(); + + /** + * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container, + * list, leaf, leaf-list. + */ + private final Map, DataSchemaNodeBuilder> addedChilds = new HashMap, DataSchemaNodeBuilder>(); + + private final Map, GroupingBuilder> addedGroupings = new HashMap, GroupingBuilder>(); + private final Set addedAugments = new HashSet(); + private final Map, UsesNodeBuilder> addedUsesNodes = new HashMap, UsesNodeBuilder>(); + private final Map, RpcDefinitionBuilder> addedRpcs = new HashMap, RpcDefinitionBuilder>(); + private final Set addedNotifications = new HashSet(); + private final Map, FeatureBuilder> addedFeatures = new HashMap, FeatureBuilder>(); + private final Map addedDeviations = new HashMap(); + private final Map, TypeDefinitionBuilder> addedTypedefs = new HashMap, TypeDefinitionBuilder>(); + private final List addedExtensions = new ArrayList(); + + private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); + + public ModuleBuilder(String name) { + this.name = name; + instance = new ModuleImpl(name); + } + + + + /** + * Build new Module object based on this builder. + */ + @Override + public Module build() { + instance.setImports(imports); + + // TYPEDEFS + final Set> typedefs = buildModuleTypedefs(addedTypedefs); + instance.setTypeDefinitions(typedefs); + + // CHILD NODES + final Map childNodes = buildModuleChildNodes(addedChilds); + instance.setChildNodes(childNodes); + + // GROUPINGS + final Set groupings = buildModuleGroupings(addedGroupings); + instance.setGroupings(groupings); + + // USES + final Set usesNodeDefinitions = buildUsesNodes(addedUsesNodes); + instance.setUses(usesNodeDefinitions); + + // FEATURES + final Set features = buildModuleFeatures(addedFeatures); + instance.setFeatures(features); + + // NOTIFICATIONS + final Set notifications = new HashSet(); + for (NotificationBuilder entry : addedNotifications) { + notifications.add((NotificationDefinition) entry.build()); + } + instance.setNotifications(notifications); + + // AUGMENTATIONS + instance.setAugmentations(augmentations); + + // RPCs + final Set rpcs = buildModuleRpcs(addedRpcs); + instance.setRpcs(rpcs); + + // DEVIATIONS + final Set deviations = new HashSet(); + for (Map.Entry entry : addedDeviations + .entrySet()) { + deviations.add(entry.getValue().build()); + } + instance.setDeviations(deviations); + + // EXTENSIONS + final List extensions = new ArrayList(); + for(ExtensionBuilder b : addedExtensions) { + extensions.add(b.build()); + } + instance.setExtensionSchemaNodes(extensions); + + return instance; + } + + public Builder getNode(List path) { + return moduleNodes.get(path); + } + + public Map, TypeAwareBuilder> getDirtyNodes() { + return dirtyNodes; + } + + public String getName() { + return name; + } + + public String getPrefix() { + return prefix; + } + + public Date getRevision() { + return revision; + } + + public Set getAddedAugments() { + return addedAugments; + } + + public void addDirtyNode(List path) { + List dirtyNodePath = new ArrayList(path); + TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes + .get(dirtyNodePath); + dirtyNodes.put(dirtyNodePath, nodeBuilder); + } + + public void setNamespace(URI namespace) { + instance.setNamespace(namespace); + } + + public void setRevision(Date revision) { + this.revision = revision; + instance.setRevision(revision); + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + instance.setPrefix(prefix); + } + + public void setYangVersion(String yangVersion) { + instance.setYangVersion(yangVersion); + } + + public void setDescription(String description) { + instance.setDescription(description); + } + + public void setReference(String reference) { + instance.setReference(reference); + } + + public void setOrganization(String organization) { + instance.setOrganization(organization); + } + + public void setContact(String contact) { + instance.setContact(contact); + } + + public void setAugmentations(Set augmentations) { + this.augmentations = augmentations; + } + + public boolean addModuleImport(final String moduleName, + final Date revision, final String prefix) { + ModuleImport moduleImport = createModuleImport(moduleName, revision, + prefix); + return imports.add(moduleImport); + } + + public Set getModuleImports() { + return imports; + } + + public ExtensionBuilder addExtension(QName qname) { + ExtensionBuilder builder = new ExtensionBuilder(qname); + return builder; + } + + public ContainerSchemaNodeBuilder addContainerNode(QName containerName, + List parentPath) { + List pathToNode = new ArrayList(parentPath); + + ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( + containerName); + + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); + if (parent != null) { + if(parent instanceof AugmentationSchemaBuilder) { + containerBuilder.setAugmenting(true); + } + parent.addChildNode(containerBuilder); + } + + pathToNode.add(containerName.getLocalName()); + moduleNodes.put(pathToNode, containerBuilder); + addedChilds.put(pathToNode, containerBuilder); + + return containerBuilder; + } + + public ListSchemaNodeBuilder addListNode(QName listName, + List parentPath) { + List pathToNode = new ArrayList(parentPath); + + ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName); + + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); + if (parent != null) { + if(parent instanceof AugmentationSchemaBuilder) { + listBuilder.setAugmenting(true); + } + parent.addChildNode(listBuilder); + } + + pathToNode.add(listName.getLocalName()); + moduleNodes.put(pathToNode, listBuilder); + addedChilds.put(pathToNode, listBuilder); + + return listBuilder; + } + + public LeafSchemaNodeBuilder addLeafNode(QName leafName, + List parentPath) { + List pathToNode = new ArrayList(parentPath); + + LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName); + + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + if (parent != null) { + if(parent instanceof AugmentationSchemaBuilder) { + leafBuilder.setAugmenting(true); + } + parent.addChildNode(leafBuilder); + } + + pathToNode.add(leafName.getLocalName()); + addedChilds.put(pathToNode, leafBuilder); + moduleNodes.put(pathToNode, leafBuilder); + + return leafBuilder; + } + + public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName, + List parentPath) { + List pathToNode = new ArrayList(parentPath); + + LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( + leafListName); + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + if (parent != null) { + if(parent instanceof AugmentationSchemaBuilder) { + leafListBuilder.setAugmenting(true); + } + parent.addChildNode(leafListBuilder); + } + + pathToNode.add(leafListName.getLocalName()); + addedChilds.put(pathToNode, leafListBuilder); + moduleNodes.put(pathToNode, leafListBuilder); + + return leafListBuilder; + } + + public GroupingBuilder addGrouping(QName qname, List parentPath) { + List pathToGroup = new ArrayList(parentPath); + + GroupingBuilder builder = new GroupingBuilderImpl(qname); + ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes.get(pathToGroup); + if (parentNodeBuilder != null) { + parentNodeBuilder.addGrouping(builder); + } + + pathToGroup.add(qname.getLocalName()); + moduleNodes.put(pathToGroup, builder); + addedGroupings.put(pathToGroup, builder); + + return builder; + } + + public AugmentationSchemaBuilder addAugment(String name, + List parentPath) { + List pathToAugment = new ArrayList(parentPath); + + AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name); + + // augment can only be in 'module' or 'uses' statement + UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); + if (parent != null) { + parent.addAugment(builder); + } + + pathToAugment.add(name); + moduleNodes.put(pathToAugment, builder); + addedAugments.add(builder); + + return builder; + } + + public UsesNodeBuilder addUsesNode(String groupingPathStr, + List parentPath) { + List pathToUses = new ArrayList(parentPath); + + UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr); + + ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses); + if (parent != null) { + if(parent instanceof AugmentationSchemaBuilder) { + usesBuilder.setAugmenting(true); + } + parent.addUsesNode(usesBuilder); + } + + pathToUses.add(groupingPathStr); + addedUsesNodes.put(pathToUses, usesBuilder); + + return usesBuilder; + } + + public RpcDefinitionBuilder addRpc(QName qname, List parentPath) { + List pathToRpc = new ArrayList(parentPath); + + RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); + + pathToRpc.add(qname.getLocalName()); + addedRpcs.put(pathToRpc, rpcBuilder); + + QName inputQName = new QName(qname.getNamespace(), qname.getRevision(), + qname.getPrefix(), "input"); + ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName); + List pathToInput = new ArrayList(pathToRpc); + pathToInput.add("input"); + moduleNodes.put(pathToInput, inputBuilder); + rpcBuilder.setInput(inputBuilder); + + QName outputQName = new QName(qname.getNamespace(), + qname.getRevision(), qname.getPrefix(), "output"); + ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName); + List pathToOutput = new ArrayList(pathToRpc); + pathToOutput.add("output"); + moduleNodes.put(pathToOutput, outputBuilder); + rpcBuilder.setOutput(outputBuilder); + + return rpcBuilder; + } + + public NotificationBuilder addNotification(QName notificationName, + List parentPath) { + List pathToNotification = new ArrayList(parentPath); + + NotificationBuilder notificationBuilder = new NotificationBuilder( + notificationName); + + pathToNotification.add(notificationName.getLocalName()); + moduleNodes.put(pathToNotification, notificationBuilder); + addedNotifications.add(notificationBuilder); + + return notificationBuilder; + } + + public FeatureBuilder addFeature(QName featureName, List parentPath) { + List pathToFeature = new ArrayList(parentPath); + pathToFeature.add(featureName.getLocalName()); + + FeatureBuilder builder = new FeatureBuilder(featureName); + addedFeatures.put(pathToFeature, builder); + return builder; + } + + public TypedefBuilder addTypedef(QName typeDefName, List parentPath) { + List pathToType = new ArrayList(parentPath); + TypedefBuilder builder = new TypedefBuilder(typeDefName); + TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes.get(pathToType); + if (parent != null) { + parent.addTypedef(builder); + } + pathToType.add(typeDefName.getLocalName()); + addedTypedefs.put(pathToType, builder); + moduleNodes.put(pathToType, builder); + return builder; + } + + public Set getModuleTypedefs() { + Set typedefs = new HashSet(); + for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { + if (entry.getKey().size() == 2) { + typedefs.add(entry.getValue()); + } + } + return typedefs; + } + + public void setType(TypeDefinition type, List parentPath) { + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath); + parent.setType(type); + } + + public DeviationBuilder addDeviation(String targetPath) { + DeviationBuilder builder = new DeviationBuilder(targetPath); + addedDeviations.put(targetPath, builder); + return builder; + } + + public void addConfiguration(boolean configuration, List parentPath) { + Builder builder = moduleNodes.get(parentPath); + if (builder instanceof DeviationBuilder) { + // skip + // TODO + } else { + DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes.get(parentPath); + configBuilder.setConfiguration(configuration); + } + } + + public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List parentPath) { + UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(qname); + return builder; + } + + + private class ModuleImpl implements Module { + private URI namespace; + private final String name; + private Date revision; + private String prefix; + private String yangVersion; + private String description; + private String reference; + private String organization; + private String contact; + private Set imports = Collections.emptySet(); + private Set features = Collections.emptySet(); + private Set> typeDefinitions = Collections.emptySet(); + private Set notifications = Collections.emptySet(); + private Set augmentations = Collections.emptySet(); + private Set rpcs = Collections.emptySet(); + private Set deviations = Collections.emptySet(); + private Map childNodes = Collections.emptyMap(); + private Set groupings = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private List extensionSchemaNodes = Collections.emptyList(); + + private ModuleImpl(String name) { + this.name = name; + } + + @Override + public URI getNamespace() { + return namespace; + } + + private void setNamespace(URI namespace) { + this.namespace = namespace; + } + + @Override + public String getName() { + return name; + } + + @Override + public Date getRevision() { + return revision; + } + + private void setRevision(Date revision) { + this.revision = revision; + } + + @Override + public String getPrefix() { + return prefix; + } + + private void setPrefix(String prefix) { + this.prefix = prefix; + } + + @Override + public String getYangVersion() { + return yangVersion; + } + + private void setYangVersion(String yangVersion) { + this.yangVersion = yangVersion; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public String getOrganization() { + return organization; + } + + private void setOrganization(String organization) { + this.organization = organization; + } + + @Override + public String getContact() { + return contact; + } + + private void setContact(String contact) { + this.contact = contact; + } + + @Override + public Set getImports() { + return imports; + } + + private void setImports(Set imports) { + this.imports = imports; + } + + @Override + public Set getFeatures() { + return features; + } + + private void setFeatures(Set features) { + this.features = features; + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + this.typeDefinitions = typeDefinitions; + } + + @Override + public Set getNotifications() { + return notifications; + } + + private void setNotifications(Set notifications) { + this.notifications = notifications; + } + + @Override + public Set getAugmentations() { + return augmentations; + } + + private void setAugmentations(Set augmentations) { + this.augmentations = augmentations; + } + + @Override + public Set getRpcs() { + return rpcs; + } + + private void setRpcs(Set rpcs) { + this.rpcs = rpcs; + } + + @Override + public Set getDeviations() { + return deviations; + } + + private void setDeviations(Set deviations) { + this.deviations = deviations; + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + this.childNodes = childNodes; + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + this.groupings = groupings; + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + this.uses = uses; + } + + @Override + public List getExtensionSchemaNodes() { + return extensionSchemaNodes; + } + + private void setExtensionSchemaNodes(List extensionSchemaNodes) { + if(extensionSchemaNodes != null) { + this.extensionSchemaNodes = extensionSchemaNodes; + } + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((namespace == null) ? 0 : namespace.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((revision == null) ? 0 : revision.hashCode()); + result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((reference == null) ? 0 : reference.hashCode()); + + result = prime * result + ((organization == null) ? 0 : organization.hashCode()); + result = prime * result + ((contact == null) ? 0 : contact.hashCode()); + result = prime * result + ((imports == null) ? 0 : imports.hashCode()); + result = prime * result + ((features == null) ? 0 : features.hashCode()); + result = prime * result + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode()); + result = prime * result + ((notifications == null) ? 0 : notifications.hashCode()); + result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); + result = prime * result + ((rpcs == null) ? 0 : rpcs.hashCode()); + result = prime * result + ((deviations == null) ? 0 : deviations.hashCode()); + result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ModuleImpl other = (ModuleImpl) obj; + if (namespace == null) { + if (other.namespace != null) { + return false; + } + } else if (!namespace.equals(other.namespace)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (revision == null) { + if (other.revision != null) { + return false; + } + } else if (!revision.equals(other.revision)) { + return false; + } + if (prefix == null) { + if (other.prefix != null) { + return false; + } + } else if (!prefix.equals(other.prefix)) { + return false; + } + if (yangVersion == null) { + if (other.yangVersion != null) { + return false; + } + } else if (!yangVersion.equals(other.yangVersion)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (organization == null) { + if (other.organization != null) { + return false; + } + } else if (!organization.equals(other.organization)) { + return false; + } + if (contact == null) { + if (other.contact != null) { + return false; + } + } else if (!contact.equals(other.contact)) { + return false; + } + if (imports == null) { + if (other.imports != null) { + return false; + } + } else if (!imports.equals(other.imports)) { + return false; + } + if (features == null) { + if (other.features != null) { + return false; + } + } else if (!features.equals(other.features)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (notifications == null) { + if (other.notifications != null) { + return false; + } + } else if (!notifications.equals(other.notifications)) { + return false; + } + if (augmentations == null) { + if (other.augmentations != null) { + return false; + } + } else if (!augmentations.equals(other.augmentations)) { + return false; + } + if (rpcs == null) { + if (other.rpcs != null) { + return false; + } + } else if (!rpcs.equals(other.rpcs)) { + return false; + } + if (deviations == null) { + if (other.deviations != null) { + return false; + } + } else if (!deviations.equals(other.deviations)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + ModuleImpl.class.getSimpleName()); + sb.append("[\n"); + sb.append("name=" + name + ",\n"); + sb.append("namespace=" + namespace + ",\n"); + sb.append("revision=" + revision + ",\n"); + sb.append("prefix=" + prefix + ",\n"); + sb.append("yangVersion=" + yangVersion + ",\n"); + sb.append("description=" + description + ",\n"); + sb.append("reference=" + reference + ",\n"); + sb.append("organization=" + organization + ",\n"); + sb.append("contact=" + contact + ",\n"); + sb.append("childNodes=" + childNodes.values() + ",\n"); + sb.append("groupings=" + groupings + ",\n"); + sb.append("imports=" + imports + ",\n"); + sb.append("features=" + features + ",\n"); + sb.append("typeDefinitions=" + typeDefinitions + ",\n"); + sb.append("notifications=" + notifications + ",\n"); + sb.append("augmentations=" + augmentations + ",\n"); + sb.append("rpcs=" + rpcs + ",\n"); + sb.append("deviations=" + deviations + "\n"); + sb.append("uses=" + uses + "\n"); + sb.append("]"); + return sb.toString(); + } + } + + private ModuleImport createModuleImport(final String moduleName, + final Date revision, final String prefix) { + ModuleImport moduleImport = new ModuleImport() { + @Override + public String getModuleName() { + return moduleName; + } + + @Override + public Date getRevision() { + return revision; + } + + @Override + public String getPrefix() { + return prefix; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((moduleName == null) ? 0 : moduleName.hashCode()); + result = prime * result + + ((revision == null) ? 0 : revision.hashCode()); + result = prime * result + + ((prefix == null) ? 0 : prefix.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ModuleImport other = (ModuleImport) obj; + if (getModuleName() == null) { + if (other.getModuleName() != null) { + return false; + } + } else if (!getModuleName().equals(other.getModuleName())) { + return false; + } + if (getRevision() == null) { + if (other.getRevision() != null) { + return false; + } + } else if (!getRevision().equals(other.getRevision())) { + return false; + } + if (getPrefix() == null) { + if (other.getPrefix() != null) { + return false; + } + } else if (!getPrefix().equals(other.getPrefix())) { + return false; + } + return true; + } + + @Override + public String toString() { + return "ModuleImport[moduleName=" + moduleName + ", revision=" + + revision + ", prefix=" + prefix + "]"; + } + }; + return moduleImport; + } + + /** + * Traverse through given addedChilds and add only direct module childs. + * Direct module child path size is 2 (1. module name, 2. child name). + * + * @param addedChilds + * @return map of children, where key is child QName and value is child + * itself + */ + private Map buildModuleChildNodes( + Map, DataSchemaNodeBuilder> addedChilds) { + final Map childNodes = new HashMap(); + for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds + .entrySet()) { + if (entry.getKey().size() == 2) { + DataSchemaNode node = entry.getValue().build(); + QName qname = entry.getValue().getQName(); + childNodes.put(qname, node); + } + } + return childNodes; + } + + /** + * Traverse through given addedGroupings and add only direct module + * groupings. Direct module grouping path size is 2 (1. module name, 2. + * grouping name). + * + * @param addedGroupings + * @return set of built GroupingDefinition objects + */ + private Set buildModuleGroupings( + Map, GroupingBuilder> addedGroupings) { + final Set groupings = new HashSet(); + for (Map.Entry, GroupingBuilder> entry : addedGroupings + .entrySet()) { + if (entry.getKey().size() == 2) { + groupings.add(entry.getValue().build()); + } + } + return groupings; + } + + /** + * Traverse through given addedRpcs and build RpcDefinition objects. + * + * @param addedRpcs + * @return set of built RpcDefinition objects + */ + private Set buildModuleRpcs( + Map, RpcDefinitionBuilder> addedRpcs) { + final Set rpcs = new HashSet(); + RpcDefinitionBuilder builder; + for (Map.Entry, RpcDefinitionBuilder> entry : addedRpcs + .entrySet()) { + builder = entry.getValue(); + RpcDefinition rpc = builder.build(); + rpcs.add(rpc); + } + return rpcs; + } + + /** + * Traverse through given addedTypedefs and add only direct module typedef + * statements. Direct module typedef path size is 2 (1. module name, 2. + * typedef name). + * + * @param addedTypedefs + * @return set of built module typedef statements + */ + private Set> buildModuleTypedefs( + Map, TypeDefinitionBuilder> addedTypedefs) { + Set> typedefs = new HashSet>(); + for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs + .entrySet()) { + if (entry.getKey().size() == 2) { + TypeDefinition> node = entry + .getValue().build(); + typedefs.add(node); + } + } + return typedefs; + } + + /** + * Traverse through given addedUsesNodes and add only direct module uses + * nodes. Direct module uses node path size is 2 (1. module name, 2. uses + * name). + * + * @param addedUsesNodes + * @return set of built module uses nodes + */ + private Set buildUsesNodes( + Map, UsesNodeBuilder> addedUsesNodes) { + final Set usesNodeDefinitions = new HashSet(); + for (Map.Entry, UsesNodeBuilder> entry : addedUsesNodes + .entrySet()) { + if (entry.getKey().size() == 2) { + usesNodeDefinitions.add(entry.getValue().build()); + } + } + return usesNodeDefinitions; + } + + /** + * Traverse through given addedFeatures and add only direct module features. + * Direct module feature path size is 2 (1. module name, 2. feature name). + * + * @param addedFeatures + * @return set of built module features + */ + private Set buildModuleFeatures( + Map, FeatureBuilder> addedFeatures) { + Set features = new HashSet(); + for (Map.Entry, FeatureBuilder> entry : addedFeatures + .entrySet()) { + if (entry.getKey().size() == 2) { + features.add(entry.getValue().build()); + } + } + return features; + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java new file mode 100644 index 0000000000..783b21e04b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/NotificationBuilder.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.NotificationDefinition; +import org.opendaylight.controller.yang.model.api.SchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AbstractChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class NotificationBuilder extends AbstractChildNodeBuilder implements + TypeDefinitionAwareBuilder, SchemaNodeBuilder { + + private final NotificationDefinitionImpl instance; + private final Set addedTypedefs = new HashSet(); + private final Set addedUsesNodes = new HashSet(); + + NotificationBuilder(QName qname) { + super(qname); + instance = new NotificationDefinitionImpl(qname); + } + + @Override + public SchemaNode build() { + // CHILD NODES + Map childs = new HashMap(); + for (DataSchemaNodeBuilder node : childNodes) { + childs.put(node.getQName(), node.build()); + } + instance.setChildNodes(childs); + + // GROUPINGS + Set groupingDefinitions = new HashSet(); + for (GroupingBuilder builder : groupings) { + groupingDefinitions.add(builder.build()); + } + instance.setGroupings(groupingDefinitions); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // USES + Set uses = new HashSet(); + for (UsesNodeBuilder builder : addedUsesNodes) { + uses.add(builder.build()); + } + instance.setUses(uses); + + return instance; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void addUsesNode(UsesNodeBuilder usesNodeBuilder) { + addedUsesNodes.add(usesNodeBuilder); + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + private class NotificationDefinitionImpl implements NotificationDefinition { + + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status; + private Map childNodes = Collections.emptyMap(); + private Set groupings = Collections.emptySet(); + private Set> typeDefinitions = Collections.emptySet(); + private Set uses = Collections.emptySet(); + private List unknownSchemaNodes = Collections.emptyList(); + + private NotificationDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public Set getChildNodes() { + return new HashSet(childNodes.values()); + } + + private void setChildNodes(Map childNodes) { + if(childNodes != null) { + this.childNodes = childNodes; + } + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + if(groupings != null) { + this.groupings = groupings; + } + } + + @Override + public Set getUses() { + return uses; + } + + private void setUses(Set uses) { + if(uses != null) { + this.uses = uses; + } + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + if(typeDefinitions != null) { + this.typeDefinitions = typeDefinitions; + } + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public DataSchemaNode getDataChildByName(QName name) { + return childNodes.get(name); + } + + @Override + public DataSchemaNode getDataChildByName(String name) { + DataSchemaNode result = null; + for (Map.Entry entry : childNodes.entrySet()) { + if (entry.getKey().getLocalName().equals(name)) { + result = entry.getValue(); + break; + } + } + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((childNodes == null) ? 0 : childNodes.hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + result = prime * result + + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode()); + result = prime * result + ((uses == null) ? 0 : uses.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + NotificationDefinitionImpl other = (NotificationDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (childNodes == null) { + if (other.childNodes != null) { + return false; + } + } else if (!childNodes.equals(other.childNodes)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (uses == null) { + if (other.uses != null) { + return false; + } + } else if (!uses.equals(other.uses)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + NotificationDefinitionImpl.class.getSimpleName()); + sb.append("[qname=" + qname + "]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/RpcDefinitionBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java similarity index 61% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/RpcDefinitionBuilder.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java index 55f361b26a..822a8359c4 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/RpcDefinitionBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/RpcDefinitionBuilder.java @@ -1,264 +1,364 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.opendaylight.controller.model.parser.api.ChildNodeBuilder; -import org.opendaylight.controller.model.parser.api.DataSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.SchemaNodeBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionAwareBuilder; -import org.opendaylight.controller.model.parser.api.TypeDefinitionBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.RpcDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; - -public class RpcDefinitionBuilder implements ChildNodeBuilder, - SchemaNodeBuilder, TypeDefinitionAwareBuilder { - - private final RpcDefinitionImpl instance; - private final QName qname; - private ContainerSchemaNodeBuilder inputBuilder; - private ContainerSchemaNodeBuilder outputBuilder; - private final Set addedTypedefs = new HashSet(); - private final Set addedGroupings = new HashSet(); - - RpcDefinitionBuilder(QName qname) { - this.qname = qname; - this.instance = new RpcDefinitionImpl(qname); - } - - @Override - public RpcDefinition build() { - final ContainerSchemaNode input = inputBuilder.build(); - final ContainerSchemaNode output = outputBuilder.build(); - instance.setInput(input); - instance.setOutput(output); - - // TYPEDEFS - Set> typedefs = new HashSet>(); - for (TypeDefinitionBuilder entry : addedTypedefs) { - typedefs.add(entry.build()); - } - instance.setTypeDefinitions(typedefs); - - // GROUPINGS - final Set groupings = new HashSet(); - for (GroupingBuilder entry : addedGroupings) { - groupings.add(entry.build()); - } - instance.setGroupings(groupings); - - return instance; - } - - void setInput(ContainerSchemaNodeBuilder inputBuilder) { - this.inputBuilder = inputBuilder; - } - - void setOutput(ContainerSchemaNodeBuilder outputBuilder) { - this.outputBuilder = outputBuilder; - } - - @Override - public void addTypedef(TypeDefinitionBuilder type) { - addedTypedefs.add(type); - } - - @Override - public void setPath(SchemaPath schemaPath) { - instance.setPath(schemaPath); - } - - @Override - public void setDescription(String description) { - instance.setDescription(description); - } - - @Override - public void setReference(String reference) { - instance.setReference(reference); - } - - @Override - public void setStatus(Status status) { - instance.setStatus(status); - } - - @Override - public QName getQName() { - return null; - } - - @Override - public void addChildNode(DataSchemaNodeBuilder childNode) { - throw new UnsupportedOperationException( - "Can not add child node to rpc definition: rpc can not contains child nodes."); - } - - @Override - public void addGrouping(GroupingBuilder grouping) { - addedGroupings.add(grouping); - } - - @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - throw new UnsupportedOperationException( - "Can not add uses node to rpc definition: rpc can not contains uses nodes."); - } - - @Override - public int hashCode() { - return qname.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (!(obj instanceof RpcDefinitionBuilder)) { - return false; - } - RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj; - if (other.qname == null) { - if (this.qname != null) { - return false; - } - } else if (!other.qname.equals(this.qname)) { - return false; - } - return true; - } - - private static class RpcDefinitionImpl implements RpcDefinition { - - private final QName qname; - private SchemaPath path; - private String description; - private String reference; - private Status status; - - private ContainerSchemaNode input; - private ContainerSchemaNode output; - - private Set> typeDefinitions; - private Set groupings; - - private RpcDefinitionImpl(QName qname) { - this.qname = qname; - } - - @Override - public QName getQName() { - return qname; - } - - @Override - public SchemaPath getPath() { - return path; - } - - private void setPath(SchemaPath path) { - this.path = path; - } - - @Override - public String getDescription() { - return description; - } - - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public Status getStatus() { - return status; - } - - private void setStatus(Status status) { - this.status = status; - } - - @Override - public ContainerSchemaNode getInput() { - return input; - } - - private void setInput(ContainerSchemaNode input) { - this.input = input; - } - - @Override - public ContainerSchemaNode getOutput() { - return output; - } - - private void setOutput(ContainerSchemaNode output) { - this.output = output; - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - - private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; - } - - @Override - public Set getGroupings() { - return groupings; - } - - private void setGroupings(Set groupings) { - this.groupings = groupings; - } - - @Override - public List getExtensionSchemaNodes() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder( - RpcDefinitionImpl.class.getSimpleName() + "["); - sb.append("qname=" + qname); - sb.append(", path=" + path); - sb.append(", description=" + description); - sb.append(", reference=" + reference); - sb.append(", status=" + status); - sb.append(", input=" + input); - sb.append(", output=" + output + "]"); - return sb.toString(); - } - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.RpcDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class RpcDefinitionBuilder implements ChildNodeBuilder, + SchemaNodeBuilder, TypeDefinitionAwareBuilder { + + private final RpcDefinitionImpl instance; + private final QName qname; + private ContainerSchemaNodeBuilder inputBuilder; + private ContainerSchemaNodeBuilder outputBuilder; + private final Set addedTypedefs = new HashSet(); + private final Set addedGroupings = new HashSet(); + + RpcDefinitionBuilder(QName qname) { + this.qname = qname; + this.instance = new RpcDefinitionImpl(qname); + } + + @Override + public RpcDefinition build() { + final ContainerSchemaNode input = inputBuilder.build(); + final ContainerSchemaNode output = outputBuilder.build(); + instance.setInput(input); + instance.setOutput(output); + + // TYPEDEFS + Set> typedefs = new HashSet>(); + for (TypeDefinitionBuilder entry : addedTypedefs) { + typedefs.add(entry.build()); + } + instance.setTypeDefinitions(typedefs); + + // GROUPINGS + final Set groupings = new HashSet(); + for (GroupingBuilder entry : addedGroupings) { + groupings.add(entry.build()); + } + instance.setGroupings(groupings); + + return instance; + } + + void setInput(ContainerSchemaNodeBuilder inputBuilder) { + this.inputBuilder = inputBuilder; + } + + void setOutput(ContainerSchemaNodeBuilder outputBuilder) { + this.outputBuilder = outputBuilder; + } + + @Override + public void addTypedef(TypeDefinitionBuilder type) { + addedTypedefs.add(type); + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + @Override + public QName getQName() { + return null; + } + + @Override + public void addChildNode(DataSchemaNodeBuilder childNode) { + throw new UnsupportedOperationException( + "Can not add child node to rpc definition: rpc can not contains child nodes."); + } + + @Override + public void addGrouping(GroupingBuilder grouping) { + addedGroupings.add(grouping); + } + + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + throw new UnsupportedOperationException( + "Can not add uses node to rpc definition: rpc can not contains uses nodes."); + } + + @Override + public int hashCode() { + return qname.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (!(obj instanceof RpcDefinitionBuilder)) { + return false; + } + RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj; + if (other.qname == null) { + if (this.qname != null) { + return false; + } + } else if (!other.qname.equals(this.qname)) { + return false; + } + return true; + } + + private static class RpcDefinitionImpl implements RpcDefinition { + + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status; + private ContainerSchemaNode input; + private ContainerSchemaNode output; + private Set> typeDefinitions; + private Set groupings; + private List unknownSchemaNodes = Collections.emptyList(); + + private RpcDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public ContainerSchemaNode getInput() { + return input; + } + + private void setInput(ContainerSchemaNode input) { + this.input = input; + } + + @Override + public ContainerSchemaNode getOutput() { + return output; + } + + private void setOutput(ContainerSchemaNode output) { + this.output = output; + } + + @Override + public Set> getTypeDefinitions() { + return typeDefinitions; + } + + private void setTypeDefinitions(Set> typeDefinitions) { + this.typeDefinitions = typeDefinitions; + } + + @Override + public Set getGroupings() { + return groupings; + } + + private void setGroupings(Set groupings) { + this.groupings = groupings; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((input == null) ? 0 : input.hashCode()); + result = prime * result + + ((output == null) ? 0 : output.hashCode()); + result = prime * result + + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode()); + result = prime * result + + ((groupings == null) ? 0 : groupings.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RpcDefinitionImpl other = (RpcDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (input == null) { + if (other.input != null) { + return false; + } + } else if (!input.equals(other.input)) { + return false; + } + if (output == null) { + if (other.output != null) { + return false; + } + } else if (!output.equals(other.output)) { + return false; + } + if (typeDefinitions == null) { + if (other.typeDefinitions != null) { + return false; + } + } else if (!typeDefinitions.equals(other.typeDefinitions)) { + return false; + } + if (groupings == null) { + if (other.groupings != null) { + return false; + } + } else if (!groupings.equals(other.groupings)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + RpcDefinitionImpl.class.getSimpleName() + "["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", input=" + input); + sb.append(", output=" + output + "]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java new file mode 100644 index 0000000000..1a2c43d148 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.model.util.UnknownType; +import org.opendaylight.controller.model.util.YangTypesConverter; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; + +public class TypedefBuilder implements TypeDefinitionBuilder, + SchemaNodeBuilder, TypeAwareBuilder { + + private final QName qname; + private SchemaPath schemaPath; + private TypeDefinition baseType; + + private String description; + private String reference; + private Status status; + private String units; + + TypedefBuilder(QName qname) { + this.qname = qname; + } + + @Override + public TypeDefinition> build() { + final TypeDefinition type = YangTypesConverter + .javaTypeForBaseYangType(qname); + if (type != null) { + return type; + } else { + if (baseType != null) { + // typedef + TypeDefinitionImpl instance = new TypeDefinitionImpl(qname); + instance.setDescription(description); + instance.setReference(reference); + instance.setStatus(status); + instance.setPath(schemaPath); + instance.setBaseType(baseType); + instance.setUnits(units); + return instance; + } else { + // type + final UnknownType.Builder unknownBuilder = new UnknownType.Builder( + qname, description, reference); + unknownBuilder.status(status); + return unknownBuilder.build(); + } + } + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(final SchemaPath schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public void setDescription(final String description) { + this.description = description; + } + + @Override + public void setReference(final String reference) { + this.reference = reference; + } + + @Override + public void setStatus(final Status status) { + if (status != null) { + this.status = status; + } + } + + @Override + public void setUnits(String units) { + this.units = units; + } + + @Override + public TypeDefinition getType() { + return baseType; + } + + @Override + public void setType(TypeDefinition baseType) { + this.baseType = baseType; + } + + @Override + public TypeDefinition getBaseType() { + return baseType; + } + + private static class TypeDefinitionImpl> + implements TypeDefinition { + + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private T baseType; + private String units; + private List unknownSchemaNodes = Collections.emptyList(); + + private TypeDefinitionImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + this.status = status; + } + + @Override + public T getBaseType() { + return baseType; + } + + private void setBaseType(T type) { + this.baseType = type; + } + + @Override + public String getUnits() { + return units; + } + + private void setUnits(String units) { + this.units = units; + } + + @Override + public Object getDefaultValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((baseType == null) ? 0 : baseType.hashCode()); + result = prime * result + ((units == null) ? 0 : units.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TypeDefinitionImpl other = (TypeDefinitionImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (baseType == null) { + if (other.baseType != null) { + return false; + } + } else if (!baseType.equals(other.baseType)) { + return false; + } + if (units == null) { + if (other.units != null) { + return false; + } + } else if (!units.equals(other.units)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder( + TypeDefinitionImpl.class.getSimpleName()); + sb.append("["); + sb.append("qname=" + qname); + sb.append(", path=" + path); + sb.append(", description=" + description); + sb.append(", reference=" + reference); + sb.append(", status=" + status); + sb.append(", baseType=" + baseType + "]"); + return sb.toString(); + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java new file mode 100644 index 0000000000..d0bb01cf34 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnknownSchemaNodeBuilder.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; + +public class UnknownSchemaNodeBuilder implements SchemaNodeBuilder { + + private final QName qname; + private final UnknownSchemaNodeImpl instance; + + UnknownSchemaNodeBuilder(final QName qname) { + this.qname = qname; + instance = new UnknownSchemaNodeImpl(qname); + } + + + @Override + public UnknownSchemaNode build() { + return instance; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public void setPath(SchemaPath schemaPath) { + instance.setPath(schemaPath); + } + + @Override + public void setDescription(String description) { + instance.setDescription(description); + } + + @Override + public void setReference(String reference) { + instance.setReference(reference); + } + + @Override + public void setStatus(Status status) { + instance.setStatus(status); + } + + private static class UnknownSchemaNodeImpl implements UnknownSchemaNode { + private final QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status = Status.CURRENT; + private List unknownSchemaNodes = Collections.emptyList(); + + private UnknownSchemaNodeImpl(QName qname) { + this.qname = qname; + } + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + private void setPath(SchemaPath path) { + this.path = path; + } + + @Override + public String getDescription() { + return description; + } + + private void setDescription(String description) { + this.description = description; + } + + @Override + public String getReference() { + return reference; + } + + private void setReference(String reference) { + this.reference = reference; + } + + @Override + public Status getStatus() { + return status; + } + + private void setStatus(Status status) { + if(status != null) { + this.status = status; + } + } + + @Override + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; + } + + private void setUnknownSchemaNodes(List unknownSchemaNodes) { + if(unknownSchemaNodes != null) { + this.unknownSchemaNodes = unknownSchemaNodes; + } + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java new file mode 100644 index 0000000000..2096c3bdf8 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { + + private final UsesNodeImpl instance; + private final Set addedAugments = new HashSet(); + + UsesNodeBuilderImpl(String groupingPathStr) { + SchemaPath groupingPath = parseUsesPath(groupingPathStr); + instance = new UsesNodeImpl(groupingPath); + } + + @Override + public UsesNode build() { + // AUGMENTATIONS + final Set augments = new HashSet(); + for (AugmentationSchemaBuilder builder : addedAugments) { + augments.add(builder.build()); + } + instance.setAugmentations(augments); + + return instance; + } + + @Override + public void addAugment(AugmentationSchemaBuilder augmentBuilder) { + addedAugments.add(augmentBuilder); + } + + @Override + public void setAugmenting(boolean augmenting) { + instance.setAugmenting(augmenting); + } + + private SchemaPath parseUsesPath(String augmentPath) { + String[] splittedPath = augmentPath.split("/"); + List path = new ArrayList(); + QName name; + for (String pathElement : splittedPath) { + String[] splittedElement = pathElement.split(":"); + if (splittedElement.length == 1) { + name = new QName(null, null, null, splittedElement[0]); + } else { + name = new QName(null, null, splittedElement[0], + splittedElement[1]); + } + path.add(name); + } + final boolean absolute = augmentPath.startsWith("/"); + return new SchemaPath(path, absolute); + } + + private static class UsesNodeImpl implements UsesNode { + + private final SchemaPath groupingPath; + private Set augmentations = Collections.emptySet(); + private boolean augmenting; + + private UsesNodeImpl(SchemaPath groupingPath) { + this.groupingPath = groupingPath; + } + + @Override + public SchemaPath getGroupingPath() { + return groupingPath; + } + + @Override + public Set getAugmentations() { + return augmentations; + } + + private void setAugmentations(Set augmentations) { + if (augmentations != null) { + this.augmentations = augmentations; + } + } + + @Override + public boolean isAugmenting() { + return augmenting; + } + + private void setAugmenting(boolean augmenting) { + this.augmenting = augmenting; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode()); + result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); + result = prime * result + (augmenting ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + UsesNodeImpl other = (UsesNodeImpl) obj; + if (groupingPath == null) { + if (other.groupingPath != null) { + return false; + } + } else if (!groupingPath.equals(other.groupingPath)) { + return false; + } + if (augmentations == null) { + if (other.augmentations != null) { + return false; + } + } else if (!augmentations.equals(other.augmentations)) { + return false; + } + if (augmenting != other.augmenting) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder( + UsesNodeImpl.class.getSimpleName()); + sb.append("[groupingPath=" + groupingPath +"]"); + return sb.toString(); + } + + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java new file mode 100644 index 0000000000..d86b49d78b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java @@ -0,0 +1,321 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.impl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ParseTreeWalker; +import org.opendaylight.controller.antlrv4.code.gen.YangLexer; +import org.opendaylight.controller.antlrv4.code.gen.YangParser; +import org.opendaylight.controller.model.util.UnknownType; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.ExtensionDefinition; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.NotificationDefinition; +import org.opendaylight.controller.yang.model.api.RpcDefinition; +import org.opendaylight.controller.yang.model.api.SchemaContext; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationTargetBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class YangModelParserImpl implements YangModelParser { + + private static final Logger logger = LoggerFactory + .getLogger(YangModelParserImpl.class); + + @Override + public Module parseYangModel(String yangFile) { + final Map> modules = loadFiles(yangFile); + Set result = build(modules); + return result.iterator().next(); + } + + @Override + public Set parseYangModels(String... yangFiles) { + final Map> modules = loadFiles(yangFiles); + Set result = build(modules); + return result; + } + + @Override + public SchemaContext resolveSchemaContext(Set modules) { + return new SchemaContextImpl(modules); + } + + private Set build(Map> modules) { + // first validate + for (Map.Entry> entry : modules.entrySet()) { + for (Map.Entry childEntry : entry.getValue().entrySet()) { + ModuleBuilder moduleBuilder = childEntry.getValue(); + validateBuilder(modules, moduleBuilder); + } + } + + // then build + final Set result = new HashSet(); + for (Map.Entry> entry : modules.entrySet()) { + final Map modulesByRevision = new HashMap(); + for (Map.Entry childEntry : entry.getValue().entrySet()) { + ModuleBuilder moduleBuilder = childEntry.getValue(); + modulesByRevision.put(childEntry.getKey(),moduleBuilder.build()); + result.add(moduleBuilder.build()); + } + } + + return result; + } + + private void validateBuilder(Map> modules, ModuleBuilder builder) { + resolveTypedefs(modules, builder); + resolveAugments(modules, builder); + } + + private void resolveTypedefs(Map> modules, ModuleBuilder builder) { + Map, TypeAwareBuilder> dirtyNodes = builder.getDirtyNodes(); + if (dirtyNodes.size() == 0) { + return; + } else { + for (Map.Entry, TypeAwareBuilder> entry : dirtyNodes.entrySet()) { + TypeAwareBuilder tab = entry.getValue(); + TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(modules,entry.getValue(), builder); + tab.setType(tdb.build()); + } + } + } + + private TypeDefinitionBuilder findTypeDefinitionBuilder(Map> modules, TypeAwareBuilder typeBuilder, ModuleBuilder builder) { + UnknownType type = (UnknownType) typeBuilder.getType(); + QName typeQName = type.getQName(); + String typeName = type.getQName().getLocalName(); + String prefix = typeQName.getPrefix(); + + ModuleBuilder dependentModuleBuilder; + if (prefix.equals(builder.getPrefix())) { + dependentModuleBuilder = builder; + } else { + ModuleImport dependentModuleImport = getDependentModuleImport(builder, prefix); + String dependentModuleName = dependentModuleImport.getModuleName(); + Date dependentModuleRevision = dependentModuleImport.getRevision(); + TreeMap moduleBuildersByRevision = modules.get(dependentModuleName); + if(dependentModuleRevision == null) { + dependentModuleBuilder = moduleBuildersByRevision.lastEntry().getValue(); + } else { + dependentModuleBuilder = moduleBuildersByRevision.get(dependentModuleRevision); + } + } + + final Set typedefs = dependentModuleBuilder.getModuleTypedefs(); + + TypeDefinitionBuilder lookedUpBuilder = null; + for (TypeDefinitionBuilder tdb : typedefs) { + QName qname = tdb.getQName(); + if (qname.getLocalName().equals(typeName)) { + lookedUpBuilder = tdb; + break; + } + } + + if (lookedUpBuilder.getBaseType() instanceof UnknownType) { + return findTypeDefinitionBuilder(modules, (TypeAwareBuilder) lookedUpBuilder, dependentModuleBuilder); + } else { + return lookedUpBuilder; + } + } + + private void resolveAugments(Map> modules, ModuleBuilder builder) { + Set augmentBuilders = builder.getAddedAugments(); + + Set augments = new HashSet(); + for (AugmentationSchemaBuilder augmentBuilder : augmentBuilders) { + SchemaPath augmentTargetSchemaPath = augmentBuilder.getTargetPath(); + String prefix = null; + List augmentTargetPath = new ArrayList(); + for (QName pathPart : augmentTargetSchemaPath.getPath()) { + prefix = pathPart.getPrefix(); + augmentTargetPath.add(pathPart.getLocalName()); + } + ModuleImport dependentModuleImport = getDependentModuleImport(builder, prefix); + String dependentModuleName = dependentModuleImport.getModuleName(); + augmentTargetPath.add(0, dependentModuleName); + + Date dependentModuleRevision = dependentModuleImport.getRevision(); + + TreeMap moduleBuildersByRevision = modules.get(dependentModuleName); + ModuleBuilder dependentModule; + if(dependentModuleRevision == null) { + dependentModule = moduleBuildersByRevision.lastEntry().getValue(); + } else { + dependentModule = moduleBuildersByRevision.get(dependentModuleRevision); + } + + AugmentationTargetBuilder augmentTarget = (AugmentationTargetBuilder) dependentModule.getNode(augmentTargetPath); + AugmentationSchema result = augmentBuilder.build(); + augmentTarget.addAugmentation(result); + fillAugmentTarget(augmentBuilder, (ChildNodeBuilder) augmentTarget); + augments.add(result); + } + builder.setAugmentations(augments); + } + + private void fillAugmentTarget(AugmentationSchemaBuilder augment, + ChildNodeBuilder target) { + for (DataSchemaNodeBuilder builder : augment.getChildNodes()) { + builder.setAugmenting(true); + target.addChildNode(builder); + } + } + + private Map> loadFiles(String... yangFiles) { + final Map> modules = new HashMap>(); + + final YangModelParserListenerImpl yangModelParser = new YangModelParserListenerImpl(); + final ParseTreeWalker walker = new ParseTreeWalker(); + + List trees = parseFiles(yangFiles); + + ModuleBuilder[] builders = new ModuleBuilder[trees.size()]; + + for (int i = 0; i < trees.size(); i++) { + walker.walk(yangModelParser, trees.get(i)); + builders[i] = yangModelParser.getModuleBuilder(); + } + + for (ModuleBuilder builder : builders) { + final String builderName = builder.getName(); + Date builderRevision = builder.getRevision(); + if(builderRevision == null) { + builderRevision = createEpochTime(); + } + + TreeMap builderByRevision = modules.get(builderName); + if (builderByRevision == null) { + builderByRevision = new TreeMap(); + } + builderByRevision.put(builderRevision, builder); + + modules.put(builderName, builderByRevision); + } + return modules; + } + + private List parseFiles(String... yangFileNames) { + List trees = new ArrayList(); + for (String fileName : yangFileNames) { + trees.add(parseFile(fileName)); + } + return trees; + } + + private ParseTree parseFile(String yangFileName) { + ParseTree result = null; + try { + final File yangFile = new File(yangFileName); + final FileInputStream inStream = new FileInputStream(yangFile); + final ANTLRInputStream input = new ANTLRInputStream(inStream); + final YangLexer lexer = new YangLexer(input); + final CommonTokenStream tokens = new CommonTokenStream(lexer); + final YangParser parser = new YangParser(tokens); + result = parser.yang(); + } catch (IOException e) { + logger.warn("Exception while reading yang file: " + yangFileName, e); + } + return result; + } + + private ModuleImport getDependentModuleImport(ModuleBuilder builder, String prefix) { + ModuleImport moduleImport = null; + for (ModuleImport mi : builder.getModuleImports()) { + if (mi.getPrefix().equals(prefix)) { + moduleImport = mi; + break; + } + } + return moduleImport; + } + + private Date createEpochTime() { + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(0); + return c.getTime(); + } + + private static class SchemaContextImpl implements SchemaContext { + private final Set modules; + + private SchemaContextImpl(Set modules) { + this.modules = modules; + } + + @Override + public Set getDataDefinitions() { + final Set dataDefs = new HashSet(); + for (Module m : modules) { + dataDefs.addAll(m.getChildNodes()); + } + return dataDefs; + } + + @Override + public Set getModules() { + return modules; + } + + @Override + public Set getNotifications() { + final Set notifications = new HashSet(); + for (Module m : modules) { + notifications.addAll(m.getNotifications()); + } + return notifications; + } + + @Override + public Set getOperations() { + final Set rpcs = new HashSet(); + for (Module m : modules) { + rpcs.addAll(m.getRpcs()); + } + return rpcs; + } + + @Override + public Set getExtensions() { + final Set extensions = new HashSet(); + for (Module m : modules) { + extensions.addAll(m.getExtensionSchemaNodes()); + } + return extensions; + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/impl/YangModelParserImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java similarity index 63% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/impl/YangModelParserImpl.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java index 7b121bdebc..510bec8cb2 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/impl/YangModelParserImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java @@ -1,703 +1,629 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.impl; - -import static org.opendaylight.controller.model.parser.util.YangModelBuilderHelper.*; - -import java.net.URI; -import java.net.URISyntaxException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Stack; - -import org.antlr.v4.runtime.tree.ParseTree; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_argContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Container_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_add_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_not_supported_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_replace_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Key_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_list_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.List_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_argContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Presence_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext; -import org.opendaylight.controller.model.api.type.EnumTypeDefinition; -import org.opendaylight.controller.model.api.type.LengthConstraint; -import org.opendaylight.controller.model.api.type.PatternConstraint; -import org.opendaylight.controller.model.api.type.RangeConstraint; -import org.opendaylight.controller.model.parser.api.AugmentationSchemaBuilder; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.builder.ContainerSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.DeviationBuilder; -import org.opendaylight.controller.model.parser.builder.FeatureBuilder; -import org.opendaylight.controller.model.parser.builder.LeafListSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.LeafSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.ListSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.ModuleBuilder; -import org.opendaylight.controller.model.parser.builder.MustDefinitionBuilder; -import org.opendaylight.controller.model.parser.builder.NotificationBuilder; -import org.opendaylight.controller.model.parser.builder.RpcDefinitionBuilder; -import org.opendaylight.controller.model.parser.builder.TypedefBuilder; -import org.opendaylight.controller.model.parser.util.YangModelBuilderHelper; -import org.opendaylight.controller.model.util.BitsType; -import org.opendaylight.controller.model.util.EnumerationType; -import org.opendaylight.controller.model.util.Leafref; -import org.opendaylight.controller.model.util.StringType; -import org.opendaylight.controller.model.util.YangTypesConverter; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class YangModelParserImpl extends YangParserBaseListener { - - private static final Logger logger = LoggerFactory - .getLogger(YangModelParserImpl.class); - - private ModuleBuilder moduleBuilder; - - private String moduleName; - private URI namespace; - private String yangModelPrefix; - private Date revision; - - private final DateFormat simpleDateFormat = new SimpleDateFormat( - "yyyy-mm-dd"); - private final Stack actualPath = new Stack(); - - @Override - public void enterModule_stmt(YangParser.Module_stmtContext ctx) { - moduleName = stringFromNode(ctx); - actualPath.push(moduleName); - moduleBuilder = new ModuleBuilder(moduleName); - } - - @Override - public void exitModule_stmt(YangParser.Module_stmtContext ctx) { - final String moduleName = actualPath.pop(); - logger.debug("Exiting module " + moduleName); - } - - @Override - public void enterModule_header_stmts(final Module_header_stmtsContext ctx) { - super.enterModule_header_stmts(ctx); - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Namespace_stmtContext) { - String namespaceStr = stringFromNode(treeNode); - try { - this.namespace = new URI(namespaceStr); - moduleBuilder.setNamespace(namespace); - } catch (URISyntaxException e) { - logger.warn("Failed to parse module namespace", e); - } - } else if (treeNode instanceof Prefix_stmtContext) { - yangModelPrefix = stringFromNode(treeNode); - moduleBuilder.setPrefix(yangModelPrefix); - } else if (treeNode instanceof Yang_version_stmtContext) { - final String yangVersion = stringFromNode(treeNode); - moduleBuilder.setYangVersion(yangVersion); - } - } - } - - // TODO: resolve submodule parsing - @Override - public void enterSubmodule_header_stmts( - YangParser.Submodule_header_stmtsContext ctx) { - String submoduleName = stringFromNode(ctx); - QName submoduleQName = new QName(namespace, revision, yangModelPrefix, - submoduleName); - moduleBuilder.addSubmodule(submoduleQName); - updatePath(submoduleName); - } - - @Override - public void exitSubmodule_header_stmts( - YangParser.Submodule_header_stmtsContext ctx) { - final String submodule = actualPath.pop(); - logger.debug("exiting submodule " + submodule); - } - - @Override - public void enterOrganization_stmt(YangParser.Organization_stmtContext ctx) { - final String organization = stringFromNode(ctx); - moduleBuilder.setOrganization(organization); - } - - @Override - public void enterContact_stmt(YangParser.Contact_stmtContext ctx) { - String contact = stringFromNode(ctx); - moduleBuilder.setContact(contact); - } - - @Override - public void enterRevision_stmts(Revision_stmtsContext ctx) { - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Revision_stmtContext) { - final String revisionDateStr = stringFromNode(treeNode); - try { - revision = simpleDateFormat.parse(revisionDateStr); - } catch (ParseException e) { - logger.warn("Failed to parse revision string: " - + revisionDateStr); - } - } - } - } - - @Override - public void enterDescription_stmt(YangParser.Description_stmtContext ctx) { - // if this is module description... - if (actualPath.size() == 1) { - moduleBuilder.setDescription(stringFromNode(ctx)); - } - } - - @Override - public void enterImport_stmt(Import_stmtContext ctx) { - super.enterImport_stmt(ctx); - - final String importName = stringFromNode(ctx); - String importPrefix = null; - Date importRevision = null; - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree treeNode = ctx.getChild(i); - if (treeNode instanceof Prefix_stmtContext) { - importPrefix = stringFromNode(treeNode); - } - if (treeNode instanceof Revision_date_stmtContext) { - String importRevisionStr = stringFromNode(treeNode); - try { - importRevision = simpleDateFormat.parse(importRevisionStr); - } catch (Exception e) { - logger.warn("Failed to parse import revision-date.", e); - } - } - } - moduleBuilder.addModuleImport(importName, importRevision, importPrefix); - } - - @Override - public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) { - final String augmentPath = stringFromNode(ctx); - AugmentationSchemaBuilder builder = moduleBuilder.addAugment( - augmentPath, actualPath); - updatePath(augmentPath); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Description_stmtContext) { - String desc = stringFromNode(child); - builder.setDescription(desc); - } else if (child instanceof Reference_stmtContext) { - String ref = stringFromNode(child); - builder.setReference(ref); - } else if (child instanceof Status_stmtContext) { - Status status = getStatus((Status_stmtContext) child); - builder.setStatus(status); - } - } - } - - @Override - public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) { - final String augment = actualPath.pop(); - logger.debug("exiting augment " + augment); - } - - @Override - public void enterMust_stmt(YangParser.Must_stmtContext ctx) { - String mustText = ""; - String description = null; - String reference = null; - for (int i = 0; i < ctx.getChildCount(); ++i) { - ParseTree child = ctx.getChild(i); - if (child instanceof StringContext) { - final StringContext context = (StringContext) child; - for (int j = 0; j < context.getChildCount(); j++) { - String mustPart = context.getChild(j).getText(); - if (j == 0) { - mustText += mustPart - .substring(0, mustPart.length() - 1); - continue; - } - if (j % 2 == 0) { - mustText += mustPart.substring(1); - } - } - } else if (child instanceof Description_stmtContext) { - description = stringFromNode(child); - } else if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } - } - MustDefinitionBuilder builder = moduleBuilder.addMustDefinition( - mustText, actualPath); - builder.setDescription(description); - builder.setReference(reference); - } - - @Override - public void enterTypedef_stmt(YangParser.Typedef_stmtContext ctx) { - String typedefName = stringFromNode(ctx); - QName typedefQName = new QName(namespace, revision, yangModelPrefix, - typedefName); - TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName, - actualPath); - updatePath(typedefName); - - builder.setPath(getActualSchemaPath(actualPath, namespace, revision, - yangModelPrefix)); - parseSchemaNodeArgs(ctx, builder); - } - - @Override - public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterType_stmt(YangParser.Type_stmtContext ctx) { - String typeName = stringFromNode(ctx); - QName typeQName; - if (typeName.contains(":")) { - String[] splittedName = typeName.split(":"); - // if this type contains prefix, it means that it point to type in - // external module - typeQName = new QName(null, null, splittedName[0], splittedName[1]); - } else { - typeQName = new QName(namespace, revision, yangModelPrefix, - typeName); - } - - TypeDefinition type = null; - - if (!YangTypesConverter.isBaseYangType(typeName)) { - if (typeName.equals("leafref")) { - // TODO: RevisionAwareXPath implementation - type = new Leafref(new RevisionAwareXPath() { - }); - } else { - type = parseUnknownType(typeQName, ctx); - // mark parent node of this type statement as dirty - moduleBuilder.addDirtyNode(actualPath); - } - } else { - - Type_body_stmtsContext typeBody = null; - for (int i = 0; i < ctx.getChildCount(); i++) { - if (ctx.getChild(i) instanceof Type_body_stmtsContext) { - typeBody = (Type_body_stmtsContext) ctx.getChild(i); - break; - } - } - - if (typeBody == null) { - // if there are no constraints, just grab default base yang type - type = YangTypesConverter.javaTypeForBaseYangType(typeName); - } else { - List rangeStatements = getRangeConstraints(typeBody); - Integer fractionDigits = getFractionDigits(typeBody); - List lengthStatements = getLengthConstraints(typeBody); - List patternStatements = getPatternConstraint(typeBody); - List enumConstants = YangModelBuilderHelper - .getEnumConstants(typeBody); - - if (typeName.equals("decimal64")) { - type = YangTypesConverter.javaTypeForBaseYangDecimal64Type( - rangeStatements, fractionDigits); - } else if (typeName.startsWith("int") - || typeName.startsWith("uint")) { - type = YangTypesConverter.javaTypeForBaseYangIntegerType( - typeName, rangeStatements); - } else if (typeName.equals("enumeration")) { - type = new EnumerationType(enumConstants); - } else if (typeName.equals("string")) { - type = new StringType(lengthStatements, patternStatements); - } else if (typeName.equals("bits")) { - type = new BitsType(getBits(typeBody, actualPath, - namespace, revision, yangModelPrefix)); - } else { - // TODO: implement binary + instance-identifier types - } - } - - } - - moduleBuilder.setType(type, actualPath); - updatePath(typeName); - } - - @Override - public void exitType_stmt(YangParser.Type_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterGrouping_stmt(YangParser.Grouping_stmtContext ctx) { - final String groupName = stringFromNode(ctx); - QName groupQName = new QName(namespace, revision, yangModelPrefix, - groupName); - GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName, - actualPath); - updatePath("grouping"); - updatePath(groupName); - parseSchemaNodeArgs(ctx, groupBuilder); - } - - @Override - public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) { - String actContainer = actualPath.pop(); - actContainer += "-" + actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterContainer_stmt(Container_stmtContext ctx) { - super.enterContainer_stmt(ctx); - String containerName = stringFromNode(ctx); - QName containerQName = new QName(namespace, revision, yangModelPrefix, - containerName); - ContainerSchemaNodeBuilder containerBuilder = moduleBuilder - .addContainerNode(containerQName, actualPath); - updatePath(containerName); - - containerBuilder.setPath(getActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, containerBuilder); - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree childNode = ctx.getChild(i); - if (childNode instanceof Presence_stmtContext) { - containerBuilder.setPresenceContainer(true); - } else if (childNode instanceof Config_stmtContext) { - for (int j = 0; j < childNode.getChildCount(); j++) { - ParseTree configArg = childNode.getChild(j); - if (configArg instanceof Config_argContext) { - String config = stringFromNode(configArg); - if (config.equals("true")) { - containerBuilder.setConfiguration(true); - } else { - containerBuilder.setConfiguration(false); - } - } - } - } - } - } - - @Override - public void exitContainer_stmt(Container_stmtContext ctx) { - super.exitContainer_stmt(ctx); - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - private boolean isLeafReadOnly(final ParseTree leaf) { - if (leaf != null) { - for (int i = 0; i < leaf.getChildCount(); ++i) { - final ParseTree configContext = leaf.getChild(i); - if (configContext instanceof Config_argContext) { - final String value = stringFromNode(configContext); - if (value.equals("true")) { - return true; - } - } - } - } - return false; - } - - @Override - public void enterLeaf_stmt(Leaf_stmtContext ctx) { - super.enterLeaf_stmt(ctx); - - final String leafName = stringFromNode(ctx); - QName leafQName = new QName(namespace, revision, yangModelPrefix, - leafName); - LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode( - leafQName, actualPath); - updatePath(leafName); - - leafBuilder.setPath(getActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, leafBuilder); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Config_stmtContext) { - leafBuilder.setConfiguration(isLeafReadOnly(child)); - } - } - } - - @Override - public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) { - final String actLeaf = actualPath.pop(); - logger.debug("exiting " + actLeaf); - } - - @Override - public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { - final String groupingPathStr = stringFromNode(ctx); - moduleBuilder.addUsesNode(groupingPathStr, actualPath); - updatePath(groupingPathStr); - } - - @Override - public void exitUses_stmt(YangParser.Uses_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { - super.enterLeaf_list_stmt(ctx); - - final String leafListName = stringFromNode(ctx); - QName leafListQName = new QName(namespace, revision, yangModelPrefix, - leafListName); - LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder - .addLeafListNode(leafListQName, actualPath); - updatePath(leafListName); - - parseSchemaNodeArgs(ctx, leafListBuilder); - - for (int i = 0; i < ctx.getChildCount(); ++i) { - final ParseTree childNode = ctx.getChild(i); - if (childNode instanceof Config_stmtContext) { - leafListBuilder.setConfiguration(isLeafReadOnly(childNode)); - } else if (childNode instanceof Ordered_by_stmtContext) { - final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; - final boolean userOrdered = parseUserOrdered(orderedBy); - leafListBuilder.setUserOrdered(userOrdered); - } - } - } - - @Override - public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterList_stmt(List_stmtContext ctx) { - super.enterList_stmt(ctx); - - final String containerName = stringFromNode(ctx); - QName containerQName = new QName(namespace, revision, yangModelPrefix, - containerName); - ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode( - containerQName, actualPath); - updatePath(containerName); - - listBuilder.setPath(getActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, listBuilder); - - String keyDefinition = ""; - for (int i = 0; i < ctx.getChildCount(); ++i) { - ParseTree childNode = ctx.getChild(i); - - if (childNode instanceof Ordered_by_stmtContext) { - final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; - final boolean userOrdered = parseUserOrdered(orderedBy); - listBuilder.setUserOrdered(userOrdered); - } else if (childNode instanceof Key_stmtContext) { - List key = createListKey(keyDefinition, namespace, - revision, keyDefinition); - listBuilder.setKeyDefinition(key); - } - } - } - - @Override - public void exitList_stmt(List_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterNotification_stmt(YangParser.Notification_stmtContext ctx) { - final String notificationName = stringFromNode(ctx); - QName notificationQName = new QName(namespace, revision, - yangModelPrefix, notificationName); - NotificationBuilder notificationBuilder = moduleBuilder - .addNotification(notificationQName, actualPath); - updatePath(notificationName); - - notificationBuilder.setPath(getActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, notificationBuilder); - } - - @Override - public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterRpc_stmt(YangParser.Rpc_stmtContext ctx) { - final String rpcName = stringFromNode(ctx); - QName rpcQName = new QName(namespace, revision, yangModelPrefix, - rpcName); - RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, - actualPath); - updatePath(rpcName); - - rpcBuilder.setPath(getActualSchemaPath(actualPath, namespace, revision, - yangModelPrefix)); - parseSchemaNodeArgs(ctx, rpcBuilder); - } - - @Override - public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterInput_stmt(YangParser.Input_stmtContext ctx) { - updatePath("input"); - } - - @Override - public void exitInput_stmt(YangParser.Input_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterOutput_stmt(YangParser.Output_stmtContext ctx) { - updatePath("output"); - } - - @Override - public void exitOutput_stmt(YangParser.Output_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterFeature_stmt(YangParser.Feature_stmtContext ctx) { - final String featureName = stringFromNode(ctx); - QName featureQName = new QName(namespace, revision, yangModelPrefix, - featureName); - FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, - actualPath); - updatePath(featureName); - - featureBuilder.setPath(getActualSchemaPath(actualPath, namespace, - revision, yangModelPrefix)); - parseSchemaNodeArgs(ctx, featureBuilder); - } - - @Override - public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - @Override - public void enterDeviation_stmt(YangParser.Deviation_stmtContext ctx) { - final String targetPath = stringFromNode(ctx); - String reference = null; - String deviate = null; - DeviationBuilder builder = moduleBuilder.addDeviation(targetPath); - updatePath(targetPath); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Reference_stmtContext) { - reference = stringFromNode(child); - } else if (child instanceof Deviate_not_supported_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_add_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_replace_stmtContext) { - deviate = stringFromNode(child); - } else if (child instanceof Deviate_delete_stmtContext) { - deviate = stringFromNode(child); - } - } - builder.setReference(reference); - builder.setDeviate(deviate); - } - - @Override - public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) { - final String actContainer = actualPath.pop(); - logger.debug("exiting " + actContainer); - } - - public ModuleBuilder getModuleBuilder() { - return moduleBuilder; - } - - private void updatePath(String containerName) { - actualPath.push(containerName); - } - - /** - * Parse ordered-by statement. - * - * @param childNode - * Ordered_by_stmtContext - * @return true, if ordered-by contains value 'user' or false otherwise - */ - private boolean parseUserOrdered(Ordered_by_stmtContext childNode) { - boolean result = false; - for (int j = 0; j < childNode.getChildCount(); j++) { - ParseTree orderArg = childNode.getChild(j); - if (orderArg instanceof Ordered_by_argContext) { - String orderStr = stringFromNode(orderArg); - if (orderStr.equals("system")) { - result = false; - } else if (orderStr.equals("user")) { - result = true; - } else { - logger.warn("Invalid 'ordered-by' statement."); - } - } - } - return result; - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.impl; + +import static org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil.*; + +import java.net.URI; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Stack; + +import org.antlr.v4.runtime.tree.ParseTree; +import org.opendaylight.controller.antlrv4.code.gen.YangParser; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Container_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_add_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_not_supported_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Deviate_replace_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Key_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_list_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leaf_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.List_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Organization_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Presence_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener; +import org.opendaylight.controller.model.util.YangTypesConverter; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ContainerSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.DeviationBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ExtensionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.FeatureBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.LeafSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.NotificationBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.RpcDefinitionBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class YangModelParserListenerImpl extends YangParserBaseListener { + + private static final Logger logger = LoggerFactory + .getLogger(YangModelParserListenerImpl.class); + + private ModuleBuilder moduleBuilder; + + private String moduleName; + private URI namespace; + private String yangModelPrefix; + private Date revision; + + private final DateFormat simpleDateFormat = new SimpleDateFormat( + "yyyy-mm-dd"); + private final Stack actualPath = new Stack(); + + + @Override + public void enterModule_stmt(YangParser.Module_stmtContext ctx) { + moduleName = stringFromNode(ctx); + actualPath.push(moduleName); + moduleBuilder = new ModuleBuilder(moduleName); + + String description = null; + String reference = null; + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else { + if (description != null && reference != null) { + break; + } + } + } + moduleBuilder.setDescription(description); + moduleBuilder.setReference(reference); + } + + @Override + public void exitModule_stmt(YangParser.Module_stmtContext ctx) { + final String moduleName = actualPath.pop(); + logger.debug("Exiting module " + moduleName); + } + + @Override + public void enterModule_header_stmts(final Module_header_stmtsContext ctx) { + super.enterModule_header_stmts(ctx); + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Namespace_stmtContext) { + final String namespaceStr = stringFromNode(treeNode); + namespace = URI.create(namespaceStr); + moduleBuilder.setNamespace(namespace); + } else if (treeNode instanceof Prefix_stmtContext) { + yangModelPrefix = stringFromNode(treeNode); + moduleBuilder.setPrefix(yangModelPrefix); + } else if (treeNode instanceof Yang_version_stmtContext) { + final String yangVersion = stringFromNode(treeNode); + moduleBuilder.setYangVersion(yangVersion); + } + } + } + + @Override + public void enterMeta_stmts(YangParser.Meta_stmtsContext ctx) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Organization_stmtContext) { + final String organization = stringFromNode(child); + moduleBuilder.setOrganization(organization); + } else if (child instanceof Contact_stmtContext) { + final String contact = stringFromNode(child); + moduleBuilder.setContact(contact); + } else if (child instanceof Description_stmtContext) { + final String description = stringFromNode(child); + moduleBuilder.setDescription(description); + } else if (child instanceof Reference_stmtContext) { + final String reference = stringFromNode(child); + moduleBuilder.setReference(reference); + } + } + } + + @Override + public void exitSubmodule_header_stmts( + YangParser.Submodule_header_stmtsContext ctx) { + final String submodule = actualPath.pop(); + logger.debug("exiting submodule " + submodule); + } + + @Override + public void enterRevision_stmts(Revision_stmtsContext ctx) { + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Revision_stmtContext) { + final String revisionDateStr = stringFromNode(treeNode); + try { + revision = simpleDateFormat.parse(revisionDateStr); + moduleBuilder.setRevision(revision); + } catch (ParseException e) { + final String message = "Failed to parse revision string: "+ revisionDateStr; + logger.warn(message); + } + } + } + } + + @Override + public void enterImport_stmt(Import_stmtContext ctx) { + super.enterImport_stmt(ctx); + + final String importName = stringFromNode(ctx); + String importPrefix = null; + Date importRevision = null; + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree treeNode = ctx.getChild(i); + if (treeNode instanceof Prefix_stmtContext) { + importPrefix = stringFromNode(treeNode); + } + if (treeNode instanceof Revision_date_stmtContext) { + String importRevisionStr = stringFromNode(treeNode); + try { + importRevision = simpleDateFormat.parse(importRevisionStr); + } catch(ParseException e) { + logger.warn("Failed to parse import revision-date: "+ importRevisionStr); + } + } + } + moduleBuilder.addModuleImport(importName, importRevision, importPrefix); + } + + @Override + public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) { + final String augmentPath = stringFromNode(ctx); + AugmentationSchemaBuilder builder = moduleBuilder.addAugment( + augmentPath, getActualPath()); + updatePath(augmentPath); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + String desc = stringFromNode(child); + builder.setDescription(desc); + } else if (child instanceof Reference_stmtContext) { + String ref = stringFromNode(child); + builder.setReference(ref); + } else if (child instanceof Status_stmtContext) { + Status status = parseStatus((Status_stmtContext) child); + builder.setStatus(status); + } + } + } + + @Override + public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) { + final String augment = actualPath.pop(); + logger.debug("exiting augment " + augment); + } + + @Override + public void enterExtension_stmt(YangParser.Extension_stmtContext ctx) { + String argument = stringFromNode(ctx); + QName qname = new QName(namespace, revision, yangModelPrefix, argument); + ExtensionBuilder builder = moduleBuilder.addExtension(qname); + parseSchemaNodeArgs(ctx, builder); + } + + @Override + public void enterTypedef_stmt(YangParser.Typedef_stmtContext ctx) { + String typedefName = stringFromNode(ctx); + QName typedefQName = new QName(namespace, revision, yangModelPrefix, + typedefName); + TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName, + getActualPath()); + updatePath(typedefName); + + builder.setPath(createActualSchemaPath(actualPath, namespace, revision, + yangModelPrefix)); + parseSchemaNodeArgs(ctx, builder); + builder.setUnits(parseUnits(ctx)); + } + + @Override + public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterType_stmt(YangParser.Type_stmtContext ctx) { + String typeName = stringFromNode(ctx); + QName typeQName; + if (typeName.contains(":")) { + String[] splittedName = typeName.split(":"); + String prefix = splittedName[0]; + String name = splittedName[1]; + if (prefix.equals(yangModelPrefix)) { + typeQName = new QName(namespace, revision, prefix, name); + } else { + typeQName = new QName(null, null, prefix, name); + } + } else { + typeQName = new QName(namespace, revision, yangModelPrefix, + typeName); + } + + TypeDefinition type = null; + Type_body_stmtsContext typeBody = null; + for (int i = 0; i < ctx.getChildCount(); i++) { + if (ctx.getChild(i) instanceof Type_body_stmtsContext) { + typeBody = (Type_body_stmtsContext) ctx.getChild(i); + break; + } + } + + // if this is base yang type... + if(YangTypesConverter.isBaseYangType(typeName)) { + if (typeBody == null) { + // if there are no constraints, just grab default base yang type + type = YangTypesConverter.javaTypeForBaseYangType(typeName); + } else { + type = parseTypeBody(typeName, typeBody, actualPath, namespace, revision, yangModelPrefix); + } + } else { + type = parseUnknownTypeBody(typeQName, typeBody); + // mark parent node of this type statement as dirty + moduleBuilder.addDirtyNode(actualPath); + } + + moduleBuilder.setType(type, actualPath); + updatePath(typeName); + } + + @Override + public void exitType_stmt(YangParser.Type_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterGrouping_stmt(YangParser.Grouping_stmtContext ctx) { + final String groupName = stringFromNode(ctx); + QName groupQName = new QName(namespace, revision, yangModelPrefix, + groupName); + GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName, + actualPath); + updatePath("grouping"); + updatePath(groupName); + parseSchemaNodeArgs(ctx, groupBuilder); + } + + @Override + public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) { + String actContainer = actualPath.pop(); + actContainer += "-" + actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterContainer_stmt(Container_stmtContext ctx) { + super.enterContainer_stmt(ctx); + String containerName = stringFromNode(ctx); + QName containerQName = new QName(namespace, revision, yangModelPrefix, + containerName); + ContainerSchemaNodeBuilder containerBuilder = moduleBuilder + .addContainerNode(containerQName, actualPath); + updatePath(containerName); + + containerBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, containerBuilder); + parseConstraints(ctx, containerBuilder.getConstraintsBuilder()); + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Presence_stmtContext) { + containerBuilder.setPresenceContainer(true); + break; + } + } + } + + @Override + public void exitContainer_stmt(Container_stmtContext ctx) { + super.exitContainer_stmt(ctx); + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterLeaf_stmt(Leaf_stmtContext ctx) { + super.enterLeaf_stmt(ctx); + + final String leafName = stringFromNode(ctx); + QName leafQName = new QName(namespace, revision, yangModelPrefix, + leafName); + LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode( + leafQName, actualPath); + updatePath(leafName); + + leafBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, leafBuilder); + parseConstraints(ctx, leafBuilder.getConstraintsBuilder()); + } + + @Override + public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) { + final String actLeaf = actualPath.pop(); + logger.debug("exiting " + actLeaf); + } + + @Override + public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { + final String groupingPathStr = stringFromNode(ctx); + moduleBuilder.addUsesNode(groupingPathStr, actualPath); + updatePath(groupingPathStr); + } + + @Override + public void exitUses_stmt(YangParser.Uses_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { + super.enterLeaf_list_stmt(ctx); + + final String leafListName = stringFromNode(ctx); + QName leafListQName = new QName(namespace, revision, yangModelPrefix, + leafListName); + LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder + .addLeafListNode(leafListQName, actualPath); + updatePath(leafListName); + + parseSchemaNodeArgs(ctx, leafListBuilder); + parseConstraints(ctx, leafListBuilder.getConstraintsBuilder()); + + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Ordered_by_stmtContext) { + final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; + final boolean userOrdered = parseUserOrdered(orderedBy); + leafListBuilder.setUserOrdered(userOrdered); + break; + } + } + } + + @Override + public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterList_stmt(List_stmtContext ctx) { + super.enterList_stmt(ctx); + + final String containerName = stringFromNode(ctx); + QName containerQName = new QName(namespace, revision, yangModelPrefix, + containerName); + ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode( + containerQName, actualPath); + updatePath(containerName); + + listBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, listBuilder); + parseConstraints(ctx, listBuilder.getConstraintsBuilder()); + + String keyDefinition = ""; + for (int i = 0; i < ctx.getChildCount(); ++i) { + ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Ordered_by_stmtContext) { + final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode; + final boolean userOrdered = parseUserOrdered(orderedBy); + listBuilder.setUserOrdered(userOrdered); + } else if (childNode instanceof Key_stmtContext) { + keyDefinition = stringFromNode(childNode); + List key = createListKey(keyDefinition, namespace, + revision, yangModelPrefix); + listBuilder.setKeyDefinition(key); + } + } + } + + @Override + public void exitList_stmt(List_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterNotification_stmt(YangParser.Notification_stmtContext ctx) { + final String notificationName = stringFromNode(ctx); + QName notificationQName = new QName(namespace, revision, + yangModelPrefix, notificationName); + NotificationBuilder notificationBuilder = moduleBuilder + .addNotification(notificationQName, actualPath); + updatePath(notificationName); + + notificationBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, notificationBuilder); + } + + @Override + public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + // Unknown types + @Override + public void enterIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { + String name = stringFromNode(ctx); + + QName qname; + if(name != null) { + String[] splittedName = name.split(":"); + if(splittedName.length == 2) { + qname = new QName(null, null, splittedName[0], splittedName[1]); + } else { + qname = new QName(namespace, revision, yangModelPrefix, splittedName[0]); + } + } else { + qname = new QName(namespace, revision, yangModelPrefix, name); + } + + UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(qname, getActualPath()); + updatePath(name); + + builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, builder); + } + + @Override + public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterRpc_stmt(YangParser.Rpc_stmtContext ctx) { + final String rpcName = stringFromNode(ctx); + QName rpcQName = new QName(namespace, revision, yangModelPrefix, + rpcName); + RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, + actualPath); + updatePath(rpcName); + + rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, + yangModelPrefix)); + parseSchemaNodeArgs(ctx, rpcBuilder); + } + + @Override + public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterInput_stmt(YangParser.Input_stmtContext ctx) { + updatePath("input"); + } + + @Override + public void exitInput_stmt(YangParser.Input_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterOutput_stmt(YangParser.Output_stmtContext ctx) { + updatePath("output"); + } + + @Override + public void exitOutput_stmt(YangParser.Output_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterFeature_stmt(YangParser.Feature_stmtContext ctx) { + final String featureName = stringFromNode(ctx); + QName featureQName = new QName(namespace, revision, yangModelPrefix, + featureName); + FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, + actualPath); + updatePath(featureName); + + featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, + revision, yangModelPrefix)); + parseSchemaNodeArgs(ctx, featureBuilder); + } + + @Override + public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterDeviation_stmt(YangParser.Deviation_stmtContext ctx) { + final String targetPath = stringFromNode(ctx); + String reference = null; + String deviate = null; + DeviationBuilder builder = moduleBuilder.addDeviation(targetPath); + updatePath(targetPath); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else if (child instanceof Deviate_not_supported_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_add_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_replace_stmtContext) { + deviate = stringFromNode(child); + } else if (child instanceof Deviate_delete_stmtContext) { + deviate = stringFromNode(child); + } + } + builder.setReference(reference); + builder.setDeviate(deviate); + } + + @Override + public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + + @Override + public void enterConfig_stmt(YangParser.Config_stmtContext ctx) { + boolean configuration = parseConfig(ctx); + moduleBuilder.addConfiguration(configuration, actualPath); + } + + public ModuleBuilder getModuleBuilder() { + return moduleBuilder; + } + + private void updatePath(String containerName) { + actualPath.push(containerName); + } + + private List getActualPath() { + return Collections.unmodifiableList(actualPath); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java new file mode 100644 index 0000000000..022798e0d9 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java @@ -0,0 +1,1094 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/eplv10.html + */ +package org.opendaylight.controller.yang.model.parser.util; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Stack; + +import org.antlr.v4.runtime.tree.ParseTree; +import org.opendaylight.controller.antlrv4.code.gen.YangParser; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bits_specificationContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_argContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Config_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Decimal64_specificationContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Description_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_specificationContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Enum_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Fraction_digits_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Leafref_specificationContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Length_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Mandatory_argContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Mandatory_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Max_elements_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Min_elements_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Must_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Numerical_restrictionsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_argContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Ordered_by_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Path_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Pattern_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Position_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Range_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Reference_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Require_instance_argContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Require_instance_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_argContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Status_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext; +import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext; +import org.opendaylight.controller.model.api.type.BitsTypeDefinition; +import org.opendaylight.controller.model.api.type.BitsTypeDefinition.Bit; +import org.opendaylight.controller.model.api.type.EnumTypeDefinition; +import org.opendaylight.controller.model.api.type.LengthConstraint; +import org.opendaylight.controller.model.api.type.PatternConstraint; +import org.opendaylight.controller.model.api.type.RangeConstraint; +import org.opendaylight.controller.model.util.BaseConstraints; +import org.opendaylight.controller.model.util.BinaryType; +import org.opendaylight.controller.model.util.BitsType; +import org.opendaylight.controller.model.util.EnumerationType; +import org.opendaylight.controller.model.util.InstanceIdentifier; +import org.opendaylight.controller.model.util.Leafref; +import org.opendaylight.controller.model.util.RevisionAwareXPathImpl; +import org.opendaylight.controller.model.util.StringType; +import org.opendaylight.controller.model.util.UnknownType; +import org.opendaylight.controller.model.util.YangTypesConverter; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class YangModelBuilderUtil { + + private static final Logger logger = LoggerFactory + .getLogger(YangModelBuilderUtil.class); + + /** + * Parse given tree and get first string value. + * + * @param treeNode + * tree to parse + * @return first string value from given tree + */ + public static String stringFromNode(final ParseTree treeNode) { + final String result = ""; + for (int i = 0; i < treeNode.getChildCount(); ++i) { + if (treeNode.getChild(i) instanceof StringContext) { + final StringContext context = (StringContext) treeNode + .getChild(i); + if (context != null) { + return context.getChild(0).getText().replace("\"", ""); + } + } + } + return result; + } + + /** + * Parse 'description', 'reference' and 'status' statements and fill in + * given builder. + * + * @param ctx + * context to parse + * @param builder + * builder to fill in with parsed statements + */ + public static void parseSchemaNodeArgs(ParseTree ctx, + SchemaNodeBuilder builder) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + String desc = stringFromNode(child); + builder.setDescription(desc); + } else if (child instanceof Reference_stmtContext) { + String ref = stringFromNode(child); + builder.setReference(ref); + } else if (child instanceof Status_stmtContext) { + Status status = parseStatus((Status_stmtContext) child); + builder.setStatus(status); + } + } + } + + /** + * Parse given context and return its value; + * + * @param ctx + * status context + * @return value parsed from context + */ + public static Status parseStatus(Status_stmtContext ctx) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree statusArg = ctx.getChild(i); + if (statusArg instanceof Status_argContext) { + String statusArgStr = stringFromNode(statusArg); + if (statusArgStr.equals("current")) { + return Status.CURRENT; + } else if (statusArgStr.equals("deprecated")) { + return Status.DEPRECATED; + } else if (statusArgStr.equals("obsolete")) { + return Status.OBSOLETE; + } else { + logger.warn("Invalid 'status' statement: " + statusArgStr); + } + } + } + return null; + } + + /** + * Parse given tree and returns units statement as string. + * + * @param ctx + * context to parse + * @return value of units statement as string or null if there is no units + * statement + */ + public static String parseUnits(ParseTree ctx) { + String units = null; + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Units_stmtContext) { + units = stringFromNode(child); + break; + } + } + return units; + } + + /** + * Create SchemaPath object from given path list with namespace, revision + * and prefix based on given values. + * + * @param actualPath + * @param namespace + * @param revision + * @param prefix + * @return SchemaPath object. + */ + public static SchemaPath createActualSchemaPath(List actualPath, + URI namespace, Date revision, String prefix) { + final List path = new ArrayList(); + QName qname; + for (String pathElement : actualPath) { + qname = new QName(namespace, revision, prefix, pathElement); + path.add(qname); + } + return new SchemaPath(path, true); + } + + /** + * Create SchemaPath from given string. + * + * @param augmentPath + * string representation of path + * @return SchemaPath object + */ + public static SchemaPath parseAugmentPath(String augmentPath) { + boolean absolute = augmentPath.startsWith("/"); + String[] splittedPath = augmentPath.split("/"); + List path = new ArrayList(); + QName name; + for (String pathElement : splittedPath) { + if (pathElement.length() > 0) { + String[] splittedElement = pathElement.split(":"); + if (splittedElement.length == 1) { + name = new QName(null, null, null, splittedElement[0]); + } else { + name = new QName(null, null, splittedElement[0], + splittedElement[1]); + } + path.add(name); + } + } + return new SchemaPath(path, absolute); + } + + /** + * Create java.util.List of QName objects from given key definition as + * string. + * + * @param keyDefinition + * key definition as string + * @param namespace + * current namespace + * @param revision + * current revision + * @param prefix + * current prefix + * @return YANG list key as java.util.List of QName objects + */ + public static List createListKey(String keyDefinition, + URI namespace, Date revision, String prefix) { + List key = new ArrayList(); + String[] splittedKey = keyDefinition.split(" "); + + QName qname = null; + for (String keyElement : splittedKey) { + if (keyElement.length() != 0) { + qname = new QName(namespace, revision, prefix, keyElement); + key.add(qname); + } + } + return key; + } + + private static List getEnumConstants( + Type_body_stmtsContext ctx, List path, URI namespace, + Date revision, String prefix) { + List enumConstants = new ArrayList(); + + out: for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree enumSpecChild = ctx.getChild(j); + if (enumSpecChild instanceof Enum_specificationContext) { + for (int k = 0; k < enumSpecChild.getChildCount(); k++) { + ParseTree enumChild = enumSpecChild.getChild(k); + if (enumChild instanceof Enum_stmtContext) { + enumConstants.add(createEnumPair( + (Enum_stmtContext) enumChild, k, path, + namespace, revision, prefix)); + if (k == enumSpecChild.getChildCount() - 1) { + break out; + } + } + } + } + } + return enumConstants; + } + + private static EnumTypeDefinition.EnumPair createEnumPair( + Enum_stmtContext ctx, final int value, List path, + final URI namespace, final Date revision, final String prefix) { + final String name = stringFromNode(ctx); + final QName qname = new QName(namespace, revision, prefix, name); + String description = null; + String reference = null; + Status status = null; + List enumPairPath = new ArrayList(path); + enumPairPath.add(name); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else if (child instanceof Status_stmtContext) { + status = parseStatus((Status_stmtContext) child); + } + } + + EnumPairImpl result = new EnumPairImpl(); + result.qname = qname; + result.path = createActualSchemaPath(enumPairPath, namespace, revision, + prefix); + result.description = description; + result.reference = reference; + result.status = status; + // TODO: extensionSchemaNodes + result.name = name; + result.value = value; + return result; + } + + private static class EnumPairImpl implements EnumTypeDefinition.EnumPair { + + private QName qname; + private SchemaPath path; + private String description; + private String reference; + private Status status; + private List extensionSchemaNodes = Collections + .emptyList(); + private String name; + private Integer value; + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return path; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Status getStatus() { + return status; + } + + @Override + public List getUnknownSchemaNodes() { + return extensionSchemaNodes; + } + + @Override + public String getName() { + return name; + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime + * result + + ((extensionSchemaNodes == null) ? 0 + : extensionSchemaNodes.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnumPairImpl other = (EnumPairImpl) obj; + if (qname == null) { + if (other.qname != null) { + return false; + } + } else if (!qname.equals(other.qname)) { + return false; + } + if (path == null) { + if (other.path != null) { + return false; + } + } else if (!path.equals(other.path)) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (reference == null) { + if (other.reference != null) { + return false; + } + } else if (!reference.equals(other.reference)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + if (extensionSchemaNodes == null) { + if (other.extensionSchemaNodes != null) { + return false; + } + } else if (!extensionSchemaNodes.equals(other.extensionSchemaNodes)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + + @Override + public String toString() { + return EnumTypeDefinition.EnumPair.class.getSimpleName() + "[name=" + + name + ", value=" + value + "]"; + } + }; + + private static List getRangeConstraints( + Type_body_stmtsContext ctx) { + final List rangeConstraints = new ArrayList(); + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree numRestrChild = ctx.getChild(j); + if (numRestrChild instanceof Numerical_restrictionsContext) { + for (int k = 0; k < numRestrChild.getChildCount(); k++) { + ParseTree rangeChild = numRestrChild.getChild(k); + if (rangeChild instanceof Range_stmtContext) { + rangeConstraints + .addAll(parseRangeConstraints((Range_stmtContext) rangeChild)); + break; + } + } + } + } + return rangeConstraints; + } + + private static List parseRangeConstraints( + Range_stmtContext ctx) { + List rangeConstraints = new ArrayList(); + String description = null; + String reference = null; + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } + } + + String rangeStr = stringFromNode(ctx); + String trimmed = rangeStr.replace(" ", ""); + String[] splittedRange = trimmed.split("\\|"); + for (String rangeDef : splittedRange) { + String[] splittedRangeDef = rangeDef.split("\\.\\."); + Long min; + Long max; + if (splittedRangeDef.length == 1) { + min = max = parseRangeValue(splittedRangeDef[0]); + } else { + min = parseRangeValue(splittedRangeDef[0]); + max = parseRangeValue(splittedRangeDef[1]); + } + RangeConstraint range = BaseConstraints.rangeConstraint(min, max, + description, reference); + rangeConstraints.add(range); + } + + return rangeConstraints; + } + + private static List getLengthConstraints( + Type_body_stmtsContext ctx) { + List lengthConstraints = new ArrayList(); + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree stringRestrChild = ctx.getChild(j); + if (stringRestrChild instanceof String_restrictionsContext) { + for (int k = 0; k < stringRestrChild.getChildCount(); k++) { + ParseTree lengthChild = stringRestrChild.getChild(k); + if (lengthChild instanceof Length_stmtContext) { + lengthConstraints + .addAll(parseLengthConstraints((Length_stmtContext) lengthChild)); + } + } + } + } + return lengthConstraints; + } + + private static List parseLengthConstraints( + Length_stmtContext ctx) { + List lengthConstraints = new ArrayList(); + String description = null; + String reference = null; + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } + } + + String lengthStr = stringFromNode(ctx); + String trimmed = lengthStr.replace(" ", ""); + String[] splittedRange = trimmed.split("\\|"); + for (String rangeDef : splittedRange) { + String[] splittedRangeDef = rangeDef.split("\\.\\."); + Long min; + Long max; + if (splittedRangeDef.length == 1) { + min = max = parseRangeValue(splittedRangeDef[0]); + } else { + min = parseRangeValue(splittedRangeDef[0]); + max = parseRangeValue(splittedRangeDef[1]); + } + LengthConstraint range = BaseConstraints.lengthConstraint(min, max, + description, reference); + lengthConstraints.add(range); + } + + return lengthConstraints; + } + + private static Long parseRangeValue(String value) { + Long result = null; + if (value.equals("min")) { + result = Long.MIN_VALUE; + } else if (value.equals("max")) { + result = Long.MAX_VALUE; + } else { + result = Long.valueOf(value); + } + return result; + } + + private static List getPatternConstraint( + Type_body_stmtsContext ctx) { + List patterns = new ArrayList(); + + out: for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree stringRestrChild = ctx.getChild(j); + if (stringRestrChild instanceof String_restrictionsContext) { + for (int k = 0; k < stringRestrChild.getChildCount(); k++) { + ParseTree lengthChild = stringRestrChild.getChild(k); + if (lengthChild instanceof Pattern_stmtContext) { + patterns.add(parsePatternConstraint((Pattern_stmtContext) lengthChild)); + if (k == lengthChild.getChildCount() - 1) { + break out; + } + } + } + } + } + return patterns; + } + + /** + * Internal helper method. + * + * @param ctx + * pattern context + * @return PatternConstraint object + */ + private static PatternConstraint parsePatternConstraint( + Pattern_stmtContext ctx) { + String description = null; + String reference = null; + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } + } + String pattern = stringFromNode(ctx); + return BaseConstraints.patternConstraint(pattern, description, + reference); + } + + private static Integer getFractionDigits(Type_body_stmtsContext ctx) { + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree dec64specChild = ctx.getChild(j); + if (dec64specChild instanceof Decimal64_specificationContext) { + return parseFractionDigits((Decimal64_specificationContext) dec64specChild); + } + } + return null; + } + + private static Integer parseFractionDigits( + Decimal64_specificationContext ctx) { + for (int k = 0; k < ctx.getChildCount(); k++) { + ParseTree fdChild = ctx.getChild(k); + if (fdChild instanceof Fraction_digits_stmtContext) { + return Integer.valueOf(stringFromNode(fdChild)); + } + } + return null; + } + + private static List getBits( + Type_body_stmtsContext ctx, List actualPath, URI namespace, + Date revision, String prefix) { + List bits = new ArrayList(); + for (int j = 0; j < ctx.getChildCount(); j++) { + ParseTree bitsSpecChild = ctx.getChild(j); + if (bitsSpecChild instanceof Bits_specificationContext) { + for (int k = 0; k < bitsSpecChild.getChildCount(); k++) { + ParseTree bitChild = bitsSpecChild.getChild(k); + if (bitChild instanceof Bit_stmtContext) { + bits.add(parseBit((Bit_stmtContext) bitChild, + actualPath, namespace, revision, prefix)); + } + } + } + } + return bits; + } + + private static boolean isRequireInstance(Type_body_stmtsContext ctx) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Require_instance_stmtContext) { + for (int j = 0; j < child.getChildCount(); j++) { + ParseTree reqArg = child.getChild(j); + if (reqArg instanceof Require_instance_argContext) { + return Boolean.valueOf(stringFromNode(reqArg)); + } + } + } + } + return false; + } + + private static BitsTypeDefinition.Bit parseBit(final Bit_stmtContext ctx, + List actualPath, final URI namespace, final Date revision, + final String prefix) { + String name = stringFromNode(ctx); + final QName qname = new QName(namespace, revision, prefix, name); + Long position = null; + + String description = null; + String reference = null; + Status status = Status.CURRENT; + + Stack bitPath = new Stack(); + bitPath.addAll(actualPath); + bitPath.add(name); + + SchemaPath schemaPath = createActualSchemaPath(bitPath, namespace, + revision, prefix); + + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Position_stmtContext) { + String positionStr = stringFromNode(child); + position = Long.valueOf(positionStr); + if (position < 0 || position > 4294967295L) { + throw new IllegalArgumentException( + "position value MUST be in the range 0 to 4294967295, but was: " + + position); + } + } else if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } else if (child instanceof Status_stmtContext) { + status = parseStatus((Status_stmtContext) child); + } + } + + // TODO: extensionDefinitions + return createBit(qname, schemaPath, description, reference, status, + null, position); + } + + private static BitsTypeDefinition.Bit createBit(final QName qname, + final SchemaPath schemaPath, final String description, + final String reference, final Status status, + final List extensionDefinitions, + final Long position) { + return new BitsTypeDefinition.Bit() { + + @Override + public QName getQName() { + return qname; + } + + @Override + public SchemaPath getPath() { + return schemaPath; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Status getStatus() { + return status; + } + + @Override + public List getUnknownSchemaNodes() { + return extensionDefinitions; + } + + @Override + public Long getPosition() { + return position; + } + + @Override + public String getName() { + return qname.getLocalName(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((qname == null) ? 0 : qname.hashCode()); + result = prime * result + + ((schemaPath == null) ? 0 : schemaPath.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + + ((status == null) ? 0 : status.hashCode()); + result = prime * result + + ((position == null) ? 0 : position.hashCode()); + result = prime + * result + + ((extensionDefinitions == null) ? 0 + : extensionDefinitions.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Bit other = (Bit) obj; + if (qname == null) { + if (other.getQName() != null) { + return false; + } + } else if (!qname.equals(other.getQName())) { + return false; + } + if (schemaPath == null) { + if (other.getPath() != null) { + return false; + } + } else if (!schemaPath.equals(other.getPath())) { + return false; + } + if (description == null) { + if (other.getDescription() != null) { + return false; + } + } else if (!description.equals(other.getDescription())) { + return false; + } + if (reference == null) { + if (other.getReference() != null) { + return false; + } + } else if (!reference.equals(other.getReference())) { + return false; + } + if (status == null) { + if (other.getStatus() != null) { + return false; + } + } else if (!status.equals(other.getStatus())) { + return false; + } + if (extensionDefinitions == null) { + if (other.getUnknownSchemaNodes() != null) { + return false; + } + } else if (!extensionDefinitions.equals(other + .getUnknownSchemaNodes())) { + return false; + } + if (position == null) { + if (other.getPosition() != null) { + return false; + } + } else if (!position.equals(other.getPosition())) { + return false; + } + return true; + } + + @Override + public String toString() { + return Bit.class.getSimpleName() + "[name=" + + qname.getLocalName() + ", position=" + position + "]"; + } + }; + } + + /** + * Parse orderedby statement. + * + * @param childNode + * Ordered_by_stmtContext + * @return true, if orderedby contains value 'user' or false otherwise + */ + public static boolean parseUserOrdered(Ordered_by_stmtContext childNode) { + boolean result = false; + for (int j = 0; j < childNode.getChildCount(); j++) { + ParseTree orderArg = childNode.getChild(j); + if (orderArg instanceof Ordered_by_argContext) { + String orderStr = stringFromNode(orderArg); + if (orderStr.equals("system")) { + result = false; + } else if (orderStr.equals("user")) { + result = true; + } else { + logger.warn("Invalid 'orderedby' statement."); + } + } + } + return result; + } + + /** + * Parse given config context and return true if it contains string 'true', + * false otherwise. + * + * @param ctx + * config context to parse. + * @return true if given context contains string 'true', false otherwise + */ + public static boolean parseConfig(final Config_stmtContext ctx) { + if (ctx != null) { + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree configContext = ctx.getChild(i); + if (configContext instanceof Config_argContext) { + final String value = stringFromNode(configContext); + if (value.equals("true")) { + return true; + } + } + } + } + return false; + } + + /** + * Parse given type body and creates UnknownType definition. + * + * @param typedefQName + * qname of current type + * @param ctx + * type body + * @return UnknownType object with constraints from parsed type body + */ + public static TypeDefinition parseUnknownTypeBody(QName typedefQName, + Type_body_stmtsContext ctx) { + UnknownType.Builder ut = new UnknownType.Builder(typedefQName); + + if (ctx != null) { + List rangeStatements = getRangeConstraints(ctx); + List lengthStatements = getLengthConstraints(ctx); + List patternStatements = getPatternConstraint(ctx); + + ut.rangeStatements(rangeStatements); + ut.lengthStatements(lengthStatements); + ut.patterns(patternStatements); + } + + return ut.build(); + } + + /** + * Create TypeDefinition object based on given type name and type body. + * + * @param typeName + * name of type + * @param typeBody + * type body + * @param actualPath + * current path in schema + * @param namespace + * current namespace + * @param revision + * current revision + * @param prefix + * current prefix + * @return TypeDefinition object based on parsed values. + */ + public static TypeDefinition parseTypeBody(String typeName, + Type_body_stmtsContext typeBody, List actualPath, + URI namespace, Date revision, String prefix) { + TypeDefinition type = null; + + List rangeStatements = getRangeConstraints(typeBody); + Integer fractionDigits = getFractionDigits(typeBody); + List lengthStatements = getLengthConstraints(typeBody); + List patternStatements = getPatternConstraint(typeBody); + List enumConstants = getEnumConstants(typeBody, actualPath, namespace, revision, prefix); + + if (typeName.equals("decimal64")) { + type = YangTypesConverter.javaTypeForBaseYangDecimal64Type( + rangeStatements, fractionDigits); + } else if (typeName.startsWith("int") || typeName.startsWith("uint")) { + type = YangTypesConverter.javaTypeForBaseYangIntegerType(typeName, + rangeStatements); + } else if (typeName.equals("enumeration")) { + type = new EnumerationType(enumConstants); + } else if (typeName.equals("string")) { + type = new StringType(lengthStatements, patternStatements); + } else if (typeName.equals("bits")) { + type = new BitsType(getBits(typeBody, actualPath, namespace, + revision, prefix)); + } else if (typeName.equals("leafref")) { + final String path = parseLeafrefPath(typeBody); + final boolean absolute = path.startsWith("/"); + RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path, + absolute); + type = new Leafref(xpath); + } else if (typeName.equals("binary")) { + type = new BinaryType(null, lengthStatements, null); + } else if (typeName.equals("instanceidentifier")) { + boolean requireInstance = isRequireInstance(typeBody); + type = new InstanceIdentifier(null, requireInstance); + } + return type; + } + + private static String parseLeafrefPath(Type_body_stmtsContext ctx) { + for (int i = 0; i < ctx.getChildCount(); i++) { + ParseTree child = ctx.getChild(i); + if (child instanceof Leafref_specificationContext) { + for (int j = 0; j < child.getChildCount(); j++) { + ParseTree leafRefSpec = child.getChild(j); + if (leafRefSpec instanceof Path_stmtContext) { + return stringFromNode(leafRefSpec); + } + } + } + } + return null; + } + + /** + * Internal helper method for parsing Must_stmtContext. + * + * @param ctx + * Must_stmtContext + * @return an array of strings with following fields: [0] must text [1] + * description [2] reference + */ + public static String[] parseMust(YangParser.Must_stmtContext ctx) { + String[] params = new String[3]; + + String mustText = ""; + String description = null; + String reference = null; + for (int i = 0; i < ctx.getChildCount(); ++i) { + ParseTree child = ctx.getChild(i); + if (child instanceof StringContext) { + final StringContext context = (StringContext) child; + for (int j = 0; j < context.getChildCount(); j++) { + String mustPart = context.getChild(j).getText(); + if (j == 0) { + mustText += mustPart + .substring(0, mustPart.length() - 1); + continue; + } + if (j % 2 == 0) { + mustText += mustPart.substring(1); + } + } + } else if (child instanceof Description_stmtContext) { + description = stringFromNode(child); + } else if (child instanceof Reference_stmtContext) { + reference = stringFromNode(child); + } + } + params[0] = mustText; + params[1] = description; + params[2] = reference; + + return params; + } + + /** + * Parse given tree and set constraints to given builder. + * + * @param ctx + * Context to search. + * @param constraintsBuilder + * ConstraintsBuilder to fill. + */ + public static void parseConstraints(ParseTree ctx, + ConstraintsBuilder constraintsBuilder) { + for (int i = 0; i < ctx.getChildCount(); ++i) { + final ParseTree childNode = ctx.getChild(i); + if (childNode instanceof Max_elements_stmtContext) { + Integer max = Integer.valueOf(stringFromNode(childNode)); + constraintsBuilder.setMinElements(max); + } else if (childNode instanceof Min_elements_stmtContext) { + Integer min = Integer.valueOf(stringFromNode(childNode)); + constraintsBuilder.setMinElements(min); + } else if (childNode instanceof Must_stmtContext) { + String[] mustParams = parseMust((Must_stmtContext) childNode); + constraintsBuilder.addMustDefinition(mustParams[0], + mustParams[1], mustParams[2]); + } else if (childNode instanceof Mandatory_stmtContext) { + for (int j = 0; j < childNode.getChildCount(); j++) { + ParseTree mandatoryTree = ctx.getChild(j); + if (mandatoryTree instanceof Mandatory_argContext) { + Boolean mandatory = Boolean + .valueOf(stringFromNode(mandatoryTree)); + constraintsBuilder.setMandatory(mandatory); + } + } + } else if (childNode instanceof When_stmtContext) { + constraintsBuilder.addWhenCondition(stringFromNode(childNode)); + } + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilderTest.java deleted file mode 100644 index 55e1197716..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ContainerSchemaNodeBuilderTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.net.URI; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.model.parser.builder.ContainerSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.MustDefinitionBuilder; -import org.opendaylight.controller.model.parser.builder.TypedefBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class ContainerSchemaNodeBuilderTest { - - private ContainerSchemaNodeBuilder tested; - - private final String NAME = "test-container"; - - private final URI namespace = URI.create("test:container.name"); - private final Date revision = new Date(); - private final String prefix = "x"; - - private SchemaPath schemaPath; - private final String description = "description of container"; - private final String reference = "reference"; - - private QName typedefQName; - private TypedefBuilder typeBuilder; - @Mock private AugmentationSchema augment; - @Mock private ConstraintDefinition constraint; - @Mock private UsesNodeBuilder usesBuilder; - @Mock private UsesNode uses; - @Mock private MustDefinitionBuilder mustBuilder; - @Mock private MustDefinition must; - @Mock private GroupingBuilder groupingBuilder; - @Mock private GroupingDefinition grouping; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - when(usesBuilder.build()).thenReturn(uses); - when(mustBuilder.build()).thenReturn(must); - when(groupingBuilder.build()).thenReturn(grouping); - - schemaPath = TestUtils.createSchemaPath(true, namespace, "main", "interface"); - typedefQName = new QName(namespace, "test-type"); - typeBuilder = new TypedefBuilder(typedefQName); - - QName qname = new QName(namespace, revision, prefix, NAME); - tested = new ContainerSchemaNodeBuilder(qname); - } - - @Test - public void test() { - tested.addTypedef(typeBuilder); - tested.setPath(schemaPath); - tested.setDescription(description); - tested.setReference(reference); - tested.setStatus(Status.OBSOLOTE); - tested.setConfiguration(false); - tested.setConstraints(constraint); - tested.addUsesNode(usesBuilder); - tested.addAugmentation(augment); - tested.setMustDefinitionBuilder(mustBuilder); - tested.setPresenceContainer(true); - - ContainerSchemaNode result = tested.build(); - - Set> expectedTypedefs = result.getTypeDefinitions(); - assertEquals(1, expectedTypedefs.size()); - assertEquals(typedefQName, expectedTypedefs.iterator().next().getQName()); - - Set expectedAugments = new HashSet(); - expectedAugments.add(augment); - assertEquals(expectedAugments, result.getAvailableAugmentations()); - - assertEquals(schemaPath, result.getPath()); - assertEquals(description, result.getDescription()); - assertEquals(reference, result.getReference()); - assertEquals(Status.OBSOLOTE, result.getStatus()); - assertFalse(result.isConfiguration()); - assertEquals(constraint, result.getConstraints()); - - Set expectedUses = new HashSet(); - expectedUses.add(uses); - assertEquals(expectedUses, result.getUses()); - - assertTrue(result.isPresenceContainer()); - assertEquals(must, result.getMustDefinition()); - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilderTest.java deleted file mode 100644 index 9df458a233..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/LeafListSchemaNodeBuilderTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.net.URI; -import java.util.Date; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.model.parser.builder.LeafSchemaNodeBuilder; -import org.opendaylight.controller.model.parser.builder.MustDefinitionBuilder; -import org.opendaylight.controller.model.parser.builder.TypedefBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.LeafSchemaNode; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class LeafListSchemaNodeBuilderTest { - - private LeafSchemaNodeBuilder tested; - - private final String NAME = "test-leaf"; - - private final URI namespace = URI.create("test:leaf.name"); - private final Date revision = new Date(); - private final String prefix = "x"; - - private SchemaPath schemaPath; - private final String description = "description of container"; - private final String reference = "reference"; - - private QName typedefQName; - private TypeDefinition type; - @Mock private ConstraintDefinition constraint; - @Mock private UsesNodeBuilder usesBuilder; - @Mock private UsesNode uses; - @Mock private MustDefinitionBuilder mustBuilder; - @Mock private MustDefinition must; - @Mock private GroupingBuilder groupingBuilder; - @Mock private GroupingDefinition grouping; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - when(usesBuilder.build()).thenReturn(uses); - when(mustBuilder.build()).thenReturn(must); - when(groupingBuilder.build()).thenReturn(grouping); - - schemaPath = TestUtils.createSchemaPath(true, namespace, "main", "interface"); - typedefQName = new QName(namespace, "test-type"); - TypedefBuilder typeBuilder = new TypedefBuilder(typedefQName); - type = typeBuilder.build(); - - QName qname = new QName(namespace, revision, prefix, NAME); - tested = new LeafSchemaNodeBuilder(qname); - } - - @Test - public void test() { - tested.setType(type); - tested.setPath(schemaPath); - tested.setDescription(description); - tested.setReference(reference); - tested.setStatus(Status.OBSOLOTE); - tested.setConfiguration(false); - tested.setConstraints(constraint); - tested.setMustDefinitionBuilder(mustBuilder); - - LeafSchemaNode result = tested.build(); - - assertEquals(type, result.getType()); - assertEquals(schemaPath, result.getPath()); - assertEquals(description, result.getDescription()); - assertEquals(reference, result.getReference()); - assertEquals(Status.OBSOLOTE, result.getStatus()); - assertFalse(result.isConfiguration()); - assertEquals(constraint, result.getConstraints()); - assertEquals(must, result.getMustDefinition()); - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilderTest.java deleted file mode 100644 index 7085dae3da..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/ListSchemaNodeBuilderTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.model.parser.api.GroupingBuilder; -import org.opendaylight.controller.model.parser.api.UsesNodeBuilder; -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.AugmentationSchema; -import org.opendaylight.controller.yang.model.api.ConstraintDefinition; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.ListSchemaNode; -import org.opendaylight.controller.yang.model.api.MustDefinition; -import org.opendaylight.controller.yang.model.api.SchemaPath; -import org.opendaylight.controller.yang.model.api.Status; -import org.opendaylight.controller.yang.model.api.TypeDefinition; -import org.opendaylight.controller.yang.model.api.UsesNode; - - -public class ListSchemaNodeBuilderTest { - - private ListSchemaNodeBuilder tested; - - private static final String NAME = "test-list"; - - private final URI namespace = URI.create("test:list.name"); - private final Date revision = new Date(); - private final String prefix = "x"; - - private SchemaPath schemaPath; - private final String description = "description of list"; - private final String reference = "reference"; - - private QName typedefQName; - private TypedefBuilder typeBuilder; - @Mock private AugmentationSchema augment; - @Mock private ConstraintDefinition constraint; - @Mock private UsesNodeBuilder usesBuilder; - @Mock private UsesNode uses; - @Mock private MustDefinitionBuilder mustBuilder; - @Mock private MustDefinition must; - @Mock private GroupingBuilder groupingBuilder; - @Mock private GroupingDefinition grouping; - private List keyDefinition; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - when(usesBuilder.build()).thenReturn(uses); - when(mustBuilder.build()).thenReturn(must); - when(groupingBuilder.build()).thenReturn(grouping); - - schemaPath = TestUtils.createSchemaPath(true, namespace, "main", NAME); - typedefQName = new QName(namespace, "test-type"); - typeBuilder = new TypedefBuilder(typedefQName); - - keyDefinition = new ArrayList(); - keyDefinition.add(new QName(namespace, "name")); - - QName qname = new QName(namespace, revision, prefix, NAME); - tested = new ListSchemaNodeBuilder(qname); - } - - @Test - public void test() { - tested.addTypedef(typeBuilder); - tested.setPath(schemaPath); - tested.setDescription(description); - tested.setReference(reference); - tested.setStatus(Status.OBSOLOTE); - tested.setConfiguration(false); - tested.setConstraints(constraint); - tested.addUsesNode(usesBuilder); - tested.addAugmentation(augment); - tested.setUserOrdered(true); - tested.setKeyDefinition(keyDefinition); - - ListSchemaNode result = tested.build(); - - Set> expectedTypedefs = result.getTypeDefinitions(); - assertEquals(1, expectedTypedefs.size()); - assertEquals(typedefQName, expectedTypedefs.iterator().next().getQName()); - - Set expectedAugments = new HashSet(); - expectedAugments.add(augment); - assertEquals(expectedAugments, result.getAvailableAugmentations()); - - assertEquals(schemaPath, result.getPath()); - assertEquals(description, result.getDescription()); - assertEquals(reference, result.getReference()); - assertEquals(Status.OBSOLOTE, result.getStatus()); - assertFalse(result.isConfiguration()); - assertEquals(constraint, result.getConstraints()); - - Set expectedUses = new HashSet(); - expectedUses.add(uses); - assertEquals(expectedUses, result.getUses()); - - assertTrue(result.isUserOrdered()); - assertEquals(keyDefinition, result.getKeyDefinition()); - } - -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/impl/YangModelParserTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/impl/YangModelParserTest.java deleted file mode 100644 index 4a90d8033b..0000000000 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/impl/YangModelParserTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.impl; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Set; - -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.ParseTreeWalker; -import org.junit.Test; -import org.opendaylight.controller.antlrv4.code.gen.YangLexer; -import org.opendaylight.controller.antlrv4.code.gen.YangParser; -import org.opendaylight.controller.sal.binding.model.api.GeneratedType; - -public class YangModelParserTest { - - @Test - public void testPackageNameConstruction() { - try { - final InputStream inStream = getClass().getResourceAsStream( - "/simple-list-demo.yang"); - if (inStream != null) { - ANTLRInputStream input = new ANTLRInputStream(inStream); - final YangLexer lexer = new YangLexer(input); - final CommonTokenStream tokens = new CommonTokenStream(lexer); - final YangParser parser = new YangParser(tokens); - - final ParseTree tree = parser.yang(); - final ParseTreeWalker walker = new ParseTreeWalker(); - - // final YangModelParserImpl modelParser = new - // YangModelParserImpl(tree, new TypeProviderImpl()); - // walker.walk(modelParser, tree); - // final Set genTypes = - // modelParser.generatedTypes(); - - // getTypesTest(genTypes); - - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void getTypesTest(final Set genTypes) { - int typesCount = 0; - for (final GeneratedType type : genTypes) { - if (type.getName().equals("Topology")) { - assertEquals(4, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("NetworkNodes")) { - assertEquals(2, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("NetworkNode")) { - assertEquals(1, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("NodeAttributes")) { - assertEquals(2, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("NetworkLinks")) { - assertEquals(2, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("NetworkLink")) { - assertEquals(3, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("Source")) { - assertEquals(2, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("Destination")) { - assertEquals(2, type.getMethodDefinitions().size()); - ++typesCount; - } - if (type.getName().equals("LinkAttributes")) { - assertEquals(0, type.getMethodDefinitions().size()); - ++typesCount; - } - } - assertEquals(9, typesCount); - } -} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilderTest.java new file mode 100644 index 0000000000..709d5e3750 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ContainerSchemaNodeBuilderTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.net.URI; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ContainerSchemaNodeBuilderTest { + + private ContainerSchemaNodeBuilder tested; + + private final String NAME = "test-container"; + + private final URI namespace = URI.create("test:container.name"); + private final Date revision = new Date(); + private final String prefix = "x"; + + private SchemaPath schemaPath; + private final String description = "description of container"; + private final String reference = "reference"; + + private QName typedefQName; + private TypedefBuilder typeBuilder; + @Mock + private AugmentationSchema augment; + @Mock + private UsesNodeBuilder usesBuilder; + @Mock + private UsesNode uses; + @Mock + private GroupingBuilder groupingBuilder; + @Mock + private GroupingDefinition grouping; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + when(usesBuilder.build()).thenReturn(uses); + when(groupingBuilder.build()).thenReturn(grouping); + + schemaPath = TestUtils.createSchemaPath(true, namespace, "main", + "interface"); + typedefQName = new QName(namespace, "test-type"); + typeBuilder = new TypedefBuilder(typedefQName); + + QName qname = new QName(namespace, revision, prefix, NAME); + tested = new ContainerSchemaNodeBuilder(qname); + } + + @Test + public void test() { + tested.addTypedef(typeBuilder); + tested.setPath(schemaPath); + tested.setDescription(description); + tested.setReference(reference); + tested.setStatus(Status.OBSOLETE); + tested.setConfiguration(false); + tested.addUsesNode(usesBuilder); + tested.addAugmentation(augment); + tested.setPresenceContainer(true); + + ContainerSchemaNode result = tested.build(); + + Set> expectedTypedefs = result.getTypeDefinitions(); + assertEquals(1, expectedTypedefs.size()); + assertEquals(typedefQName, expectedTypedefs.iterator().next() + .getQName()); + + Set expectedAugments = new HashSet(); + expectedAugments.add(augment); + assertEquals(expectedAugments, result.getAvailableAugmentations()); + + assertEquals(schemaPath, result.getPath()); + assertEquals(description, result.getDescription()); + assertEquals(reference, result.getReference()); + assertEquals(Status.OBSOLETE, result.getStatus()); + assertFalse(result.isConfiguration()); + + Set expectedUses = new HashSet(); + expectedUses.add(uses); + assertEquals(expectedUses, result.getUses()); + + assertTrue(result.isPresenceContainer()); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilderTest.java new file mode 100644 index 0000000000..367669f8df --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafListSchemaNodeBuilderTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.net.URI; +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.LeafListSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class LeafListSchemaNodeBuilderTest { + + private LeafListSchemaNodeBuilder tested; + + private final String NAME = "test-leaf"; + + private final URI namespace = URI.create("test:leaf.name"); + private final Date revision = new Date(); + private final String prefix = "x"; + + private SchemaPath schemaPath; + private final String description = "description of container"; + private final String reference = "reference"; + + private QName typedefQName; + private TypeDefinition type; + + @Mock + private UsesNodeBuilder usesBuilder; + @Mock + private UsesNode uses; + @Mock + private GroupingBuilder groupingBuilder; + @Mock + private GroupingDefinition grouping; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + when(usesBuilder.build()).thenReturn(uses); + when(groupingBuilder.build()).thenReturn(grouping); + + schemaPath = TestUtils.createSchemaPath(true, namespace, "main", + "interface"); + typedefQName = new QName(namespace, "test-type"); + TypedefBuilder typeBuilder = new TypedefBuilder(typedefQName); + type = typeBuilder.build(); + + QName qname = new QName(namespace, revision, prefix, NAME); + tested = new LeafListSchemaNodeBuilder(qname); + } + + @Test + public void test() { + tested.setType(type); + tested.setPath(schemaPath); + tested.setDescription(description); + tested.setReference(reference); + tested.setStatus(Status.OBSOLETE); + tested.setConfiguration(false); + + LeafListSchemaNode result = tested.build(); + + assertEquals(type, result.getType()); + assertEquals(schemaPath, result.getPath()); + assertEquals(description, result.getDescription()); + assertEquals(reference, result.getReference()); + assertEquals(Status.OBSOLETE, result.getStatus()); + assertFalse(result.isConfiguration()); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilderTest.java new file mode 100644 index 0000000000..622c82d4fc --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/LeafSchemaNodeBuilderTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.net.URI; +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.LeafSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class LeafSchemaNodeBuilderTest { + + private LeafSchemaNodeBuilder tested; + + private final String NAME = "test-leaf"; + + private final URI namespace = URI.create("test:leaf.name"); + private final Date revision = new Date(); + private final String prefix = "x"; + + private SchemaPath schemaPath; + private final String description = "description of container"; + private final String reference = "reference"; + + private QName typedefQName; + private TypeDefinition type; + @Mock + private UsesNodeBuilder usesBuilder; + @Mock + private UsesNode uses; + @Mock + private GroupingBuilder groupingBuilder; + @Mock + private GroupingDefinition grouping; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + when(usesBuilder.build()).thenReturn(uses); + when(groupingBuilder.build()).thenReturn(grouping); + + schemaPath = TestUtils.createSchemaPath(true, namespace, "main", + "interface"); + typedefQName = new QName(namespace, "test-type"); + TypedefBuilder typeBuilder = new TypedefBuilder(typedefQName); + type = typeBuilder.build(); + + QName qname = new QName(namespace, revision, prefix, NAME); + tested = new LeafSchemaNodeBuilder(qname); + } + + @Test + public void test() { + tested.setType(type); + tested.setPath(schemaPath); + tested.setDescription(description); + tested.setReference(reference); + tested.setStatus(Status.OBSOLETE); + tested.setConfiguration(false); + + LeafSchemaNode result = tested.build(); + + assertEquals(type, result.getType()); + assertEquals(schemaPath, result.getPath()); + assertEquals(description, result.getDescription()); + assertEquals(reference, result.getReference()); + assertEquals(Status.OBSOLETE, result.getStatus()); + assertFalse(result.isConfiguration()); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilderTest.java new file mode 100644 index 0000000000..c5f336179b --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/ListSchemaNodeBuilderTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UsesNode; +import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; + +public class ListSchemaNodeBuilderTest { + + private ListSchemaNodeBuilder tested; + + private static final String NAME = "test-list"; + + private final URI namespace = URI.create("test:list.name"); + private final Date revision = new Date(); + private final String prefix = "x"; + + private SchemaPath schemaPath; + private final String description = "description of list"; + private final String reference = "reference"; + + private QName typedefQName; + private TypedefBuilder typeBuilder; + @Mock + private AugmentationSchema augment; + @Mock + private UsesNodeBuilder usesBuilder; + @Mock + private UsesNode uses; + @Mock + private GroupingBuilder groupingBuilder; + @Mock + private GroupingDefinition grouping; + private List keyDefinition; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + when(usesBuilder.build()).thenReturn(uses); + when(groupingBuilder.build()).thenReturn(grouping); + + schemaPath = TestUtils.createSchemaPath(true, namespace, "main", NAME); + typedefQName = new QName(namespace, "test-type"); + typeBuilder = new TypedefBuilder(typedefQName); + + keyDefinition = new ArrayList(); + keyDefinition.add(new QName(namespace, "name")); + + QName qname = new QName(namespace, revision, prefix, NAME); + tested = new ListSchemaNodeBuilder(qname); + } + + @Test + public void test() { + tested.addTypedef(typeBuilder); + tested.setPath(schemaPath); + tested.setDescription(description); + tested.setReference(reference); + tested.setStatus(Status.OBSOLETE); + tested.setConfiguration(false); + tested.addUsesNode(usesBuilder); + tested.addAugmentation(augment); + tested.setUserOrdered(true); + tested.setKeyDefinition(keyDefinition); + + ListSchemaNode result = tested.build(); + + Set> expectedTypedefs = result.getTypeDefinitions(); + assertEquals(1, expectedTypedefs.size()); + assertEquals(typedefQName, expectedTypedefs.iterator().next() + .getQName()); + + Set expectedAugments = new HashSet(); + expectedAugments.add(augment); + assertEquals(expectedAugments, result.getAvailableAugmentations()); + + assertEquals(schemaPath, result.getPath()); + assertEquals(description, result.getDescription()); + assertEquals(reference, result.getReference()); + assertEquals(Status.OBSOLETE, result.getStatus()); + assertFalse(result.isConfiguration()); + + Set expectedUses = new HashSet(); + expectedUses.add(uses); + assertEquals(expectedUses, result.getUses()); + + assertTrue(result.isUserOrdered()); + assertEquals(keyDefinition, result.getKeyDefinition()); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/TestUtils.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java similarity index 53% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/TestUtils.java rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java index 0c5bb48324..f8627b2188 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/model/parser/builder/TestUtils.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/TestUtils.java @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.model.parser.builder; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.SchemaPath; - - -public class TestUtils { - - private TestUtils () { - } - - public static SchemaPath createSchemaPath(boolean absolute, URI namespace, String... path) { - List names = new ArrayList(); - QName qname; - for(String pathPart : path) { - qname = new QName(namespace, pathPart); - names.add(qname); - } - return new SchemaPath(names, absolute); - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; + +public class TestUtils { + + private TestUtils() { + } + + public static SchemaPath createSchemaPath(boolean absolute, URI namespace, + String... path) { + List names = new ArrayList(); + QName qname; + for (String pathPart : path) { + qname = new QName(namespace, pathPart); + names.add(qname); + } + return new SchemaPath(names, absolute); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java new file mode 100644 index 0000000000..2a1129399c --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/builder/impl/YangModelBuilderTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.builder.impl; + +import static org.junit.Assert.*; + +import java.io.File; +import java.text.ParseException; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.DataNodeContainer; +import org.opendaylight.controller.yang.model.api.LeafSchemaNode; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl; + +public class YangModelBuilderTest { + + private Set builtModules; + + @Before + public void init() { + builtModules = parseModules(); + } + + @Test + public void testAugment() throws ParseException { + for(Module module : builtModules) { + if(module.getName().equals("types2")) { + Set augmentations = module.getAugmentations(); + assertEquals(1, augmentations.size()); + AugmentationSchema augment = augmentations.iterator().next(); + LeafSchemaNode augmentedLeaf = (LeafSchemaNode)augment.getDataChildByName("ds0ChannelNumber"); + assertNotNull(augmentedLeaf); + assertTrue(augmentedLeaf.isAugmenting()); + } else if(module.getName().equals("types1")) { + DataNodeContainer interfaces = (DataNodeContainer)module.getDataChildByName("interfaces"); + DataNodeContainer ifEntry = (DataNodeContainer)interfaces.getDataChildByName("ifEntry"); + assertNotNull(ifEntry); + } else { + fail("unexpected module"); + } + } + } + + private Set parseModules() { + String yangFilesDir = "src/test/resources/model"; + File resourceDir = new File(yangFilesDir); + + String[] dirList = resourceDir.list(); + String[] absFiles = new String[dirList.length]; + + int i = 0; + for (String fileName : dirList) { + File abs = new File(resourceDir, fileName); + absFiles[i] = abs.getAbsolutePath(); + i++; + } + + YangModelParserImpl parser = new YangModelParserImpl(); + Set modules = parser.parseYangModels(absFiles); + + return modules; + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java new file mode 100644 index 0000000000..a9bcb918b7 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerTest.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.impl; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ParseTreeWalker; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.antlrv4.code.gen.YangLexer; +import org.opendaylight.controller.antlrv4.code.gen.YangParser; +import org.opendaylight.controller.model.util.UnknownType; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.DataNodeContainer; +import org.opendaylight.controller.yang.model.api.DataSchemaNode; +import org.opendaylight.controller.yang.model.api.LeafSchemaNode; +import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.api.ModuleImport; +import org.opendaylight.controller.yang.model.api.SchemaNode; +import org.opendaylight.controller.yang.model.api.SchemaPath; +import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; + +public class YangModelParserListenerTest { + + private final String testFile = "/test-model.yang"; + ModuleBuilder builder; + Module module; + + + @Before + public void init() throws IOException { + builder = getBuilder(testFile); + module = builder.build(); + } + + @Test + public void testParseModule() throws IOException { + Set imports = module.getImports(); + assertEquals(3, imports.size()); + + URI namespace = module.getNamespace(); + URI expectedNS = URI.create("urn:cisco:params:xml:ns:yang:controller:network"); + assertEquals(expectedNS, namespace); + + Date revision = module.getRevision(); + assertNull(revision); + + String prefix = module.getPrefix(); + String expectedPrefix = "topos"; + assertEquals(expectedPrefix, prefix); + + String expectedDescription = "module description"; + assertEquals(expectedDescription, module.getDescription()); + + String expectedReference = "module reference"; + assertEquals(expectedReference, module.getReference()); + + Set> typedefs = module.getTypeDefinitions(); + assertEquals(10, typedefs.size()); + + Set childNodes = module.getChildNodes(); + assertEquals(1, childNodes.size()); + + final String containerName = "network"; + final QName containerQName = new QName(namespace, revision, prefix, containerName); + ContainerSchemaNode tested = (ContainerSchemaNode) module.getChildNodes().iterator().next(); + DataSchemaNode container1 = module.getDataChildByName(containerName); + DataSchemaNode container2 = module.getDataChildByName(containerQName); + + assertEquals(tested, container1); + assertEquals(container1, container2); + } + + @Test + public void testParseContainer() { + URI namespace = module.getNamespace(); + Date revision = module.getRevision(); + String prefix = module.getPrefix(); + final QName containerQName = new QName(namespace, revision, prefix, "network"); + + ContainerSchemaNode tested = (ContainerSchemaNode)module.getDataChildByName(containerQName); + + Set containerChildNodes = tested.getChildNodes(); + assertEquals(3, containerChildNodes.size()); + + String expectedDescription = "network-description"; + String expectedReference = "network-reference"; + Status expectedStatus = Status.OBSOLETE; + testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); + + List path = new ArrayList(); + path.add(new QName(namespace, revision, prefix, "test-model")); + path.add(containerQName); + SchemaPath expectedSchemaPath = new SchemaPath(path, true); + assertEquals(expectedSchemaPath, tested.getPath()); + + assertTrue(tested.isConfiguration()); + assertTrue(tested.isPresenceContainer()); + } + + @Test + public void testParseList() { + URI namespace = module.getNamespace(); + Date revision = module.getRevision(); + String prefix = module.getPrefix(); + final QName listQName = new QName(namespace, revision, prefix, "topology"); + + DataNodeContainer networkContainer = (DataNodeContainer)module.getDataChildByName("network"); + DataNodeContainer topologiesContainer = (DataNodeContainer)networkContainer.getDataChildByName("topologies"); + ListSchemaNode tested = (ListSchemaNode)topologiesContainer.getDataChildByName(listQName); + assertEquals(listQName, tested.getQName()); + + String expectedDescription = "Test description of list 'topology'."; + String expectedReference = null; + Status expectedStatus = Status.CURRENT; + testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); + + List path = new ArrayList(); + path.add(new QName(namespace, revision, prefix, "test-model")); + path.add(new QName(namespace, revision, prefix, "network")); + path.add(new QName(namespace, revision, prefix, "topologies")); + path.add(listQName); + SchemaPath expectedSchemaPath = new SchemaPath(path, true); + assertEquals(expectedSchemaPath, tested.getPath()); + + List expectedKey = new ArrayList(); + expectedKey.add(new QName(namespace, revision, prefix, "topology-id")); + assertEquals(expectedKey, tested.getKeyDefinition()); + + assertEquals(Collections.EMPTY_SET, tested.getTypeDefinitions()); + assertEquals(Collections.EMPTY_SET, tested.getUses()); + assertEquals(Collections.EMPTY_SET, tested.getGroupings()); + + assertTrue(tested.getDataChildByName("topology-id") instanceof LeafSchemaNode); + } + + @Test + public void testParseLeaf() { + URI namespace = module.getNamespace(); + Date revision = module.getRevision(); + String prefix = module.getPrefix(); + final QName leafQName = new QName(namespace, revision, prefix, "topology-id"); + + DataNodeContainer networkContainer = (DataNodeContainer)module.getDataChildByName("network"); + DataNodeContainer topologiesContainer = (DataNodeContainer)networkContainer.getDataChildByName("topologies"); + DataNodeContainer topologyList = (DataNodeContainer)topologiesContainer.getDataChildByName("topology"); + LeafSchemaNode tested = (LeafSchemaNode)topologyList.getDataChildByName(leafQName); + assertEquals(leafQName, tested.getQName()); + + String expectedDescription = "Test description of leaf 'topology-id'"; + String expectedReference = null; + Status expectedStatus = Status.CURRENT; + testDesc_Ref_Status(tested, expectedDescription, expectedReference, expectedStatus); + + List path = new ArrayList(); + path.add(new QName(namespace, revision, prefix, "test-model")); + path.add(new QName(namespace, revision, prefix, "network")); + path.add(new QName(namespace, revision, prefix, "topologies")); + path.add(new QName(namespace, revision, prefix, "topology")); + path.add(leafQName); + SchemaPath expectedSchemaPath = new SchemaPath(path, true); + assertEquals(expectedSchemaPath, tested.getPath()); + + UnknownType.Builder typeBuilder = new UnknownType.Builder(new QName(namespace, revision, prefix, "topology-id"), null, null); + TypeDefinition expectedType = typeBuilder.build(); + assertEquals(expectedType, tested.getType()); + } + + + private void testDesc_Ref_Status(SchemaNode tested, String expectedDescription, String expectedReference, Status expectedStatus) { + assertEquals(expectedDescription, tested.getDescription()); + assertEquals(expectedReference, tested.getReference()); + assertEquals(expectedStatus, tested.getStatus()); + } + + private ModuleBuilder getBuilder(String fileName) throws IOException { + final InputStream inStream = getClass().getResourceAsStream(fileName); + ANTLRInputStream input = new ANTLRInputStream(inStream); + final YangLexer lexer = new YangLexer(input); + final CommonTokenStream tokens = new CommonTokenStream(lexer); + final YangParser parser = new YangParser(tokens); + + final ParseTree tree = parser.yang(); + final ParseTreeWalker walker = new ParseTreeWalker(); + + final YangModelParserListenerImpl modelParser = new YangModelParserListenerImpl(); + walker.walk(modelParser, tree); + return modelParser.getModuleBuilder(); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java new file mode 100644 index 0000000000..74cfed5fb1 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.parser.impl; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.model.util.Int32; +import org.opendaylight.controller.yang.model.api.AugmentationSchema; +import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; +import org.opendaylight.controller.yang.model.api.LeafSchemaNode; +import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.Module; +import org.opendaylight.controller.yang.model.parser.api.YangModelParser; + +public class YangModelParserTest { + + private final String testFile1 = "src/test/resources/model/testfile1.yang"; + private final String testFile2 = "src/test/resources/model/testfile2.yang"; + private YangModelParser tested; + + @Before + public void init() throws IOException { + tested = new YangModelParserImpl(); + } + + @Test + public void testAugment() { + Set modules = tested.parseYangModels(testFile1, testFile2); + assertEquals(2, modules.size()); + + Module m2 = null; + for(Module m : modules) { + if(m.getName().equals("types2")) { + m2 = m; + } + } + assertNotNull(m2); + + AugmentationSchema augment = m2.getAugmentations().iterator().next(); + assertNotNull(augment); + } + + @Test + public void testAugmentTarget() { + Set modules = tested.parseYangModels(testFile1, testFile2); + assertEquals(2, modules.size()); + + Module m1 = null; + for(Module m : modules) { + if(m.getName().equals("types1")) { + m1 = m; + } + } + assertNotNull(m1); + + ContainerSchemaNode container = (ContainerSchemaNode)m1.getDataChildByName("interfaces"); + assertNotNull(container); + + ListSchemaNode list = (ListSchemaNode)container.getDataChildByName("ifEntry"); + assertNotNull(list); + + LeafSchemaNode leaf = (LeafSchemaNode)list.getDataChildByName("ds0ChannelNumber"); + assertNotNull(leaf); + } + + @Test + public void testTypeDef() { + Set modules = tested.parseYangModels(testFile1, testFile2); + assertEquals(2, modules.size()); + + Module m1 = null; + for(Module m : modules) { + if(m.getName().equals("types1")) { + m1 = m; + } + } + assertNotNull(m1); + + LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("testleaf"); + assertTrue(testleaf.getType().getBaseType() instanceof Int32); + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang new file mode 100644 index 0000000000..2c796a9acd --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang @@ -0,0 +1,39 @@ +module types1 { + yang-version 1; + namespace "urn:simple.container.demo"; + prefix "t1"; + + import types2 { + prefix "data"; + revision-date 2013-02-27; + } + + organization "Cisco"; + contact "WILL-BE-DEFINED-LATER"; + + revision "2013-02-27" { + reference " WILL BE DEFINED LATER"; + } + + container interfaces { + list ifEntry { + key "ifIndex"; + + leaf ifIndex { + type uint32; + units minutes; + } + + leaf ifMtu { + type int32; + } + } + } + + leaf testleaf { + type data:my-base-int32-type { + range "11..max"; + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang new file mode 100644 index 0000000000..9d12207179 --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang @@ -0,0 +1,43 @@ +module types2 { + yang-version 1; + namespace "urn:simple.types.data.demo"; + prefix "t2"; + + import types1 { + prefix "if"; + revision-date 2013-02-27; + } + + organization "Cisco"; + contact "WILL-BE-DEFINED-LATER"; + description "This is types-data test description"; + + revision "2013-02-27" { + reference " WILL BE DEFINED LATER"; + } + + + augment "/if:interfaces/if:ifEntry" { + when "if:ifType='ds0'"; + leaf ds0ChannelNumber { + type string; + } + } + + leaf if-name { + type leafref { + path "/interface/name"; + } + } + + leaf name { + type string; + } + + typedef my-base-int32-type { + type int32 { + range "0..32"; + } + } + +} diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/test-model.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/test-model.yang new file mode 100644 index 0000000000..a2c485d84f --- /dev/null +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/test-model.yang @@ -0,0 +1,164 @@ +module test-model { + yang-version 1; + namespace "urn:cisco:params:xml:ns:yang:controller:network"; + prefix "topos"; + + import ietf-inet-types { prefix "inet"; } + import iana-if-type {prefix "if-type";} + import mount {prefix "mnt";} + + organization "Cisco"; + + contact "WILL-BE-DEFINED-LATER"; + + description "module description"; + reference "module reference"; + + typedef topology-id { + type inet:uri; + } + + typedef node-id { + type inet:uri; + } + + typedef link-id { + type inet:uri; + } + + typedef tp-id { + type inet:uri; + description "identifier for termination points on a port"; + } + + typedef tp-ref { + type leafref { + path "/network/topologies/topology/nodes/node/termination-points/termination-point/tp-id"; + } + } + typedef topology-ref { + type leafref { + path "/network/topologies/topology/topology-id"; + } + description "This type is used for leafs that reference topology identifier instance."; + // currently not used + } + + typedef node-ref { + type leafref { + path "/network/topologies/topology/nodes/node/node-id"; + } + description "This type is used for leafs that reference a node instance."; + } + + typedef link-ref { + type leafref { + path "/network/topologies/topology/links/link/link-id"; + } + description "This type is used for leafs that reference a link instance."; + // currently not used + } + + typedef network-element-ref { + type leafref { + path "/network/network-elements/network-element/element-id"; + } + } + + + typedef element-id { + type string; + } + + + container network { + description "network-description"; + reference "network-reference"; + status obsolete; + config true; + presence "some presence text"; + + mnt:mountpoint point { + mnt:target-ref target; + } + + leaf-list locked-node { + type instance-identifier; + min-elements 1; + when "a/b/c"; + description "List of locked nodes in the running datastore"; + } + + leaf locked-test { + mandatory true; + } + + container topologies { + list topology { + description "Test description of list 'topology'."; + key "topology-id"; + leaf topology-id { + type topology-id; + description "Test description of leaf 'topology-id'"; + } + + container nodes { + list node { + description "The list of network nodes defined for topology."; + + key "node-id"; + leaf node-id { + type node-id; + description "The Topology identifier of network-node."; + } + + leaf supporting-ne { + type network-element-ref; + } + + container termination-points { + list termination-point { + key "tp-id"; + leaf tp-id { + type tp-id; + } + } + } + } + } + + container links { + list link { + description "Test description of list 'link'."; + key "link-id"; + leaf link-id { + type link-id; + description ""; + } + + container source { + leaf source-node { + type node-ref; + description "Source node identifier."; + } + leaf source-tp { + type tp-ref; + } + } + + container destination { + leaf dest-node { + type node-ref; + description "Destination node identifier."; + } + leaf dest-tp { + type tp-ref; + } + } + } + } + } + } + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/pom.xml b/opendaylight/sal/yang-prototype/sal/pom.xml index 7cda2acbae..2c494e6bb9 100644 --- a/opendaylight/sal/yang-prototype/sal/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/pom.xml @@ -10,6 +10,8 @@ sal-core-api sal-data-api sal-binding-api + sal-binding-spi + sal-binding-broker-impl sal-schema-repository-api sal-common sal-core-spi diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java index 4c1e6f7e1c..24f5b25a19 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java @@ -160,8 +160,9 @@ public interface BindingAwareBroker { */ public interface ProviderSession extends ConsumerSession { - void addImplementation(RpcService implementation); + void addRpcImplementation(RpcService implementation); - void removeImplementation(RpcService implementation); + void removeRpcImplementation(RpcService implementation); } } + diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java index 565c3d2f01..d324b83c53 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.sal.binding.api; import java.util.Collection; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession; import org.opendaylight.controller.yang.binding.RpcService; @@ -65,4 +66,7 @@ public interface BindingAwareProvider { } + void onSessionInitiated(ProviderSession session); + } + diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml index 131630dcc3..9c5552edbd 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/pom.xml @@ -15,7 +15,11 @@ sal-binding-api 1.0-SNAPSHOT - + + org.opendaylight.controller + sal-binding-spi + 1.0-SNAPSHOT + org.opendaylight.controller sal-core-api diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java new file mode 100644 index 0000000000..4cc23b4bbf --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingBrokerImpl.java @@ -0,0 +1,188 @@ +package org.opendaylight.controller.sal.binding.impl; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.BindingAwareService; +import org.opendaylight.controller.sal.binding.spi.SALBindingModule; +import org.opendaylight.controller.yang.binding.RpcService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BindingBrokerImpl implements BindingAwareBroker { + + private static Logger log = LoggerFactory + .getLogger(BindingBrokerImpl.class); + + private Set sessions = new HashSet(); + private Set providerSessions = new HashSet(); + + private Set modules = new HashSet(); + private Map, SALBindingModule> salServiceProviders = new HashMap, SALBindingModule>(); + + @Override + public ConsumerSession registerConsumer(BindingAwareConsumer consumer) { + checkPredicates(consumer); + log.info("Registering consumer " + consumer); + + ConsumerSessionImpl session = newSessionFor(consumer); + consumer.onSessionInitialized(session); + + sessions.add(session); + + return session; + + } + + @Override + public ProviderSession registerProvider(BindingAwareProvider provider) { + checkPredicates(provider); + + ProviderSessionImpl session = newSessionFor(provider); + provider.onSessionInitiated(session); + + providerSessions.add(session); + return session; + } + + public void addModule(SALBindingModule module) { + log.info("Registering broker module " + module); + if (modules.contains(module)) { + log.error("Module already registered"); + throw new IllegalArgumentException("Module already exists."); + } + + Set> provServices = module + .getProvidedServices(); + for (Class serviceType : provServices) { + log.info(" Registering session service implementation: " + + serviceType.getCanonicalName()); + salServiceProviders.put(serviceType, module); + } + } + + public void consumerSessionClosed(ConsumerSessionImpl consumerSessionImpl) { + sessions.remove(consumerSessionImpl); + providerSessions.remove(consumerSessionImpl); + } + + private void checkPredicates(BindingAwareProvider prov) { + if (prov == null) + throw new IllegalArgumentException("Provider should not be null."); + for (ProviderSessionImpl session : providerSessions) { + if (prov.equals(session.getProvider())) + throw new IllegalStateException("Provider already registered"); + } + + } + + private void checkPredicates(BindingAwareConsumer cons) { + if (cons == null) + throw new IllegalArgumentException("Consumer should not be null."); + for (ConsumerSessionImpl session : sessions) { + if (cons.equals(session.getConsumer())) + throw new IllegalStateException("Consumer already registered"); + } + } + + private ConsumerSessionImpl newSessionFor(BindingAwareConsumer cons) { + return new ConsumerSessionImpl(cons); + } + + private ProviderSessionImpl newSessionFor(BindingAwareProvider provider) { + return new ProviderSessionImpl(provider); + } + + private T newSALServiceForSession( + Class service, ConsumerSession session) { + + SALBindingModule serviceProvider = salServiceProviders.get(service); + if (serviceProvider == null) { + return null; + } + return serviceProvider.getServiceForSession(service, session); + + } + + private class ConsumerSessionImpl implements + BindingAwareBroker.ConsumerSession { + + private final BindingAwareConsumer consumer; + private Map, BindingAwareService> sessionSalServices = new HashMap, BindingAwareService>(); + + public ConsumerSessionImpl(BindingAwareConsumer cons) { + this.consumer = cons; + } + + @Override + public T getSALService(Class service) { + + BindingAwareService serv = sessionSalServices.get(service); + if (serv != null) { + if (service.isInstance(serv)) { + @SuppressWarnings("unchecked") + T ret = (T) serv; + return ret; + } else { + log.error("Implementation for service " + service.getName() + + " does not implement the service interface"); + throw new IllegalStateException("Service implementation " + + serv.getClass().getName() + "does not implement " + + service.getName()); + } + } else { + T ret = BindingBrokerImpl.this.newSALServiceForSession(service, + this); + if (ret != null) { + sessionSalServices.put(service, ret); + } + return ret; + } + } + + @Override + public T getRpcService(Class module) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + public BindingAwareConsumer getConsumer() { + return this.consumer; + } + + } + + private class ProviderSessionImpl extends ConsumerSessionImpl implements + BindingAwareBroker.ProviderSession { + + private final BindingAwareProvider provider; + + public ProviderSessionImpl(BindingAwareProvider provider2) { + super(null); + this.provider = provider2; + } + + @Override + public void addRpcImplementation(RpcService implementation) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void removeRpcImplementation(RpcService implementation) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + public BindingAwareProvider getProvider() { + return this.provider; + } + + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java new file mode 100644 index 0000000000..810a0cbd30 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationInvoker.java @@ -0,0 +1,9 @@ +package org.opendaylight.controller.sal.binding.impl; + +import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtension; +import org.opendaylight.controller.yang.binding.Notification; +import org.opendaylight.controller.yang.binding.NotificationListener; + +public interface NotificationInvoker extends MappingExtension { + void notify(Notification notification, NotificationListener listener); +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java new file mode 100644 index 0000000000..189c58555f --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationModule.java @@ -0,0 +1,230 @@ +package org.opendaylight.controller.sal.binding.impl; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareService; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.NotificationService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; +import org.opendaylight.controller.sal.binding.spi.SALBindingModule; +import org.opendaylight.controller.sal.binding.spi.Mapper; +import org.opendaylight.controller.sal.binding.spi.MappingProvider; +import org.opendaylight.controller.sal.binding.spi.MappingProvider.MappingExtensionFactory; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.yang.binding.DataObject; +import org.opendaylight.controller.yang.binding.Notification; +import org.opendaylight.controller.yang.binding.NotificationListener; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.data.api.CompositeNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NotificationModule implements SALBindingModule { + + private ProviderSession biSession; + private org.opendaylight.controller.sal.core.api.notify.NotificationProviderService biNotifyService; + private BindingAwareBroker broker; + private MappingProvider mappingProvider; + + private Map, List> listeners = new HashMap, List>(); + private static Logger log = LoggerFactory.getLogger(NotificationModule.class); + + @Override + public Set> getProvidedServices() { + + Set> ret = new HashSet>(); + ret.add(NotificationService.class); + ret.add(NotificationProviderService.class); + return ret; + } + + @Override + public T getServiceForSession( + Class service, ConsumerSession session) { + if (service == null) + throw new IllegalArgumentException("Service should not be null"); + if (session == null) + throw new IllegalArgumentException("Session should not be null"); + + if (NotificationProviderSession.class.equals(service)) { + if (session instanceof org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderSession) { + @SuppressWarnings("unchecked") + T ret = (T) new NotificationProviderSession(session); + return ret; + } else { + throw new IllegalArgumentException( + "NotificationProviderService is available only to ProviderSession"); + } + } + + if (NotificationService.class.equals(service)) { + @SuppressWarnings("unchecked") + T ret = (T) new NotificationSession(session); + return ret; + } + return null; + } + + @Override + public Set> getSupportedProviderFunctionality() { + return Collections.emptySet(); + } + + @Override + public void setBroker(BindingAwareBroker broker) { + this.broker = broker; + } + + @Override + public void setMappingProvider(MappingProvider provider) { + this.mappingProvider = provider; + } + + @Override + public void onBISessionAvailable(ProviderSession session) { + biSession = session; + if (biSession != null) { + biNotifyService = session + .getService(org.opendaylight.controller.sal.core.api.notify.NotificationProviderService.class); + } + } + + private void notify(Notification notification) { + notifyBindingIndependent(notification); + notifyBindingAware(notification); + } + + private void notifyBindingAware(Notification notification) { + Class type = notification.getClass(); + List toNotify = listeners.get(type); + + // Invocation of notification on registered listeners + if (toNotify != null) { + + // We get factory for Notification Invoker + MappingExtensionFactory invokerFactory = mappingProvider + .getExtensionFactory(NotificationInvoker.class); + + // We get generated invoker for NoficiationListener interface + // associated to Notification Type + NotificationInvoker invoker = invokerFactory.forClass(type); + for (NotificationListener listener : toNotify) { + try { + // Invoker invokes the right method on subtype of + // NotificationListener + // associated to the type of notification + invoker.notify(notification, listener); + } catch (Exception e) { + + } + } + } + } + + private void notifyBindingIndependent(Notification notification) { + Class type = notification.getClass(); + + if (biSession == null) { + return; + } + if (biSession.isClosed()) { + return; + } + if (biNotifyService == null) { + return; + } + + // FIXME: Somehow we need to resolve this for class hierarchy. + // probably use type.getInterfaces() + Mapper mapper = mappingProvider.getMapper(type); + CompositeNode domNotification = mapper.domFromObject(notification); + + biNotifyService.sendNotification(domNotification); + } + + private class NotificationSession implements NotificationService { + private final ConsumerSession session; + + public NotificationSession(ConsumerSession session) { + this.session = session; + } + + private Map, List> sessionListeners = new HashMap, List>(); + + @Override + public void addNotificationListener( + Class notificationType, + NotificationListener listener) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public void removeNotificationListener( + Class notificationType, + NotificationListener listener) { + // TODO Implement this method + throw new UnsupportedOperationException("Not implemented"); + } + + } + + private class NotificationProviderSession extends NotificationSession + implements NotificationProviderService { + + public NotificationProviderSession(ConsumerSession session) { + super(session); + } + + @Override + public void notify(Notification notification) { + NotificationModule.this.notify(notification); + } + + } + + private class BindingIndependentListener implements org.opendaylight.controller.sal.core.api.notify.NotificationListener { + + @Override + public Set getSupportedNotifications() { + return Collections.emptySet(); + } + + @Override + public void onNotification(CompositeNode notification) { + NotificationModule.this.onBindingIndependentNotification(notification); + } + + } + + private void onBindingIndependentNotification(CompositeNode biNotification) { + QName biType = biNotification.getNodeType(); + + Mapper mapper = mappingProvider.getMapper(biType); + if(mapper == null) { + log.info("Received notification does not have a binding defined."); + return; + } + Class type = mapper.getDataObjectClass(); + + // We check if the received QName / type is really Notification + if(Notification.class.isAssignableFrom(type)) { + Notification notification = (Notification) mapper.objectFromDom(biNotification); + notifyBindingAware(notification); + } else { + // The generated type for this QName does not inherits from notification + // something went wrong - generated APIs and/or provider sending notification + // which was incorectly described in the YANG schema. + log.error("Received notification "+ biType +" is not binded as notification"); + } + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/package-info.java b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/package-info.java new file mode 100644 index 0000000000..e5f26b9b1d --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/package-info.java @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.binding.impl; \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml new file mode 100644 index 0000000000..720d1e91c3 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + org.opendaylight.controller + sal + 1.0-SNAPSHOT + + sal-binding-spi + + + + org.opendaylight.controller + sal-binding-api + 1.0-SNAPSHOT + + + org.opendaylight.controller + sal-core-api + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java new file mode 100644 index 0000000000..701e72c9dc --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/Mapper.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.binding.spi; + +import org.opendaylight.controller.yang.binding.DataObject; +import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.data.api.CompositeNode; +/** + * Translator between Binding-Independent format and generated Binding Data Objects + * + * + * + * + * @param Result Type + */ +public interface Mapper { + + QName getQName(); + Class getDataObjectClass(); + T objectFromDom(CompositeNode object); + + /** + * + * @param obj + * @return + * @throws IllegalArgumentException + */ + CompositeNode domFromObject(DataObject obj) throws IllegalArgumentException; + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java new file mode 100644 index 0000000000..a7fbb24089 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/MappingProvider.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.binding.spi; + +import org.opendaylight.controller.yang.binding.DataObject; +import org.opendaylight.controller.yang.common.QName; + +public interface MappingProvider { + + Mapper getMapper(Class type); + Mapper getMapper(QName name); + + MappingExtensionFactory getExtensionFactory(Class cls); + + public interface MappingExtension { + + } + + public interface MappingExtensionFactory { + T forClass(Class obj); + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java new file mode 100644 index 0000000000..f3ecf8004c --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-spi/src/main/java/org/opendaylight/controller/sal/binding/spi/SALBindingModule.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.binding.spi; + +import java.util.Set; + +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerSession; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; + +public interface SALBindingModule { + + void setBroker(BindingAwareBroker broker); + void onBISessionAvailable(ProviderSession session); + + void setMappingProvider(MappingProvider provider); + + Set> getProvidedServices(); + + T getServiceForSession(Class service, + ConsumerSession session); + + Set> getSupportedProviderFunctionality(); +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java index 608c24b7b5..032dd22e3c 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/ConsumerSessionImpl.java @@ -26,6 +26,7 @@ public class ConsumerSessionImpl implements ConsumerSession { private final Consumer consumer; private Map, BrokerService> instantiatedServices = new HashMap, BrokerService>(); + private boolean closed = false; public Consumer getConsumer() { return consumer; @@ -59,11 +60,16 @@ public class ConsumerSessionImpl implements ConsumerSession { @Override public void close() { Collection toStop = instantiatedServices.values(); + this.closed = true; for (BrokerService brokerService : toStop) { brokerService.closeSession(); } broker.consumerSessionClosed(this); } -} - + @Override + public boolean isClosed() { + return closed; + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java index 46a4e3f096..58ceb5f51b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java +++ b/opendaylight/sal/yang-prototype/sal/sal-broker-impl/src/main/java/org/opendaylight/controller/sal/core/impl/rpc/RpcModule.java @@ -1,11 +1,3 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - package org.opendaylight.controller.sal.core.impl.rpc; public interface RpcModule { diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java index 19c3e17779..9b3b47f8b1 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java @@ -146,6 +146,8 @@ public interface Broker { */ Future> rpc(QName rpc, CompositeNode input); + boolean isClosed(); + /** * Returns a session specific instance (implementation) of requested * service @@ -229,5 +231,8 @@ public interface Broker { */ @Override public void close(); + + @Override + boolean isClosed(); } } diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml index 91dd78c144..a162f52d69 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-demo/pom.xml @@ -10,7 +10,7 @@ - + org.opendaylight.controller sal-broker-impl 1.0-SNAPSHOT @@ -26,5 +26,34 @@ 1.7.2 runtime - + + + + + maven-assembly-plugin + 2.4 + + + jar-with-dependencies + + + + org.opendaylight.controller.sal.demo.SALDemo + + + + + + make-assembly + package + + single + + + + + + + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/DataObject.java b/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/DataObject.java new file mode 100644 index 0000000000..02a013ee19 --- /dev/null +++ b/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/DataObject.java @@ -0,0 +1,5 @@ +package org.opendaylight.controller.yang.binding; + +public interface DataObject { + +} diff --git a/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/Notification.java b/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/Notification.java index 9b8c1cff02..ae568baa43 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/Notification.java +++ b/opendaylight/sal/yang-prototype/yang/yang-binding/src/main/java/org/opendaylight/controller/yang/binding/Notification.java @@ -12,6 +12,7 @@ package org.opendaylight.controller.yang.binding; * * */ -public interface Notification { +public interface Notification extends DataObject { } + diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/BinaryTypeDefinition.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/BinaryTypeDefinition.java index babceb24d5..e99bbb14c6 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/BinaryTypeDefinition.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/BinaryTypeDefinition.java @@ -7,6 +7,8 @@ */ package org.opendaylight.controller.model.api.type; +import java.util.List; + import org.opendaylight.controller.yang.model.api.TypeDefinition; /** @@ -18,16 +20,16 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition; * 4).
* The canonical form of a binary value follows the rules in [RFC4648]. - * - * + * + * */ public interface BinaryTypeDefinition extends TypeDefinition { /** - * Returns the number of octets it that binary value contains. - * - * @return the number of octets it that binary value contains. + * Returns List of number of octets that binary value contains. + * + * @return List of number of octets that binary value contains. */ - public LengthConstraint getLengthConstraint(); + public List getLengthConstraints(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/IdentityrefTypeDefinition.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/IdentityrefTypeDefinition.java index 050802019f..1b11cd3d13 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/IdentityrefTypeDefinition.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/model/api/type/IdentityrefTypeDefinition.java @@ -7,10 +7,13 @@ */ package org.opendaylight.controller.model.api.type; +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; public interface IdentityrefTypeDefinition extends TypeDefinition { - + + public RevisionAwareXPath getPathStatement(); + public IdentityTypeDefinition getIdentity(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java index 27711c96f4..f8674176cf 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/ContainerSchemaNode.java @@ -16,6 +16,4 @@ public interface ContainerSchemaNode extends DataNodeContainer, boolean isPresenceContainer(); - MustDefinition getMustDefinition(); - } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Deviation.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Deviation.java index 83510bac0f..b3b2c06caa 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Deviation.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Deviation.java @@ -9,8 +9,6 @@ package org.opendaylight.controller.yang.model.api; public interface Deviation { - MustDefinition getMustDefinition(); - enum Deviate { NOT_SUPPORTED, ADD, REPLACE, DELETE } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafListSchemaNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafListSchemaNode.java index 2c41e19a27..1d7287f0f7 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafListSchemaNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafListSchemaNode.java @@ -13,6 +13,4 @@ public interface LeafListSchemaNode extends DataSchemaNode { boolean isUserOrdered(); - MustDefinition getMustDefinition(); - } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafSchemaNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafSchemaNode.java index ccb075f7a5..3ad047f3b9 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafSchemaNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/LeafSchemaNode.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.yang.model.api; public interface LeafSchemaNode extends DataSchemaNode { - TypeDefinition getType(); - MustDefinition getMustDefinition(); + TypeDefinition getType(); + } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Module.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Module.java index 6731844a5b..7dda61ec7e 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Module.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Module.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.yang.model.api; import java.net.URI; import java.util.Date; +import java.util.List; import java.util.Set; public interface Module extends DataNodeContainer { @@ -43,4 +44,6 @@ public interface Module extends DataNodeContainer { Set getDeviations(); + List getExtensionSchemaNodes(); + } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/RevisionAwareXPath.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/RevisionAwareXPath.java index df360eb43c..a3364d625f 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/RevisionAwareXPath.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/RevisionAwareXPath.java @@ -8,5 +8,21 @@ package org.opendaylight.controller.yang.model.api; public interface RevisionAwareXPath { - + + + /** + * Returns true if the XPapth starts in root of Yang model, otherwise returns false. + * + * @return true if the XPapth starts in root of Yang model, otherwise returns false + */ + public boolean isAbsolute(); + + /** + * Returns the XPath formatted string as is defined in model. + *
+ * For example: /prefix:container/prefix:container::cond[when()=foo]/prefix:leaf + * + * @return the XPath formatted string as is defined in model. + */ + public String toString(); } diff --git a/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/src/main/java/org/opendaylight/controller/sal/schema/api/SchemaContext.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaContext.java similarity index 61% rename from opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/src/main/java/org/opendaylight/controller/sal/schema/api/SchemaContext.java rename to opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaContext.java index 009b21cf25..c497c3d169 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-schema-repository-api/src/main/java/org/opendaylight/controller/sal/schema/api/SchemaContext.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaContext.java @@ -1,30 +1,28 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.schema.api; - -import java.util.Set; - -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.Module; -import org.opendaylight.controller.yang.model.api.NotificationDefinition; -import org.opendaylight.controller.yang.model.api.RpcDefinition; - - -/** - * - */ -public interface SchemaContext { - - Set getDataDefinitions(); - - Set getModules(); - - Set getNotifications(); - - Set getOperations(); -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.yang.model.api; + +import java.util.Set; + + + +/** + * + */ +public interface SchemaContext { + + Set getDataDefinitions(); + + Set getModules(); + + Set getNotifications(); + + Set getOperations(); + + Set getExtensions(); +} diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaNode.java index 97ca6a9585..4d3c48654d 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/SchemaNode.java @@ -23,5 +23,5 @@ public interface SchemaNode { public Status getStatus(); - public List getExtensionSchemaNodes(); + public List getUnknownSchemaNodes(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Status.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Status.java index 0cb3f14149..9a49d79d32 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Status.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/Status.java @@ -8,5 +8,5 @@ package org.opendaylight.controller.yang.model.api; public enum Status { - CURRENT, DEPRECATED, OBSOLOTE + CURRENT, DEPRECATED, OBSOLETE } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustAwareBuilder.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java similarity index 51% rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustAwareBuilder.java rename to opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java index 4798590fb9..f6f4ac7141 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/model/parser/builder/MustAwareBuilder.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java @@ -5,13 +5,8 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.model.parser.builder; +package org.opendaylight.controller.yang.model.api; -/** - * Interface for all nodes which can contain 'must' definition: [container, leaf, leaf-list, list, anyxml, deviate] - */ -public interface MustAwareBuilder { - - void setMustDefinitionBuilder(MustDefinitionBuilder mustDefinitionBuilder); +public interface UnknownSchemaNode extends SchemaNode { } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.java b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.java index 61a6d69d60..715dce7027 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.java @@ -7,7 +7,12 @@ */ package org.opendaylight.controller.yang.model.api; +import java.util.Set; + public interface UsesNode { + SchemaPath getGroupingPath(); + Set getAugmentations(); + boolean isAugmenting(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/AbstractInteger.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/AbstractInteger.java index 58040225c1..33cb2b0268 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/AbstractInteger.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/AbstractInteger.java @@ -13,9 +13,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.IntegerTypeDefinition; import org.opendaylight.controller.model.api.type.RangeConstraint; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public abstract class AbstractInteger implements IntegerTypeDefinition { @@ -112,7 +112,7 @@ public abstract class AbstractInteger implements IntegerTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BinaryType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BinaryType.java index 99a948960b..7429c01531 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BinaryType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BinaryType.java @@ -13,9 +13,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.BinaryTypeDefinition; import org.opendaylight.controller.model.api.type.LengthConstraint; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class BinaryType implements BinaryTypeDefinition { @@ -25,29 +25,28 @@ public class BinaryType implements BinaryTypeDefinition { private final String reference = ""; private List bytes; - private final LengthConstraint lengthConstraint; + private final List lengthConstraints; private String units = ""; public BinaryType() { super(); - lengthConstraint = BaseConstraints.lengthConstraint(0L, Long.MAX_VALUE, - null, null); + lengthConstraints = Collections.emptyList(); bytes = Collections.emptyList(); bytes = Collections.unmodifiableList(bytes); } public BinaryType(final List bytes, - final LengthConstraint lengthConstraint, final String units) { + final List lengthConstraints, final String units) { super(); this.bytes = bytes; - this.lengthConstraint = lengthConstraint; + this.lengthConstraints = lengthConstraints; this.units = units; } /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() */ @Override @@ -57,7 +56,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits() */ @Override @@ -67,7 +66,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue() */ @Override @@ -77,7 +76,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName() */ @Override @@ -87,7 +86,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath() */ @Override @@ -97,7 +96,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() */ @Override @@ -107,7 +106,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference() */ @Override @@ -117,7 +116,7 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus() */ @Override @@ -127,18 +126,18 @@ public class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition#getLengthConstraint * () */ @Override - public LengthConstraint getLengthConstraint() { - return lengthConstraint; + public List getLengthConstraints() { + return lengthConstraints; } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } @@ -151,7 +150,7 @@ public class BinaryType implements BinaryTypeDefinition { + ((description == null) ? 0 : description.hashCode()); result = prime * result - + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode()); + + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result @@ -186,11 +185,11 @@ public class BinaryType implements BinaryTypeDefinition { } else if (!description.equals(other.description)) { return false; } - if (lengthConstraint == null) { - if (other.lengthConstraint != null) { + if (lengthConstraints == null) { + if (other.lengthConstraints != null) { return false; } - } else if (!lengthConstraint.equals(other.lengthConstraint)) { + } else if (!lengthConstraints.equals(other.lengthConstraints)) { return false; } if (name == null) { @@ -237,8 +236,8 @@ public class BinaryType implements BinaryTypeDefinition { builder.append(reference); builder.append(", bytes="); builder.append(bytes); - builder.append(", lengthConstraint="); - builder.append(lengthConstraint); + builder.append(", lengthConstraints="); + builder.append(lengthConstraints); builder.append(", units="); builder.append(units); builder.append("]"); diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BitsType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BitsType.java index 57deb07ba1..b783bc7730 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BitsType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BitsType.java @@ -12,9 +12,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.BitsTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class BitsType implements BitsTypeDefinition { @@ -137,7 +137,7 @@ public class BitsType implements BitsTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BooleanType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BooleanType.java index 361ef56bbd..c9d319d2c6 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BooleanType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/BooleanType.java @@ -12,9 +12,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.BooleanTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class BooleanType implements BooleanTypeDefinition { @@ -137,7 +137,7 @@ public class BooleanType implements BooleanTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Decimal64.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Decimal64.java index 5c6eac1cc2..233e4607ce 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Decimal64.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Decimal64.java @@ -15,9 +15,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.DecimalTypeDefinition; import org.opendaylight.controller.model.api.type.RangeConstraint; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class Decimal64 implements DecimalTypeDefinition { @@ -103,7 +103,7 @@ public class Decimal64 implements DecimalTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/EnumerationType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/EnumerationType.java index 34d7459b36..34ac5374f7 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/EnumerationType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/EnumerationType.java @@ -12,9 +12,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.EnumTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class EnumerationType implements EnumTypeDefinition { @@ -133,7 +133,7 @@ public class EnumerationType implements EnumTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/ExtendedType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/ExtendedType.java index 44ca80430c..87c74be7a2 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/ExtendedType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/ExtendedType.java @@ -11,10 +11,10 @@ import java.util.Collections; import java.util.List; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class ExtendedType implements TypeDefinition { @@ -23,7 +23,7 @@ public class ExtendedType implements TypeDefinition { private final SchemaPath path; private final String description; private final String reference; - private final List extensions; + private final List unknownSchemaNodes; private Status status; private String units; @@ -37,7 +37,7 @@ public class ExtendedType implements TypeDefinition { private final String description; private final String reference; - private List extensions = Collections.emptyList();; + private List unknownSchemaNodes = Collections.emptyList();; private Status status = Status.CURRENT; private String units = ""; private Object defaultValue = null; @@ -66,8 +66,8 @@ public class ExtendedType implements TypeDefinition { return this; } - public Builder extensions(final List extensions) { - this.extensions = extensions; + public Builder unknownSchemaNodes(final List unknownSchemaNodes) { + this.unknownSchemaNodes = unknownSchemaNodes; return this; } @@ -82,7 +82,7 @@ public class ExtendedType implements TypeDefinition { this.path = builder.path; this.description = builder.description; this.reference = builder.reference; - this.extensions = builder.extensions; + this.unknownSchemaNodes = builder.unknownSchemaNodes; this.status = builder.status; this.units = builder.units; this.defaultValue = builder.defaultValue; @@ -129,8 +129,8 @@ public class ExtendedType implements TypeDefinition { } @Override - public List getExtensionSchemaNodes() { - return extensions; + public List getUnknownSchemaNodes() { + return unknownSchemaNodes; } @Override @@ -144,7 +144,7 @@ public class ExtendedType implements TypeDefinition { result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result - + ((extensions == null) ? 0 : extensions.hashCode()); + + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result + ((reference == null) ? 0 : reference.hashCode()); @@ -188,11 +188,11 @@ public class ExtendedType implements TypeDefinition { } else if (!description.equals(other.description)) { return false; } - if (extensions == null) { - if (other.extensions != null) { + if (unknownSchemaNodes == null) { + if (other.unknownSchemaNodes != null) { return false; } - } else if (!extensions.equals(other.extensions)) { + } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) { return false; } if (path == null) { @@ -242,8 +242,8 @@ public class ExtendedType implements TypeDefinition { builder2.append(description); builder2.append(", reference="); builder2.append(reference); - builder2.append(", extensions="); - builder2.append(extensions); + builder2.append(", unknownSchemaNodes="); + builder2.append(unknownSchemaNodes); builder2.append(", status="); builder2.append(status); builder2.append(", units="); diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/IdentityType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/IdentityType.java index 2c102060e3..775d368eaf 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/IdentityType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/IdentityType.java @@ -12,9 +12,9 @@ import java.util.List; import org.opendaylight.controller.model.api.type.IdentityTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class IdentityType implements IdentityTypeDefinition { @@ -113,7 +113,7 @@ public class IdentityType implements IdentityTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Identityref.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Identityref.java index c4040c1f23..24ab0af1ad 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Identityref.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Identityref.java @@ -13,9 +13,10 @@ import java.util.List; import org.opendaylight.controller.model.api.type.IdentityTypeDefinition; import org.opendaylight.controller.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class Identityref implements IdentityrefTypeDefinition { @@ -25,12 +26,20 @@ public class Identityref implements IdentityrefTypeDefinition { private final String reference = ""; private final IdentityTypeDefinition identity; + private final RevisionAwareXPath xpath; private String units = ""; - public Identityref(IdentityTypeDefinition identity) { + public Identityref(RevisionAwareXPath xpath, IdentityTypeDefinition identity) { super(); this.identity = identity; + this.xpath = xpath; + } + + public Identityref(RevisionAwareXPath xpath) { + super(); + this.xpath = xpath; + this.identity = null; } /* @@ -114,7 +123,7 @@ public class Identityref implements IdentityrefTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } @@ -129,96 +138,11 @@ public class Identityref implements IdentityrefTypeDefinition { public IdentityTypeDefinition getIdentity() { return identity; } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((units == null) ? 0 : units.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Identityref other = (Identityref) obj; - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (identity == null) { - if (other.identity != null) { - return false; - } - } else if (!identity.equals(other.identity)) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (path == null) { - if (other.path != null) { - return false; - } - } else if (!path.equals(other.path)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (units == null) { - if (other.units != null) { - return false; - } - } else if (!units.equals(other.units)) { - return false; - } - return true; - } - + @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("IdentityrefType [name="); - builder.append(name); - builder.append(", path="); - builder.append(path); - builder.append(", description="); - builder.append(description); - builder.append(", reference="); - builder.append(reference); - builder.append(", identity="); - builder.append(identity); - builder.append(", units="); - builder.append(units); - builder.append("]"); - return builder.toString(); + public RevisionAwareXPath getPathStatement() { + return xpath; } + + } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/InstanceIdentifier.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/InstanceIdentifier.java index 8376d9bd62..9a238aea1f 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/InstanceIdentifier.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/InstanceIdentifier.java @@ -12,10 +12,10 @@ import java.util.List; import org.opendaylight.controller.model.api.type.InstanceIdentifierTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { @@ -122,7 +122,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes() */ @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Leafref.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Leafref.java index 53c2c82ac3..9c99d4218a 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Leafref.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/Leafref.java @@ -12,10 +12,10 @@ import java.util.List; import org.opendaylight.controller.model.api.type.LeafrefTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class Leafref implements LeafrefTypeDefinition { private static final QName name = BaseTypes.constructQName("leafref"); @@ -116,7 +116,7 @@ public class Leafref implements LeafrefTypeDefinition { * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes() */ @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/RevisionAwareXPathImpl.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/RevisionAwareXPathImpl.java new file mode 100644 index 0000000000..d3328f3804 --- /dev/null +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/RevisionAwareXPathImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.model.util; + +import org.opendaylight.controller.yang.model.api.RevisionAwareXPath; + +public class RevisionAwareXPathImpl implements RevisionAwareXPath { + + private final String xpath; + private final boolean absolute; + + public RevisionAwareXPathImpl(String xpath, boolean absolute) { + this.xpath = xpath; + this.absolute = absolute; + } + + @Override + public boolean isAbsolute() { + return absolute; + } + + @Override + public String toString() { + return xpath; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((xpath == null) ? 0 : xpath.hashCode()); + result = prime * result + (absolute ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RevisionAwareXPathImpl other = (RevisionAwareXPathImpl) obj; + if (xpath == null) { + if (other.xpath != null) { + return false; + } + } else if (!xpath.equals(other.xpath)) { + return false; + } + if (absolute != other.absolute) { + return false; + } + return false; + } + +} diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/StringType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/StringType.java index f640831297..99b6d26684 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/StringType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/StringType.java @@ -14,9 +14,9 @@ import org.opendaylight.controller.model.api.type.LengthConstraint; import org.opendaylight.controller.model.api.type.PatternConstraint; import org.opendaylight.controller.model.api.type.StringTypeDefinition; import org.opendaylight.controller.yang.common.QName; -import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class StringType implements StringTypeDefinition { @@ -159,7 +159,7 @@ public class StringType implements StringTypeDefinition { } @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return Collections.emptyList(); } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/UnknownType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/UnknownType.java index b1e1082c60..f0b5ddd286 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/UnknownType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/UnknownType.java @@ -18,6 +18,7 @@ import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; public class UnknownType implements UnknownTypeDefinition { @@ -29,7 +30,7 @@ public class UnknownType implements UnknownTypeDefinition { private final List lengthStatements; private final List patterns; private final List rangeStatements; - private final List extensions; + private final List extensions; private final LengthConstraint lengthConstraint; private final Status status; @@ -47,7 +48,7 @@ public class UnknownType implements UnknownTypeDefinition { .emptyList(); private List patterns = Collections.emptyList(); private List rangeStatements = Collections.emptyList(); - private List extensions = Collections.emptyList(); + private List extensions = Collections.emptyList(); private LengthConstraint lengthConstraint = null; private Status status = Status.CURRENT; @@ -94,7 +95,7 @@ public class UnknownType implements UnknownTypeDefinition { return this; } - public Builder extensions(final List extensions) { + public Builder extensions(final List extensions) { this.extensions = extensions; return this; } @@ -231,7 +232,7 @@ public class UnknownType implements UnknownTypeDefinition { * () */ @Override - public List getExtensionSchemaNodes() { + public List getUnknownSchemaNodes() { return extensions; } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/YangTypesConverter.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/YangTypesConverter.java index 1ab1dc63b1..a09d27e340 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/YangTypesConverter.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/model/util/YangTypesConverter.java @@ -59,16 +59,21 @@ public class YangTypesConverter { baseYangTypes.add("bits"); baseYangTypes.add("boolean"); baseYangTypes.add("decimal64"); + baseYangTypes.add("empty"); baseYangTypes.add("enumeration"); + baseYangTypes.add("identityref"); + baseYangTypes.add("instance-identifier"); baseYangTypes.add("int8"); baseYangTypes.add("int16"); baseYangTypes.add("int32"); baseYangTypes.add("int64"); + baseYangTypes.add("leafref"); baseYangTypes.add("string"); baseYangTypes.add("uint8"); baseYangTypes.add("uint16"); baseYangTypes.add("uint32"); baseYangTypes.add("uint64"); + baseYangTypes.add("union"); } public static boolean isBaseYangType(String type) { -- 2.36.6