From 71796f7bd699504e4de34d1e4d8d30b73f230bf5 Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Tue, 10 Sep 2013 08:23:14 +0200 Subject: [PATCH] Fixing sonar issues 4 + unit test Int8Test.java for Int8.java was added Change-Id: Ia89f741fd46be332a8e212352798eff47eb6215c Signed-off-by: Jozef Gloncak --- .../generator/impl/BindingGeneratorImpl.xtend | 2082 ++++++++--------- .../binding/yang/types/TypeProviderImpl.java | 3 +- .../yang/data/impl/AbstractNodeTO.java | 328 +-- .../yang/data/impl/CompositeNodeTOImpl.java | 3 +- .../data/impl/MutableSimpleNodeTOImpl.java | 126 +- .../impl/NodeModificationBuilderImpl.java | 323 ++- .../yangtools/yang/data/impl/NodeUtils.java | 510 ++-- .../impl/NodeModificationBuilderImplTest.java | 597 +++-- .../yangtools/yang2sources/plugin/Util.java | 46 +- .../plugin/YangToSourcesMojo.java | 10 +- .../plugin/YangToSourcesProcessor.java | 19 +- .../plugin/GenerateSourcesTest.java | 4 +- .../yang/model/api/AugmentationSchema.java | 110 +- .../yangtools/yang/model/api/Deviation.java | 106 +- .../yang/model/api/ExtensionDefinition.java | 4 +- .../yang/model/api/ListSchemaNode.java | 77 +- .../yang/model/api/RevisionAwareXPath.java | 4 +- .../yangtools/yang/model/api/SchemaNode.java | 12 +- .../yangtools/yang/model/api/SchemaPath.java | 8 +- .../model/api/type/EnumTypeDefinition.java | 4 +- .../api/type/IdentityTypeDefinition.java | 2 +- .../InstanceIdentifierTypeDefinition.java | 4 +- yang/yang-model-util/.gitignore | 1 + yang/yang-model-util/pom.xml | 126 +- .../model/util/AbstractSignedInteger.java | 18 +- .../model/util/AbstractUnsignedInteger.java | 20 +- .../yang/model/util/BaseConstraints.java | 68 +- .../yangtools/yang/model/util/BaseTypes.java | 145 +- .../yangtools/yang/model/util/BinaryType.java | 62 +- .../yangtools/yang/model/util/BitsType.java | 50 +- .../yang/model/util/BooleanType.java | 42 +- .../yang/model/util/DataNodeIterator.java | 279 +-- .../yangtools/yang/model/util/Decimal64.java | 43 +- .../yangtools/yang/model/util/EmptyType.java | 20 +- .../yang/model/util/EnumerationType.java | 99 +- .../yang/model/util/IdentityrefType.java | 190 +- .../yang/model/util/InstanceIdentifier.java | 67 +- .../yangtools/yang/model/util/Int16.java | 10 +- .../yangtools/yang/model/util/Int32.java | 12 +- .../yangtools/yang/model/util/Int64.java | 10 +- .../yangtools/yang/model/util/Int8.java | 10 +- .../model/util/RevisionAwareXPathImpl.java | 10 +- .../yangtools/yang/model/util/StringType.java | 116 +- .../yangtools/yang/model/util/Uint16.java | 10 +- .../yangtools/yang/model/util/Uint32.java | 10 +- .../yangtools/yang/model/util/Uint64.java | 10 +- .../yangtools/yang/model/util/Uint8.java | 10 +- .../yangtools/yang/model/util/UnionType.java | 11 +- .../yang/model/util/UnknownType.java | 84 +- .../yang/model/util/YangTypesConverter.java | 172 +- .../yangtools/yang/model/util/Int8Test.java | 20 + .../model/parser/api/YangModelParser.java | 17 +- .../yang/parser/util/Comparators.java | 2 +- .../yang/parser/util/RefineUtils.java | 10 +- .../yang/parser/impl/TypesResolutionTest.java | 2 +- 55 files changed, 3030 insertions(+), 3108 deletions(-) create mode 100644 yang/yang-model-util/.gitignore create mode 100644 yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend index 838406c545..364785dede 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend @@ -53,7 +53,6 @@ import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.util.DataNodeIterator; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; import org.opendaylight.yangtools.yang.model.util.UnionType; import static com.google.common.base.Preconditions.*; @@ -62,28 +61,29 @@ import static org.opendaylight.yangtools.binding.generator.util.BindingGenerator import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*; import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort +import org.opendaylight.yangtools.yang.model.util.ExtendedType; public class BindingGeneratorImpl implements BindingGenerator { - /** + /** * Outter key represents the package name. Outter value represents map of * all builders in the same package. Inner key represents the schema node * name (in JAVA class/interface name format). Inner value represents * instance of builder for schema node specified in key part. */ - private Map> genTypeBuilders; + private Map> genTypeBuilders; - /** + /** * Provide methods for converting YANG types to JAVA types. */ - private var TypeProvider typeProvider; + private var TypeProvider typeProvider; - /** + /** * Holds reference to schema context to resolve data of augmented elemnt * when creating augmentation builder */ - private var SchemaContext schemaContext; + private var SchemaContext schemaContext; - /** + /** * Each grouping which is converted from schema node to generated type is * added to this map with its Schema path as key to make it easier to get * reference to it. In schema nodes in uses attribute there is @@ -91,21 +91,21 @@ public class BindingGeneratorImpl implements BindingGenerator { * Schema node the object of type Type is required. So in this * case is used this map. */ - private val allGroupings = new HashMap(); + private val allGroupings = new HashMap(); - private val yangToJavaMapping = new HashMap(); + private val yangToJavaMapping = new HashMap(); - /** + /** * Constant with the concrete name of namespace. */ - private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext"; + private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext"; - /** + /** * Constant with the concrete name of identifier. */ - private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier"; + private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier"; - /** + /** * Resolves generated types from context schema nodes of all * modules. * @@ -123,17 +123,17 @@ public class BindingGeneratorImpl implements BindingGenerator { * @throws IllegalStateException * if context contain no modules */ - override generateTypes(SchemaContext context) { - checkArgument(context !== null, "Schema Context reference cannot be NULL."); - checkState(context.modules !== null, "Schema Context does not contain defined modules."); - val List generatedTypes = new ArrayList(); - schemaContext = context; - typeProvider = new TypeProviderImpl(context); - val Set modules = context.modules; - return generateTypes(context, modules); - } - - /** + override generateTypes(SchemaContext context) { + checkArgument(context !== null, "Schema Context reference cannot be NULL."); + checkState(context.modules !== null, "Schema Context does not contain defined modules."); + val List generatedTypes = new ArrayList(); + schemaContext = context; + typeProvider = new TypeProviderImpl(context); + val Set modules = context.modules; + return generateTypes(context, modules); + } + + /** * Resolves generated types from context schema nodes only for * modules specified in modules * @@ -161,47 +161,47 @@ public class BindingGeneratorImpl implements BindingGenerator { * @throws IllegalStateException * if context contain no modules */ - override generateTypes(SchemaContext context, Set modules) { - checkArgument(context !== null, "Schema Context reference cannot be NULL."); - checkState(context.modules !== null, "Schema Context does not contain defined modules."); - checkArgument(modules !== null, "Set of Modules cannot be NULL."); - - val List filteredGenTypes = new ArrayList(); - - schemaContext = context; - typeProvider = new TypeProviderImpl(context); - val contextModules = ModuleDependencySort.sort(context.modules); - genTypeBuilders = new HashMap(); - - for (contextModule : contextModules) { - val List generatedTypes = new ArrayList(); - generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule)); - generatedTypes.addAll(allGroupingsToGenTypes(contextModule)); - if (false == contextModule.childNodes.isEmpty()) { - generatedTypes.add(moduleToDataType(contextModule)); - } - generatedTypes.addAll(allContainersToGenTypes(contextModule)); - generatedTypes.addAll(allListsToGenTypes(contextModule)); - generatedTypes.addAll(allChoicesToGenTypes(contextModule)); - generatedTypes.addAll(allRPCMethodsToGenType(contextModule)); - generatedTypes.addAll(allNotificationsToGenType(contextModule)); - generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context)); - - if (modules.contains(contextModule)) { - filteredGenTypes.addAll(generatedTypes); - } - } - for (contextModule : contextModules) { - val generatedTypes = (allAugmentsToGenTypes(contextModule)); - if (modules.contains(contextModule)) { - filteredGenTypes.addAll(generatedTypes); - } - - } - return filteredGenTypes; - } - - /** + override generateTypes(SchemaContext context, Set modules) { + checkArgument(context !== null, "Schema Context reference cannot be NULL."); + checkState(context.modules !== null, "Schema Context does not contain defined modules."); + checkArgument(modules !== null, "Set of Modules cannot be NULL."); + + val List filteredGenTypes = new ArrayList(); + + schemaContext = context; + typeProvider = new TypeProviderImpl(context); + val contextModules = ModuleDependencySort.sort(context.modules); + genTypeBuilders = new HashMap(); + + for (contextModule : contextModules) { + val List generatedTypes = new ArrayList(); + generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule)); + generatedTypes.addAll(allGroupingsToGenTypes(contextModule)); + if (false == contextModule.childNodes.isEmpty()) { + generatedTypes.add(moduleToDataType(contextModule)); + } + generatedTypes.addAll(allContainersToGenTypes(contextModule)); + generatedTypes.addAll(allListsToGenTypes(contextModule)); + generatedTypes.addAll(allChoicesToGenTypes(contextModule)); + generatedTypes.addAll(allRPCMethodsToGenType(contextModule)); + generatedTypes.addAll(allNotificationsToGenType(contextModule)); + generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context)); + + if (modules.contains(contextModule)) { + filteredGenTypes.addAll(generatedTypes); + } + } + for (contextModule : contextModules) { + val generatedTypes = (allAugmentsToGenTypes(contextModule)); + if (modules.contains(contextModule)) { + filteredGenTypes.addAll(generatedTypes); + } + + } + return filteredGenTypes; + } + + /** * Converts all extended type definitions of module to the list of * Type objects. * @@ -217,25 +217,25 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allTypeDefinitionsToGenTypes(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - checkArgument(module.name !== null, "Module name cannot be NULL."); - val Set> typeDefinitions = module.typeDefinitions; - checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.'''); - - val List generatedTypes = new ArrayList(); - for (TypeDefinition typedef : typeDefinitions) { - if (typedef !== null) { - val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef); - if ((type !== null) && !generatedTypes.contains(type)) { - generatedTypes.add(type); - } - } - } - return generatedTypes; - } - - /** + private def List allTypeDefinitionsToGenTypes(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + checkArgument(module.name !== null, "Module name cannot be NULL."); + val Set> typeDefinitions = module.typeDefinitions; + checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.'''); + + val List generatedTypes = new ArrayList(); + for (TypeDefinition typedef : typeDefinitions) { + if (typedef !== null) { + val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef); + if ((type !== null) && !generatedTypes.contains(type)) { + generatedTypes.add(type); + } + } + } + return generatedTypes; + } + + /** * Converts all containers of the module to the list of * Type objects. * @@ -252,29 +252,29 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allContainersToGenTypes(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - - checkArgument(module.name !== null, "Module name cannot be NULL."); - - if (module.childNodes === null) { - throw new IllegalArgumentException( - "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL."); - } - - val List generatedTypes = new ArrayList(); - val it = new DataNodeIterator(module); - val List schemaContainers = it.allContainers(); - val basePackageName = moduleNamespaceToPackageName(module); - for (container : schemaContainers) { - if (!container.isAddedByUses()) { - generatedTypes.add(containerToGenType(basePackageName, container)); - } - } - return generatedTypes; - } - - /** + private def List allContainersToGenTypes(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + + checkArgument(module.name !== null, "Module name cannot be NULL."); + + if (module.childNodes === null) { + throw new IllegalArgumentException( + "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL."); + } + + val List generatedTypes = new ArrayList(); + val it = new DataNodeIterator(module); + val List schemaContainers = it.allContainers(); + val basePackageName = moduleNamespaceToPackageName(module); + for (container : schemaContainers) { + if (!container.isAddedByUses()) { + generatedTypes.add(containerToGenType(basePackageName, container)); + } + } + return generatedTypes; + } + + /** * Converts all lists of the module to the list of Type * objects. * @@ -291,30 +291,30 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allListsToGenTypes(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - checkArgument(module.name !== null, "Module name cannot be NULL."); - - if (module.childNodes === null) { - throw new IllegalArgumentException( - "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL."); - } - - val List generatedTypes = new ArrayList(); - val it = new DataNodeIterator(module); - val List schemaLists = it.allLists(); - val basePackageName = moduleNamespaceToPackageName(module); - if (schemaLists !== null) { - for (list : schemaLists) { - if (!list.isAddedByUses()) { - generatedTypes.addAll(listToGenType(basePackageName, list)); - } - } - } - return generatedTypes; - } - - /** + private def List allListsToGenTypes(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + checkArgument(module.name !== null, "Module name cannot be NULL."); + + if (module.childNodes === null) { + throw new IllegalArgumentException( + "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL."); + } + + val List generatedTypes = new ArrayList(); + val it = new DataNodeIterator(module); + val List schemaLists = it.allLists(); + val basePackageName = moduleNamespaceToPackageName(module); + if (schemaLists !== null) { + for (list : schemaLists) { + if (!list.isAddedByUses()) { + generatedTypes.addAll(listToGenType(basePackageName, list)); + } + } + } + return generatedTypes; + } + + /** * Converts all choices of the module to the list of * Type objects. * @@ -330,24 +330,24 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allChoicesToGenTypes(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - checkArgument(module.name !== null, "Module name cannot be NULL."); - - val it = new DataNodeIterator(module); - val choiceNodes = it.allChoices(); - val basePackageName = moduleNamespaceToPackageName(module); - - val List generatedTypes = new ArrayList(); - for (choice : choiceNodes) { - if ((choice !== null) && !choice.isAddedByUses()) { - generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice)); - } - } - return generatedTypes; - } - - /** + private def List allChoicesToGenTypes(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + checkArgument(module.name !== null, "Module name cannot be NULL."); + + val it = new DataNodeIterator(module); + val choiceNodes = it.allChoices(); + val basePackageName = moduleNamespaceToPackageName(module); + + val List generatedTypes = new ArrayList(); + for (choice : choiceNodes) { + if ((choice !== null) && !choice.isAddedByUses()) { + generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice)); + } + } + return generatedTypes; + } + + /** * Converts all augmentation of the module to the list * Type objects. * @@ -364,24 +364,24 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allAugmentsToGenTypes(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - checkArgument(module.name !== null, "Module name cannot be NULL."); - if (module.childNodes === null) { - throw new IllegalArgumentException( - "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL."); - } - - val List generatedTypes = new ArrayList(); - val basePackageName = moduleNamespaceToPackageName(module); - val List augmentations = resolveAugmentations(module); - for (augment : augmentations) { - generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment)); - } - return generatedTypes; - } - - /** + private def List allAugmentsToGenTypes(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + checkArgument(module.name !== null, "Module name cannot be NULL."); + if (module.childNodes === null) { + throw new IllegalArgumentException( + "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL."); + } + + val List generatedTypes = new ArrayList(); + val basePackageName = moduleNamespaceToPackageName(module); + val List augmentations = resolveAugmentations(module); + for (augment : augmentations) { + generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment)); + } + return generatedTypes; + } + + /** * Returns list of AugmentationSchema objects. The objects are * sorted according to the length of their target path from the shortest to * the longest. @@ -397,25 +397,25 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List resolveAugmentations(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - checkState(module.augmentations !== null, "Augmentations Set cannot be NULL."); - - val Set augmentations = module.augmentations; - val List sortedAugmentations = new ArrayList(augmentations); - Collections.sort(sortedAugmentations, - [ augSchema1, augSchema2 | - if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) { - return 1; - } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) { - return -1; - } - return 0; - ]); - return sortedAugmentations; - } - - /** + private def List resolveAugmentations(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + checkState(module.augmentations !== null, "Augmentations Set cannot be NULL."); + + val Set augmentations = module.augmentations; + val List sortedAugmentations = new ArrayList(augmentations); + Collections.sort(sortedAugmentations, + [ augSchema1, augSchema2 | + if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) { + return 1; + } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) { + return -1; + } + return 0; + ]); + return sortedAugmentations; + } + + /** * Converts whole module to GeneratedType object. * Firstly is created the module builder object from which is vally * obtained reference to GeneratedType object. @@ -429,22 +429,22 @@ public class BindingGeneratorImpl implements BindingGenerator { * if the module equals null * */ - private def GeneratedType moduleToDataType(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - - val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data"); - addImplementedInterfaceFromUses(module, moduleDataTypeBuilder); - moduleDataTypeBuilder.addImplementsType(DATA_ROOT); - - val basePackageName = moduleNamespaceToPackageName(module); - if (moduleDataTypeBuilder !== null) { - val Set dataNodes = module.childNodes; - resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes); - } - return moduleDataTypeBuilder.toInstance(); - } - - /** + private def GeneratedType moduleToDataType(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + + val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data"); + addImplementedInterfaceFromUses(module, moduleDataTypeBuilder); + moduleDataTypeBuilder.addImplementsType(DATA_ROOT); + + val basePackageName = moduleNamespaceToPackageName(module); + if (moduleDataTypeBuilder !== null) { + val Set dataNodes = module.childNodes; + resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes); + } + return moduleDataTypeBuilder.toInstance(); + } + + /** * Converts all rpcs inputs and outputs substatements of the module * to the list of Type objects. In addition are to containers * and lists which belong to input or output also part of returning list. @@ -462,91 +462,91 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allRPCMethodsToGenType(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - - checkArgument(module.name !== null, "Module name cannot be NULL."); - - if (module.childNodes === null) { - throw new IllegalArgumentException( - "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL."); - } - - val basePackageName = moduleNamespaceToPackageName(module); - val Set rpcDefinitions = module.rpcs; - - if (rpcDefinitions.isEmpty()) { - return Collections.emptyList(); - } - - val List genRPCTypes = new ArrayList(); - val interfaceBuilder = moduleTypeBuilder(module, "Service"); - interfaceBuilder.addImplementsType(Types.typeForClass(RpcService)); - for (rpc : rpcDefinitions) { - if (rpc !== null) { - - val rpcName = parseToClassName(rpc.QName.localName); - val rpcMethodName = parseToValidParamName(rpcName); - val method = interfaceBuilder.addMethod(rpcMethodName); - - val rpcInOut = new ArrayList(); - - val input = rpc.input; - val output = rpc.output; - - if (input !== null) { - rpcInOut.add(new DataNodeIterator(input)); - val inType = addRawInterfaceDefinition(basePackageName, input, rpcName); - addImplementedInterfaceFromUses(input, inType); - inType.addImplementsType(DATA_OBJECT); - inType.addImplementsType(augmentable(inType)); - resolveDataSchemaNodes(basePackageName, inType, input.childNodes); - val inTypeInstance = inType.toInstance(); - genRPCTypes.add(inTypeInstance); - method.addParameter(inTypeInstance, "input"); - } - - var Type outTypeInstance = VOID; - if (output !== null) { - rpcInOut.add(new DataNodeIterator(output)); - val outType = addRawInterfaceDefinition(basePackageName, output, rpcName); - addImplementedInterfaceFromUses(output, outType); - outType.addImplementsType(DATA_OBJECT); - outType.addImplementsType(augmentable(outType)); - - resolveDataSchemaNodes(basePackageName, outType, output.childNodes); - outTypeInstance = outType.toInstance(); - genRPCTypes.add(outTypeInstance); - - } - - val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance); - method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes)); - for (iter : rpcInOut) { - val List nContainers = iter.allContainers(); - if ((nContainers !== null) && !nContainers.isEmpty()) { - for (container : nContainers) { - if (!container.isAddedByUses()) { - genRPCTypes.add(containerToGenType(basePackageName, container)); - } - } - } - val List nLists = iter.allLists(); - if ((nLists !== null) && !nLists.isEmpty()) { - for (list : nLists) { - if (!list.isAddedByUses()) { - genRPCTypes.addAll(listToGenType(basePackageName, list)); - } - } - } - } - } - } - genRPCTypes.add(interfaceBuilder.toInstance()); - return genRPCTypes; - } - - /** + private def List allRPCMethodsToGenType(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + + checkArgument(module.name !== null, "Module name cannot be NULL."); + + if (module.childNodes === null) { + throw new IllegalArgumentException( + "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL."); + } + + val basePackageName = moduleNamespaceToPackageName(module); + val Set rpcDefinitions = module.rpcs; + + if (rpcDefinitions.isEmpty()) { + return Collections.emptyList(); + } + + val List genRPCTypes = new ArrayList(); + val interfaceBuilder = moduleTypeBuilder(module, "Service"); + interfaceBuilder.addImplementsType(Types.typeForClass(RpcService)); + for (rpc : rpcDefinitions) { + if (rpc !== null) { + + val rpcName = parseToClassName(rpc.QName.localName); + val rpcMethodName = parseToValidParamName(rpcName); + val method = interfaceBuilder.addMethod(rpcMethodName); + + val rpcInOut = new ArrayList(); + + val input = rpc.input; + val output = rpc.output; + + if (input !== null) { + rpcInOut.add(new DataNodeIterator(input)); + val inType = addRawInterfaceDefinition(basePackageName, input, rpcName); + addImplementedInterfaceFromUses(input, inType); + inType.addImplementsType(DATA_OBJECT); + inType.addImplementsType(augmentable(inType)); + resolveDataSchemaNodes(basePackageName, inType, input.childNodes); + val inTypeInstance = inType.toInstance(); + genRPCTypes.add(inTypeInstance); + method.addParameter(inTypeInstance, "input"); + } + + var Type outTypeInstance = VOID; + if (output !== null) { + rpcInOut.add(new DataNodeIterator(output)); + val outType = addRawInterfaceDefinition(basePackageName, output, rpcName); + addImplementedInterfaceFromUses(output, outType); + outType.addImplementsType(DATA_OBJECT); + outType.addImplementsType(augmentable(outType)); + + resolveDataSchemaNodes(basePackageName, outType, output.childNodes); + outTypeInstance = outType.toInstance(); + genRPCTypes.add(outTypeInstance); + + } + + val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance); + method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes)); + for (iter : rpcInOut) { + val List nContainers = iter.allContainers(); + if ((nContainers !== null) && !nContainers.isEmpty()) { + for (container : nContainers) { + if (!container.isAddedByUses()) { + genRPCTypes.add(containerToGenType(basePackageName, container)); + } + } + } + val List nLists = iter.allLists(); + if ((nLists !== null) && !nLists.isEmpty()) { + for (list : nLists) { + if (!list.isAddedByUses()) { + genRPCTypes.addAll(listToGenType(basePackageName, list)); + } + } + } + } + } + } + genRPCTypes.add(interfaceBuilder.toInstance()); + return genRPCTypes; + } + + /** * Converts all notifications of the module to the list of * Type objects. In addition are to this list added containers * and lists which are part of this notification. @@ -564,59 +564,59 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List allNotificationsToGenType(Module module) { - checkArgument(module !== null, "Module reference cannot be NULL."); - - checkArgument(module.name !== null, "Module name cannot be NULL."); - - if (module.childNodes === null) { - throw new IllegalArgumentException( - "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL."); - } - val notifications = module.notifications; - if(notifications.isEmpty()) return Collections.emptyList(); - - val listenerInterface = moduleTypeBuilder(module, "Listener"); - listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER); - - val basePackageName = moduleNamespaceToPackageName(module); - val List generatedTypes = new ArrayList(); - - for (notification : notifications) { - if (notification !== null) { - val iter = new DataNodeIterator(notification); - - // Containers - for (node : iter.allContainers()) { - if (!node.isAddedByUses()) { - generatedTypes.add(containerToGenType(basePackageName, node)); - } - } - - // Lists - for (node : iter.allLists()) { - if (!node.isAddedByUses()) { - generatedTypes.addAll(listToGenType(basePackageName, node)); - } - } - val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification); - notificationInterface.addImplementsType(NOTIFICATION); - - // Notification object - resolveDataSchemaNodes(basePackageName, notificationInterface, notification.childNodes); - - listenerInterface.addMethod("on" + notificationInterface.name) // - .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification"). - setReturnType(Types.VOID); - - generatedTypes.add(notificationInterface.toInstance()); - } - } - generatedTypes.add(listenerInterface.toInstance()); - return generatedTypes; - } - - /** + private def List allNotificationsToGenType(Module module) { + checkArgument(module !== null, "Module reference cannot be NULL."); + + checkArgument(module.name !== null, "Module name cannot be NULL."); + + if (module.childNodes === null) { + throw new IllegalArgumentException( + "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL."); + } + val notifications = module.notifications; + if(notifications.isEmpty()) return Collections.emptyList(); + + val listenerInterface = moduleTypeBuilder(module, "Listener"); + listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER); + + val basePackageName = moduleNamespaceToPackageName(module); + val List generatedTypes = new ArrayList(); + + for (notification : notifications) { + if (notification !== null) { + val iter = new DataNodeIterator(notification); + + // Containers + for (node : iter.allContainers()) { + if (!node.isAddedByUses()) { + generatedTypes.add(containerToGenType(basePackageName, node)); + } + } + + // Lists + for (node : iter.allLists()) { + if (!node.isAddedByUses()) { + generatedTypes.addAll(listToGenType(basePackageName, node)); + } + } + val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification); + notificationInterface.addImplementsType(NOTIFICATION); + + // Notification object + resolveDataSchemaNodes(basePackageName, notificationInterface, notification.childNodes); + + listenerInterface.addMethod("on" + notificationInterface.name) // + .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification"). + setReturnType(Types.VOID); + + generatedTypes.add(notificationInterface.toInstance()); + } + } + generatedTypes.add(listenerInterface.toInstance()); + return generatedTypes; + } + + /** * Converts all identities of the module to the list of * Type objects. * @@ -630,22 +630,22 @@ public class BindingGeneratorImpl implements BindingGenerator { * (object of type IdentitySchemaNode * */ - private def List allIdentitiesToGenTypes(Module module, SchemaContext context) { - val List genTypes = new ArrayList(); + private def List allIdentitiesToGenTypes(Module module, SchemaContext context) { + val List genTypes = new ArrayList(); - val Set schemaIdentities = module.identities; + val Set schemaIdentities = module.identities; - val basePackageName = moduleNamespaceToPackageName(module); + val basePackageName = moduleNamespaceToPackageName(module); - if (schemaIdentities !== null && !schemaIdentities.isEmpty()) { - for (identity : schemaIdentities) { - genTypes.add(identityToGenType(basePackageName, identity, context)); - } - } - return genTypes; - } + if (schemaIdentities !== null && !schemaIdentities.isEmpty()) { + for (identity : schemaIdentities) { + genTypes.add(identityToGenType(basePackageName, identity, context)); + } + } + return genTypes; + } - /** + /** * Converts the identity object to GeneratedType. Firstly it is * created transport object builder. If identity contains base identity then * reference to base identity is added to superior identity as its extend. @@ -665,33 +665,33 @@ public class BindingGeneratorImpl implements BindingGenerator { * IdentitySchemaNode * */ - private def GeneratedType identityToGenType(String basePackageName, IdentitySchemaNode identity, - SchemaContext context) { - if (identity === null) { - return null; - } - - val packageName = packageNameForGeneratedType(basePackageName, identity.path); - val genTypeName = parseToClassName(identity.QName.localName); - val newType = new GeneratedTOBuilderImpl(packageName, genTypeName); - - val baseIdentity = identity.baseIdentity; - if (baseIdentity !== null) { - val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity); - - val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule); - val returnTypeName = parseToClassName(baseIdentity.QName.localName); - - val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance(); - newType.setExtendsType(gto); - } else { - newType.setExtendsType(Types.baseIdentityTO); - } - newType.setAbstract(true); - return newType.toInstance(); - } - - /** + private def GeneratedType identityToGenType(String basePackageName, IdentitySchemaNode identity, + SchemaContext context) { + if (identity === null) { + return null; + } + + val packageName = packageNameForGeneratedType(basePackageName, identity.path); + val genTypeName = parseToClassName(identity.QName.localName); + val newType = new GeneratedTOBuilderImpl(packageName, genTypeName); + + val baseIdentity = identity.baseIdentity; + if (baseIdentity !== null) { + val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity); + + val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule); + val returnTypeName = parseToClassName(baseIdentity.QName.localName); + + val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance(); + newType.setExtendsType(gto); + } else { + newType.setExtendsType(Types.baseIdentityTO); + } + newType.setAbstract(true); + return newType.toInstance(); + } + + /** * Converts all groupings of the module to the list of * Type objects. Firstly are groupings sorted according mutual * dependencies. At least dependend (indepedent) groupings are in the list @@ -705,24 +705,24 @@ public class BindingGeneratorImpl implements BindingGenerator { * (object of type GroupingDefinition) * */ - private def List allGroupingsToGenTypes(Module module) { - checkArgument(module !== null, "Module parameter can not be null"); - val List genTypes = new ArrayList(); - val basePackageName = moduleNamespaceToPackageName(module); - val Set groupings = module.groupings; - val List groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort( - groupings); - - for (grouping : groupingsSortedByDependencies) { - val genType = groupingToGenType(basePackageName, grouping); - genTypes.add(genType); - val schemaPath = grouping.path; - allGroupings.put(schemaPath, genType); - } - return genTypes; - } - - /** + private def List allGroupingsToGenTypes(Module module) { + checkArgument(module !== null, "Module parameter can not be null"); + val List genTypes = new ArrayList(); + val basePackageName = moduleNamespaceToPackageName(module); + val Set groupings = module.groupings; + val List groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort( + groupings); + + for (grouping : groupingsSortedByDependencies) { + val genType = groupingToGenType(basePackageName, grouping); + genTypes.add(genType); + val schemaPath = grouping.path; + allGroupings.put(schemaPath, genType); + } + return genTypes; + } + + /** * Converts individual grouping to GeneratedType. Firstly generated type * builder is created and every child node of grouping is resolved to the * method. @@ -734,20 +734,20 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return GeneratedType which is generated from grouping (object of type * GroupingDefinition) */ - private def GeneratedType groupingToGenType(String basePackageName, GroupingDefinition grouping) { - if (grouping === null) { - return null; - } + private def GeneratedType groupingToGenType(String basePackageName, GroupingDefinition grouping) { + if (grouping === null) { + return null; + } - val packageName = packageNameForGeneratedType(basePackageName, grouping.path); - val Set schemaNodes = grouping.childNodes; - val typeBuilder = addDefaultInterfaceDefinition(packageName, grouping); + val packageName = packageNameForGeneratedType(basePackageName, grouping.path); + val Set schemaNodes = grouping.childNodes; + val typeBuilder = addDefaultInterfaceDefinition(packageName, grouping); - resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes); - return typeBuilder.toInstance(); - } + resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes); + return typeBuilder.toInstance(); + } - /** + /** * Tries to find EnumTypeDefinition in typeDefinition. If base * type of typeDefinition is of the type ExtendedType then this * method is recursivelly called with this base type. @@ -758,18 +758,18 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return EnumTypeDefinition if it is found inside * typeDefinition or null in other case */ - private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition typeDefinition) { - if (typeDefinition !== null) { - if (typeDefinition.baseType instanceof EnumTypeDefinition) { - return typeDefinition.baseType as EnumTypeDefinition; - } else if (typeDefinition.baseType instanceof ExtendedType) { - return enumTypeDefFromExtendedType(typeDefinition.baseType); - } - } - return null; - } - - /** + private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition typeDefinition) { + if (typeDefinition !== null) { + if (typeDefinition.baseType instanceof EnumTypeDefinition) { + return typeDefinition.baseType as EnumTypeDefinition; + } else if (typeDefinition.baseType instanceof ExtendedType) { + return enumTypeDefFromExtendedType(typeDefinition.baseType); + } + } + return null; + } + + /** * Adds enumeration builder created from enumTypeDef to * typeBuilder. * @@ -786,21 +786,21 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return enumeration builder which contais data from * enumTypeDef */ - private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, String enumName, - GeneratedTypeBuilder typeBuilder) { - if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) && - (enumTypeDef.QName.localName !== null)) { + private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, String enumName, + GeneratedTypeBuilder typeBuilder) { + if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) && + (enumTypeDef.QName.localName !== null)) { - val enumerationName = parseToClassName(enumName); - val enumBuilder = typeBuilder.addEnumeration(enumerationName); - enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef); + val enumerationName = parseToClassName(enumName); + val enumBuilder = typeBuilder.addEnumeration(enumerationName); + enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef); - return enumBuilder; - } - return null; - } + return enumBuilder; + } + return null; + } - /** + /** * Generates type builder for module. * * @param module @@ -814,16 +814,16 @@ public class BindingGeneratorImpl implements BindingGenerator { * @throws IllegalArgumentException * if module equals null */ - private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) { - checkArgument(module !== null, "Module reference cannot be NULL."); - val packageName = moduleNamespaceToPackageName(module); - val moduleName = parseToClassName(module.name) + postfix; + private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) { + checkArgument(module !== null, "Module reference cannot be NULL."); + val packageName = moduleNamespaceToPackageName(module); + val moduleName = parseToClassName(module.name) + postfix; - return new GeneratedTypeBuilderImpl(packageName, moduleName); + return new GeneratedTypeBuilderImpl(packageName, moduleName); - } + } - /** + /** * Converts augSchema to list of Type which * contains generated type for augmentation. In addition there are also * generated types for all containers, list and choices which are child of @@ -845,47 +845,47 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • if target path of augSchema equals null
  • * */ - private def List augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema) { - checkArgument(augmentPackageName !== null, "Package Name cannot be NULL."); - checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL."); - checkState(augSchema.targetPath !== null, - "Augmentation Schema does not contain Target Path (Target Path is NULL)."); - val List genTypes = new ArrayList(); - - // EVERY augmented interface will extends Augmentation interface - // and DataObject interface!!! - val targetPath = augSchema.targetPath; - val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); - if (targetSchemaNode !== null) { - var targetType = yangToJavaMapping.get(targetSchemaNode.path); - if (targetType == null) { - - // FIXME: augmentation should be added as last, all types should already be generated - // and have assigned Java Types, - val targetModule = findParentModule(schemaContext, targetSchemaNode); - val targetBasePackage = moduleNamespaceToPackageName(targetModule); - val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath()); - val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName(); - val typeName = parseToClassName(targetSchemaNodeName); - targetType = new ReferencedTypeImpl(typePackage, typeName); - } - val augChildNodes = augSchema.childNodes; - if (!(targetSchemaNode instanceof ChoiceNode)) { - val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName, targetType, augSchema); - val augType = augTypeBuilder.toInstance(); - genTypes.add(augType); - } else { - val choiceTarget = targetSchemaNode as ChoiceNode; - val choiceCaseNodes = choiceTarget.cases; - genTypes.addAll( - generateTypesFromAugmentedChoiceCases(augmentPackageName, targetType, choiceCaseNodes)); - } - genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes)); - } - return genTypes; - } - - /** + private def List augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema) { + checkArgument(augmentPackageName !== null, "Package Name cannot be NULL."); + checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL."); + checkState(augSchema.targetPath !== null, + "Augmentation Schema does not contain Target Path (Target Path is NULL)."); + val List genTypes = new ArrayList(); + + // EVERY augmented interface will extends Augmentation interface + // and DataObject interface!!! + val targetPath = augSchema.targetPath; + val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); + if (targetSchemaNode !== null) { + var targetType = yangToJavaMapping.get(targetSchemaNode.path); + if (targetType == null) { + + // FIXME: augmentation should be added as last, all types should already be generated + // and have assigned Java Types, + val targetModule = findParentModule(schemaContext, targetSchemaNode); + val targetBasePackage = moduleNamespaceToPackageName(targetModule); + val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath()); + val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName(); + val typeName = parseToClassName(targetSchemaNodeName); + targetType = new ReferencedTypeImpl(typePackage, typeName); + } + val augChildNodes = augSchema.childNodes; + if (!(targetSchemaNode instanceof ChoiceNode)) { + val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName, targetType, augSchema); + val augType = augTypeBuilder.toInstance(); + genTypes.add(augType); + } else { + val choiceTarget = targetSchemaNode as ChoiceNode; + val choiceCaseNodes = choiceTarget.cases; + genTypes.addAll( + generateTypesFromAugmentedChoiceCases(augmentPackageName, targetType, choiceCaseNodes)); + } + genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes)); + } + return genTypes; + } + + /** * Returns a generated type builder for an augmentation. * * The name of the type builder is equal to the name of augmented node with @@ -904,50 +904,50 @@ public class BindingGeneratorImpl implements BindingGenerator { * and uses of augment * @return generated type builder for augment */ - private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(String augmentPackageName, Type targetTypeRef, - AugmentationSchema augSchema) { - var Map augmentBuilders = genTypeBuilders.get(augmentPackageName); - if (augmentBuilders === null) { - augmentBuilders = new HashMap(); - genTypeBuilders.put(augmentPackageName, augmentBuilders); - } - val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes); - - val augTypeName = if (augIdentifier !== null) { - parseToClassName(augIdentifier) - } else { - augGenTypeName(augmentBuilders, targetTypeRef.name); - } - val Set augChildNodes = augSchema.childNodes; - - val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName); - - augTypeBuilder.addImplementsType(DATA_OBJECT); - augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef)); - addImplementedInterfaceFromUses(augSchema, augTypeBuilder); - - augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes); - augmentBuilders.put(augTypeName, augTypeBuilder); - return augTypeBuilder; - } - - /** + private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(String augmentPackageName, Type targetTypeRef, + AugmentationSchema augSchema) { + var Map augmentBuilders = genTypeBuilders.get(augmentPackageName); + if (augmentBuilders === null) { + augmentBuilders = new HashMap(); + genTypeBuilders.put(augmentPackageName, augmentBuilders); + } + val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes); + + val augTypeName = if (augIdentifier !== null) { + parseToClassName(augIdentifier) + } else { + augGenTypeName(augmentBuilders, targetTypeRef.name); + } + val Set augChildNodes = augSchema.childNodes; + + val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName); + + augTypeBuilder.addImplementsType(DATA_OBJECT); + augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef)); + addImplementedInterfaceFromUses(augSchema, augTypeBuilder); + + augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes); + augmentBuilders.put(augTypeName, augTypeBuilder); + return augTypeBuilder; + } + + /** * * @param unknownSchemaNodes * @return */ - private def String getAugmentIdentifier(List unknownSchemaNodes) { - for (unknownSchemaNode : unknownSchemaNodes) { - val nodeType = unknownSchemaNode.nodeType; - if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) && - YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) { - return unknownSchemaNode.nodeParameter; - } - } - return null; - } - - /** + private def String getAugmentIdentifier(List unknownSchemaNodes) { + for (unknownSchemaNode : unknownSchemaNodes) { + val nodeType = unknownSchemaNode.nodeType; + if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) && + YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) { + return unknownSchemaNode.nodeParameter; + } + } + return null; + } + + /** * Convert a container, list and choice subnodes (and recursivelly their * subnodes) of augment to generated types * @@ -960,52 +960,52 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return list of Type which represents container, list and * choice subnodes of augment */ - private def List augmentationBodyToGenTypes(String augBasePackageName, Set augChildNodes) { - val List genTypes = new ArrayList(); - val List augSchemaIts = new ArrayList(); - for (childNode : augChildNodes) { - if (childNode instanceof DataNodeContainer) { - augSchemaIts.add(new DataNodeIterator(childNode as DataNodeContainer)); - - if (childNode instanceof ContainerSchemaNode) { - genTypes.add(containerToGenType(augBasePackageName, childNode as ContainerSchemaNode)); - } else if (childNode instanceof ListSchemaNode) { - genTypes.addAll(listToGenType(augBasePackageName, childNode as ListSchemaNode)); - } - } else if (childNode instanceof ChoiceNode) { - val choice = childNode as ChoiceNode; - for (caseNode : choice.cases) { - augSchemaIts.add(new DataNodeIterator(caseNode)); - } - genTypes.addAll(choiceToGeneratedType(augBasePackageName, childNode as ChoiceNode)); - } - } - - for (it : augSchemaIts) { - val List augContainers = it.allContainers(); - val List augLists = it.allLists(); - val List augChoices = it.allChoices(); - - if (augContainers !== null) { - for (container : augContainers) { - genTypes.add(containerToGenType(augBasePackageName, container)); - } - } - if (augLists !== null) { - for (list : augLists) { - genTypes.addAll(listToGenType(augBasePackageName, list)); - } - } - if (augChoices !== null) { - for (choice : augChoices) { - genTypes.addAll(choiceToGeneratedType(augBasePackageName, choice)); - } - } - } - return genTypes; - } - - /** + private def List augmentationBodyToGenTypes(String augBasePackageName, Set augChildNodes) { + val List genTypes = new ArrayList(); + val List augSchemaIts = new ArrayList(); + for (childNode : augChildNodes) { + if (childNode instanceof DataNodeContainer) { + augSchemaIts.add(new DataNodeIterator(childNode as DataNodeContainer)); + + if (childNode instanceof ContainerSchemaNode) { + genTypes.add(containerToGenType(augBasePackageName, childNode as ContainerSchemaNode)); + } else if (childNode instanceof ListSchemaNode) { + genTypes.addAll(listToGenType(augBasePackageName, childNode as ListSchemaNode)); + } + } else if (childNode instanceof ChoiceNode) { + val choice = childNode as ChoiceNode; + for (caseNode : choice.cases) { + augSchemaIts.add(new DataNodeIterator(caseNode)); + } + genTypes.addAll(choiceToGeneratedType(augBasePackageName, childNode as ChoiceNode)); + } + } + + for (it : augSchemaIts) { + val List augContainers = it.allContainers(); + val List augLists = it.allLists(); + val List augChoices = it.allChoices(); + + if (augContainers !== null) { + for (container : augContainers) { + genTypes.add(containerToGenType(augBasePackageName, container)); + } + } + if (augLists !== null) { + for (list : augLists) { + genTypes.addAll(listToGenType(augBasePackageName, list)); + } + } + if (augChoices !== null) { + for (choice : augChoices) { + genTypes.addAll(choiceToGeneratedType(augBasePackageName, choice)); + } + } + } + return genTypes; + } + + /** * Returns first unique name for the augment generated type builder. The * generated type builder name for augment consists from name of augmented * node and serial number of its augmentation. @@ -1017,15 +1017,15 @@ public class BindingGeneratorImpl implements BindingGenerator { * string with name of augmented node * @return string with unique name for augmentation builder */ - private def String augGenTypeName(Map builders, String genTypeName) { - var index = 1; - while ((builders !== null) && builders.containsKey(genTypeName + index)) { - index = index + 1; - } - return genTypeName + index; - } - - /** + private def String augGenTypeName(Map builders, String genTypeName) { + var index = 1; + while ((builders !== null) && builders.containsKey(genTypeName + index)) { + index = index + 1; + } + return genTypeName + index; + } + + /** * Converts containerNode to generated type. Firstly the * generated type builder is created. The subnodes of * containerNode are added as methods and the instance of @@ -1038,20 +1038,20 @@ public class BindingGeneratorImpl implements BindingGenerator { * schema paths * @return generated type for containerNode */ - private def GeneratedType containerToGenType(String basePackageName, ContainerSchemaNode containerNode) { - if (containerNode === null) { - return null; - } + private def GeneratedType containerToGenType(String basePackageName, ContainerSchemaNode containerNode) { + if (containerNode === null) { + return null; + } - val packageName = packageNameForGeneratedType(basePackageName, containerNode.path); - val schemaNodes = containerNode.childNodes; - val typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode); + val packageName = packageNameForGeneratedType(basePackageName, containerNode.path); + val schemaNodes = containerNode.childNodes; + val typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode); - resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes); - return typeBuilder.toInstance(); - } + resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes); + return typeBuilder.toInstance(); + } - /** + /** * Adds the methods to typeBuilder which represent subnodes of * node for which typeBuilder was created. * @@ -1072,20 +1072,20 @@ public class BindingGeneratorImpl implements BindingGenerator { * parameter. The getter methods (representing child nodes) could be * added to it. */ - private def GeneratedTypeBuilder resolveDataSchemaNodes(String basePackageName, GeneratedTypeBuilder typeBuilder, - Set schemaNodes) { - if ((schemaNodes !== null) && (typeBuilder !== null)) { - for (schemaNode : schemaNodes) { - if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) { - addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder); - } - - } - } - return typeBuilder; - } - - /** + private def GeneratedTypeBuilder resolveDataSchemaNodes(String basePackageName, GeneratedTypeBuilder typeBuilder, + Set schemaNodes) { + if ((schemaNodes !== null) && (typeBuilder !== null)) { + for (schemaNode : schemaNodes) { + if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) { + addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder); + } + + } + } + return typeBuilder; + } + + /** * Adds the methods to typeBuilder what represents subnodes of * node for which typeBuilder was created. * @@ -1103,19 +1103,19 @@ public class BindingGeneratorImpl implements BindingGenerator { * parameter typeBuilder. The getter method could be * added to it. */ - private def GeneratedTypeBuilder augSchemaNodeToMethods(String basePackageName, GeneratedTypeBuilder typeBuilder, - Set schemaNodes) { - if ((schemaNodes !== null) && (typeBuilder !== null)) { - for (schemaNode : schemaNodes) { - if (schemaNode.isAugmenting()) { - addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder); - } - } - } - return typeBuilder; - } - - /** + private def GeneratedTypeBuilder augSchemaNodeToMethods(String basePackageName, GeneratedTypeBuilder typeBuilder, + Set schemaNodes) { + if ((schemaNodes !== null) && (typeBuilder !== null)) { + for (schemaNode : schemaNodes) { + if (schemaNode.isAugmenting()) { + addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder); + } + } + } + return typeBuilder; + } + + /** * Adds to typeBuilder a method which is derived from * schemaNode. * @@ -1128,25 +1128,25 @@ public class BindingGeneratorImpl implements BindingGenerator { * generated type builder to which is schemaNode * added as a method. */ - private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node, - GeneratedTypeBuilder typeBuilder) { - if (node !== null && typeBuilder !== null) { - switch (node) { - case node instanceof LeafSchemaNode: - resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode) - case node instanceof LeafListSchemaNode: - resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode) - case node instanceof ContainerSchemaNode: - resolveContainerSchemaNode(basePackageName, typeBuilder, node as ContainerSchemaNode) - case node instanceof ListSchemaNode: - resolveListSchemaNode(basePackageName, typeBuilder, node as ListSchemaNode) - case node instanceof ChoiceNode: - resolveChoiceSchemaNode(basePackageName, typeBuilder, node as ChoiceNode) - } - } - } - - /** + private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node, + GeneratedTypeBuilder typeBuilder) { + if (node !== null && typeBuilder !== null) { + switch (node) { + case node instanceof LeafSchemaNode: + resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode) + case node instanceof LeafListSchemaNode: + resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode) + case node instanceof ContainerSchemaNode: + resolveContainerSchemaNode(basePackageName, typeBuilder, node as ContainerSchemaNode) + case node instanceof ListSchemaNode: + resolveListSchemaNode(basePackageName, typeBuilder, node as ListSchemaNode) + case node instanceof ChoiceNode: + resolveChoiceSchemaNode(basePackageName, typeBuilder, node as ChoiceNode) + } + } + } + + /** * Creates a getter method for a choice node. * * Firstly generated type builder for choice is created or found in @@ -1171,21 +1171,21 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def void resolveChoiceSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, - ChoiceNode choiceNode) { - checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); - checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); - checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL."); - - val choiceName = choiceNode.QName.localName; - if (choiceName !== null && !choiceNode.isAddedByUses()) { - val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path); - val choiceType = addDefaultInterfaceDefinition(packageName, choiceNode); - constructGetter(typeBuilder, choiceName, choiceNode.description, choiceType); - } - } - - /** + private def void resolveChoiceSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, + ChoiceNode choiceNode) { + checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); + checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); + checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL."); + + val choiceName = choiceNode.QName.localName; + if (choiceName !== null && !choiceNode.isAddedByUses()) { + val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path); + val choiceType = addDefaultInterfaceDefinition(packageName, choiceNode); + constructGetter(typeBuilder, choiceName, choiceNode.description, choiceType); + } + } + + /** * Converts choiceNode to the list of generated types for * choice and its cases. * @@ -1208,26 +1208,26 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def List choiceToGeneratedType(String basePackageName, ChoiceNode choiceNode) { - checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); - checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL."); - - val List generatedTypes = new ArrayList(); - val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path); - val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode); - - //choiceTypeBuilder.addImplementsType(DATA_OBJECT); - val choiceType = choiceTypeBuilder.toInstance(); - - generatedTypes.add(choiceType); - val Set caseNodes = choiceNode.cases; - if ((caseNodes !== null) && !caseNodes.isEmpty()) { - generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes)); - } - return generatedTypes; - } - - /** + private def List choiceToGeneratedType(String basePackageName, ChoiceNode choiceNode) { + checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); + checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL."); + + val List generatedTypes = new ArrayList(); + val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path); + val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode); + + //choiceTypeBuilder.addImplementsType(DATA_OBJECT); + val choiceType = choiceTypeBuilder.toInstance(); + + generatedTypes.add(choiceType); + val Set caseNodes = choiceNode.cases; + if ((caseNodes !== null) && !caseNodes.isEmpty()) { + generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes)); + } + return generatedTypes; + } + + /** * Converts caseNodes set to list of corresponding generated * types. * @@ -1253,31 +1253,31 @@ public class BindingGeneratorImpl implements BindingGenerator { * * * */ - private def List generateTypesFromChoiceCases(String basePackageName, Type refChoiceType, - Set caseNodes) { - checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); - checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL."); - checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL."); - - val List generatedTypes = new ArrayList(); - for (caseNode : caseNodes) { - if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) { - val packageName = packageNameForGeneratedType(basePackageName, caseNode.path); - val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode); - caseTypeBuilder.addImplementsType(refChoiceType); - - val Set childNodes = caseNode.childNodes; - if (childNodes !== null) { - resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes); - } - generatedTypes.add(caseTypeBuilder.toInstance()); - } - } - - return generatedTypes; - } - - /** + private def List generateTypesFromChoiceCases(String basePackageName, Type refChoiceType, + Set caseNodes) { + checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); + checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL."); + checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL."); + + val List generatedTypes = new ArrayList(); + for (caseNode : caseNodes) { + if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) { + val packageName = packageNameForGeneratedType(basePackageName, caseNode.path); + val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode); + caseTypeBuilder.addImplementsType(refChoiceType); + + val Set childNodes = caseNode.childNodes; + if (childNodes !== null) { + resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes); + } + generatedTypes.add(caseTypeBuilder.toInstance()); + } + } + + return generatedTypes; + } + + /** * Generates list of generated types for all the cases of a choice which are * added to the choice through the augment. * @@ -1302,31 +1302,31 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • if caseNodes equals null
  • * */ - private def List generateTypesFromAugmentedChoiceCases(String basePackageName, Type refChoiceType, - Set caseNodes) { - checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); - checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL."); - checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL."); - - val List generatedTypes = new ArrayList(); - for (caseNode : caseNodes) { - if (caseNode !== null && caseNode.isAugmenting()) { - val packageName = packageNameForGeneratedType(basePackageName, caseNode.path); - val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode); - caseTypeBuilder.addImplementsType(refChoiceType); - - val Set childNodes = caseNode.childNodes; - if (childNodes !== null) { - resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes); - } - generatedTypes.add(caseTypeBuilder.toInstance()); - } - } - - return generatedTypes; - } - - /** + private def List generateTypesFromAugmentedChoiceCases(String basePackageName, Type refChoiceType, + Set caseNodes) { + checkArgument(basePackageName !== null, "Base Package Name cannot be NULL."); + checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL."); + checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL."); + + val List generatedTypes = new ArrayList(); + for (caseNode : caseNodes) { + if (caseNode !== null && caseNode.isAugmenting()) { + val packageName = packageNameForGeneratedType(basePackageName, caseNode.path); + val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode); + caseTypeBuilder.addImplementsType(refChoiceType); + + val Set childNodes = caseNode.childNodes; + if (childNodes !== null) { + resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes); + } + generatedTypes.add(caseTypeBuilder.toInstance()); + } + } + + return generatedTypes; + } + + /** * Converts leaf to the getter method which is added to * typeBuilder. * @@ -1343,51 +1343,51 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • true - in other cases
  • * */ - private def boolean resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) { - if ((leaf !== null) && (typeBuilder !== null)) { - val leafName = leaf.QName.localName; - var String leafDesc = leaf.description; - if (leafDesc === null) { - leafDesc = ""; - } - - val parentModule = findParentModule(schemaContext, leaf); - if (leafName !== null && !leaf.isAddedByUses()) { - val TypeDefinition typeDef = leaf.type; - - var Type returnType = null; - if (typeDef instanceof EnumTypeDefinition) { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); - val enumTypeDef = enumTypeDefFromExtendedType(typeDef); - val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName, typeBuilder); - - if (enumBuilder !== null) { - returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name); - } - (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType); - } else if (typeDef instanceof UnionType) { - val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); - if (genTOBuilder !== null) { - returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); - } - } else if (typeDef instanceof BitsTypeDefinition) { - val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); - if (genTOBuilder !== null) { - returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); - } - } else { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); - } - if (returnType !== null) { - constructGetter(typeBuilder, leafName, leafDesc, returnType); - return true; - } - } - } - return false; - } - - /** + private def boolean resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) { + if ((leaf !== null) && (typeBuilder !== null)) { + val leafName = leaf.QName.localName; + var String leafDesc = leaf.description; + if (leafDesc === null) { + leafDesc = ""; + } + + val parentModule = findParentModule(schemaContext, leaf); + if (leafName !== null && !leaf.isAddedByUses()) { + val TypeDefinition typeDef = leaf.type; + + var Type returnType = null; + if (typeDef instanceof EnumTypeDefinition) { + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); + val enumTypeDef = enumTypeDefFromExtendedType(typeDef); + val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName, typeBuilder); + + if (enumBuilder !== null) { + returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name); + } + (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType); + } else if (typeDef instanceof UnionType) { + val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); + if (genTOBuilder !== null) { + returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); + } + } else if (typeDef instanceof BitsTypeDefinition) { + val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); + if (genTOBuilder !== null) { + returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); + } + } else { + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); + } + if (returnType !== null) { + constructGetter(typeBuilder, leafName, leafDesc, returnType); + return true; + } + } + } + return false; + } + + /** * Converts leaf schema node to property of generated TO * builder. * @@ -1406,40 +1406,40 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • true - other cases
  • * */ - private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf, - boolean isReadOnly) { - if ((leaf !== null) && (toBuilder !== null)) { - val leafName = leaf.QName.localName; - var String leafDesc = leaf.description; - if (leafDesc === null) { - leafDesc = ""; - } - - if (leafName !== null && !leaf.isAddedByUses()) { - val TypeDefinition typeDef = leaf.type; - - // TODO: properly resolve enum types - val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); - - if (returnType !== null) { - val propBuilder = toBuilder.addProperty(parseToClassName(leafName)); - - propBuilder.setReadOnly(isReadOnly); - propBuilder.setReturnType(returnType); - propBuilder.setComment(leafDesc); - - toBuilder.addEqualsIdentity(propBuilder); - toBuilder.addHashIdentity(propBuilder); - toBuilder.addToStringProperty(propBuilder); - - return true; - } - } - } - return false; - } - - /** + private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf, + boolean isReadOnly) { + if ((leaf !== null) && (toBuilder !== null)) { + val leafName = leaf.QName.localName; + var String leafDesc = leaf.description; + if (leafDesc === null) { + leafDesc = ""; + } + + if (leafName !== null && !leaf.isAddedByUses()) { + val TypeDefinition typeDef = leaf.type; + + // TODO: properly resolve enum types + val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); + + if (returnType !== null) { + val propBuilder = toBuilder.addProperty(parseToClassName(leafName)); + + propBuilder.setReadOnly(isReadOnly); + propBuilder.setReturnType(returnType); + propBuilder.setComment(leafDesc); + + toBuilder.addEqualsIdentity(propBuilder); + toBuilder.addHashIdentity(propBuilder); + toBuilder.addToStringProperty(propBuilder); + + return true; + } + } + } + return false; + } + + /** * Converts node leaf list schema node to getter method of * typeBuilder. * @@ -1456,26 +1456,26 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • false - other cases
  • * */ - private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) { - if ((node !== null) && (typeBuilder !== null)) { - val nodeName = node.QName.localName; - var String nodeDesc = node.description; - if (nodeDesc === null) { - nodeDesc = ""; - } - - if (nodeName !== null && !node.isAddedByUses()) { - val TypeDefinition type = node.type; - val listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node)); - - constructGetter(typeBuilder, nodeName, nodeDesc, listType); - return true; - } - } - return false; - } - - /** + private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) { + if ((node !== null) && (typeBuilder !== null)) { + val nodeName = node.QName.localName; + var String nodeDesc = node.description; + if (nodeDesc === null) { + nodeDesc = ""; + } + + if (nodeName !== null && !node.isAddedByUses()) { + val TypeDefinition type = node.type; + val listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node)); + + constructGetter(typeBuilder, nodeName, nodeDesc, listType); + return true; + } + } + return false; + } + + /** * Creates a getter method for a container node. * * Firstly generated type builder for container is created or found in @@ -1501,24 +1501,24 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • true - other cases
  • * */ - private def boolean resolveContainerSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, - ContainerSchemaNode containerNode) { - if ((containerNode !== null) && (typeBuilder !== null)) { - val nodeName = containerNode.QName.localName; + private def boolean resolveContainerSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, + ContainerSchemaNode containerNode) { + if ((containerNode !== null) && (typeBuilder !== null)) { + val nodeName = containerNode.QName.localName; - if (nodeName !== null && !containerNode.isAddedByUses()) { - val packageName = packageNameForGeneratedType(basePackageName, containerNode.path); + if (nodeName !== null && !containerNode.isAddedByUses()) { + val packageName = packageNameForGeneratedType(basePackageName, containerNode.path); - val rawGenType = addDefaultInterfaceDefinition(packageName, containerNode); - constructGetter(typeBuilder, nodeName, containerNode.description, rawGenType); + val rawGenType = addDefaultInterfaceDefinition(packageName, containerNode); + constructGetter(typeBuilder, nodeName, containerNode.description, rawGenType); - return true; - } - } - return false; - } + return true; + } + } + return false; + } - /** + /** * Creates a getter method for a list node. * * Firstly generated type builder for list is created or found in @@ -1543,22 +1543,22 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • true - other cases
  • * */ - private def boolean resolveListSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, - ListSchemaNode listNode) { - if ((listNode !== null) && (typeBuilder !== null)) { - val listName = listNode.QName.localName; - - if (listName !== null && !listNode.isAddedByUses()) { - val packageName = packageNameForGeneratedType(basePackageName, listNode.path); - val rawGenType = addDefaultInterfaceDefinition(packageName, listNode); - constructGetter(typeBuilder, listName, listNode.description, Types.listTypeFor(rawGenType)); - return true; - } - } - return false; - } - - /** + private def boolean resolveListSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder, + ListSchemaNode listNode) { + if ((listNode !== null) && (typeBuilder !== null)) { + val listName = listNode.QName.localName; + + if (listName !== null && !listNode.isAddedByUses()) { + val packageName = packageNameForGeneratedType(basePackageName, listNode.path); + val rawGenType = addDefaultInterfaceDefinition(packageName, listNode); + constructGetter(typeBuilder, listName, listNode.description, Types.listTypeFor(rawGenType)); + return true; + } + } + return false; + } + + /** * Instantiates generated type builder with packageName and * schemaNode. * @@ -1579,21 +1579,21 @@ public class BindingGeneratorImpl implements BindingGenerator { * schema node for which is created generated type builder * @return generated type builder schemaNode */ - private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) { - val builder = addRawInterfaceDefinition(packageName, schemaNode, ""); - builder.addImplementsType(DATA_OBJECT); - if (!(schemaNode instanceof GroupingDefinition)) { - builder.addImplementsType(augmentable(builder)); - } + private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) { + val builder = addRawInterfaceDefinition(packageName, schemaNode, ""); + builder.addImplementsType(DATA_OBJECT); + if (!(schemaNode instanceof GroupingDefinition)) { + builder.addImplementsType(augmentable(builder)); + } - if (schemaNode instanceof DataNodeContainer) { - addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, builder); - } + if (schemaNode instanceof DataNodeContainer) { + addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, builder); + } - return builder; - } + return builder; + } - /** + /** * Wraps the calling of the same overloaded method. * * @param packageName @@ -1603,11 +1603,11 @@ public class BindingGeneratorImpl implements BindingGenerator { * schema node which provide data about the schema node name * @return generated type builder for schemaNode */ - private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) { - return addRawInterfaceDefinition(packageName, schemaNode, ""); - } + private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) { + return addRawInterfaceDefinition(packageName, schemaNode, ""); + } - /** + /** * Returns reference to generated type builder for specified * schemaNode with packageName. * @@ -1630,38 +1630,38 @@ public class BindingGeneratorImpl implements BindingGenerator { * * */ - private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode, - String prefix) { - checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL."); - checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL."); - checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL."); - val schemaNodeName = schemaNode.QName.localName; - checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL."); - - var String genTypeName; - if (prefix === null) { - genTypeName = parseToClassName(schemaNodeName); - } else { - genTypeName = prefix + parseToClassName(schemaNodeName); - } - - //FIXME: Validation of name conflict - val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName); - yangToJavaMapping.put(schemaNode.path, newType); - if (!genTypeBuilders.containsKey(packageName)) { - val Map builders = new HashMap(); - builders.put(genTypeName, newType); - genTypeBuilders.put(packageName, builders); - } else { - val Map builders = genTypeBuilders.get(packageName); - if (!builders.containsKey(genTypeName)) { - builders.put(genTypeName, newType); - } - } - return newType; - } - - /** + private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode, + String prefix) { + checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL."); + checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL."); + checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL."); + val schemaNodeName = schemaNode.QName.localName; + checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL."); + + var String genTypeName; + if (prefix === null) { + genTypeName = parseToClassName(schemaNodeName); + } else { + genTypeName = prefix + parseToClassName(schemaNodeName); + } + + //FIXME: Validation of name conflict + val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName); + yangToJavaMapping.put(schemaNode.path, newType); + if (!genTypeBuilders.containsKey(packageName)) { + val Map builders = new HashMap(); + builders.put(genTypeName, newType); + genTypeBuilders.put(packageName, builders); + } else { + val Map builders = genTypeBuilders.get(packageName); + if (!builders.containsKey(genTypeName)) { + builders.put(genTypeName, newType); + } + } + return newType; + } + + /** * Creates the name of the getter method from methodName. * * @param methodName @@ -1669,18 +1669,18 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return string with the name of the getter method for * methodName in JAVA method format */ - private def String getterMethodName(String methodName, Type returnType) { - val method = new StringBuilder(); - if (BOOLEAN.equals(returnType)) { - method.append("is"); - } else { - method.append("get"); - } - method.append(parseToClassName(methodName)); - return method.toString(); - } - - /** + private def String getterMethodName(String methodName, Type returnType) { + val method = new StringBuilder(); + if (BOOLEAN.equals(returnType)) { + method.append("is"); + } else { + method.append("get"); + } + method.append(parseToClassName(methodName)); + return method.toString(); + } + + /** * Created a method signature builder as part of * interfaceBuilder. * @@ -1701,47 +1701,47 @@ public class BindingGeneratorImpl implements BindingGenerator { * @return method signature builder which represents the getter method of * interfaceBuilder */ - private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName, - String comment, Type returnType) { + private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName, + String comment, Type returnType) { - val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType)); + val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType)); - getMethod.setComment(comment); - getMethod.setReturnType(returnType); + getMethod.setComment(comment); + getMethod.setReturnType(returnType); - return getMethod; - } + return getMethod; + } - private def listToGenType(String basePackageName, ListSchemaNode list) { - checkArgument(basePackageName !== null, "Package Name for Generated Type cannot be NULL."); - checkArgument(list !== null, "List Schema Node cannot be NULL."); + private def listToGenType(String basePackageName, ListSchemaNode list) { + checkArgument(basePackageName !== null, "Package Name for Generated Type cannot be NULL."); + checkArgument(list !== null, "List Schema Node cannot be NULL."); - val packageName = packageNameForGeneratedType(basePackageName, list.path); + val packageName = packageNameForGeneratedType(basePackageName, list.path); - // val typeBuilder = - // resolveListTypeBuilder(packageName, list); - val typeBuilder = addDefaultInterfaceDefinition(packageName, list); + // val typeBuilder = + // resolveListTypeBuilder(packageName, list); + val typeBuilder = addDefaultInterfaceDefinition(packageName, list); - val List listKeys = listKeys(list); - val genTOBuilder = resolveListKeyTOBuilder(packageName, list); + val List listKeys = listKeys(list); + val genTOBuilder = resolveListKeyTOBuilder(packageName, list); - if (genTOBuilder !== null) { - val identifierMarker = IDENTIFIER.parameterizedTypeFor(typeBuilder); - val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder); - genTOBuilder.addImplementsType(identifierMarker); - typeBuilder.addImplementsType(identifiableMarker); - } - val schemaNodes = list.childNodes; + if (genTOBuilder !== null) { + val identifierMarker = IDENTIFIER.parameterizedTypeFor(typeBuilder); + val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder); + genTOBuilder.addImplementsType(identifierMarker); + typeBuilder.addImplementsType(identifiableMarker); + } + val schemaNodes = list.childNodes; - for (schemaNode : schemaNodes) { - if (!schemaNode.isAugmenting()) { - addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys); - } - } - return typeBuildersToGenTypes(typeBuilder, genTOBuilder); - } + for (schemaNode : schemaNodes) { + if (!schemaNode.isAugmenting()) { + addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys); + } + } + return typeBuildersToGenTypes(typeBuilder, genTOBuilder); + } - /** + /** * Adds schemaNode to typeBuilder as getter method * or to genTOBuilder as property. * @@ -1763,43 +1763,43 @@ public class BindingGeneratorImpl implements BindingGenerator { *
  • if typeBuilder equals null
  • * */ - private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode, - GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List listKeys) { - checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL."); - - checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); - - if (schemaNode instanceof LeafSchemaNode) { - val leaf = schemaNode as LeafSchemaNode; - val leafName = leaf.QName.localName; - if (!listKeys.contains(leafName)) { - resolveLeafSchemaNodeAsMethod(typeBuilder, leaf); - } else { - resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true); - } - } else if (schemaNode instanceof LeafListSchemaNode) { - resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode); - } else if (schemaNode instanceof ContainerSchemaNode) { - resolveContainerSchemaNode(basePackageName, typeBuilder, schemaNode as ContainerSchemaNode); - } else if (schemaNode instanceof ListSchemaNode) { - resolveListSchemaNode(basePackageName, typeBuilder, schemaNode as ListSchemaNode); - } - } - - private def typeBuildersToGenTypes(GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) { - val List genTypes = new ArrayList(); - checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); - - if (genTOBuilder !== null) { - val genTO = genTOBuilder.toInstance(); - constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO); - genTypes.add(genTO); - } - genTypes.add(typeBuilder.toInstance()); - return genTypes; - } - - /** + private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode, + GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List listKeys) { + checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL."); + + checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); + + if (schemaNode instanceof LeafSchemaNode) { + val leaf = schemaNode as LeafSchemaNode; + val leafName = leaf.QName.localName; + if (!listKeys.contains(leafName)) { + resolveLeafSchemaNodeAsMethod(typeBuilder, leaf); + } else { + resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true); + } + } else if (schemaNode instanceof LeafListSchemaNode) { + resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode); + } else if (schemaNode instanceof ContainerSchemaNode) { + resolveContainerSchemaNode(basePackageName, typeBuilder, schemaNode as ContainerSchemaNode); + } else if (schemaNode instanceof ListSchemaNode) { + resolveListSchemaNode(basePackageName, typeBuilder, schemaNode as ListSchemaNode); + } + } + + private def typeBuildersToGenTypes(GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) { + val List genTypes = new ArrayList(); + checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL."); + + if (genTOBuilder !== null) { + val genTO = genTOBuilder.toInstance(); + constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO); + genTypes.add(genTO); + } + genTypes.add(typeBuilder.toInstance()); + return genTypes; + } + + /** * Selects the names of the list keys from list and returns * them as the list of the strings * @@ -1809,19 +1809,19 @@ public class BindingGeneratorImpl implements BindingGenerator { * list contains no keys then the empty list is * returned. */ - private def listKeys(ListSchemaNode list) { - val List listKeys = new ArrayList(); - - if (list.keyDefinition !== null) { - val keyDefinitions = list.keyDefinition; - for (keyDefinition : keyDefinitions) { - listKeys.add(keyDefinition.localName); - } - } - return listKeys; - } - - /** + private def listKeys(ListSchemaNode list) { + val List listKeys = new ArrayList(); + + if (list.keyDefinition !== null) { + val keyDefinitions = list.keyDefinition; + for (keyDefinition : keyDefinitions) { + listKeys.add(keyDefinition.localName); + } + } + return listKeys; + } + + /** * Generates for the list which contains any list keys special * generated TO builder. * @@ -1833,20 +1833,20 @@ public class BindingGeneratorImpl implements BindingGenerator { * list or null if list is null or list of * key definitions is null or empty. */ - private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) { - var GeneratedTOBuilder genTOBuilder = null; - if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) { - if (list !== null) { - val listName = list.QName.localName + "Key"; - val String genTOName = parseToClassName(listName); - genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName); - } - } - return genTOBuilder; - - } - - /** + private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) { + var GeneratedTOBuilder genTOBuilder = null; + if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) { + if (list !== null) { + val listName = list.QName.localName + "Key"; + val String genTOName = parseToClassName(listName); + genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName); + } + } + return genTOBuilder; + + } + + /** * Builds generated TO builders for typeDef of type * {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or * {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition @@ -1867,31 +1867,31 @@ public class BindingGeneratorImpl implements BindingGenerator { * string with name for generated TO builder * @return generated TO builder for typeDef */ - private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition typeDef, GeneratedTypeBuilder typeBuilder, - String leafName, LeafSchemaNode leaf, Module parentModule) { - val classNameFromLeaf = parseToClassName(leafName); - val List genTOBuilders = new ArrayList(); - val packageName = typeBuilder.fullyQualifiedName; - if (typeDef instanceof UnionTypeDefinition) { - genTOBuilders.addAll( - (typeProvider as TypeProviderImpl). - provideGeneratedTOBuildersForUnionTypeDef(packageName, typeDef, classNameFromLeaf, leaf)); - } else if (typeDef instanceof BitsTypeDefinition) { - genTOBuilders.add( - ((typeProvider as TypeProviderImpl) ). - provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf)); - } - if (genTOBuilders !== null && !genTOBuilders.isEmpty()) { - for (genTOBuilder : genTOBuilders) { - typeBuilder.addEnclosingTransferObject(genTOBuilder); - } - return genTOBuilders.get(0); - } - return null; - - } - - /** + private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition typeDef, GeneratedTypeBuilder typeBuilder, + String leafName, LeafSchemaNode leaf, Module parentModule) { + val classNameFromLeaf = parseToClassName(leafName); + val List genTOBuilders = new ArrayList(); + val packageName = typeBuilder.fullyQualifiedName; + if (typeDef instanceof UnionTypeDefinition) { + genTOBuilders.addAll( + (typeProvider as TypeProviderImpl). + provideGeneratedTOBuildersForUnionTypeDef(packageName, typeDef, classNameFromLeaf, leaf)); + } else if (typeDef instanceof BitsTypeDefinition) { + genTOBuilders.add( + ((typeProvider as TypeProviderImpl) ). + provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf)); + } + if (genTOBuilders !== null && !genTOBuilders.isEmpty()) { + for (genTOBuilder : genTOBuilders) { + typeBuilder.addEnclosingTransferObject(genTOBuilder); + } + return genTOBuilders.get(0); + } + return null; + + } + + /** * Adds the implemented types to type builder. * * The method passes through the list of uses in @@ -1907,17 +1907,17 @@ public class BindingGeneratorImpl implements BindingGenerator { * dataNodeContainer * @return generated type builder with all implemented types */ - private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) { - for (usesNode : dataNodeContainer.uses) { - if (usesNode.groupingPath !== null) { - val genType = allGroupings.get(usesNode.groupingPath); - if (genType === null) { - throw new IllegalStateException( - "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name); - } - builder.addImplementsType(genType); - } - } - return builder; - } + private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) { + for (usesNode : dataNodeContainer.uses) { + if (usesNode.groupingPath !== null) { + val genType = allGroupings.get(usesNode.groupingPath); + if (genType === null) { + throw new IllegalStateException( + "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name); + } + builder.addImplementsType(genType); + } + } + return builder; + } } diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index fde03cbdb1..9bb36e07af 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -254,7 +254,8 @@ public final class TypeProviderImpl implements TypeProvider { */ private Type provideTypeForIdentityref(IdentityrefTypeDefinition idref) { QName baseIdQName = idref.getIdentity(); - Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),baseIdQName.getRevision()); + Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(), + baseIdQName.getRevision()); IdentitySchemaNode identity = null; for (IdentitySchemaNode id : module.getIdentities()) { if (id.getQName().equals(baseIdQName)) { diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/AbstractNodeTO.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/AbstractNodeTO.java index d84696d13d..71644923af 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/AbstractNodeTO.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/AbstractNodeTO.java @@ -1,160 +1,168 @@ -/* - * 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.yangtools.yang.data.impl; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.NodeModification; - -/** - * @author michal.rehak - * @param - * type of node value - * - */ -public abstract class AbstractNodeTO implements Node, NodeModification { - - private QName qName; - private CompositeNode parent; - private T value; - private ModifyAction modifyAction; - - /** - * @param qname - * @param parent - * @param value - */ - public AbstractNodeTO(QName qname, CompositeNode parent, T value) { - this.qName = qname; - this.parent = parent; - this.value = value; - } - - /** - * @param qname - * @param parent - * @param value - * @param modifyAction - */ - public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) { - this.qName = qname; - this.parent = parent; - this.value = value; - this.modifyAction = modifyAction; - } - - @Override - public QName getNodeType() { - return qName; - } - - /** - * @return the qName - */ - public QName getQName() { - return qName; - } - - @Override - public CompositeNode getParent() { - return parent; - } - - /** - * @param parent the parent to set - */ - public void setParent(CompositeNode parent) { - this.parent = parent; - } - - /** - * @param value the value to set - */ - protected void setValue(T value) { - this.value = value; - } - - @Override - public T getValue() { - return value; - } - - /** - * @return modification action - * @see org.opendaylight.yangtools.yang.data.impl.NodeModificationSupport#getModificationAction() - */ - @Override - public ModifyAction getModificationAction() { - return modifyAction; - } - - /** - * @param modifyAction - * the modifyAction to set - */ - protected void setModificationAction(ModifyAction modifyAction) { - this.modifyAction = modifyAction; - } - - @Override - public String toString() { - StringBuffer out = new StringBuffer(); - out.append(String.format("Node[%s], qName[%s], modify[%s]", - getClass().getSimpleName(), getQName().getLocalName(), - getModificationAction() == null ? "n/a" : getModificationAction())); - return out.toString(); - } - - /* */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modifyAction == null) ? 0 : modifyAction.hashCode()); -// result = prime * result + ((parent == null) ? 0 : parent.hashCode()); - result = prime * result + ((qName == null) ? 0 : qName.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result % 2; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - @SuppressWarnings("unchecked") - AbstractNodeTO other = (AbstractNodeTO) obj; - if (modifyAction != other.modifyAction) - return false; - if (parent == null) { - if (other.parent != null) - return false; - } else if (other.parent == null) { - return false; - } - if (qName == null) { - if (other.qName != null) - return false; - } else if (!qName.equals(other.qName)) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equals(other.value)) - return false; - return true; - } - /* */ - -} +/* + * 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.yangtools.yang.data.impl; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.ModifyAction; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.NodeModification; + +/** + * @author michal.rehak + * @param + * type of node value + * + */ +public abstract class AbstractNodeTO implements Node, NodeModification { + + private QName qName; + private CompositeNode parent; + private T value; + private ModifyAction modifyAction; + + /** + * @param qname + * @param parent + * @param value + */ + public AbstractNodeTO(QName qname, CompositeNode parent, T value) { + this.qName = qname; + this.parent = parent; + this.value = value; + } + + /** + * @param qname + * @param parent + * @param value + * @param modifyAction + */ + public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) { + this.qName = qname; + this.parent = parent; + this.value = value; + this.modifyAction = modifyAction; + } + + @Override + public QName getNodeType() { + return qName; + } + + /** + * @return the qName + */ + public QName getQName() { + return qName; + } + + @Override + public CompositeNode getParent() { + return parent; + } + + /** + * @param parent + * the parent to set + */ + public void setParent(CompositeNode parent) { + this.parent = parent; + } + + /** + * @param value + * the value to set + */ + protected void setValue(T value) { + this.value = value; + } + + @Override + public T getValue() { + return value; + } + + /** + * @return modification action + * @see org.opendaylight.yangtools.yang.data.impl.NodeModificationSupport#getModificationAction() + */ + @Override + public ModifyAction getModificationAction() { + return modifyAction; + } + + /** + * @param modifyAction + * the modifyAction to set + */ + protected void setModificationAction(ModifyAction modifyAction) { + this.modifyAction = modifyAction; + } + + @Override + public String toString() { + StringBuffer out = new StringBuffer(); + out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName() + .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction())); + return out.toString(); + } + + /* */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((modifyAction == null) ? 0 : modifyAction.hashCode()); + result = prime * result + ((qName == null) ? 0 : qName.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result % 2; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + @SuppressWarnings("unchecked") + AbstractNodeTO other = (AbstractNodeTO) obj; + if (modifyAction != other.modifyAction) { + return false; + } + if (parent == null) { + if (other.parent != null) { + return false; + } + } else if (other.parent == null) { + return false; + } + if (qName == null) { + if (other.qName != null) { + return false; + } + } else if (!qName.equals(other.qName)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + /* */ + +} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/CompositeNodeTOImpl.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/CompositeNodeTOImpl.java index 5ba7ed8b3c..3945fdda5e 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/CompositeNodeTOImpl.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/CompositeNodeTOImpl.java @@ -91,8 +91,9 @@ public class CompositeNodeTOImpl extends AbstractNodeTO>> implement List> list = new ArrayList>(); for (Node node : toFilter) { - if (node instanceof SimpleNode) + if (node instanceof SimpleNode) { list.add((SimpleNode) node); + } } return list; } diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/MutableSimpleNodeTOImpl.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/MutableSimpleNodeTOImpl.java index 62f45beea1..e55cc0137e 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/MutableSimpleNodeTOImpl.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/MutableSimpleNodeTOImpl.java @@ -1,63 +1,63 @@ -/* - * 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.yangtools.yang.data.impl; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; -import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; - -/** - * @author michal.rehak - * @param type of simple node value - * - */ -public class MutableSimpleNodeTOImpl extends SimpleNodeTOImpl - implements MutableSimpleNode { - - private SimpleNode original; - - /** - * @param qname - * @param parent - * @param value - * @param modifyAction - */ - public MutableSimpleNodeTOImpl(QName qname, CompositeNode parent, T value, - ModifyAction modifyAction) { - super(qname, parent, value, modifyAction); - } - - @Override - public void setValue(T value) { - super.setValue(value); - } - - @Override - public void setModifyAction(ModifyAction action) { - super.setModificationAction(action); - } - - @Override - public MutableSimpleNode asMutable() { - return this; - } - - @Override - public SimpleNode getOriginal() { - return original; - } - - /** - * @param original the original to set - */ - public void setOriginal(SimpleNode original) { - this.original = original; - } -} +/* + * 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.yangtools.yang.data.impl; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.ModifyAction; +import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; + +/** + * @author michal.rehak + * @param + * type of simple node value + * + */ +public class MutableSimpleNodeTOImpl extends SimpleNodeTOImpl implements MutableSimpleNode { + + private SimpleNode original; + + /** + * @param qname + * @param parent + * @param value + * @param modifyAction + */ + public MutableSimpleNodeTOImpl(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) { + super(qname, parent, value, modifyAction); + } + + @Override + public void setValue(T value) { + super.setValue(value); + } + + @Override + public void setModifyAction(ModifyAction action) { + super.setModificationAction(action); + } + + @Override + public MutableSimpleNode asMutable() { + return this; + } + + @Override + public SimpleNode getOriginal() { + return original; + } + + /** + * @param original + * the original to set + */ + public void setOriginal(SimpleNode original) { + this.original = original; + } +} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImpl.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImpl.java index 503b07fc63..f1c2a44a03 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImpl.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImpl.java @@ -1,162 +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.yangtools.yang.data.impl; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; -import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; -import org.opendaylight.yangtools.yang.data.api.MutableNode; -import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.NodeModificationBuilder; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * @author michal.rehak - * - */ -public class NodeModificationBuilderImpl implements NodeModificationBuilder { - - private SchemaContext context; - - private Set> changeLog; - private LazyNodeToNodeMap originalToMutable; - - /** - * @param originalTreeRootNode - * @param context - */ - public NodeModificationBuilderImpl(CompositeNode originalTreeRootNode, SchemaContext context) { - this.context = context; - originalToMutable = new LazyNodeToNodeMap(); - changeLog = new HashSet<>(); - } - - /** - * @param modNode - * @param action - */ - private void addModificationToLog(MutableNode modNode, ModifyAction action) { - modNode.setModifyAction(action); - changeLog.add(modNode); - } - - @Override - public void addNode(MutableSimpleNode newNode) { - NodeUtils.fixParentRelation(newNode); - addModificationToLog(newNode, ModifyAction.CREATE); - } - - @Override - public void addNode(MutableCompositeNode newNode) { - NodeUtils.fixParentRelation(newNode); - addModificationToLog(newNode, ModifyAction.CREATE); - } - - @Override - public void replaceNode(MutableSimpleNode replacementNode) { - addModificationToLog(replacementNode, ModifyAction.REPLACE); - } - - @Override - public void replaceNode(MutableCompositeNode replacementNode) { - addModificationToLog(replacementNode, ModifyAction.REPLACE); - } - - @Override - public void deleteNode(MutableCompositeNode deadNode) { - addModificationToLog(deadNode, ModifyAction.DELETE); - } - - @Override - public void deleteNode(MutableSimpleNode deadNode) { - addModificationToLog(deadNode, ModifyAction.DELETE); - } - - @Override - public void removeNode(MutableSimpleNode deadNode) { - addModificationToLog(deadNode, ModifyAction.REMOVE); - } - - @Override - public void removeNode(MutableCompositeNode deadNode) { - addModificationToLog(deadNode, ModifyAction.REMOVE); - } - - @Override - public void mergeNode(MutableCompositeNode alteredNode) { - addModificationToLog(alteredNode, ModifyAction.MERGE); - } - - /** - * @return minimalistic tree containing diffs only - */ - @Override - public CompositeNode buildDiffTree() { - Set> wanted = new HashSet<>(); - - // walk changeLog, collect all required nodes - for (MutableNode mutant : changeLog) { - wanted.addAll(collectSelfAndAllParents(mutant)); - } - - // walk wanted and add relevant keys - Map mapOfLists = NodeUtils.buildMapOfListNodes(context); - for (Node outlaw : wanted) { - if (outlaw instanceof CompositeNode) { - String path = NodeUtils.buildPath(outlaw); - if (mapOfLists.containsKey(path)) { - ListSchemaNode listSchema = mapOfLists.get(path); - if (listSchema.getQName().equals(outlaw.getNodeType())) { - // try to add key subnode to wanted list - List supportedKeys = listSchema.getKeyDefinition(); - CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal(); - for (Node outlawOriginalChild : outlawOriginal.getChildren()) { - if (supportedKeys.contains(outlawOriginalChild.getNodeType())) { - originalToMutable.getMutableEquivalent(outlawOriginalChild); - } - } - } - } - } - } - - return originalToMutable.getMutableRoot(); - } - - /** - * @param focusedDescendant - * @return set of parents and focusedAncestor itself - */ - private static Set> collectSelfAndAllParents(Node focusedDescendant) { - Set> family = new HashSet<>(); - Node tmpNode = focusedDescendant; - while (tmpNode != null) { - family.add(tmpNode); - tmpNode = tmpNode.getParent(); - } - return family; - } - - /** - * @param originalNode - * @return mutable version of given node - */ - @Override - public Node getMutableEquivalent(Node originalNode) { - return originalToMutable.getMutableEquivalent(originalNode); - } - -} +/* + * 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.yangtools.yang.data.impl; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.ModifyAction; +import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; +import org.opendaylight.yangtools.yang.data.api.MutableNode; +import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.NodeModificationBuilder; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +/** + * @author michal.rehak + * + */ +public class NodeModificationBuilderImpl implements NodeModificationBuilder { + + private SchemaContext context; + + private Set> changeLog; + private LazyNodeToNodeMap originalToMutable; + + /** + * @param context + */ + public NodeModificationBuilderImpl(SchemaContext context) { + this.context = context; + originalToMutable = new LazyNodeToNodeMap(); + changeLog = new HashSet<>(); + } + + /** + * @param modNode + * @param action + */ + private void addModificationToLog(MutableNode modNode, ModifyAction action) { + modNode.setModifyAction(action); + changeLog.add(modNode); + } + + @Override + public void addNode(MutableSimpleNode newNode) { + NodeUtils.fixParentRelation(newNode); + addModificationToLog(newNode, ModifyAction.CREATE); + } + + @Override + public void addNode(MutableCompositeNode newNode) { + NodeUtils.fixParentRelation(newNode); + addModificationToLog(newNode, ModifyAction.CREATE); + } + + @Override + public void replaceNode(MutableSimpleNode replacementNode) { + addModificationToLog(replacementNode, ModifyAction.REPLACE); + } + + @Override + public void replaceNode(MutableCompositeNode replacementNode) { + addModificationToLog(replacementNode, ModifyAction.REPLACE); + } + + @Override + public void deleteNode(MutableCompositeNode deadNode) { + addModificationToLog(deadNode, ModifyAction.DELETE); + } + + @Override + public void deleteNode(MutableSimpleNode deadNode) { + addModificationToLog(deadNode, ModifyAction.DELETE); + } + + @Override + public void removeNode(MutableSimpleNode deadNode) { + addModificationToLog(deadNode, ModifyAction.REMOVE); + } + + @Override + public void removeNode(MutableCompositeNode deadNode) { + addModificationToLog(deadNode, ModifyAction.REMOVE); + } + + @Override + public void mergeNode(MutableCompositeNode alteredNode) { + addModificationToLog(alteredNode, ModifyAction.MERGE); + } + + /** + * @return minimalistic tree containing diffs only + */ + @Override + public CompositeNode buildDiffTree() { + Set> wanted = new HashSet<>(); + + // walk changeLog, collect all required nodes + for (MutableNode mutant : changeLog) { + wanted.addAll(collectSelfAndAllParents(mutant)); + } + + // walk wanted and add relevant keys + Map mapOfLists = NodeUtils.buildMapOfListNodes(context); + for (Node outlaw : wanted) { + if (outlaw instanceof CompositeNode) { + String path = NodeUtils.buildPath(outlaw); + if (mapOfLists.containsKey(path)) { + ListSchemaNode listSchema = mapOfLists.get(path); + if (listSchema.getQName().equals(outlaw.getNodeType())) { + // try to add key subnode to wanted list + List supportedKeys = listSchema.getKeyDefinition(); + CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal(); + for (Node outlawOriginalChild : outlawOriginal.getChildren()) { + if (supportedKeys.contains(outlawOriginalChild.getNodeType())) { + originalToMutable.getMutableEquivalent(outlawOriginalChild); + } + } + } + } + } + } + + return originalToMutable.getMutableRoot(); + } + + /** + * @param focusedDescendant + * @return set of parents and focusedAncestor itself + */ + private static Set> collectSelfAndAllParents(Node focusedDescendant) { + Set> family = new HashSet<>(); + Node tmpNode = focusedDescendant; + while (tmpNode != null) { + family.add(tmpNode); + tmpNode = tmpNode.getParent(); + } + return family; + } + + /** + * @param originalNode + * @return mutable version of given node + */ + @Override + public Node getMutableEquivalent(Node originalNode) { + return originalToMutable.getMutableEquivalent(originalNode); + } + +} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeUtils.java index df7960ddb8..6473c8100a 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeUtils.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/NodeUtils.java @@ -1,261 +1,251 @@ -/* - * 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.yangtools.yang.data.impl; - -import java.util.AbstractMap.SimpleEntry; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; -import java.util.Vector; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.NodeModification; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Element; - -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; - - -/** - * @author michal.rehak - * - */ -public abstract class NodeUtils { - - private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class); - - /** - * - */ - private static final String USER_KEY_NODE = "node"; - - /** - * @param node - * @return node path up till root node - */ - public static String buildPath(Node node) { - Vector breadCrumbs = new Vector<>(); - Node tmpNode = node; - while (tmpNode != null) { - breadCrumbs.insertElementAt(tmpNode.getNodeType().getLocalName(), 0); - tmpNode = tmpNode.getParent(); - } - - return Joiner.on(".").join(breadCrumbs); - } - - - /** - * @param treeRootNode - * @return dom tree, containing same node structure, yang nodes are associated - * to dom nodes as user data - */ +/* + * 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.yangtools.yang.data.impl; + +import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.ModifyAction; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.NodeModification; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + +/** + * @author michal.rehak + * + */ +public abstract class NodeUtils { + + private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class); + + /** + * + */ + private static final String USER_KEY_NODE = "node"; + + /** + * @param node + * @return node path up till root node + */ + public static String buildPath(Node node) { + List breadCrumbs = new ArrayList<>(); + Node tmpNode = node; + while (tmpNode != null) { + breadCrumbs.add(0, tmpNode.getNodeType().getLocalName()); + tmpNode = tmpNode.getParent(); + } + + return Joiner.on(".").join(breadCrumbs); + } + + /** + * @param treeRootNode + * @return dom tree, containing same node structure, yang nodes are + * associated to dom nodes as user data + */ public static org.w3c.dom.Document buildShadowDomTree(CompositeNode treeRootNode) { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - org.w3c.dom.Document doc = null; - try { - DocumentBuilder bob = dbf.newDocumentBuilder(); - doc = bob.newDocument(); - } catch (ParserConfigurationException e) { - LOG.error("documentBuilder problem", e); - return null; - } - - - Stack>> jobQueue = new Stack<>(); - jobQueue.push(new SimpleEntry>(doc, treeRootNode)); - - while (!jobQueue.isEmpty()) { - SimpleEntry> job = jobQueue.pop(); - org.w3c.dom.Node jointPlace = job.getKey(); - Node item = job.getValue(); - QName nodeType = item.getNodeType(); - Element itemEl = doc.createElementNS(nodeType.getNamespace().toString(), - item.getNodeType().getLocalName()); - itemEl.setUserData(USER_KEY_NODE, item, null); - if (item instanceof SimpleNode) { - Object value = ((SimpleNode) item).getValue(); - itemEl.setTextContent(String.valueOf(value)); - //itemEl.setAttribute("type", value.getClass().getSimpleName()); - } - if (item instanceof NodeModification) { - ModifyAction modificationAction = ((NodeModification) item).getModificationAction(); - if (modificationAction != null) { - itemEl.setAttribute("modifyAction", modificationAction.toString()); - } - } - - jointPlace.appendChild(itemEl); - - if (item instanceof CompositeNode) { - for (Node child : ((CompositeNode) item).getChildren()) { - jobQueue.push(new SimpleEntry>(itemEl, child)); - } - } - } - - return doc; - } - - /** - * @param doc - * @param xpathEx - * @return user data value on found node - * @throws XPathExpressionException - */ - @SuppressWarnings("unchecked") - public static T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) - throws XPathExpressionException { - T userNode = null; - XPathFactory xPathfactory = XPathFactory.newInstance(); - XPath xpath = xPathfactory.newXPath(); - XPathExpression expr = xpath.compile(xpathEx); - - org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE); - if (result != null) { - userNode = (T) result.getUserData(USER_KEY_NODE); - } - - return userNode; - } - - - /** - * build NodeMap, where key = qName; value = node - * - * @param value - * @return map of children, where key = qName and value is list of children groupped by qName - */ - public static Map>> buildNodeMap(List> value) { - Map>> nodeMapTmp = new HashMap<>(); - if (value == null || value.isEmpty()) { - throw new IllegalStateException( - "nodeList should not be null or empty"); - } - for (Node node : value) { - List> qList = nodeMapTmp.get(node.getNodeType()); - if (qList == null) { - qList = new ArrayList<>(); - nodeMapTmp.put(node.getNodeType(), qList); - } - qList.add(node); - } - return nodeMapTmp; - } - - - /** - * @param context - * @return map of lists, where key = path; value = {@link DataSchemaNode} - */ - public static Map buildMapOfListNodes( - SchemaContext context) { - Map mapOfLists = new HashMap<>(); - - Stack jobQueue = new Stack<>(); - jobQueue.addAll(context.getDataDefinitions()); - - while (!jobQueue.isEmpty()) { - DataSchemaNode dataSchema = jobQueue.pop(); - if (dataSchema instanceof ListSchemaNode) { - mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPath()), (ListSchemaNode) dataSchema); - } - - if (dataSchema instanceof DataNodeContainer) { - jobQueue.addAll(((DataNodeContainer) dataSchema).getChildNodes()); - } - } - - return mapOfLists; - } - - /** - * @param path - * @return - */ - private static String schemaPathToPath(List qNamesPath) { - List pathSeed = new ArrayList<>(); - for (QName qNameItem : qNamesPath) { - pathSeed.add(qNameItem.getLocalName()); - } - return Joiner.on(".").join(pathSeed); - } - - /** - * add given node to it's parent's list of children - * @param newNode - */ - public static void fixParentRelation(Node newNode) { - if (newNode.getParent() != null) { - List> siblings = newNode.getParent().getChildren(); - if (!siblings.contains(newNode)) { - siblings.add(newNode); - } - } - } - - /** - * crawl all children of given node and assign it as their parent - * @param parentNode - */ - public static void fixChildrenRelation(CompositeNode parentNode) { - if (parentNode.getChildren() != null) { - for (Node child : parentNode.getChildren()) { - if (child instanceof AbstractNodeTO) { - ((AbstractNodeTO) child).setParent(parentNode); - } - } - } - } - - - /** - * @param keys - * @param dataMap - * @return list of values of map, found by given keys - */ - public static List collectMapValues(List keys, - Map dataMap) { - List valueSubList = new ArrayList<>(); - for (T key : keys) { - valueSubList.add(dataMap.get(key)); - } - - return valueSubList; - } - - /** - * @param nodes - * @return list of children in list of appropriate type - */ - public static List> buildChildrenList(Node...nodes) { - return Lists.newArrayList(nodes); - } - -} + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + org.w3c.dom.Document doc = null; + try { + DocumentBuilder bob = dbf.newDocumentBuilder(); + doc = bob.newDocument(); + } catch (ParserConfigurationException e) { + LOG.error("documentBuilder problem", e); + return null; + } + + Stack>> jobQueue = new Stack<>(); + jobQueue.push(new SimpleEntry>(doc, treeRootNode)); + + while (!jobQueue.isEmpty()) { + SimpleEntry> job = jobQueue.pop(); + org.w3c.dom.Node jointPlace = job.getKey(); + Node item = job.getValue(); + QName nodeType = item.getNodeType(); + Element itemEl = doc.createElementNS(nodeType.getNamespace().toString(), item.getNodeType().getLocalName()); + itemEl.setUserData(USER_KEY_NODE, item, null); + if (item instanceof SimpleNode) { + Object value = ((SimpleNode) item).getValue(); + itemEl.setTextContent(String.valueOf(value)); + } + if (item instanceof NodeModification) { + ModifyAction modificationAction = ((NodeModification) item).getModificationAction(); + if (modificationAction != null) { + itemEl.setAttribute("modifyAction", modificationAction.toString()); + } + } + + jointPlace.appendChild(itemEl); + + if (item instanceof CompositeNode) { + for (Node child : ((CompositeNode) item).getChildren()) { + jobQueue.push(new SimpleEntry>(itemEl, child)); + } + } + } + + return doc; + } + + /** + * @param doc + * @param xpathEx + * @return user data value on found node + * @throws XPathExpressionException + */ + @SuppressWarnings("unchecked") + public static T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) throws XPathExpressionException { + T userNode = null; + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile(xpathEx); + + org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE); + if (result != null) { + userNode = (T) result.getUserData(USER_KEY_NODE); + } + + return userNode; + } + + /** + * build NodeMap, where key = qName; value = node + * + * @param value + * @return map of children, where key = qName and value is list of children + * groupped by qName + */ + public static Map>> buildNodeMap(List> value) { + Map>> nodeMapTmp = new HashMap<>(); + if (value == null || value.isEmpty()) { + throw new IllegalStateException("nodeList should not be null or empty"); + } + for (Node node : value) { + List> qList = nodeMapTmp.get(node.getNodeType()); + if (qList == null) { + qList = new ArrayList<>(); + nodeMapTmp.put(node.getNodeType(), qList); + } + qList.add(node); + } + return nodeMapTmp; + } + + /** + * @param context + * @return map of lists, where key = path; value = {@link DataSchemaNode} + */ + public static Map buildMapOfListNodes(SchemaContext context) { + Map mapOfLists = new HashMap<>(); + + Stack jobQueue = new Stack<>(); + jobQueue.addAll(context.getDataDefinitions()); + + while (!jobQueue.isEmpty()) { + DataSchemaNode dataSchema = jobQueue.pop(); + if (dataSchema instanceof ListSchemaNode) { + mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPath()), (ListSchemaNode) dataSchema); + } + + if (dataSchema instanceof DataNodeContainer) { + jobQueue.addAll(((DataNodeContainer) dataSchema).getChildNodes()); + } + } + + return mapOfLists; + } + + /** + * @param path + * @return + */ + private static String schemaPathToPath(List qNamesPath) { + List pathSeed = new ArrayList<>(); + for (QName qNameItem : qNamesPath) { + pathSeed.add(qNameItem.getLocalName()); + } + return Joiner.on(".").join(pathSeed); + } + + /** + * add given node to it's parent's list of children + * + * @param newNode + */ + public static void fixParentRelation(Node newNode) { + if (newNode.getParent() != null) { + List> siblings = newNode.getParent().getChildren(); + if (!siblings.contains(newNode)) { + siblings.add(newNode); + } + } + } + + /** + * crawl all children of given node and assign it as their parent + * + * @param parentNode + */ + public static void fixChildrenRelation(CompositeNode parentNode) { + if (parentNode.getChildren() != null) { + for (Node child : parentNode.getChildren()) { + if (child instanceof AbstractNodeTO) { + ((AbstractNodeTO) child).setParent(parentNode); + } + } + } + } + + /** + * @param keys + * @param dataMap + * @return list of values of map, found by given keys + */ + public static List collectMapValues(List keys, Map dataMap) { + List valueSubList = new ArrayList<>(); + for (T key : keys) { + valueSubList.add(dataMap.get(key)); + } + + return valueSubList; + } + + /** + * @param nodes + * @return list of children in list of appropriate type + */ + public static List> buildChildrenList(Node... nodes) { + return Lists.newArrayList(nodes); + } + +} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImplTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImplTest.java index c6558f6227..f7fc7c22b8 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImplTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/NodeModificationBuilderImplTest.java @@ -1,301 +1,296 @@ -/* - * 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.yangtools.yang.data.impl; - -import java.net.URI; -import java.util.Date; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; -import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; - -/** - * @author michal.rehak - * - */ -public class NodeModificationBuilderImplTest { - - private static final Logger LOG = LoggerFactory - .getLogger(NodeModificationBuilderImplTest.class); - - private SchemaContext schemaCtx; - private QName qName; - private CompositeNode network; - private NodeModificationBuilderImpl nodeModificationBuilder; - - private String ns; - - /** - * @throws Exception - */ - private void dumpResult() throws Exception { - CompositeNode diffTree = nodeModificationBuilder.buildDiffTree(); - CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null); - - Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable); - NodeHelper.dumpDoc(diffShadow, System.out); - } - - /** - * prepare schemaContext - * @throws Exception - */ - @Before - public void setUp() throws Exception { - schemaCtx = NodeHelper.loadSchemaContext(); - - ns = "urn:opendaylight:controller:network"; - qName = new QName( - new URI(ns), - new Date(1369000800000L), "topos"); - network = NodeHelper.buildTestConfigTree(qName); - - nodeModificationBuilder = new NodeModificationBuilderImpl(network, schemaCtx); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)} - * . - */ - @Test - public void testGetMutableEquivalent() { - MutableCompositeNode rootMutable = (MutableCompositeNode) - nodeModificationBuilder.getMutableEquivalent(network); - - CompositeNode topologies = network.getCompositesByName("topologies").iterator().next(); - Node mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies); - CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next(); - - Assert.assertSame(topologiesMutable, mutableEquivalent); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeAddSimple() throws Exception { - LOG.debug("testBuildDiffTreeAddSimple"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); - - MutableCompositeNode mutableParent = (MutableCompositeNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode( - new QName(needle.getNodeType(), "anySubNode"), mutableParent, "42", null, null); - - nodeModificationBuilder.addNode(newMutable); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeAddComposite() throws Exception { - LOG.debug("testBuildDiffTreeAddComposite"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); - - MutableCompositeNode mutableParent = (MutableCompositeNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode( - new QName(needle.getNodeType(), "anySubNode"), null, "42", null, null); - - MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode( - new QName(needle.getNodeType(), "anySubNode"), mutableParent, - NodeUtils.buildChildrenList(newMutable), null, null); - NodeUtils.fixChildrenRelation(newMutableCom); - newMutableCom.init(); - - nodeModificationBuilder.addNode(newMutableCom); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeDeleteComposite() throws Exception { - LOG.debug("testBuildDiffTreeDeleteComposite"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable()); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeDeleteSimple() throws Exception { - LOG.debug("testBuildDiffTreeDeleteSimple"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - nodeModificationBuilder.deleteNode(mutableNeedle); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeMerge() throws Exception { - LOG.debug("testBuildDiffTreeMerge"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - mutableNeedle.setValue("tpId_18x"); - nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable()); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeRemoveComposite() throws Exception { - LOG.debug("testBuildDiffTreeRemoveComposite"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable()); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeRemoveSimple() throws Exception { - LOG.debug("testBuildDiffTreeRemoveSimple"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - nodeModificationBuilder.removeNode(mutableNeedle); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeReplaceComposite() throws Exception { - LOG.debug("testBuildDiffTreeReplaceComposite"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - mutableNeedle.setValue("tpId_18x"); - nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable()); - dumpResult(); - } - - /** - * Test method for - * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} - * . - * @throws Exception - */ - @Test - public void testBuildDiffTreeReplaceSimple() throws Exception { - LOG.debug("testBuildDiffTreeReplaceSimple"); - Document networkShadow = NodeUtils.buildShadowDomTree(network); - SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, - NodeHelper.AddNamespaceToPattern( - "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); - - @SuppressWarnings("unchecked") - MutableSimpleNode mutableNeedle = (MutableSimpleNode) - nodeModificationBuilder.getMutableEquivalent(needle); - - mutableNeedle.setValue("tpId_18x"); - nodeModificationBuilder.replaceNode(mutableNeedle); - dumpResult(); - } - - -} +/* + * 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.yangtools.yang.data.impl; + +import java.net.URI; +import java.util.Date; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; +import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; + +/** + * @author michal.rehak + * + */ +public class NodeModificationBuilderImplTest { + + private static final Logger LOG = LoggerFactory.getLogger(NodeModificationBuilderImplTest.class); + + private SchemaContext schemaCtx; + private QName qName; + private CompositeNode network; + private NodeModificationBuilderImpl nodeModificationBuilder; + + private String ns; + + /** + * @throws Exception + */ + private void dumpResult() throws Exception { + CompositeNode diffTree = nodeModificationBuilder.buildDiffTree(); + CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null); + + Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable); + NodeHelper.dumpDoc(diffShadow, System.out); + } + + /** + * prepare schemaContext + * + * @throws Exception + */ + @Before + public void setUp() throws Exception { + schemaCtx = NodeHelper.loadSchemaContext(); + + ns = "urn:opendaylight:controller:network"; + qName = new QName(new URI(ns), new Date(1369000800000L), "topos"); + network = NodeHelper.buildTestConfigTree(qName); + + nodeModificationBuilder = new NodeModificationBuilderImpl(schemaCtx); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)} + * . + */ + @Test + public void testGetMutableEquivalent() { + MutableCompositeNode rootMutable = (MutableCompositeNode) nodeModificationBuilder.getMutableEquivalent(network); + + CompositeNode topologies = network.getCompositesByName("topologies").iterator().next(); + Node mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies); + CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next(); + + Assert.assertSame(topologiesMutable, mutableEquivalent); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeAddSimple() throws Exception { + LOG.debug("testBuildDiffTreeAddSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); + + MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode(new QName(needle.getNodeType(), + "anySubNode"), mutableParent, "42", null, null); + + nodeModificationBuilder.addNode(newMutable); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeAddComposite() throws Exception { + LOG.debug("testBuildDiffTreeAddComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow, + NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns)); + + MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + MutableSimpleNode newMutable = NodeFactory.createMutableSimpleNode(new QName(needle.getNodeType(), + "anySubNode"), null, "42", null, null); + + MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode(new QName(needle.getNodeType(), + "anySubNode"), mutableParent, NodeUtils.buildChildrenList(newMutable), null, null); + NodeUtils.fixChildrenRelation(newMutableCom); + newMutableCom.init(); + + nodeModificationBuilder.addNode(newMutableCom); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeDeleteComposite() throws Exception { + LOG.debug("testBuildDiffTreeDeleteComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeDeleteSimple() throws Exception { + LOG.debug("testBuildDiffTreeDeleteSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + nodeModificationBuilder.deleteNode(mutableNeedle); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeMerge() throws Exception { + LOG.debug("testBuildDiffTreeMerge"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + mutableNeedle.setValue("tpId_18x"); + nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeRemoveComposite() throws Exception { + LOG.debug("testBuildDiffTreeRemoveComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeRemoveSimple() throws Exception { + LOG.debug("testBuildDiffTreeRemoveSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + nodeModificationBuilder.removeNode(mutableNeedle); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeReplaceComposite() throws Exception { + LOG.debug("testBuildDiffTreeReplaceComposite"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + mutableNeedle.setValue("tpId_18x"); + nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable()); + dumpResult(); + } + + /** + * Test method for + * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()} + * . + * + * @throws Exception + */ + @Test + public void testBuildDiffTreeReplaceSimple() throws Exception { + LOG.debug("testBuildDiffTreeReplaceSimple"); + Document networkShadow = NodeUtils.buildShadowDomTree(network); + SimpleNode needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern( + "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns)); + + @SuppressWarnings("unchecked") + MutableSimpleNode mutableNeedle = (MutableSimpleNode) nodeModificationBuilder + .getMutableEquivalent(needle); + + mutableNeedle.setValue("tpId_18x"); + nodeModificationBuilder.replaceNode(mutableNeedle); + dumpResult(); + } + +} diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java index 0621cb4ab6..d5c53338a4 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java @@ -36,22 +36,31 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; final class Util { + + /** + * It isn't desirable to create instances of this class + */ + private Util() { + } + static final String YANG_SUFFIX = "yang"; + private static final int CACHE_SIZE = 10; // Cache for listed directories and found yang files. Typically yang files // are utilized twice. First: code is generated during generate-sources // phase Second: yang files are copied as resources during // generate-resources phase. This cache ensures that yang files are listed // only once. - private static Map> cache = Maps.newHashMapWithExpectedSize(10); + private static Map> cache = Maps.newHashMapWithExpectedSize(CACHE_SIZE); /** * List files recursively and return as array of String paths. Use cache of * size 1. */ static Collection listFiles(File root) throws FileNotFoundException { - if (cache.get(root) != null) + if (cache.get(root) != null) { return cache.get(root); + } if (!root.exists()) { throw new FileNotFoundException(root.toString()); @@ -78,7 +87,7 @@ final class Util { } } if (excluded) { - if(log != null) { + if (log != null) { log.info(Util.message("%s file excluded %s", YangToSourcesProcessor.LOG_PREFIX, Util.YANG_SUFFIX.toUpperCase(), f)); } @@ -131,15 +140,17 @@ final class Util { private static Class resolveClass(String codeGeneratorClass, Class baseType) throws ClassNotFoundException { Class clazz = Class.forName(codeGeneratorClass); - if (!isImplemented(baseType, clazz)) + if (!isImplemented(baseType, clazz)) { throw new IllegalArgumentException("Code generator " + clazz + " has to implement " + baseType); + } return clazz; } private static boolean isImplemented(Class expectedIface, Class byClazz) { for (Class iface : byClazz.getInterfaces()) { - if (iface.equals(expectedIface)) + if (iface.equals(expectedIface)) { return true; + } } return false; } @@ -170,8 +181,8 @@ final class Util { return Preconditions.checkNotNull(obj, "Parameter " + paramName + " is null"); } - final static class YangsInZipsResult implements Closeable { - final List yangStreams; + static final class YangsInZipsResult implements Closeable { + private final List yangStreams; private final List zipInputStreams; private YangsInZipsResult(List yangStreams, List zipInputStreams) { @@ -188,6 +199,10 @@ final class Util { is.close(); } } + + public List getYangStreams() { + return this.yangStreams; + } } static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project) @@ -225,14 +240,13 @@ final class Util { ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); - if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) { - if (entry.isDirectory() == false && entryName.endsWith(".yang")) { - foundFilesForReporting.add(entryName); - // This will be closed after all strams are - // parsed. - InputStream entryStream = zip.getInputStream(entry); - yangsFromDependencies.add(entryStream); - } + if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR) + && !entry.isDirectory() && entryName.endsWith(".yang")) { + foundFilesForReporting.add(entryName); + // This will be closed after all strams are + // parsed. + InputStream entryStream = zip.getInputStream(entry); + yangsFromDependencies.add(entryStream); } } } @@ -248,7 +262,7 @@ final class Util { return new YangsInZipsResult(yangsFromDependencies, zips); } - final static class ContextHolder { + static final class ContextHolder { private final SchemaContext context; private final Set yangModules; diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java index cebef8c69c..429b57ce70 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java @@ -20,7 +20,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg; import org.slf4j.impl.StaticLoggerBinder; @@ -56,13 +55,14 @@ public final class YangToSourcesMojo extends AbstractMojo { * with .yang suffix). */ @Parameter(required = false) - private String yangFilesRootDir; // defaults to ${basedir}/src/main/yang + // defaults to ${basedir}/src/main/yang + private String yangFilesRootDir; @Parameter(required = false) private String[] excludeFiles; @Parameter(property = "project", required = true, readonly = true) - protected MavenProject project; + private MavenProject project; @Parameter(property = "inspectDependencies", required = true, readonly = true) private boolean inspectDependencies; @@ -73,6 +73,10 @@ public final class YangToSourcesMojo extends AbstractMojo { } + public void setProject(MavenProject project) { + this.project = project; + } + @VisibleForTesting YangToSourcesMojo(YangToSourcesProcessor processor) { this.yangToSourcesProcessor = processor; diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java index eb7269d818..c32dcc27fe 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java @@ -54,7 +54,11 @@ class YangToSourcesProcessor { MavenProject project, boolean inspectDependencies, YangProvider yangProvider) { this.log = Util.checkNotNull(log, "log"); this.yangFilesRootDir = Util.checkNotNull(yangFilesRootDir, "yangFilesRootDir"); - this.excludedFiles = excludedFiles; + this.excludedFiles = new File[excludedFiles.length]; + int i = 0; + for (File file : excludedFiles) { + this.excludedFiles[i++] = new File(file.getPath()); + } this.codeGenerators = Collections.unmodifiableList(Util.checkNotNull(codeGenerators, "codeGenerators")); this.project = Util.checkNotNull(project, "project"); this.inspectDependencies = inspectDependencies; @@ -69,7 +73,7 @@ class YangToSourcesProcessor { public void execute() throws MojoExecutionException, MojoFailureException { ContextHolder context = processYang(); generateSources(context); - yangProvider.addYangsToMETA_INF(log, project, yangFilesRootDir, excludedFiles); + yangProvider.addYangsToMetaInf(log, project, yangFilesRootDir, excludedFiles); } private ContextHolder processYang() throws MojoExecutionException { @@ -87,7 +91,7 @@ class YangToSourcesProcessor { YangsInZipsResult dependentYangResult = Util.findYangFilesInDependenciesAsStream(log, project); Closeable dependentYangResult1 = dependentYangResult; closeables.add(dependentYangResult1); - all.addAll(dependentYangResult.yangStreams); + all.addAll(dependentYangResult.getYangStreams()); } allYangModules = parser.parseYangModelsFromStreamsMapped(all); @@ -119,11 +123,11 @@ class YangToSourcesProcessor { static class YangProvider { - private static final String yangResourceDir = "target" + File.separator + "yang"; + private static final String YANG_RESOURCE_DIR = "target" + File.separator + "yang"; - void addYangsToMETA_INF(Log log, MavenProject project, File yangFilesRootDir, File[] excludedFiles) + void addYangsToMetaInf(Log log, MavenProject project, File yangFilesRootDir, File[] excludedFiles) throws MojoFailureException { - File targetYangDir = new File(project.getBasedir(), yangResourceDir); + File targetYangDir = new File(project.getBasedir(), YANG_RESOURCE_DIR); try { Collection files = Util.listFiles(yangFilesRootDir, excludedFiles, null); @@ -145,8 +149,9 @@ class YangToSourcesProcessor { private static void setResource(File targetYangDir, String targetPath, MavenProject project) { Resource res = new Resource(); res.setDirectory(targetYangDir.getPath()); - if (targetPath != null) + if (targetPath != null) { res.setTargetPath(targetPath); + } project.addResource(res); } } diff --git a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java index 2f7a050cb0..a48124028a 100644 --- a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java +++ b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java @@ -49,7 +49,7 @@ public class GenerateSourcesTest { yang = new File(getClass().getResource("/yang/mock.yang").getFile()).getParent(); outDir = new File("/outputDir"); YangProvider mock = mock(YangProvider.class); - doNothing().when(mock).addYangsToMETA_INF(any(Log.class), any(MavenProject.class), any(File.class), + doNothing().when(mock).addYangsToMetaInf(any(Log.class), any(MavenProject.class), any(File.class), any(File[].class)); YangToSourcesProcessor processor = new YangToSourcesProcessor(mock(Log.class), new File(yang), new File[] {}, @@ -57,7 +57,7 @@ public class GenerateSourcesTest { mock); mojo = new YangToSourcesMojo(processor); doReturn(new File("")).when(project).getBasedir(); - mojo.project = project; + mojo.setProject(project); } @Test diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/AugmentationSchema.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/AugmentationSchema.java index 22b952ce36..967a61d76a 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/AugmentationSchema.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/AugmentationSchema.java @@ -1,55 +1,55 @@ -/* - * 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.yangtools.yang.model.api; - -import java.util.List; - -/** - * AugmentationSchema represents augment definition. The "augment" statement - * allows a module or submodule to add to the schema tree defined in an external - * module, or the current module and its submodules, and to add to the nodes - * from a grouping in a "uses" statement. - */ -public interface AugmentationSchema extends DataNodeContainer { - - /** - * @return when statement - */ - RevisionAwareXPath getWhenCondition(); - - /** - * @return textual description of this augment. - */ - String getDescription(); - - /** - * @return textual cross-reference to an external document that provides - * additional information relevant to this node. - */ - String getReference(); - - /** - * @return actual status of this node. - */ - Status getStatus(); - - /** - * @return SchemaPath that identifies a node in the schema tree. This node - * is called the augment's target node. The target node MUST be - * either a container, list, choice, case, input, output, or - * notification node. It is augmented with the nodes defined as - * child nodes of this AugmentationSchema. - */ - SchemaPath getTargetPath(); - - /** - * @return collection of all unknown nodes defined in this augmentation - */ - public List getUnknownSchemaNodes(); - -} +/* + * 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.yangtools.yang.model.api; + +import java.util.List; + +/** + * AugmentationSchema represents augment definition. The "augment" statement + * allows a module or submodule to add to the schema tree defined in an external + * module, or the current module and its submodules, and to add to the nodes + * from a grouping in a "uses" statement. + */ +public interface AugmentationSchema extends DataNodeContainer { + + /** + * @return when statement + */ + RevisionAwareXPath getWhenCondition(); + + /** + * @return textual description of this augment. + */ + String getDescription(); + + /** + * @return textual cross-reference to an external document that provides + * additional information relevant to this node. + */ + String getReference(); + + /** + * @return actual status of this node. + */ + Status getStatus(); + + /** + * @return SchemaPath that identifies a node in the schema tree. This node + * is called the augment's target node. The target node MUST be + * either a container, list, choice, case, input, output, or + * notification node. It is augmented with the nodes defined as + * child nodes of this AugmentationSchema. + */ + SchemaPath getTargetPath(); + + /** + * @return collection of all unknown nodes defined in this augmentation + */ + List getUnknownSchemaNodes(); + +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Deviation.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Deviation.java index 8c3391bd21..3a7cce85b5 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Deviation.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Deviation.java @@ -1,53 +1,53 @@ -/* - * 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.yangtools.yang.model.api; - -import java.util.List; - -/** - * Interface describing YANG 'deviation' statement. - *

    - * The 'deviation' statement defines a hierarchy of a module that the device - * does not implement faithfully. Deviations define the way a device deviate - * from a standard. - *

    - */ -public interface Deviation { - - /** - * Enum describing YANG deviation 'deviate' statement. It defines how the - * device's implementation of the target node deviates from its original - * definition. - */ - enum Deviate { - NOT_SUPPORTED, ADD, REPLACE, DELETE - } - - /** - * @return SchemaPath that identifies the node in the schema tree where a - * deviation from the module occurs. - */ - SchemaPath getTargetPath(); - - /** - * @return deviate statement of this deviation - */ - Deviate getDeviate(); - - /** - * @return textual cross-reference to an external document that provides - * additional information relevant to this node. - */ - String getReference(); - - /** - * @return collection of all unknown nodes defined under this schema node. - */ - public List getUnknownSchemaNodes(); - -} +/* + * 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.yangtools.yang.model.api; + +import java.util.List; + +/** + * Interface describing YANG 'deviation' statement. + *

    + * The 'deviation' statement defines a hierarchy of a module that the device + * does not implement faithfully. Deviations define the way a device deviate + * from a standard. + *

    + */ +public interface Deviation { + + /** + * Enum describing YANG deviation 'deviate' statement. It defines how the + * device's implementation of the target node deviates from its original + * definition. + */ + enum Deviate { + NOT_SUPPORTED, ADD, REPLACE, DELETE + } + + /** + * @return SchemaPath that identifies the node in the schema tree where a + * deviation from the module occurs. + */ + SchemaPath getTargetPath(); + + /** + * @return deviate statement of this deviation + */ + Deviate getDeviate(); + + /** + * @return textual cross-reference to an external document that provides + * additional information relevant to this node. + */ + String getReference(); + + /** + * @return collection of all unknown nodes defined under this schema node. + */ + List getUnknownSchemaNodes(); + +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ExtensionDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ExtensionDefinition.java index c65200c7e8..5154df6d86 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ExtensionDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ExtensionDefinition.java @@ -27,7 +27,7 @@ public interface ExtensionDefinition extends SchemaNode { * Keyword. If no argument statement is present the method will * return null */ - public String getArgument(); + String getArgument(); /** * This statement indicates if the argument is mapped to an XML element in @@ -46,5 +46,5 @@ public interface ExtensionDefinition extends SchemaNode { * YIN or returns false if the argument is mapped to an * XML attribute. */ - public boolean isYinElement(); + boolean isYinElement(); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ListSchemaNode.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ListSchemaNode.java index c36528adbb..ad8d999816 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ListSchemaNode.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ListSchemaNode.java @@ -1,39 +1,38 @@ -/* - * 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.yangtools.yang.model.api; - -import java.util.List; - -import org.opendaylight.yangtools.yang.common.QName; - -/** - * Interface describing YANG 'list' statement. - *

    - * The 'list' statement is used to define an interior data node in the schema - * tree. A list entry is uniquely identified by the values of the list's keys, - * if defined. - *

    - */ -public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget, - DataSchemaNode { - - /** - * @return List of QNames of leaf identifiers of this list - */ - public List getKeyDefinition(); - - /** - * YANG 'ordered-by' statement. It defines whether the order of entries - * within a list are determined by the user or the system. If not present, - * default is false. - * - * @return true if ordered-by argument is "user", false otherwise - */ - boolean isUserOrdered(); - -} +/* + * 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.yangtools.yang.model.api; + +import java.util.List; + +import org.opendaylight.yangtools.yang.common.QName; + +/** + * Interface describing YANG 'list' statement. + *

    + * The 'list' statement is used to define an interior data node in the schema + * tree. A list entry is uniquely identified by the values of the list's keys, + * if defined. + *

    + */ +public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget, DataSchemaNode { + + /** + * @return List of QNames of leaf identifiers of this list + */ + List getKeyDefinition(); + + /** + * YANG 'ordered-by' statement. It defines whether the order of entries + * within a list are determined by the user or the system. If not present, + * default is false. + * + * @return true if ordered-by argument is "user", false otherwise + */ + boolean isUserOrdered(); + +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/RevisionAwareXPath.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/RevisionAwareXPath.java index 95d46ac8b2..f2d911a7da 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/RevisionAwareXPath.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/RevisionAwareXPath.java @@ -23,7 +23,7 @@ public interface RevisionAwareXPath { * @return true if the XPapth starts in root of Yang model, * otherwise returns false */ - public boolean isAbsolute(); + boolean isAbsolute(); /** * Returns the XPath formatted string as is defined in model.
    @@ -32,5 +32,5 @@ public interface RevisionAwareXPath { * * @return the XPath formatted string as is defined in model. */ - public String toString(); + String toString(); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaNode.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaNode.java index 84dc24a0b4..146da3ae65 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaNode.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaNode.java @@ -21,7 +21,7 @@ public interface SchemaNode { * * @return QName with the name of the schema node */ - public QName getQName(); + QName getQName(); /** * Returns the schema path of the instance of the type @@ -29,7 +29,7 @@ public interface SchemaNode { * * @return schema path of the schema node */ - public SchemaPath getPath(); + SchemaPath getPath(); /** * Returns description of the instance of the type SchemaNode @@ -37,7 +37,7 @@ public interface SchemaNode { * @return string with textual description the node which represents the * argument of the YANG description substatement */ - public String getDescription(); + String getDescription(); /** * Returns reference of the instance of the type SchemaNode @@ -49,7 +49,7 @@ public interface SchemaNode { * represents the argument of the YANG reference * substatement */ - public String getReference(); + String getReference(); /** * Returns status of the instance of the type SchemaNode @@ -57,7 +57,7 @@ public interface SchemaNode { * @return status of this node which represents the argument of the YANG * status substatement */ - public Status getStatus(); + Status getStatus(); /** * @@ -66,6 +66,6 @@ public interface SchemaNode { * * @return list of unknown schema nodes defined under this schema node. */ - public List getUnknownSchemaNodes(); + List getUnknownSchemaNodes(); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java index 325b0c2c0a..f05c2b26da 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java @@ -19,17 +19,19 @@ import org.opendaylight.yangtools.yang.common.QName; * */ public class SchemaPath { + private final int hashBooleanTrue = 1231; + private final int hashBooleanFalse = 1237; /** * List of QName instances which represents complete path to the node. */ - final List path; + private final List path; /** * Boolean value which represents type of schema path (relative or * absolute). */ - final boolean absolute; + private final boolean absolute; /** * Constructs new instance of this class with the concrete path. @@ -70,7 +72,7 @@ public class SchemaPath { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (absolute ? 1231 : 1237); + result = prime * result + (absolute ? hashBooleanTrue : hashBooleanFalse); result = prime * result + ((path == null) ? 0 : path.hashCode()); return result; } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java index 64a3fd2ac5..320fdca5a8 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java @@ -41,7 +41,7 @@ public interface EnumTypeDefinition extends TypeDefinition { * * @return name of each assigned name of an enumeration type. */ - public String getName(); + String getName(); /** * The "value" statement, which is optional, is used to associate an @@ -51,6 +51,6 @@ public interface EnumTypeDefinition extends TypeDefinition { * * @return integer value assigned to enumeration */ - public Integer getValue(); + Integer getValue(); } } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/IdentityTypeDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/IdentityTypeDefinition.java index c5647b7835..86f6379f1f 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/IdentityTypeDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/IdentityTypeDefinition.java @@ -21,5 +21,5 @@ public interface IdentityTypeDefinition extends TypeDefinitionRevisionAwareXPath
    */ - public RevisionAwareXPath getPathStatement(); + RevisionAwareXPath getPathStatement(); /** * Returns true|false which represents argument of @@ -33,5 +33,5 @@ public interface InstanceIdentifierTypeDefinition extends TypeDefinitionrequire-instance * statement is true and vice versa */ - public boolean requireInstance(); + boolean requireInstance(); } diff --git a/yang/yang-model-util/.gitignore b/yang/yang-model-util/.gitignore new file mode 100644 index 0000000000..0aba2ebbb3 --- /dev/null +++ b/yang/yang-model-util/.gitignore @@ -0,0 +1 @@ +/src/main/xtend-gen \ No newline at end of file diff --git a/yang/yang-model-util/pom.xml b/yang/yang-model-util/pom.xml index 7b02980732..799ac6bac8 100644 --- a/yang/yang-model-util/pom.xml +++ b/yang/yang-model-util/pom.xml @@ -1,61 +1,65 @@ - - - - org.opendaylight.yangtools - yang - 0.5.7-SNAPSHOT - - - 4.0.0 - yang-model-util - ${project.artifactId} - ${project.artifactId} - - - - - - org.eclipse.xtend - xtend-maven-plugin - 2.4.2 - - - - compile - - - ${basedir}/src/main/xtend-gen - - - - - - maven-clean-plugin - 2.4.1 - - - - ${basedir}/src/main/xtend-gen - - ** - - - - - - - - - - - ${project.groupId} - yang-model-api - - - org.eclipse.xtend - org.eclipse.xtend.lib - 2.4.2 - - - + + + + org.opendaylight.yangtools + yang + 0.5.7-SNAPSHOT + + + 4.0.0 + yang-model-util + ${project.artifactId} + ${project.artifactId} + + + + + + org.eclipse.xtend + xtend-maven-plugin + 2.4.2 + + + + compile + + + ${basedir}/src/main/xtend-gen + + + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir}/src/main/xtend-gen + + ** + + + + + + + + + + + ${project.groupId} + yang-model-api + + + org.eclipse.xtend + org.eclipse.xtend.lib + 2.4.2 + + + junit + junit + + + diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java index 23528e52e4..8dd79e6a2d 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSignedInteger.java @@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; * interface which represents SIGNED Integer values defined in Yang language.
    * The integer built-in types in Yang are int8, int16, int32, int64. They * represent signed integers of different sizes: - * + * *
      *
    • int8 - represents integer values between -128 and 127, inclusively.
    • *
    • int16 - represents integer values between -32768 and 32767, inclusively.
    • @@ -32,13 +32,13 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; *
    • int64 - represents integer values between -9223372036854775808 and * 9223372036854775807, inclusively.
    • *
    - * + * */ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { private final QName name; private final SchemaPath path; private final String description; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2"; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2"; private final String units; private final List rangeStatements; @@ -83,7 +83,7 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { @Override public String getReference() { - return reference; + return REFERENCE; } @Override @@ -109,7 +109,6 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); result = prime * result + ((units == null) ? 0 : units.hashCode()); return result; } @@ -154,13 +153,6 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { } else if (!rangeStatements.equals(other.rangeStatements)) { 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; @@ -181,7 +173,7 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { builder.append(", description="); builder.append(description); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", units="); builder.append(units); builder.append(", rangeStatements="); diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java index 7d5a8f68d3..646fecb9b6 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractUnsignedInteger.java @@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * interface which represents UNSIGNED Integer values defined in Yang language.
    * The integer built-in types in Yang are uint8, uint16, uint32, and uint64. * They represent unsigned integers of different sizes: - * + * *
      *
    • uint8 - represents integer values between 0 and 255, inclusively.
    • *
    • uint16 - represents integer values between 0 and 65535, inclusively.
    • @@ -28,19 +28,19 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit *
    • uint64 - represents integer values between 0 and 18446744073709551615, * inclusively.
    • *
    - * + * */ public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition { private static final long MIN_VALUE = 0; private final QName name; private final SchemaPath path; private final String description; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2"; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2"; private final String units; private final List rangeStatements; /** - * + * * @param name * @param description * @param maxRange @@ -79,7 +79,7 @@ public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefi @Override public String getReference() { - return reference; + return REFERENCE; } @Override @@ -105,7 +105,6 @@ public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefi result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); result = prime * result + ((units == null) ? 0 : units.hashCode()); return result; } @@ -150,13 +149,6 @@ public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefi } else if (!rangeStatements.equals(other.rangeStatements)) { 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; @@ -177,7 +169,7 @@ public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefi builder.append(", description="); builder.append(description); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", units="); builder.append(units); builder.append(", rangeStatements="); diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java index 5a3622a89e..c6ba5d619c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java @@ -16,18 +16,18 @@ public final class BaseConstraints { private BaseConstraints() { } - public static LengthConstraint lengthConstraint(final Number min, - final Number max, final String description, final String reference) { + public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description, + final String reference) { return new LengthConstraintImpl(min, max, description, reference); } - public static RangeConstraint rangeConstraint(final Number min, - final Number max, final String description, final String reference) { + public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description, + final String reference) { return new RangeConstraintImpl(min, max, description, reference); } - public static PatternConstraint patternConstraint(final String pattern, - final String description, final String reference) { + public static PatternConstraint patternConstraint(final String pattern, final String description, + final String reference) { return new PatternConstraintImpl(pattern, description, reference); } @@ -42,8 +42,7 @@ public final class BaseConstraints { private final String errorAppTag; private final String errorMessage; - public LengthConstraintImpl(Number min, Number max, - final String description, final String reference) { + public LengthConstraintImpl(Number min, Number max, final String description, final String reference) { super(); this.min = min; this.max = max; @@ -51,8 +50,7 @@ public final class BaseConstraints { this.reference = reference; this.errorAppTag = "length-out-of-specified-bounds"; - this.errorMessage = "The argument is out of bounds <" + min + ", " - + max + ">"; + this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">"; } @Override @@ -89,16 +87,12 @@ public final class BaseConstraints { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); - result = prime * result - + ((errorMessage == null) ? 0 : errorMessage.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); + result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode()); result = prime * result + ((max == null) ? 0 : max.hashCode()); result = prime * result + ((min == null) ? 0 : min.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + ((reference == null) ? 0 : reference.hashCode()); return result; } @@ -171,7 +165,7 @@ public final class BaseConstraints { } } - private final static class RangeConstraintImpl implements RangeConstraint { + private static final class RangeConstraintImpl implements RangeConstraint { private final Number min; private final Number max; @@ -181,8 +175,7 @@ public final class BaseConstraints { private final String errorAppTag; private final String errorMessage; - public RangeConstraintImpl(Number min, Number max, String description, - String reference) { + public RangeConstraintImpl(Number min, Number max, String description, String reference) { super(); this.min = min; this.max = max; @@ -190,8 +183,7 @@ public final class BaseConstraints { this.reference = reference; this.errorAppTag = "range-out-of-specified-bounds"; - this.errorMessage = "The argument is out of bounds <" + min + ", " - + max + ">"; + this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">"; } @Override @@ -228,16 +220,12 @@ public final class BaseConstraints { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); - result = prime * result - + ((errorMessage == null) ? 0 : errorMessage.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); + result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode()); result = prime * result + ((max == null) ? 0 : max.hashCode()); result = prime * result + ((min == null) ? 0 : min.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + ((reference == null) ? 0 : reference.hashCode()); return result; } @@ -318,8 +306,7 @@ public final class BaseConstraints { } } - private final static class PatternConstraintImpl implements - PatternConstraint { + private static final class PatternConstraintImpl implements PatternConstraint { private final String regex; private final String description; @@ -328,8 +315,7 @@ public final class BaseConstraints { private final String errorAppTag; private final String errorMessage; - public PatternConstraintImpl(final String regex, - final String description, final String reference) { + public PatternConstraintImpl(final String regex, final String description, final String reference) { super(); this.regex = regex; this.description = description; @@ -369,14 +355,10 @@ public final class BaseConstraints { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); - result = prime * result - + ((errorMessage == null) ? 0 : errorMessage.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); + result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode()); + result = prime * result + ((reference == null) ? 0 : reference.hashCode()); result = prime * result + ((regex == null) ? 0 : regex.hashCode()); return result; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java index 76157fbcb1..4688f58aa6 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java @@ -1,70 +1,75 @@ -/* - * 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.yangtools.yang.model.util; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public final class BaseTypes { - - private BaseTypes() {} - - public static final URI BaseTypesNamespace = URI - .create("urn:ietf:params:xml:ns:yang:1"); - - /** - * Construct QName for Built-in base Yang type. The namespace for - * built-in base yang types is defined as: urn:ietf:params:xml:ns:yang:1 - * - * @param typeName yang type name - * @return built-in base yang type QName. - */ - public static final QName constructQName(final String typeName) { - return new QName(BaseTypesNamespace, typeName); - } - - /** - * Creates Schema Path from Qname. - * - * @param typeName yang type QName - * @return Schema Path from Qname. - */ - public static final SchemaPath schemaPath(final QName typeName) { - List pathList = Collections.singletonList(typeName); - return new SchemaPath(pathList, true); - } - - /** - * Creates Schema Path from List of partial paths defined as Strings, module Namespace and - * module latest Revision Date. - * - * @param actualPath List of partial paths - * @param namespace Module Namespace - * @param revision Revision Date - * @return Schema Path - */ - public static final SchemaPath schemaPath(final List actualPath, final URI namespace, final Date revision) { - if (actualPath == null) { - throw new IllegalArgumentException("The actual path List MUST be specified."); - } - final List pathList = new ArrayList(); - for (final String path : actualPath) { - final QName qname = new QName(namespace, revision, path); - if (qname != null) { - pathList.add(qname); - } - } - return new SchemaPath(pathList, true); - } -} +/* + * 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.yangtools.yang.model.util; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public final class BaseTypes { + + private BaseTypes() { + } + + public static final URI BASE_TYPES_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1"); + + /** + * Construct QName for Built-in base Yang type. The namespace for built-in + * base yang types is defined as: urn:ietf:params:xml:ns:yang:1 + * + * @param typeName + * yang type name + * @return built-in base yang type QName. + */ + public static QName constructQName(final String typeName) { + return new QName(BASE_TYPES_NAMESPACE, typeName); + } + + /** + * Creates Schema Path from Qname. + * + * @param typeName + * yang type QName + * @return Schema Path from Qname. + */ + public static SchemaPath schemaPath(final QName typeName) { + List pathList = Collections.singletonList(typeName); + return new SchemaPath(pathList, true); + } + + /** + * Creates Schema Path from List of partial paths defined as Strings, module + * Namespace and module latest Revision Date. + * + * @param actualPath + * List of partial paths + * @param namespace + * Module Namespace + * @param revision + * Revision Date + * @return Schema Path + */ + public static SchemaPath schemaPath(final List actualPath, final URI namespace, final Date revision) { + if (actualPath == null) { + throw new IllegalArgumentException("The actual path List MUST be specified."); + } + final List pathList = new ArrayList(); + for (final String path : actualPath) { + final QName qname = new QName(namespace, revision, path); + if (qname != null) { + pathList.add(qname); + } + } + return new SchemaPath(pathList, true); + } +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java index 89a78d2614..d7495ada74 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BinaryType.java @@ -20,18 +20,18 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; /** * The default implementation of Binary Type Definition interface. - * + * * @see BinaryTypeDefinition */ public final class BinaryType implements BinaryTypeDefinition { private static final BinaryType INSTANCE = new BinaryType(); private final QName name = BaseTypes.constructQName("binary"); private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true); - private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8"; + private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8"; private final List bytes; private final List lengthConstraints; - private final String units = ""; + private static final String UNITS = ""; private BinaryType() { final List constraints = new ArrayList(); @@ -46,7 +46,7 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @@ -57,17 +57,17 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue * () @@ -79,7 +79,7 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override @@ -89,7 +89,7 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override @@ -99,28 +99,28 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { - return description; + return DESCRIPTION; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -130,7 +130,7 @@ public final class BinaryType implements BinaryTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.base.type.api.BinaryTypeDefinition * #getLengthConstraint () @@ -150,12 +150,9 @@ public final class BinaryType implements BinaryTypeDefinition { final int prime = 31; int result = 1; result = prime * result + ((bytes == null) ? 0 : bytes.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.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; } @@ -178,13 +175,6 @@ public final class BinaryType implements BinaryTypeDefinition { } else if (!bytes.equals(other.bytes)) { return false; } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } if (lengthConstraints == null) { if (other.lengthConstraints != null) { return false; @@ -206,20 +196,6 @@ public final class BinaryType implements BinaryTypeDefinition { } 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; } @@ -231,15 +207,15 @@ public final class BinaryType implements BinaryTypeDefinition { builder.append(", path="); builder.append(path); builder.append(", description="); - builder.append(description); + builder.append(DESCRIPTION); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", bytes="); builder.append(bytes); builder.append(", lengthConstraints="); builder.append(lengthConstraints); builder.append(", units="); - builder.append(units); + builder.append(UNITS); builder.append("]"); return builder.toString(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java index 6fa221df6e..cacfeb305d 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BitsType.java @@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; /** * The default implementation of Bits Type Definition interface. - * + * * @see BitsTypeDefinition */ public final class BitsType implements BitsTypeDefinition { @@ -28,15 +28,15 @@ public final class BitsType implements BitsTypeDefinition { + "That is, a bits value is a set of flags identified by small integer position " + "numbers starting at 0. Each bit number has an assigned name."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7"; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7"; private final BitsTypeDefinition baseType; private final List bits; - private final String units = ""; + private static final String UNITS = ""; /** * Default constructor.
    * Instantiates Bits type as empty bits list. - * + * * @param path */ public BitsType(final SchemaPath path) { @@ -48,7 +48,7 @@ public final class BitsType implements BitsTypeDefinition { /** * Constructor with explicit definition of bits assigned to BitsType. - * + * * @param path * @param bits */ @@ -61,7 +61,7 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @@ -72,17 +72,17 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue * () @@ -94,7 +94,7 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override @@ -104,7 +104,7 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override @@ -114,7 +114,7 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @@ -125,17 +125,17 @@ public final class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -161,8 +161,6 @@ public final class BitsType implements BitsTypeDefinition { result = prime * result + ((description == null) ? 0 : description.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; } @@ -206,20 +204,6 @@ public final class BitsType implements BitsTypeDefinition { } 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; } @@ -233,11 +217,11 @@ public final class BitsType implements BitsTypeDefinition { builder.append(", description="); builder.append(description); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", bits="); builder.append(bits); builder.append(", units="); - builder.append(units); + builder.append(UNITS); builder.append("]"); return builder.toString(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BooleanType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BooleanType.java index 7ecba89748..9d7aff3366 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BooleanType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BooleanType.java @@ -18,16 +18,16 @@ import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; /** * The default implementation of Boolean Type Definition interface. - * + * * @see BooleanTypeDefinition */ public final class BooleanType implements BooleanTypeDefinition { private static final BooleanType INSTANCE = new BooleanType(); - private static final QName name = BaseTypes.constructQName("boolean"); - private static final SchemaPath path = new SchemaPath(Collections.singletonList(name), true); - private static final String description = "The boolean built-in type represents a boolean value."; - private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5"; - private final String units = ""; + private static final QName NAME = BaseTypes.constructQName("boolean"); + private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true); + private static final String DESCRIPTION = "The boolean built-in type represents a boolean value."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.5"; + private static final String UNITS = ""; /** * Default constructor with default value set to "false". @@ -41,7 +41,7 @@ public final class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @@ -52,17 +52,17 @@ public final class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue * () @@ -74,48 +74,48 @@ public final class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override public QName getQName() { - return name; + return NAME; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override public SchemaPath getPath() { - return path; + return PATH; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { - return description; + return DESCRIPTION; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -132,9 +132,9 @@ public final class BooleanType implements BooleanTypeDefinition { public String toString() { StringBuilder builder = new StringBuilder(); builder.append("BooleanType [name="); - builder.append(name); + builder.append(NAME); builder.append(", path="); - builder.append(path); + builder.append(PATH); builder.append("]"); return builder.toString(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java index 24e7f221e0..6fb90d96cb 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java @@ -1,136 +1,143 @@ -/* - * 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.yangtools.yang.model.util; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.opendaylight.yangtools.yang.model.api.*; - -public class DataNodeIterator implements Iterator { - - private final DataNodeContainer container; - private final List allLists; - private final List allContainers; - private final List allChoices; - private final List allChilds; - - public DataNodeIterator(final DataNodeContainer container) { - if (container == null) { - throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!"); - } - - this.allContainers = new ArrayList<>(); - this.allLists = new ArrayList<>(); - this.allChilds = new ArrayList<>(); - this.allChoices = new ArrayList<>(); - - this.container = container; - traverse(this.container); - } - - public List allContainers() { - return allContainers; - } - - public List allLists() { - return allLists; - } - - public List allChoices() { - return allChoices; - } - - private void traverse(final DataNodeContainer dataNode) { - if (dataNode == null) { - return; - } - - final Set childNodes = dataNode.getChildNodes(); - if (childNodes != null) { - for (DataSchemaNode childNode : childNodes) { - if (childNode.isAugmenting()) { - continue; - } - allChilds.add(childNode); - if (childNode instanceof ContainerSchemaNode) { - final ContainerSchemaNode container = (ContainerSchemaNode) childNode; - allContainers.add(container); - traverse(container); - } else if (childNode instanceof ListSchemaNode) { - final ListSchemaNode list = (ListSchemaNode) childNode; - allLists.add(list); - traverse(list); - } else if (childNode instanceof ChoiceNode) { - final ChoiceNode choiceNode = (ChoiceNode) childNode; - allChoices.add(choiceNode); - final Set cases = choiceNode.getCases(); - if (cases != null) { - for (final ChoiceCaseNode caseNode : cases) { - traverse(caseNode); - } - } - } - } - } - - if(dataNode instanceof Module) { - traverseModule((Module)dataNode); - } - - final Set groupings = dataNode.getGroupings(); - if (groupings != null) { - for (GroupingDefinition grouping : groupings) { - traverse(grouping); - } - } - } - - - private void traverseModule(Module module) { - final Set notifications = module.getNotifications(); - for (NotificationDefinition notificationDefinition : notifications) { - traverse(notificationDefinition); - } - final Set rpcs = module.getRpcs(); - for (RpcDefinition rpcDefinition : rpcs) { - ContainerSchemaNode input = rpcDefinition.getInput(); - if(input != null) { - traverse(input); - } - ContainerSchemaNode output = rpcDefinition.getInput(); - if(input != null) { - traverse(output); - } - } - } - - @Override - public boolean hasNext() { - if (container.getChildNodes() != null) { - final Set childNodes = container.getChildNodes(); - - if ((childNodes != null) && !childNodes.isEmpty()) { - return childNodes.iterator().hasNext(); - } - } - return false; - } - - @Override - public DataSchemaNode next() { - return allChilds.iterator().next(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } -} +/* + * 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.yangtools.yang.model.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.opendaylight.yangtools.yang.model.api.*; + +public class DataNodeIterator implements Iterator { + + private final DataNodeContainer container; + private final List allLists; + private final List allContainers; + private final List allChoices; + private final List allChilds; + + public DataNodeIterator(final DataNodeContainer container) { + if (container == null) { + throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!"); + } + + this.allContainers = new ArrayList<>(); + this.allLists = new ArrayList<>(); + this.allChilds = new ArrayList<>(); + this.allChoices = new ArrayList<>(); + + this.container = container; + traverse(this.container); + } + + public List allContainers() { + return allContainers; + } + + public List allLists() { + return allLists; + } + + public List allChoices() { + return allChoices; + } + + private void traverse(final DataNodeContainer dataNode) { + if (dataNode == null) { + return; + } + + final Set childNodes = dataNode.getChildNodes(); + if (childNodes != null) { + for (DataSchemaNode childNode : childNodes) { + if (childNode.isAugmenting()) { + continue; + } + allChilds.add(childNode); + if (childNode instanceof ContainerSchemaNode) { + final ContainerSchemaNode containerNode = (ContainerSchemaNode) childNode; + allContainers.add(containerNode); + traverse(containerNode); + } else if (childNode instanceof ListSchemaNode) { + final ListSchemaNode list = (ListSchemaNode) childNode; + allLists.add(list); + traverse(list); + } else if (childNode instanceof ChoiceNode) { + final ChoiceNode choiceNode = (ChoiceNode) childNode; + allChoices.add(choiceNode); + final Set cases = choiceNode.getCases(); + if (cases != null) { + for (final ChoiceCaseNode caseNode : cases) { + traverse(caseNode); + } + } + } + } + } + + traverseModule(dataNode); + traverseGroupings(dataNode); + + } + + private void traverseModule(DataNodeContainer dataNode) { + final Module module; + if (dataNode instanceof Module) { + module = (Module) dataNode; + } else { + return; + } + final Set notifications = module.getNotifications(); + for (NotificationDefinition notificationDefinition : notifications) { + traverse(notificationDefinition); + } + final Set rpcs = module.getRpcs(); + for (RpcDefinition rpcDefinition : rpcs) { + ContainerSchemaNode input = rpcDefinition.getInput(); + if (input != null) { + traverse(input); + } + ContainerSchemaNode output = rpcDefinition.getInput(); + if (input != null) { + traverse(output); + } + } + } + + private void traverseGroupings(DataNodeContainer dataNode) { + final Set groupings = dataNode.getGroupings(); + if (groupings != null) { + for (GroupingDefinition grouping : groupings) { + traverse(grouping); + } + } + } + + @Override + public boolean hasNext() { + if (container.getChildNodes() != null) { + final Set childNodes = container.getChildNodes(); + + if ((childNodes != null) && !childNodes.isEmpty()) { + return childNodes.iterator().hasNext(); + } + } + return false; + } + + @Override + public DataSchemaNode next() { + return allChilds.iterator().next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java index cfc3999479..64f1dc6e8e 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Decimal64.java @@ -21,26 +21,27 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; /** * The default implementation of Decimal Type Definition interface. - * - * + * + * * @see DecimalTypeDefinition */ public final class Decimal64 implements DecimalTypeDefinition { private final QName name = BaseTypes.constructQName("decimal64"); private final SchemaPath path; - private final String units = ""; - private final BigDecimal defaultValue = null; + private static final String UNITS = ""; + private static final BigDecimal DEFAULT_VALUE = null; private final String description = "The decimal64 type represents a subset of the real numbers, which can " + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can " + "be obtained by multiplying a 64-bit signed integer by a negative power of ten, i.e., expressible as " + "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.3"; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.3"; private final List rangeStatements; private final Integer fractionDigits; private final DecimalTypeDefinition baseType; + private static final int MAX_NUMBER_OF_FRACTION_DIGITS = 18; /** * Default Decimal64 Type Constructor.
    @@ -48,20 +49,21 @@ public final class Decimal64 implements DecimalTypeDefinition { * The initial range statements are set to Decimal64 * min=-922337203685477580.8 and * max=922337203685477580.7
    - * The fractions digits MUST be defined as integer between 1 and 18 - * inclusively as defined interface {@link DecimalTypeDefinition}
    + * The fractions digits MUST be defined as integer between 1 and + * {@link #MAX_NUMBER_OF_FRACTION_DIGITS} inclusively as defined interface + * {@link DecimalTypeDefinition}
    * If the fraction digits are not defined inner the definition boundaries * the constructor will throw {@link IllegalArgumentException} - * + * * @param path * @param fractionDigits * integer between 1 and 18 inclusively - * + * * @see DecimalTypeDefinition * @exception IllegalArgumentException */ public Decimal64(final SchemaPath path, final Integer fractionDigits) { - if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= 18))) { + if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) { throw new IllegalArgumentException( "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively"); } @@ -73,19 +75,17 @@ public final class Decimal64 implements DecimalTypeDefinition { /** * Returns unmodifiable List with default definition of Range Statements. - * + * * @return unmodifiable List with default definition of Range Statements. */ private List defaultRangeStatements() { - final List rangeStatements = new ArrayList(); + final List rangeStmts = new ArrayList(); final BigDecimal min = new BigDecimal("-922337203685477580.8"); final BigDecimal max = new BigDecimal("922337203685477580.7"); - final String rangeDescription = "Integer values between " + min - + " and " + max + ", inclusively."; - rangeStatements.add(BaseConstraints.rangeConstraint(min, max, - rangeDescription, + final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively."; + rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription, "https://tools.ietf.org/html/rfc6020#section-9.2.4")); - return Collections.unmodifiableList(rangeStatements); + return Collections.unmodifiableList(rangeStmts); } @Override @@ -95,12 +95,12 @@ public final class Decimal64 implements DecimalTypeDefinition { @Override public String getUnits() { - return units; + return UNITS; } @Override public Object getDefaultValue() { - return defaultValue; + return DEFAULT_VALUE; } @Override @@ -120,7 +120,7 @@ public final class Decimal64 implements DecimalTypeDefinition { @Override public String getReference() { - return reference; + return REFERENCE; } @Override @@ -183,7 +183,6 @@ public final class Decimal64 implements DecimalTypeDefinition { @Override public String toString() { - return Decimal64.class.getSimpleName() + "[qname=" + name - + ", fractionDigits=" + fractionDigits + "]"; + return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]"; } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EmptyType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EmptyType.java index 4a1200e129..ee56f760d4 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EmptyType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EmptyType.java @@ -17,20 +17,20 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; public final class EmptyType implements EmptyTypeDefinition { - private static EmptyType INSTANCE; + private static EmptyType instance; private static final QName NAME = BaseTypes.constructQName("empty"); - private static final SchemaPath path = new SchemaPath(Collections.singletonList(NAME), true); - private static final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence."; - private static final String reference = "https://tools.ietf.org/html/rfc6020#page-131"; + private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true); + private static final String DESCRIPTION = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#page-131"; private EmptyType() { } public static EmptyType getInstance() { - if (INSTANCE == null) { - INSTANCE = new EmptyType(); + if (instance == null) { + instance = new EmptyType(); } - return INSTANCE; + return instance; } @Override @@ -55,17 +55,17 @@ public final class EmptyType implements EmptyTypeDefinition { @Override public SchemaPath getPath() { - return path; + return PATH; } @Override public String getDescription() { - return description; + return DESCRIPTION; } @Override public String getReference() { - return reference; + return REFERENCE; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java index 472bc69517..3ae8eb346d 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EnumerationType.java @@ -1,10 +1,10 @@ /* - * 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 - */ + * 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.yangtools.yang.model.util; import java.util.Collections; @@ -17,19 +17,20 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; /** - * The default implementation of Enumertaion Type Definition interface. - * + * The default implementation of Enumertaion Type Definition + * interface. + * * @see EnumTypeDefinition */ public final class EnumerationType implements EnumTypeDefinition { private final QName name = BaseTypes.constructQName("enumeration"); private final SchemaPath path; - private final String description = "The enumeration built-in type represents values from a set of assigned names."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.6"; + private static final String DESCRIPTION = "The enumeration built-in type represents values from a set of assigned names."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.6"; private final EnumPair defaultEnum; private final List enums; - private final String units = ""; + private static final String UNITS = ""; private final EnumTypeDefinition baseType; public EnumerationType(final SchemaPath path, final List enums) { @@ -40,8 +41,7 @@ public final class EnumerationType implements EnumTypeDefinition { this.baseType = this; } - public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, - final List enums) { + public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List enums) { super(); this.path = path; this.baseType = this; @@ -51,8 +51,9 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() + * + * @see + * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @Override public EnumTypeDefinition getBaseType() { @@ -61,18 +62,20 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue() + * + * @see + * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue + * () */ @Override public Object getDefaultValue() { @@ -81,7 +84,7 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override @@ -91,7 +94,7 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override @@ -101,27 +104,28 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() + * + * @see + * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { - return description; + return DESCRIPTION; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -131,8 +135,10 @@ public final class EnumerationType implements EnumTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition#getValues() + * + * @see + * org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition + * #getValues() */ @Override public List getValues() { @@ -148,16 +154,10 @@ public final class EnumerationType implements EnumTypeDefinition { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((defaultEnum == null) ? 0 : defaultEnum.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((defaultEnum == null) ? 0 : defaultEnum.hashCode()); result = prime * result + ((enums == null) ? 0 : enums.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; } @@ -180,13 +180,6 @@ public final class EnumerationType implements EnumTypeDefinition { } else if (!defaultEnum.equals(other.defaultEnum)) { return false; } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } if (enums == null) { if (other.enums != null) { return false; @@ -208,20 +201,6 @@ public final class EnumerationType implements EnumTypeDefinition { } 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; } @@ -233,15 +212,15 @@ public final class EnumerationType implements EnumTypeDefinition { builder.append(", path="); builder.append(path); builder.append(", description="); - builder.append(description); + builder.append(DESCRIPTION); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", defaultEnum="); builder.append(defaultEnum); builder.append(", enums="); builder.append(enums); builder.append(", units="); - builder.append(units); + builder.append(UNITS); builder.append("]"); return builder.toString(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/IdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/IdentityrefType.java index f498608c0f..1156762cca 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/IdentityrefType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/IdentityrefType.java @@ -1,95 +1,95 @@ -/* - * 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.yangtools.yang.model.util; - -import java.util.Collections; -import java.util.List; - -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.api.Status; -import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; -import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; - -/** - * The default implementation of Identityref Type Definition - * interface. - * - * @see IdentityrefTypeDefinition - */ -public final class IdentityrefType implements IdentityrefTypeDefinition { - private final QName name = BaseTypes.constructQName("identityref"); - private final SchemaPath path; - private final String description = "The identityref type is used to reference an existing identity."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10"; - private final IdentityrefTypeDefinition baseType; - private final QName identity; - private final String units = ""; - - public IdentityrefType(QName identity, SchemaPath schemaPath) { - this.identity = identity; - this.path = schemaPath; - this.baseType = this; - } - - @Override - public String getUnits() { - return units; - } - - @Override - public Object getDefaultValue() { - return identity; - } - - @Override - public QName getQName() { - return name; - } - - @Override - public SchemaPath getPath() { - return path; - } - - @Override - public String getDescription() { - return description; - } - - @Override - public String getReference() { - return reference; - } - - @Override - public Status getStatus() { - return Status.CURRENT; - } - - @Override - public List getUnknownSchemaNodes() { - return Collections.emptyList(); - } - - @Override - public QName getIdentity() { - return identity; - } - - @Override - public IdentityrefTypeDefinition getBaseType() { - return baseType; - } - - @Override - public String toString() { - return "identityref " + identity.getLocalName(); - } - -} +/* + * 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.yangtools.yang.model.util; + +import java.util.Collections; +import java.util.List; + +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.Status; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; + +/** + * The default implementation of Identityref Type Definition + * interface. + * + * @see IdentityrefTypeDefinition + */ +public final class IdentityrefType implements IdentityrefTypeDefinition { + private final QName name = BaseTypes.constructQName("identityref"); + private final SchemaPath path; + private static final String DESCRIPTION = "The identityref type is used to reference an existing identity."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10"; + private final IdentityrefTypeDefinition baseType; + private final QName identity; + private static final String UNITS = ""; + + public IdentityrefType(QName identity, SchemaPath schemaPath) { + this.identity = identity; + this.path = schemaPath; + this.baseType = this; + } + + @Override + public String getUnits() { + return UNITS; + } + + @Override + public Object getDefaultValue() { + return identity; + } + + @Override + public QName getQName() { + return name; + } + + @Override + public SchemaPath getPath() { + return path; + } + + @Override + public String getDescription() { + return DESCRIPTION; + } + + @Override + public String getReference() { + return REFERENCE; + } + + @Override + public Status getStatus() { + return Status.CURRENT; + } + + @Override + public List getUnknownSchemaNodes() { + return Collections.emptyList(); + } + + @Override + public QName getIdentity() { + return identity; + } + + @Override + public IdentityrefTypeDefinition getBaseType() { + return baseType; + } + + @Override + public String toString() { + return "identityref " + identity.getLocalName(); + } + +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/InstanceIdentifier.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/InstanceIdentifier.java index 1af0fb8ff0..4949d4ebee 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/InstanceIdentifier.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/InstanceIdentifier.java @@ -20,20 +20,23 @@ import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefi /** * The default implementation of Instance Identifier Type * Definition interface. - * + * * @see InstanceIdentifierTypeDefinition */ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition { - private static final QName name = BaseTypes.constructQName("instance-identifier"); - private static final SchemaPath path = new SchemaPath(Collections.singletonList(name), true); - private static final String description = "The instance-identifier built-in type is used to " + private static final QName NAME = BaseTypes.constructQName("instance-identifier"); + private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true); + private static final String DESCRIPTION = "The instance-identifier built-in type is used to " + "uniquely identify a particular instance node in the data tree."; - private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13"; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13"; private final RevisionAwareXPath xpath; - private static final String units = ""; + private static final String UNITS = ""; private boolean requireInstance = true; + private static final int HASH_BOOLEAN_TRUE = 1231; + private static final int HASH_BOOLEAN_FALSE = 1237; + public InstanceIdentifier(final RevisionAwareXPath xpath) { this.xpath = xpath; } @@ -45,7 +48,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @@ -56,17 +59,17 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue * () @@ -78,48 +81,48 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override public QName getQName() { - return name; + return NAME; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override public SchemaPath getPath() { - return path; + return PATH; } /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { - return description; + return DESCRIPTION; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -129,7 +132,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes * () @@ -141,7 +144,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.type. * InstanceIdentifierTypeDefinition# getPathStatement() */ @@ -152,7 +155,7 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.type. * InstanceIdentifierTypeDefinition# requireInstance() */ @@ -165,27 +168,33 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (requireInstance ? 1231 : 1237); + result = prime * result + (requireInstance ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE); result = prime * result + ((xpath == null) ? 0 : xpath.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } InstanceIdentifier other = (InstanceIdentifier) obj; - if (requireInstance != other.requireInstance) + if (requireInstance != other.requireInstance) { return false; + } if (xpath == null) { - if (other.xpath != null) + if (other.xpath != null) { return false; - } else if (!xpath.equals(other.xpath)) + } + } else if (!xpath.equals(other.xpath)) { return false; + } return true; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int16.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int16.java index 629e9ff7d3..d73bf754ff 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int16.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int16.java @@ -14,11 +14,11 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; * Implementation of Yang int16 built-in type.
    * int16 represents integer values between -32768 and 32767, inclusively. The * Java counterpart of Yang int16 built-in type is {@link Short}. - * + * * @see AbstractSignedInteger */ public final class Int16 extends AbstractSignedInteger { - private static Int16 INSTANCE; + private static Int16 instance; private static final QName NAME = BaseTypes.constructQName("int16"); private static final String DESCRIPTION = "int16 represents integer values between -32768 and 32767, inclusively."; @@ -27,10 +27,10 @@ public final class Int16 extends AbstractSignedInteger { } public static Int16 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Int16(); + if (instance == null) { + instance = new Int16(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int32.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int32.java index 82f278c40f..799ca00d0c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int32.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int32.java @@ -15,12 +15,12 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; * int32 represents integer values between -2147483648 and 2147483647, * inclusively. The Java counterpart of Yang int32 built-in type is * {@link Integer}. - * + * * @see AbstractSignedInteger - * + * */ public final class Int32 extends AbstractSignedInteger { - private static Int32 INSTANCE; + private static Int32 instance; private static final QName NAME = BaseTypes.constructQName("int32"); private static final String DESCRIPTION = "int32 represents integer values between -2147483648 and 2147483647, inclusively."; @@ -29,10 +29,10 @@ public final class Int32 extends AbstractSignedInteger { } public static Int32 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Int32(); + if (instance == null) { + instance = new Int32(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int64.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int64.java index 0800f3c8c5..a22d2d5a6c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int64.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int64.java @@ -15,10 +15,10 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; * int64 represents integer values between -9223372036854775808 and * 9223372036854775807, inclusively. The Java counterpart of Yang int64 built-in * type is {@link Long}. - * + * */ public final class Int64 extends AbstractSignedInteger { - private static Int64 INSTANCE; + private static Int64 instance; private static final QName NAME = BaseTypes.constructQName("int64"); private static final String DESCRIPTION = "int64 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively."; @@ -27,10 +27,10 @@ public final class Int64 extends AbstractSignedInteger { } public static Int64 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Int64(); + if (instance == null) { + instance = new Int64(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int8.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int8.java index 537eef44de..16f7ee68f5 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int8.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Int8.java @@ -14,11 +14,11 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; * Implementation of Yang int8 built-in type.
    * int8 represents integer values between -128 and 127, inclusively. The Java * counterpart of Yang int8 built-in type is {@link Byte}. - * + * * @see AbstractSignedInteger */ public final class Int8 extends AbstractSignedInteger { - private static Int8 INSTANCE; + private static Int8 instance; private static final QName NAME = BaseTypes.constructQName("int8"); private static final String DESCRIPTION = "represents integer values between -128 and 127, inclusively."; @@ -27,10 +27,10 @@ public final class Int8 extends AbstractSignedInteger { } public static Int8 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Int8(); + if (instance == null) { + instance = new Int8(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java index a3577ba0ae..c5852696e4 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RevisionAwareXPathImpl.java @@ -10,7 +10,8 @@ package org.opendaylight.yangtools.yang.model.util; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; /** - * The default implementation of Instance Rewision Aware XPath interface. + * The default implementation of Instance Rewision Aware XPath + * interface. * * @see RevisionAwareXPath */ @@ -19,6 +20,9 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath { private final String xpath; private final boolean absolute; + private static final int HASH_BOOLEAN_TRUE = 1231; + private static final int HASH_BOOLEAN_FALSE = 1237; + public RevisionAwareXPathImpl(String xpath, boolean absolute) { this.xpath = xpath; this.absolute = absolute; @@ -34,7 +38,7 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath { final int prime = 31; int result = 1; result = prime * result + ((xpath == null) ? 0 : xpath.hashCode()); - result = prime * result + (absolute ? 1231 : 1237); + result = prime * result + (absolute ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE); return result; } @@ -62,7 +66,7 @@ public class RevisionAwareXPathImpl implements RevisionAwareXPath { } return false; } - + @Override public String toString() { return xpath; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java index bad6067a41..93f0c7c13c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/StringType.java @@ -1,10 +1,10 @@ /* - * 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 - */ + * 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.yangtools.yang.model.util; import java.util.ArrayList; @@ -21,19 +21,19 @@ import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; /** * The default implementation of String Type Definition interface. - * + * * @see StringTypeDefinition */ public final class StringType implements StringTypeDefinition { private static final StringType INSTANCE = new StringType(); private final QName name = BaseTypes.constructQName("string"); private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true); - private final String defaultValue = ""; - private final String description = ""; - private final String reference = ""; + private static final String DEFAULT_VALUE = ""; + private static final String DESCRIPTION = ""; + private static final String REFERENCE = ""; private final List lengthStatements; private final List patterns; - private final String units = ""; + private static final String UNITS = ""; /** * Default Constructor. @@ -51,8 +51,9 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() + * + * @see + * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @Override public StringTypeDefinition getBaseType() { @@ -61,27 +62,29 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override public String getUnits() { - return units; + return UNITS; } /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue() + * + * @see + * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue + * () */ @Override public Object getDefaultValue() { - return defaultValue; + return DEFAULT_VALUE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override @@ -91,7 +94,7 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override @@ -101,27 +104,28 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() + * + * @see + * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { - return description; + return DESCRIPTION; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override public String getReference() { - return reference; + return REFERENCE; } /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -131,7 +135,7 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * + * * @see * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements * () @@ -143,7 +147,7 @@ public final class StringType implements StringTypeDefinition { /* * (non-Javadoc) - * + * * @see * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns() */ @@ -161,20 +165,10 @@ public final class StringType implements StringTypeDefinition { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((defaultValue == null) ? 0 : defaultValue.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime - * result - + ((lengthStatements == null) ? 0 : lengthStatements.hashCode()); + result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result - + ((patterns == null) ? 0 : patterns.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); - result = prime * result + ((units == null) ? 0 : units.hashCode()); + result = prime * result + ((patterns == null) ? 0 : patterns.hashCode()); return result; } @@ -190,20 +184,6 @@ public final class StringType implements StringTypeDefinition { return false; } StringType other = (StringType) obj; - if (defaultValue == null) { - if (other.defaultValue != null) { - return false; - } - } else if (!defaultValue.equals(other.defaultValue)) { - return false; - } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } if (lengthStatements == null) { if (other.lengthStatements != null) { return false; @@ -222,10 +202,8 @@ public final class StringType implements StringTypeDefinition { if (other.path != null) { return false; } - } else if ((path != null) && (other.path != null)) { - if (!path.getPath().equals(other.path.getPath())) { - return false; - } + } else if (!path.getPath().equals(other.path.getPath())) { + return false; } if (patterns == null) { if (other.patterns != null) { @@ -234,20 +212,6 @@ public final class StringType implements StringTypeDefinition { } else if (!patterns.equals(other.patterns)) { 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; } @@ -259,17 +223,17 @@ public final class StringType implements StringTypeDefinition { builder.append(", path="); builder.append(path); builder.append(", defaultValue="); - builder.append(defaultValue); + builder.append(DEFAULT_VALUE); builder.append(", description="); - builder.append(description); + builder.append(DESCRIPTION); builder.append(", reference="); - builder.append(reference); + builder.append(REFERENCE); builder.append(", lengthStatements="); builder.append(lengthStatements); builder.append(", patterns="); builder.append(patterns); builder.append(", units="); - builder.append(units); + builder.append(UNITS); builder.append("]"); return builder.toString(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint16.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint16.java index 05cead85ff..120f4926cf 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint16.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint16.java @@ -14,11 +14,11 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * Implementation of Yang uint16 built-in type.
    * uint16 represents integer values between 0 and 65535, inclusively. The Java * counterpart of Yang uint16 built-in type is {@link Integer}. - * + * */ public final class Uint16 extends AbstractUnsignedInteger { public static final int MAX_VALUE = 65535; - private static Uint16 INSTANCE; + private static Uint16 instance; private static final QName NAME = BaseTypes.constructQName("uint16"); private static final String DESCRIPTION = "uint16 represents integer values between 0 and 65535, inclusively."; @@ -27,10 +27,10 @@ public final class Uint16 extends AbstractUnsignedInteger { } public static Uint16 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Uint16(); + if (instance == null) { + instance = new Uint16(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint32.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint32.java index d5d3e9efe6..375a26bf91 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint32.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint32.java @@ -13,11 +13,11 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit /** * Implementation of Yang uint32 built-in type.
    * uint32 represents integer values between 0 and 4294967295, inclusively. - * + * */ public final class Uint32 extends AbstractUnsignedInteger { public static final long MAX_VALUE = 4294967295L; - private static Uint32 INSTANCE; + private static Uint32 instance; private static final QName NAME = BaseTypes.constructQName("uint32"); private static final String DESCRIPTION = "uint32 represents integer values between 0 and 4294967295, inclusively."; @@ -26,10 +26,10 @@ public final class Uint32 extends AbstractUnsignedInteger { } public static Uint32 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Uint32(); + if (instance == null) { + instance = new Uint32(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint64.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint64.java index 078b569e15..e003873eb6 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint64.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint64.java @@ -17,11 +17,11 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * uint64 represents integer values between 0 and 18446744073709551615, * inclusively. The Java counterpart of Yang uint64 built-in type is * {@link BigInteger}. - * + * */ public final class Uint64 extends AbstractUnsignedInteger { public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615"); - private static Uint64 INSTANCE; + private static Uint64 instance; private static final QName NAME = BaseTypes.constructQName("uint64"); private static final String DESCRIPTION = "uint64 represents integer values between 0 and 18446744073709551615, inclusively."; @@ -30,10 +30,10 @@ public final class Uint64 extends AbstractUnsignedInteger { } public static Uint64 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Uint64(); + if (instance == null) { + instance = new Uint64(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint8.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint8.java index 4befa856ec..4c36ae1d90 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint8.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Uint8.java @@ -13,12 +13,12 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit /** * Implementation of Yang uint8 built-in type.
    * uint8 represents integer values between 0 and 255, inclusively. - * + * * @see AbstractUnsignedInteger */ public final class Uint8 extends AbstractUnsignedInteger { public static final int MAX_VALUE = 255; - private static Uint8 INSTANCE; + private static Uint8 instance; private static final QName NAME = BaseTypes.constructQName("uint8"); private static final String DESCRIPTION = "uint8 represents integer values between 0 and 255, inclusively."; @@ -27,10 +27,10 @@ public final class Uint8 extends AbstractUnsignedInteger { } public static Uint8 getInstance() { - if (INSTANCE == null) { - INSTANCE = new Uint8(); + if (instance == null) { + instance = new Uint8(); } - return INSTANCE; + return instance; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnionType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnionType.java index 81bda38776..a12c1c1119 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnionType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnionType.java @@ -20,14 +20,13 @@ import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; public final class UnionType implements UnionTypeDefinition { private final QName name = BaseTypes.constructQName("union"); private final SchemaPath path = BaseTypes.schemaPath(name); - private final String description = "The union built-in type represents a value that corresponds to one of its member types."; - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12"; + private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types."; + private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12"; private final List> types; public UnionType(List> types) { if (types == null) { - throw new NullPointerException( - "When the type is 'union', the 'type' statement MUST be present."); + throw new IllegalArgumentException("When the type is 'union', the 'type' statement MUST be present."); } this.types = types; } @@ -59,12 +58,12 @@ public final class UnionType implements UnionTypeDefinition { @Override public String getDescription() { - return description; + return DESCRIPTION; } @Override public String getReference() { - return reference; + return REFERENCE; } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnknownType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnknownType.java index 7459e6f6e6..748507f38a 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnknownType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnknownType.java @@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition; -public class UnknownType implements UnknownTypeDefinition { +public final class UnknownType implements UnknownTypeDefinition { private final QName name; private final SchemaPath path; @@ -44,8 +44,7 @@ public class UnknownType implements UnknownTypeDefinition { private String description; private String reference; - private List lengthStatements = Collections - .emptyList(); + private List lengthStatements = Collections.emptyList(); private List patterns = Collections.emptyList(); private List rangeStatements = Collections.emptyList(); private List extensions = Collections.emptyList(); @@ -57,8 +56,7 @@ public class UnknownType implements UnknownTypeDefinition { private Object defaultValue = null; private boolean referenceOnly = false; - public Builder(final QName name, final String description, - final String reference) { + public Builder(final QName name, final String description, final String reference) { this.name = name; this.path = BaseTypes.schemaPath(name); this.description = description; @@ -80,8 +78,7 @@ public class UnknownType implements UnknownTypeDefinition { return this; } - public Builder lengthStatements( - final List lengthStatements) { + public Builder lengthStatements(final List lengthStatements) { this.lengthStatements = lengthStatements; return this; } @@ -91,8 +88,7 @@ public class UnknownType implements UnknownTypeDefinition { return this; } - public Builder rangeStatements( - final List rangeStatements) { + public Builder rangeStatements(final List rangeStatements) { this.rangeStatements = rangeStatements; return this; } @@ -132,8 +128,8 @@ public class UnknownType implements UnknownTypeDefinition { } public void setReferenceOnly(boolean b) { - this.referenceOnly = b; - + this.referenceOnly = b; + } } @@ -156,7 +152,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType() */ @@ -167,7 +163,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits() */ @Override @@ -177,7 +173,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue * () @@ -189,7 +185,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName() */ @Override @@ -199,7 +195,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath() */ @Override @@ -209,7 +205,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription() */ @@ -220,7 +216,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference() */ @Override @@ -230,7 +226,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus() */ @Override @@ -240,7 +236,7 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * + * * @see * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes * () @@ -252,9 +248,8 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * - * @see - * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition + * + * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition * #getRangeStatements() */ @Override @@ -264,9 +259,8 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * - * @see - * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition + * + * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition * #getLengthStatements() */ @Override @@ -276,9 +270,8 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * - * @see - * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition + * + * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition * #getPatterns() */ @Override @@ -288,9 +281,8 @@ public class UnknownType implements UnknownTypeDefinition { /* * (non-Javadoc) - * - * @see - * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition + * + * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition * #getLengthConstraint() */ @Override @@ -307,31 +299,21 @@ public class UnknownType implements UnknownTypeDefinition { public boolean isReferenceOnly() { return referenceOnly; } - + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((defaultValue == null) ? 0 : defaultValue.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((extensions == null) ? 0 : extensions.hashCode()); - result = prime - * result - + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode()); - result = prime - * result - + ((lengthStatements == null) ? 0 : lengthStatements.hashCode()); + result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((extensions == null) ? 0 : extensions.hashCode()); + result = prime * result + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode()); + result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); - result = prime * result - + ((patterns == null) ? 0 : patterns.hashCode()); - result = prime * result - + ((rangeStatements == null) ? 0 : rangeStatements.hashCode()); - result = prime * result - + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + ((patterns == null) ? 0 : patterns.hashCode()); + result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode()); + result = prime * result + ((reference == null) ? 0 : reference.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((units == null) ? 0 : units.hashCode()); return result; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/YangTypesConverter.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/YangTypesConverter.java index 7b75a30247..0cf3b859bc 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/YangTypesConverter.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/YangTypesConverter.java @@ -1,83 +1,89 @@ -/* - * 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.yangtools.yang.model.util; - -import java.util.HashSet; -import java.util.Set; - -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; - -public final class YangTypesConverter { - private static final Set baseYangTypes = new HashSet(); - - static { - baseYangTypes.add("binary"); - 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) { - return baseYangTypes.contains(type); - } - - public static TypeDefinition javaTypeForBaseYangType(String typeName) { - TypeDefinition type = null; - - if (typeName.startsWith("int")) { - if ("int8".equals(typeName)) { - type = Int8.getInstance(); - } else if ("int16".equals(typeName)) { - type = Int16.getInstance(); - } else if ("int32".equals(typeName)) { - type = Int32.getInstance(); - } else if ("int64".equals(typeName)) { - type = Int64.getInstance(); - } - } else if (typeName.startsWith("uint")) { - if ("uint8".equals(typeName)) { - type = Uint8.getInstance(); - } else if ("uint16".equals(typeName)) { - type = Uint16.getInstance(); - } else if ("uint32".equals(typeName)) { - type = Uint32.getInstance(); - } else if ("uint64".equals(typeName)) { - type = Uint64.getInstance(); - } - } else if ("string".equals(typeName)) { - type = StringType.getIntance(); - } else if("binary".equals(typeName)) { - type = BinaryType.getInstance(); - } else if("boolean".equals(typeName)) { - type = BooleanType.getInstance(); - } else if("empty".equals(typeName)) { - type = EmptyType.getInstance(); - } else if("instance-identifier".equals(typeName)) { - // FIXME - type = new InstanceIdentifier(null, true); - } - - return 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.yangtools.yang.model.util; + +import java.util.HashSet; +import java.util.Set; + +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; + +public final class YangTypesConverter { + private static final Set BASE_YANG_TYPES = new HashSet(); + + /** + * It isn't desirable to create the instances of this class + */ + private YangTypesConverter() { + } + + static { + BASE_YANG_TYPES.add("binary"); + BASE_YANG_TYPES.add("bits"); + BASE_YANG_TYPES.add("boolean"); + BASE_YANG_TYPES.add("decimal64"); + BASE_YANG_TYPES.add("empty"); + BASE_YANG_TYPES.add("enumeration"); + BASE_YANG_TYPES.add("identityref"); + BASE_YANG_TYPES.add("instance-identifier"); + BASE_YANG_TYPES.add("int8"); + BASE_YANG_TYPES.add("int16"); + BASE_YANG_TYPES.add("int32"); + BASE_YANG_TYPES.add("int64"); + BASE_YANG_TYPES.add("leafref"); + BASE_YANG_TYPES.add("string"); + BASE_YANG_TYPES.add("uint8"); + BASE_YANG_TYPES.add("uint16"); + BASE_YANG_TYPES.add("uint32"); + BASE_YANG_TYPES.add("uint64"); + BASE_YANG_TYPES.add("union"); + } + + public static boolean isBaseYangType(String type) { + return BASE_YANG_TYPES.contains(type); + } + + public static TypeDefinition javaTypeForBaseYangType(String typeName) { + TypeDefinition type = null; + + if (typeName.startsWith("int")) { + if ("int8".equals(typeName)) { + type = Int8.getInstance(); + } else if ("int16".equals(typeName)) { + type = Int16.getInstance(); + } else if ("int32".equals(typeName)) { + type = Int32.getInstance(); + } else if ("int64".equals(typeName)) { + type = Int64.getInstance(); + } + } else if (typeName.startsWith("uint")) { + if ("uint8".equals(typeName)) { + type = Uint8.getInstance(); + } else if ("uint16".equals(typeName)) { + type = Uint16.getInstance(); + } else if ("uint32".equals(typeName)) { + type = Uint32.getInstance(); + } else if ("uint64".equals(typeName)) { + type = Uint64.getInstance(); + } + } else if ("string".equals(typeName)) { + type = StringType.getIntance(); + } else if ("binary".equals(typeName)) { + type = BinaryType.getInstance(); + } else if ("boolean".equals(typeName)) { + type = BooleanType.getInstance(); + } else if ("empty".equals(typeName)) { + type = EmptyType.getInstance(); + } else if ("instance-identifier".equals(typeName)) { + // FIXME + type = new InstanceIdentifier(null, true); + } + + return type; + } + +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java new file mode 100644 index 0000000000..aab41b8534 --- /dev/null +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java @@ -0,0 +1,20 @@ +package org.opendaylight.yangtools.yang.model.util; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class Int8Test { + + @Test + public void testInt8() { + Int8 int8 = Int8.getInstance(); + Int8 int8Second = Int8.getInstance(); + assertTrue("The method 'getInstance()' has to return the same instance", int8 == int8Second); + assertTrue("The method 'getBaseType()' is returning incorrect value", int8.getBaseType() == int8); + assertTrue("The method 'getDefaultType()' is returning incorrect value", int8.getDefaultValue() == null); + assertEquals("The method 'toString()' is returning incorrect value", + "type (urn:ietf:params:xml:ns:yang:1)int8", int8.toString()); + + } + +} diff --git a/yang/yang-parser-api/src/main/java/org/opendaylight/yangtools/yang/model/parser/api/YangModelParser.java b/yang/yang-parser-api/src/main/java/org/opendaylight/yangtools/yang/model/parser/api/YangModelParser.java index 820c976c13..553ab2bd8f 100644 --- a/yang/yang-parser-api/src/main/java/org/opendaylight/yangtools/yang/model/parser/api/YangModelParser.java +++ b/yang/yang-parser-api/src/main/java/org/opendaylight/yangtools/yang/model/parser/api/YangModelParser.java @@ -15,12 +15,11 @@ import java.util.Set; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition; /** * Yang Model Parser interface is designed for parsing yang models and convert * the information to Data Schema Tree. - * + * */ public interface YangModelParser { @@ -29,7 +28,7 @@ public interface YangModelParser { * 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 @@ -42,7 +41,7 @@ public interface YangModelParser { * This method SHOULD be used if user has already parsed context and need to * parse additinal yang models which can have dependencies on models in this * context. - * + * * @param yangFiles * yang files to parse * @param context @@ -54,7 +53,7 @@ public interface YangModelParser { /** * Equivalent to {@link #parseYangModels(List)} that returns parsed modules * mapped to Files from which they were parsed. - * + * * @param yangFiles * yang files to parse * @return Map of Yang Modules @@ -66,7 +65,7 @@ public interface YangModelParser { * 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 yangModelStreams * yang streams to parse * @return Set of Yang Modules @@ -79,7 +78,7 @@ public interface YangModelParser { * This method SHOULD be used if user has already parsed context and need to * parse additinal yang models which can have dependencies on models in this * context. - * + * * @param yangModelStreams * yang streams to parse * @param context @@ -91,7 +90,7 @@ public interface YangModelParser { /** * Equivalent to {@link #parseYangModels(List)} that returns parsed modules * mapped to IputStreams from which they were parsed. - * + * * @param yangModelStreams * yang streams to parse * @return Map of Yang Modules @@ -105,7 +104,7 @@ public interface YangModelParser { * 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. diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/Comparators.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/Comparators.java index 7183d0c82c..e390c4ad32 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/Comparators.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/Comparators.java @@ -12,7 +12,7 @@ import java.util.Comparator; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -public class Comparators { +public final class Comparators { public static final QNameComparator QNAME_COMP = new QNameComparator(); public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator(); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java index 743b9afb91..53e5205d9e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineUtils.java @@ -28,7 +28,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuil * Utility class with helper methods to perform operations tied to refine * process. */ -public class RefineUtils { +public final class RefineUtils { private RefineUtils() { } @@ -155,7 +155,7 @@ public class RefineUtils { /** * Check if refine can be performed on given node. - * + * * @param node * node to refine * @param refine @@ -245,9 +245,9 @@ public class RefineUtils { *
  • reference
  • *
  • config
  • * - * + * * These parameters may be refined for any node. - * + * * @param node * node to refine * @param refine @@ -291,7 +291,7 @@ public class RefineUtils { /** * Perform refine operation on given node. - * + * * @param nodeToRefine * builder of node to refine * @param refine diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java index 0cd9a7b6e1..62304cdd6f 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java @@ -304,7 +304,7 @@ public class TypesResolutionTest { assertEquals("iit", identity.getPrefix()); assertEquals("service-type", identity.getLocalName()); - LeafSchemaNode type = (LeafSchemaNode)tested.getDataChildByName("type"); + LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName("type"); assertNotNull(type); } -- 2.36.6