X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=code-generator%2Fbinding-generator-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fsal%2Fbinding%2Fgenerator%2Fimpl%2FBindingGeneratorImpl.xtend;h=94d4812cd039f3c5e72b6f46d85f503d51f761fb;hb=8a22fe9a9294bf02c4c2829a547dfae02b434aea;hp=4411c09aecbe8057a247483f66efa8f2d7230008;hpb=f6856fd5f6c7f092ab19838ad4fe55c039cf2896;p=yangtools.git 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 4411c09aec..94d4812cd0 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 @@ -1,25 +1,25 @@ -/* - * 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.sal.binding.generator.impl; - -import static com.google.common.base.Preconditions.*; -import static extension org.opendaylight.yangtools.binding.generator.util.Types.*; -import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*; -import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; -import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*; + +import static com.google.common.base.Preconditions.*; +import static extension org.opendaylight.yangtools.binding.generator.util.Types.*; +import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*; +import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; +import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.Iterator +import java.util.Set; +import java.util.Iterator import java.util.Collection import org.opendaylight.yangtools.binding.generator.util.BindingTypes; import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl; @@ -75,7 +75,8 @@ import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil import org.opendaylight.yangtools.sal.binding.model.api.Restrictions import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl -import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.binding.BindingMapping +import org.opendaylight.yangtools.yang.common.QName +import org.opendaylight.yangtools.yang.binding.BindingMapping import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilderBase import com.google.common.collect.Sets @@ -86,52 +87,52 @@ public class BindingGeneratorImpl implements BindingGenerator { private final Map genCtx = new HashMap() - /** - * Outer key represents the package name. Outer 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. + /** + * Outer key represents the package name. Outer 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; - /** - * Provide methods for converting YANG types to JAVA types. + /** + * Provide methods for converting YANG types to JAVA types. */ private var TypeProvider typeProvider; - /** - * Holds reference to schema context to resolve data of augmented element - * when creating augmentation builder + /** + * Holds reference to schema context to resolve data of augmented element + * when creating augmentation builder */ private var SchemaContext schemaContext; - /** - * Constant with the concrete name of namespace. + /** + * Constant with the concrete name of namespace. */ private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext"; - /** - * Constant with the concrete name of identifier. + /** + * Constant with the concrete name of identifier. */ private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier"; - /** - * Resolves generated types from context schema nodes of all - * modules. - * - * Generated types are created for modules, groupings, types, containers, - * lists, choices, augments, rpcs, notification, identities. - * - * @param context - * schema context which contains data about all schema nodes - * saved in modules - * @return list of types (usually GeneratedType - * GeneratedTransferObjectwhich are generated from - * context data. - * @throws IllegalArgumentException - * if param context is null - * @throws IllegalStateException - * if context contain no modules + /** + * Resolves generated types from context schema nodes of all + * modules. + * + * Generated types are created for modules, groupings, types, containers, + * lists, choices, augments, rpcs, notification, identities. + * + * @param context + * schema context which contains data about all schema nodes + * saved in modules + * @return list of types (usually GeneratedType + * GeneratedTransferObjectwhich are generated from + * context data. + * @throws IllegalArgumentException + * if param context is null + * @throws IllegalStateException + * if context contain no modules */ override generateTypes(SchemaContext context) { checkArgument(context !== null, "Schema Context reference cannot be NULL."); @@ -142,33 +143,33 @@ public class BindingGeneratorImpl implements BindingGenerator { return generateTypes(context, modules); } - /** - * Resolves generated types from context schema nodes only for - * modules specified in modules - * - * Generated types are created for modules, groupings, types, containers, - * lists, choices, augments, rpcs, notification, identities. - * - * @param context - * schema context which contains data about all schema nodes - * saved in modules - * @param modules - * set of modules for which schema nodes should be generated - * types - * @return list of types (usually GeneratedType or - * GeneratedTransferObject) which: - * - * @throws IllegalArgumentException - * - * @throws IllegalStateException - * if context contain no modules + /** + * Resolves generated types from context schema nodes only for + * modules specified in modules + * + * Generated types are created for modules, groupings, types, containers, + * lists, choices, augments, rpcs, notification, identities. + * + * @param context + * schema context which contains data about all schema nodes + * saved in modules + * @param modules + * set of modules for which schema nodes should be generated + * types + * @return list of types (usually GeneratedType or + * GeneratedTransferObject) which: + * + * @throws IllegalArgumentException + * + * @throws IllegalStateException + * if context contain no modules */ override generateTypes(SchemaContext context, Set modules) { checkArgument(context !== null, "Schema Context reference cannot be NULL."); @@ -189,12 +190,13 @@ public class BindingGeneratorImpl implements BindingGenerator { val List filteredGenTypes = new ArrayList(); for (Module m : modules) { - filteredGenTypes.addAll(genCtx.get(m).generatedTypes); - val Set additionalTypes = (typeProvider as TypeProviderImpl).additionalTypes.get(m) - if (additionalTypes != null) { - filteredGenTypes.addAll(additionalTypes) + val ctx = checkNotNull(genCtx.get(m), "Module context not found for module %s", m) + filteredGenTypes.addAll(ctx.generatedTypes); + val Set additionalTypes = (typeProvider as TypeProviderImpl).additionalTypes.get(m) + if (additionalTypes != null) { + filteredGenTypes.addAll(additionalTypes) } - } + } return filteredGenTypes; } @@ -215,19 +217,19 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Converts all extended type definitions of module to the list of - * Type objects. - * - * @param module - * module from which is obtained set of type definitions - * @throws IllegalArgumentException - *
    - *
  • if module equals null
  • - *
  • if name of module equals null
  • - *
  • if type definitions of module equal null
  • - *
- * + /** + * Converts all extended type definitions of module to the list of + * Type objects. + * + * @param module + * module from which is obtained set of type definitions + * @throws IllegalArgumentException + *
    + *
  • if module equals null
  • + *
  • if name of module equals null
  • + *
  • if type definitions of module equal null
  • + *
+ * */ private def void allTypeDefinitionsToGenTypes(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -244,8 +246,8 @@ public class BindingGeneratorImpl implements BindingGenerator { } } } - } - + } + private def GeneratedTypeBuilder processDataSchemaNode(Module module, String basePackageName, GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, DataSchemaNode node) { if (node.augmenting || node.addedByUses) { @@ -292,7 +294,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - // serialVersionUID + // serialVersionUID if (genTOBuilder !== null) { val GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID"); prop.setValue(Long.toString(computeDefaultSUID(genTOBuilder as GeneratedTOBuilderImpl))); @@ -307,26 +309,26 @@ public class BindingGeneratorImpl implements BindingGenerator { val basePackageName = moduleNamespaceToPackageName(module); for (usesNode : node.uses) { for (augment : usesNode.augmentations) { - augmentationToGenTypes(basePackageName, augment, module, usesNode); + usesAugmentationToGenTypes(basePackageName, augment, module, usesNode, node); processUsesAugments(augment, module); } } } - /** - * Converts all augmentation of the module to the list - * Type objects. - * - * @param module - * module from which is obtained list of all augmentation objects - * to iterate over them - * @throws IllegalArgumentException - *
    - *
  • if the module equals null
  • - *
  • if the name of module equals null
  • - *
  • if the set of child nodes equals null
  • - *
- * + /** + * Converts all augmentation of the module to the list + * Type objects. + * + * @param module + * module from which is obtained list of all augmentation objects + * to iterate over them + * @throws IllegalArgumentException + *
    + *
  • if the module equals null
  • + *
  • if the name of module equals null
  • + *
  • if the set of child nodes equals null
  • + *
+ * */ private def void allAugmentsToGenTypes(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -339,25 +341,25 @@ public class BindingGeneratorImpl implements BindingGenerator { val basePackageName = moduleNamespaceToPackageName(module); val List augmentations = resolveAugmentations(module); for (augment : augmentations) { - augmentationToGenTypes(basePackageName, augment, module, null); - } - } - - /** - * Returns list of AugmentationSchema objects. The objects are - * sorted according to the length of their target path from the shortest to - * the longest. - * - * @param module - * module from which is obtained list of all augmentation objects - * @return list of sorted AugmentationSchema objects obtained - * from module - * @throws IllegalArgumentException - *
    - *
  • if the module equals null
  • - *
  • if the set of augmentation equals null
  • - *
- * + augmentationToGenTypes(basePackageName, augment, module); + } + } + + /** + * Returns list of AugmentationSchema objects. The objects are + * sorted according to the length of their target path from the shortest to + * the longest. + * + * @param module + * module from which is obtained list of all augmentation objects + * @return list of sorted AugmentationSchema objects obtained + * from module + * @throws IllegalArgumentException + *
    + *
  • if the module equals null
  • + *
  • if the set of augmentation equals null
  • + *
+ * */ private def List resolveAugmentations(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -377,19 +379,19 @@ public class BindingGeneratorImpl implements BindingGenerator { return sortedAugmentations; } - /** - * Converts whole module to GeneratedType object. - * Firstly is created the module builder object from which is vally - * obtained reference to GeneratedType object. - * - * @param module - * module from which are obtained the module name, child nodes, - * uses and is derived package name - * @return GeneratedType which is internal representation of - * the module - * @throws IllegalArgumentException - * if the module equals null - * + /** + * Converts whole module to GeneratedType object. + * Firstly is created the module builder object from which is vally + * obtained reference to GeneratedType object. + * + * @param module + * module from which are obtained the module name, child nodes, + * uses and is derived package name + * @return GeneratedType which is internal representation of + * the module + * @throws IllegalArgumentException + * if the module equals null + * */ private def GeneratedTypeBuilder moduleToDataType(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -400,21 +402,21 @@ public class BindingGeneratorImpl implements BindingGenerator { return moduleDataTypeBuilder; } - /** - * 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. - * - * @param module - * module from which is obtained set of all rpc objects to - * iterate over them - * @throws IllegalArgumentException - *
    - *
  • if the module equals null
  • - *
  • if the name of module equals null
  • - *
  • if the set of child nodes equals null
  • - *
- * + /** + * 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. + * + * @param module + * module from which is obtained set of all rpc objects to + * iterate over them + * @throws IllegalArgumentException + *
    + *
  • if the module equals null
  • + *
  • if the name of module equals null
  • + *
  • if the set of child nodes equals null
  • + *
+ * */ private def void rpcMethodsToGenType(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -468,21 +470,21 @@ public class BindingGeneratorImpl implements BindingGenerator { genCtx.get(module).addTopLevelNodeType(interfaceBuilder) } - /** - * 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. - * - * @param module - * module from which is obtained set of all notification objects - * to iterate over them - * @throws IllegalArgumentException - *
    - *
  • if the module equals null
  • - *
  • if the name of module equals null
  • - *
  • if the set of child nodes equals null
  • - *
- * + /** + * 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. + * + * @param module + * module from which is obtained set of all notification objects + * to iterate over them + * @throws IllegalArgumentException + *
    + *
  • if the module equals null
  • + *
  • if the name of module equals null
  • + *
  • if the set of child nodes equals null
  • + *
+ * */ private def void notificationsToGenType(Module module) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -508,11 +510,11 @@ public class BindingGeneratorImpl implements BindingGenerator { notificationInterface.addImplementsType(NOTIFICATION); genCtx.get(module).addChildNodeType(notification.path, notificationInterface) - // Notification object + // Notification object resolveDataSchemaNodes(module, basePackageName, notificationInterface, notificationInterface, notification.childNodes); - listenerInterface.addMethod("on" + notificationInterface.name) // + listenerInterface.addMethod("on" + notificationInterface.name) // .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification"). setReturnType(Types.VOID); } @@ -521,17 +523,17 @@ public class BindingGeneratorImpl implements BindingGenerator { genCtx.get(module).addTopLevelNodeType(listenerInterface) } - /** - * Converts all identities of the module to the list of - * Type objects. - * - * @param module - * module from which is obtained set of all identity objects to - * iterate over them - * @param context - * schema context only used as input parameter for method - * {@link identityToGenType} - * + /** + * Converts all identities of the module to the list of + * Type objects. + * + * @param module + * module from which is obtained set of all identity objects to + * iterate over them + * @param context + * schema context only used as input parameter for method + * {@link identityToGenType} + * */ private def void allIdentitiesToGenTypes(Module module, SchemaContext context) { val Set schemaIdentities = module.identities; @@ -544,23 +546,23 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * 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. - * If identity doesn't contain base identity then only reference to abstract - * class {@link org.opendaylight.yangtools.yang.model.api.BaseIdentity - * BaseIdentity} is added - * - * @param module current module - * @param basePackageName - * string contains the module package name - * @param identity - * IdentitySchemaNode which contains data about identity - * @param context - * SchemaContext which is used to get package and name - * information about base of identity - * + /** + * 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. + * If identity doesn't contain base identity then only reference to abstract + * class {@link org.opendaylight.yangtools.yang.model.api.BaseIdentity + * BaseIdentity} is added + * + * @param module current module + * @param basePackageName + * string contains the module package name + * @param identity + * IdentitySchemaNode which contains data about identity + * @param context + * SchemaContext which is used to get package and name + * information about base of identity + * */ private def void identityToGenType(Module module, String basePackageName, IdentitySchemaNode identity, SchemaContext context) { @@ -580,31 +582,31 @@ public class BindingGeneratorImpl implements BindingGenerator { val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance(); newType.setExtendsType(gto); } - newType.setAbstract(true); - val qname = identity.QName; - - newType.qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,qname); + newType.setAbstract(true); + val qname = identity.QName; + + newType.qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,qname); genCtx.get(module).addIdentityType(identity.QName,newType) - } - + } + private static def qnameConstant(GeneratedTypeBuilderBase toBuilder, String constantName, QName name) { - toBuilder.addConstant(QName.typeForClass,constantName,''' - org.opendaylight.yangtools.yang.common.QName.create("«name.namespace»","«name.formattedRevision»","«name.localName»") + toBuilder.addConstant(QName.typeForClass,constantName,''' + org.opendaylight.yangtools.yang.common.QName.create("«name.namespace»","«name.formattedRevision»","«name.localName»") '''); } - /** - * Converts all groupings of the module to the list of - * Type objects. Firstly are groupings sorted according mutual - * dependencies. At least dependent (independent) groupings are in the list - * saved at first positions. For every grouping the record is added to map - * {@link BindingGeneratorImpl#allGroupings allGroupings} - * - * @param module - * current module - * @param collection of groupings from which types will be generated - * + /** + * Converts all groupings of the module to the list of + * Type objects. Firstly are groupings sorted according mutual + * dependencies. At least dependent (independent) groupings are in the list + * saved at first positions. For every grouping the record is added to map + * {@link BindingGeneratorImpl#allGroupings allGroupings} + * + * @param module + * current module + * @param collection of groupings from which types will be generated + * */ private def void groupingsToGenTypes(Module module, Collection groupings) { val basePackageName = moduleNamespaceToPackageName(module); @@ -615,18 +617,18 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Converts individual grouping to GeneratedType. Firstly generated type - * builder is created and every child node of grouping is resolved to the - * method. - * - * @param basePackageName - * string contains the module package name - * @param grouping - * GroupingDefinition which contains data about grouping - * @param module current module - * @return GeneratedType which is generated from grouping (object of type - * GroupingDefinition) + /** + * Converts individual grouping to GeneratedType. Firstly generated type + * builder is created and every child node of grouping is resolved to the + * method. + * + * @param basePackageName + * string contains the module package name + * @param grouping + * GroupingDefinition which contains data about grouping + * @param module current module + * @return GeneratedType which is generated from grouping (object of type + * GroupingDefinition) */ private def void groupingToGenType(String basePackageName, GroupingDefinition grouping, Module module) { val packageName = packageNameForGeneratedType(basePackageName, grouping.path); @@ -637,16 +639,16 @@ public class BindingGeneratorImpl implements BindingGenerator { processUsesAugments(grouping, module); } - /** - * Tries to find EnumTypeDefinition in typeDefinition. If base - * type of typeDefinition is of the type ExtendedType then this - * method is recursively called with this base type. - * - * @param typeDefinition - * TypeDefinition in which should be EnumTypeDefinition found as - * base type - * @return EnumTypeDefinition if it is found inside - * typeDefinition or null in other case + /** + * Tries to find EnumTypeDefinition in typeDefinition. If base + * type of typeDefinition is of the type ExtendedType then this + * method is recursively called with this base type. + * + * @param typeDefinition + * TypeDefinition in which should be EnumTypeDefinition found as + * base type + * @return EnumTypeDefinition if it is found inside + * typeDefinition or null in other case */ private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition typeDefinition) { if (typeDefinition !== null) { @@ -659,22 +661,22 @@ public class BindingGeneratorImpl implements BindingGenerator { return null; } - /** - * Adds enumeration builder created from enumTypeDef to - * typeBuilder. - * - * Each enumTypeDef item is added to builder with its name and - * value. - * - * @param enumTypeDef - * EnumTypeDefinition contains enum data - * @param enumName - * string contains name which will be assigned to enumeration - * builder - * @param typeBuilder - * GeneratedTypeBuilder to which will be enum builder assigned - * @return enumeration builder which contains data from - * enumTypeDef + /** + * Adds enumeration builder created from enumTypeDef to + * typeBuilder. + * + * Each enumTypeDef item is added to builder with its name and + * value. + * + * @param enumTypeDef + * EnumTypeDefinition contains enum data + * @param enumName + * string contains name which will be assigned to enumeration + * builder + * @param typeBuilder + * GeneratedTypeBuilder to which will be enum builder assigned + * @return enumeration builder which contains data from + * enumTypeDef */ private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, QName enumName, GeneratedTypeBuilder typeBuilder) { @@ -688,19 +690,19 @@ public class BindingGeneratorImpl implements BindingGenerator { return null; } - /** - * Generates type builder for module. - * - * @param module - * Module which is source of package name for generated type - * builder - * @param postfix - * string which is added to the module class name representation - * as suffix - * @return instance of GeneratedTypeBuilder which represents - * module. - * @throws IllegalArgumentException - * if module equals null + /** + * Generates type builder for module. + * + * @param module + * Module which is source of package name for generated type + * builder + * @param postfix + * string which is added to the module class name representation + * as suffix + * @return instance of GeneratedTypeBuilder which represents + * module. + * @throws IllegalArgumentException + * if module equals null */ private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) { checkArgument(module !== null, "Module reference cannot be NULL."); @@ -709,81 +711,111 @@ public class BindingGeneratorImpl implements BindingGenerator { 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 - * augSchema node or a generated types for cases are added if - * augmented node is choice. - * - * @param augmentPackageName - * string with the name of the package to which the augmentation - * belongs - * @param augSchema - * AugmentationSchema which is contains data about augmentation - * (target path, childs...) - * @param module current module - * @param parentUsesNode parent uses node of this augment (can be null if this augment is not defined under uses statement) - * @throws IllegalArgumentException - *
    - *
  • if augmentPackageName equals null
  • - *
  • if augSchema equals null
  • - *
  • if target path of augSchema equals null
  • - *
+ /** + * 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 + * augSchema node or a generated types for cases are added if + * augmented node is choice. + * + * @param augmentPackageName + * string with the name of the package to which the augmentation + * belongs + * @param augSchema + * AugmentationSchema which is contains data about augmentation + * (target path, childs...) + * @param module current module + * @param parentUsesNode parent uses node of this augment (can be null if this augment is not defined under uses statement) + * @throws IllegalArgumentException + *
    + *
  • if augmentPackageName equals null
  • + *
  • if augSchema equals null
  • + *
  • if target path of augSchema equals null
  • + *
*/ - private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module, - UsesNode parentUsesNode) { + private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module) { 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)."); - processUsesAugments(augSchema, module); + processUsesAugments(augSchema, module); val targetPath = augSchema.targetPath; - var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); + var SchemaNode targetSchemaNode = null + + targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) { - if (parentUsesNode == null) { - targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode); - } else { - targetSchemaNode = findOriginalTargetFromGrouping(targetSchemaNode.QName.localName, parentUsesNode); - } + targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode); if (targetSchemaNode == null) { throw new NullPointerException( - "Failed to find target node from grouping for augmentation " + augSchema + " in module " + + "Failed to find target node from grouping in augmentation " + augSchema + " in module " + module.name); } - } - - if (targetSchemaNode == null) { - throw new IllegalArgumentException("augment target not found: " + targetPath) - } - - if (targetSchemaNode !== null) { - var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path) - if (targetTypeBuilder === null) { - targetTypeBuilder = findCaseByPath(targetSchemaNode.path) - } - if (targetTypeBuilder === null) { - throw new NullPointerException("Target type not yet generated: " + targetSchemaNode); - } - if (!(targetSchemaNode instanceof ChoiceNode)) { - var packageName = augmentPackageName; - if (parentUsesNode != null) { - packageName = packageNameForGeneratedType(augmentPackageName, augSchema.targetPath); - } - val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName, - targetTypeBuilder.toInstance, augSchema); - genCtx.get(module).addAugmentType(augTypeBuilder) - genCtx.get(module).addTypeToAugmentation(augTypeBuilder,augSchema); - } else { - generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance, - targetSchemaNode as ChoiceNode, augSchema.childNodes); + } + if (targetSchemaNode == null) { + throw new IllegalArgumentException("augment target not found: " + targetPath) + } + + var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path) + if (targetTypeBuilder === null) { + targetTypeBuilder = findCaseByPath(targetSchemaNode.path) + } + if (targetTypeBuilder === null) { + throw new NullPointerException("Target type not yet generated: " + targetSchemaNode); + } + + if (!(targetSchemaNode instanceof ChoiceNode)) { + var packageName = augmentPackageName; + val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName, + targetTypeBuilder.toInstance, augSchema); + genCtx.get(module).addAugmentType(augTypeBuilder) + genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema); + } else { + generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance, + targetSchemaNode as ChoiceNode, augSchema.childNodes); + } + } + + private def void usesAugmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module, + UsesNode usesNode, DataNodeContainer usesNodeParent) { + 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)."); + + processUsesAugments(augSchema, module); + val targetPath = augSchema.targetPath; + var SchemaNode targetSchemaNode = null + targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode); + if (targetSchemaNode == null) { + throw new IllegalArgumentException("augment target not found: " + targetPath) + } + + var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path) + if (targetTypeBuilder === null) { + targetTypeBuilder = findCaseByPath(targetSchemaNode.path) + } + if (targetTypeBuilder === null) { + throw new NullPointerException("Target type not yet generated: " + targetSchemaNode); + } + + if (!(targetSchemaNode instanceof ChoiceNode)) { + var packageName = augmentPackageName; + if (usesNodeParent instanceof SchemaNode) { + packageName = packageNameForGeneratedType(augmentPackageName, (usesNodeParent as SchemaNode).path, true) } + val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName, + targetTypeBuilder.toInstance, augSchema); + genCtx.get(module).addAugmentType(augTypeBuilder) + genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema); + } else { + generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance, + targetSchemaNode as ChoiceNode, augSchema.childNodes); } } - /** - * Utility method which search for original node defined in grouping. + /** + * Utility method which search for original node defined in grouping. */ private def DataSchemaNode findOriginal(DataSchemaNode node) { var DataSchemaNode result = findCorrectTargetFromGrouping(node); @@ -803,26 +835,26 @@ public class BindingGeneratorImpl implements BindingGenerator { return null } - var QName currentName = node.QName + var QName currentName = node.QName var Object currentNode = node - var Object parent = node; - val tmpPath = new ArrayList() - val tmpTree = new ArrayList() + var Object parent = node; + val tmpPath = new ArrayList() + val tmpTree = new ArrayList() var AugmentationSchema augment = null; - do { - val SchemaPath sp = (parent as SchemaNode).path - val List names = sp.path - val List newNames = new ArrayList(names) - newNames.remove(newNames.size - 1) - val SchemaPath newSp = new SchemaPath(newNames, sp.absolute) - parent = findDataSchemaNode(schemaContext, newSp) + do { + val SchemaPath sp = (parent as SchemaNode).path + val List names = sp.path + val List newNames = new ArrayList(names) + newNames.remove(newNames.size - 1) + val SchemaPath newSp = new SchemaPath(newNames, sp.absolute) + parent = findDataSchemaNode(schemaContext, newSp) if (parent instanceof AugmentationTarget) { - tmpPath.add(currentName); - tmpTree.add(currentNode as SchemaNode) + tmpPath.add(currentName); + tmpTree.add(currentNode as SchemaNode) augment = findNodeInAugment((parent as AugmentationTarget).availableAugmentations, currentName); if (augment == null) { - currentName = (parent as DataSchemaNode).QName + currentName = (parent as DataSchemaNode).QName currentNode = parent } } @@ -831,7 +863,7 @@ public class BindingGeneratorImpl implements BindingGenerator { if (augment == null) { return null; } else { - Collections.reverse(tmpPath); + Collections.reverse(tmpPath); Collections.reverse(tmpTree); var Object actualParent = augment; var DataSchemaNode result = null; @@ -847,7 +879,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - if (result.addedByUses) { + if (result.addedByUses) { result = findCorrectTargetFromAugmentGrouping(result, augment, tmpTree); } @@ -856,37 +888,37 @@ public class BindingGeneratorImpl implements BindingGenerator { } private def AugmentationSchema findNodeInAugment(Collection augments, QName name) { - for (augment : augments) { - val DataSchemaNode node = augment.getDataChildByName(name); + for (augment : augments) { + val DataSchemaNode node = augment.getDataChildByName(name); if (node != null) { return augment; } } return null; } - - private def DataSchemaNode findCorrectTargetFromGrouping(DataSchemaNode node) { - if (node.path.path.size == 1) { - // uses is under module statement - val Module m = findParentModule(schemaContext, node); - var DataSchemaNode result = null; - for (u : m.uses) { - var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, u.groupingPath.path); - if (!(targetGrouping instanceof GroupingDefinition)) { - throw new IllegalArgumentException("Failed to generate code for augment in " + u); - } - var gr = targetGrouping as GroupingDefinition; - result = gr.getDataChildByName(node.QName.localName); - } - if (result == null) { - throw new IllegalArgumentException("Failed to generate code for augment") - } - return result - } else { - var DataSchemaNode result = null; - var QName currentName = node.QName - var tmpPath = new ArrayList() - var Object parent = null + + private def DataSchemaNode findCorrectTargetFromGrouping(DataSchemaNode node) { + if (node.path.path.size == 1) { + // uses is under module statement + val Module m = findParentModule(schemaContext, node); + var DataSchemaNode result = null; + for (u : m.uses) { + var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, u.groupingPath.path); + if (!(targetGrouping instanceof GroupingDefinition)) { + throw new IllegalArgumentException("Failed to generate code for augment in " + u); + } + var gr = targetGrouping as GroupingDefinition; + result = gr.getDataChildByName(node.QName.localName); + } + if (result == null) { + throw new IllegalArgumentException("Failed to generate code for augment") + } + return result + } else { + var DataSchemaNode result = null; + var QName currentName = node.QName + var tmpPath = new ArrayList() + var Object parent = null val SchemaPath sp = node.path val List names = sp.path @@ -894,15 +926,17 @@ public class BindingGeneratorImpl implements BindingGenerator { newNames.remove(newNames.size - 1) val SchemaPath newSp = new SchemaPath(newNames, sp.absolute) parent = findDataSchemaNode(schemaContext, newSp) - - do { - tmpPath.add(currentName); - val dataNodeParent = parent as DataNodeContainer; - for (u : dataNodeParent.uses) { - if (result == null) { - result = getResultFromUses(u, currentName.localName) - } - } + + do { + tmpPath.add(currentName); + if (parent instanceof DataNodeContainer) { + val dataNodeParent = parent as DataNodeContainer; + for (u : dataNodeParent.uses) { + if (result == null) { + result = getResultFromUses(u, currentName.localName) + } + } + } if (result == null) { currentName = (parent as SchemaNode).QName if (parent instanceof SchemaNode) { @@ -919,52 +953,52 @@ public class BindingGeneratorImpl implements BindingGenerator { } else { throw new IllegalArgumentException("Failed to generate code for augment") } - } - } while (result == null && !(parent instanceof Module)); - - if (result != null) { - result = getTargetNode(tmpPath, result) - } - return result; - } - } - + } + } while (result == null && !(parent instanceof Module)); + + if (result != null) { + result = getTargetNode(tmpPath, result) + } + return result; + } + } + private def DataSchemaNode findCorrectTargetFromAugmentGrouping(DataSchemaNode node, AugmentationSchema parentNode, - List dataTree) { - + List dataTree) { + var DataSchemaNode result = null; var QName currentName = node.QName - var tmpPath = new ArrayList() - tmpPath.add(currentName) - var int i = 1; + var tmpPath = new ArrayList() + tmpPath.add(currentName) + var int i = 1; var Object parent = null - - do { + + do { if (dataTree.size < 2 || dataTree.size == i) { parent = parentNode } else { parent = dataTree.get(dataTree.size - (i+1)) tmpPath.add((parent as SchemaNode).QName) - } + } val dataNodeParent = parent as DataNodeContainer; for (u : dataNodeParent.uses) { - if (result == null) { + if (result == null) { result = getResultFromUses(u, currentName.localName) } } if (result == null) { - i = i + 1 + i = i + 1 currentName = (parent as SchemaNode).QName } } while (result == null); - + if (result != null) { - result = getTargetNode(tmpPath, result) + result = getTargetNode(tmpPath, result) } return result; - } - + } + private def getResultFromUses(UsesNode u, String currentName) { var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, u.groupingPath.path) if (!(targetGrouping instanceof GroupingDefinition)) { @@ -972,8 +1006,8 @@ public class BindingGeneratorImpl implements BindingGenerator { } var gr = targetGrouping as GroupingDefinition return gr.getDataChildByName(currentName) - } - + } + private def getTargetNode(List tmpPath, DataSchemaNode node) { var DataSchemaNode result = node if (tmpPath.size == 1) { @@ -986,67 +1020,81 @@ public class BindingGeneratorImpl implements BindingGenerator { Collections.reverse(tmpPath); tmpPath.remove(0); - for (name : tmpPath) { + for (name : tmpPath) { // searching by local name is must, because node has different namespace in its original location - newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName); + if (newParent instanceof DataNodeContainer) { + newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName); + } else { + newParent = (newParent as ChoiceNode).getCaseNodeByName(name.localName); + } } if (newParent != null && newParent.addedByUses) { newParent = findOriginal(newParent); } return newParent; } - } + } - /** - * Convenient method to find node added by uses statement. + /** + * Convenient method to find node added by uses statement. */ - private def DataSchemaNode findOriginalTargetFromGrouping(String targetSchemaNodeName, UsesNode parentUsesNode) { + private def DataSchemaNode findOriginalTargetFromGrouping(SchemaPath targetPath, UsesNode parentUsesNode) { var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, parentUsesNode.groupingPath.path); if (!(targetGrouping instanceof GroupingDefinition)) { throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode); } var grouping = targetGrouping as GroupingDefinition; - var result = grouping.getDataChildByName(targetSchemaNodeName); + var SchemaNode result = grouping; + val List path = targetPath.path + for (node : path) { + // finding by local name is valid, grouping cannot contain nodes with same name and different namespace + if (result instanceof DataNodeContainer) { + result = (result as DataNodeContainer).getDataChildByName(node.localName) + } else if (result instanceof ChoiceNode) { + result = (result as ChoiceNode).getCaseNodeByName(node.localName) + } + } if (result == null) { return null; } - var boolean fromUses = result.addedByUses; + val String targetSchemaNodeName = result.QName.localName; + var boolean fromUses = (result as DataSchemaNode).addedByUses var Iterator groupingUses = grouping.uses.iterator; while (fromUses) { if (groupingUses.hasNext()) { grouping = findNodeInSchemaContext(schemaContext, groupingUses.next().groupingPath.path) as GroupingDefinition; result = grouping.getDataChildByName(targetSchemaNodeName); - fromUses = result.addedByUses; + fromUses = (result as DataSchemaNode).addedByUses; } else { throw new NullPointerException("Failed to generate code for augment in " + parentUsesNode); } } - return result; + return result as DataSchemaNode } - /** - * Returns a generated type builder for an augmentation. - * - * The name of the type builder is equal to the name of augmented node with - * serial number as suffix. - * - * @param module current module - * @param augmentPackageName - * string with contains the package name to which the augment - * belongs - * @param basePackageName - * string with the package name to which the augmented node - * belongs - * @param targetTypeRef - * target type - * @param augSchema - * augmentation schema which contains data about the child nodes - * and uses of augment - * @return generated type builder for augment + /** + * Returns a generated type builder for an augmentation. + * + * The name of the type builder is equal to the name of augmented node with + * serial number as suffix. + * + * @param module current module + * @param augmentPackageName + * string with contains the package name to which the augment + * belongs + * @param basePackageName + * string with the package name to which the augmented node + * belongs + * @param targetTypeRef + * target type + * @param augSchema + * augmentation schema which contains data about the child nodes + * and uses of augment + * @return generated type builder for augment */ private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(Module module, String augmentPackageName, String basePackageName, Type targetTypeRef, AugmentationSchema augSchema) { @@ -1074,10 +1122,10 @@ public class BindingGeneratorImpl implements BindingGenerator { return augTypeBuilder; } - /** - * - * @param unknownSchemaNodes - * @return nodeParameter of UnknownSchemaNode + /** + * + * @param unknownSchemaNodes + * @return nodeParameter of UnknownSchemaNode */ private def String getAugmentIdentifier(List unknownSchemaNodes) { for (unknownSchemaNode : unknownSchemaNodes) { @@ -1090,17 +1138,17 @@ public class BindingGeneratorImpl implements BindingGenerator { return null; } - /** - * 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. - * - * @param builders - * map of builders which were created in the package to which the - * augmentation belongs - * @param genTypeName - * string with name of augmented node - * @return string with unique name for augmentation builder + /** + * 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. + * + * @param builders + * map of builders which were created in the package to which the + * augmentation belongs + * @param genTypeName + * 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; @@ -1110,28 +1158,28 @@ public class BindingGeneratorImpl implements BindingGenerator { return genTypeName + index; } - /** - * Adds the methods to typeBuilder which represent subnodes of - * node for which typeBuilder was created. - * - * The subnodes aren't mapped to the methods if they are part of grouping or - * augment (in this case are already part of them). - * - * @param module current module - * @param basePackageName - * string contains the module package name - * @param parent - * generated type builder which represents any node. The subnodes - * of this node are added to the typeBuilder as - * methods. The subnode can be of type leaf, leaf-list, list, - * container, choice. - * @param childOf parent type - * @param schemaNodes - * set of data schema nodes which are the children of the node - * for which typeBuilder was created - * @return generated type builder which is the same builder as input - * parameter. The getter methods (representing child nodes) could be - * added to it. + /** + * Adds the methods to typeBuilder which represent subnodes of + * node for which typeBuilder was created. + * + * The subnodes aren't mapped to the methods if they are part of grouping or + * augment (in this case are already part of them). + * + * @param module current module + * @param basePackageName + * string contains the module package name + * @param parent + * generated type builder which represents any node. The subnodes + * of this node are added to the typeBuilder as + * methods. The subnode can be of type leaf, leaf-list, list, + * container, choice. + * @param childOf parent type + * @param schemaNodes + * set of data schema nodes which are the children of the node + * for which typeBuilder was created + * @return generated type builder which is the same builder as input + * parameter. The getter methods (representing child nodes) could be + * added to it. */ private def GeneratedTypeBuilder resolveDataSchemaNodes(Module module, String basePackageName, GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, Set schemaNodes) { @@ -1145,25 +1193,25 @@ public class BindingGeneratorImpl implements BindingGenerator { return parent; } - /** - * Adds the methods to typeBuilder what represents subnodes of - * node for which typeBuilder was created. - * - * @param module current module - * @param basePackageName - * string contains the module package name - * @param typeBuilder - * generated type builder which represents any node. The subnodes - * of this node are added to the typeBuilder as - * methods. The subnode can be of type leaf, leaf-list, list, - * container, choice. - * @param childOf parent type - * @param schemaNodes - * set of data schema nodes which are the children of the node - * for which typeBuilder was created - * @return generated type builder which is the same object as the input - * parameter typeBuilder. The getter method could be - * added to it. + /** + * Adds the methods to typeBuilder what represents subnodes of + * node for which typeBuilder was created. + * + * @param module current module + * @param basePackageName + * string contains the module package name + * @param typeBuilder + * generated type builder which represents any node. The subnodes + * of this node are added to the typeBuilder as + * methods. The subnode can be of type leaf, leaf-list, list, + * container, choice. + * @param childOf parent type + * @param schemaNodes + * set of data schema nodes which are the children of the node + * for which typeBuilder was created + * @return generated type builder which is the same object as the input + * parameter typeBuilder. The getter method could be + * added to it. */ private def GeneratedTypeBuilder augSchemaNodeToMethods(Module module, String basePackageName, GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Set schemaNodes) { @@ -1177,20 +1225,20 @@ public class BindingGeneratorImpl implements BindingGenerator { return typeBuilder; } - /** - * Adds to typeBuilder a method which is derived from - * schemaNode. - * - * @param basePackageName - * string with the module package name - * @param node - * data schema node which is added to typeBuilder as - * a method - * @param typeBuilder - * generated type builder to which is schemaNode - * added as a method. - * @param childOf parent type - * @param module current module + /** + * Adds to typeBuilder a method which is derived from + * schemaNode. + * + * @param basePackageName + * string with the module package name + * @param node + * data schema node which is added to typeBuilder as + * a method + * @param typeBuilder + * generated type builder to which is schemaNode + * added as a method. + * @param childOf parent type + * @param module current module */ private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node, GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Module module) { @@ -1210,28 +1258,28 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Converts choiceNode to the list of generated types for - * choice and its cases. - * - * The package names for choice and for its cases are created as - * concatenation of the module package (basePackageName) and - * names of all parents node. - * - * @param module current module - * @param basePackageName - * string with the module package name - * @param parent parent type - * @param childOf concrete parent for case child nodes - * @param choiceNode - * choice node which is mapped to generated type. Also child - * nodes - cases are mapped to generated types. - * @throws IllegalArgumentException - *
    - *
  • if basePackageName equals null
  • - *
  • if choiceNode equals null
  • - *
- * + /** + * Converts choiceNode to the list of generated types for + * choice and its cases. + * + * The package names for choice and for its cases are created as + * concatenation of the module package (basePackageName) and + * names of all parents node. + * + * @param module current module + * @param basePackageName + * string with the module package name + * @param parent parent type + * @param childOf concrete parent for case child nodes + * @param choiceNode + * choice node which is mapped to generated type. Also child + * nodes - cases are mapped to generated types. + * @throws IllegalArgumentException + *
    + *
  • if basePackageName equals null
  • + *
  • if choiceNode equals null
  • + *
+ * */ private def void choiceToGeneratedType(Module module, String basePackageName, GeneratedTypeBuilder parent, ChoiceNode choiceNode) { @@ -1248,31 +1296,31 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Converts caseNodes set to list of corresponding generated - * types. - * - * For every case which isn't added through augment or uses is - * created generated type builder. The package names for the builder is - * created as concatenation of the module package ( - * basePackageName) and names of all parents nodes of the - * concrete case. There is also relation "implements type" - * between every case builder and choice type - * - * @param basePackageName - * string with the module package name - * @param refChoiceType - * type which represents superior case - * @param caseNodes - * set of choice case nodes which are mapped to generated types - * @return list of generated types for caseNodes. - * @throws IllegalArgumentException - *
    - *
  • if basePackageName equals null
  • - *
  • if refChoiceType equals null
  • - *
  • if caseNodes equals null
  • - *
- * * + /** + * Converts caseNodes set to list of corresponding generated + * types. + * + * For every case which isn't added through augment or uses is + * created generated type builder. The package names for the builder is + * created as concatenation of the module package ( + * basePackageName) and names of all parents nodes of the + * concrete case. There is also relation "implements type" + * between every case builder and choice type + * + * @param basePackageName + * string with the module package name + * @param refChoiceType + * type which represents superior case + * @param caseNodes + * set of choice case nodes which are mapped to generated types + * @return list of generated types for caseNodes. + * @throws IllegalArgumentException + *
    + *
  • if basePackageName equals null
  • + *
  • if refChoiceType equals null
  • + *
  • if caseNodes equals null
  • + *
+ * * */ private def void generateTypesFromChoiceCases(Module module, String basePackageName, GeneratedTypeBuilder choiceParent, Type refChoiceType, ChoiceNode choiceNode) { @@ -1293,13 +1341,13 @@ public class BindingGeneratorImpl implements BindingGenerator { genCtx.get(module).addCaseType(caseNode.path, caseTypeBuilder) val Set caseChildNodes = caseNode.childNodes if (caseChildNodes !== null) { - var Object parentNode = null - val SchemaPath nodeSp = choiceNode.path - val List nodeNames = nodeSp.path - val List nodeNewNames = new ArrayList(nodeNames) - nodeNewNames.remove(nodeNewNames.size - 1) - val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute) - parentNode = findDataSchemaNode(schemaContext, nodeNewSp) + var Object parentNode = null + val SchemaPath nodeSp = choiceNode.path + val List nodeNames = nodeSp.path + val List nodeNewNames = new ArrayList(nodeNames) + nodeNewNames.remove(nodeNewNames.size - 1) + val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute) + parentNode = findDataSchemaNode(schemaContext, nodeNewSp) var SchemaNode parent if (parentNode instanceof AugmentationSchema) { @@ -1317,12 +1365,12 @@ public class BindingGeneratorImpl implements BindingGenerator { } parent = targetSchemaNode } else { - val SchemaPath sp = choiceNode.path - val List names = sp.path - val List newNames = new ArrayList(names) - newNames.remove(newNames.size - 1) - val SchemaPath newSp = new SchemaPath(newNames, sp.absolute) - parent = findDataSchemaNode(schemaContext, newSp) + val SchemaPath sp = choiceNode.path + val List names = sp.path + val List newNames = new ArrayList(names) + newNames.remove(newNames.size - 1) + val SchemaPath newSp = new SchemaPath(newNames, sp.absolute) + parent = findDataSchemaNode(schemaContext, newSp) } var GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.path) resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes) @@ -1333,30 +1381,30 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Generates list of generated types for all the cases of a choice which are - * added to the choice through the augment. - * - * - * @param basePackageName - * string contains name of package to which augment belongs. If - * an augmented choice is from an other package (pcg1) than an - * augmenting choice (pcg2) then case's of the augmenting choice - * will belong to pcg2. - * @param refChoiceType - * Type which represents the choice to which case belongs. Every - * case has to contain its choice in extend part. - * @param caseNodes - * set of choice case nodes for which is checked if are/aren't - * added to choice through augmentation - * @return list of generated types which represents augmented cases of - * choice refChoiceType - * @throws IllegalArgumentException - *
    - *
  • if basePackageName equals null
  • - *
  • if refChoiceType equals null
  • - *
  • if caseNodes equals null
  • - *
+ /** + * Generates list of generated types for all the cases of a choice which are + * added to the choice through the augment. + * + * + * @param basePackageName + * string contains name of package to which augment belongs. If + * an augmented choice is from an other package (pcg1) than an + * augmenting choice (pcg2) then case's of the augmenting choice + * will belong to pcg2. + * @param refChoiceType + * Type which represents the choice to which case belongs. Every + * case has to contain its choice in extend part. + * @param caseNodes + * set of choice case nodes for which is checked if are/aren't + * added to choice through augmentation + * @return list of generated types which represents augmented cases of + * choice refChoiceType + * @throws IllegalArgumentException + *
    + *
  • if basePackageName equals null
  • + *
  • if refChoiceType equals null
  • + *
  • if caseNodes equals null
  • + *
*/ private def void generateTypesFromAugmentedChoiceCases(Module module, String basePackageName, Type targetType, ChoiceNode targetNode, Set augmentedNodes) { @@ -1370,13 +1418,13 @@ public class BindingGeneratorImpl implements BindingGenerator { val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode); caseTypeBuilder.addImplementsType(targetType); - var SchemaNode parent = null - val SchemaPath nodeSp = targetNode.path - val List nodeNames = nodeSp.path - val List nodeNewNames = new ArrayList(nodeNames) - nodeNewNames.remove(nodeNewNames.size - 1) - val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute) - parent = findDataSchemaNode(schemaContext, nodeNewSp) + var SchemaNode parent = null + val SchemaPath nodeSp = targetNode.path + val List nodeNames = nodeSp.path + val List nodeNewNames = new ArrayList(nodeNames) + nodeNewNames.remove(nodeNewNames.size - 1) + val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute) + parent = findDataSchemaNode(schemaContext, nodeNewSp) var GeneratedTypeBuilder childOfType = null; if (parent instanceof Module) { @@ -1413,22 +1461,22 @@ public class BindingGeneratorImpl implements BindingGenerator { } - /** - * Converts leaf to the getter method which is added to - * typeBuilder. - * - * @param typeBuilder - * generated type builder to which is added getter method as - * leaf mapping - * @param leaf - * leaf schema node which is mapped as getter method which is - * added to typeBuilder - * @return boolean value - *
    - *
  • false - if leaf or typeBuilder are - * null
  • - *
  • true - in other cases
  • - *
+ /** + * Converts leaf to the getter method which is added to + * typeBuilder. + * + * @param typeBuilder + * generated type builder to which is added getter method as + * leaf mapping + * @param leaf + * leaf schema node which is mapped as getter method which is + * added to typeBuilder + * @return boolean value + *
    + *
  • false - if leaf or typeBuilder are + * null
  • + *
  • true - in other cases
  • + *
*/ private def boolean resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) { if ((leaf !== null) && (typeBuilder !== null)) { @@ -1454,14 +1502,14 @@ public class BindingGeneratorImpl implements BindingGenerator { } (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType); } else if (typeDef instanceof UnionType) { - genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule); - if (genTOBuilder !== null) { - returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule) + genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule); + if (genTOBuilder !== null) { + returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule) } } else if (typeDef instanceof BitsTypeDefinition) { - genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule); - if (genTOBuilder !== null) { - returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); + genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule); + if (genTOBuilder !== null) { + returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); } } else { val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef); @@ -1533,27 +1581,27 @@ public class BindingGeneratorImpl implements BindingGenerator { return null; } - /** - * Converts leaf schema node to property of generated TO - * builder. - * - * @param toBuilder - * generated TO builder to which is leaf added as - * property - * @param leaf - * leaf schema node which is added to toBuilder as - * property - * @param isReadOnly - * boolean value which says if leaf property is|isn't read only - * @return boolean value - *
    - *
  • false - if leaf, toBuilder or leaf - * name equals null or if leaf is added by uses.
  • - *
  • true - other cases
  • - *
+ /** + * Converts leaf schema node to property of generated TO + * builder. + * + * @param toBuilder + * generated TO builder to which is leaf added as + * property + * @param leaf + * leaf schema node which is added to toBuilder as + * property + * @param isReadOnly + * boolean value which says if leaf property is|isn't read only + * @return boolean value + *
    + *
  • false - if leaf, toBuilder or leaf + * name equals null or if leaf is added by uses.
  • + *
  • true - other cases
  • + *
*/ private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf, - boolean isReadOnly) { + boolean isReadOnly, Module module) { if ((leaf !== null) && (toBuilder !== null)) { val leafName = leaf.QName.localName; var String leafDesc = leaf.description; @@ -1562,10 +1610,23 @@ public class BindingGeneratorImpl implements BindingGenerator { } if (leafName !== null) { + var Type returnType = null; val TypeDefinition typeDef = leaf.type; + if (typeDef instanceof UnionTypeDefinition) { + // GeneratedType for this type definition should be already created + var qname = typeDef.QName + var Module unionModule = null + if (qname.prefix == null || qname.prefix.empty) { + unionModule = module + } else { + unionModule = findModuleFromImports(module.imports, qname.prefix) + } + val ModuleContext mc = genCtx.get(unionModule) + returnType = mc.typedefs.get(typeDef.path) + } else { + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); + } - // TODO: properly resolve enum types - val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); if (returnType !== null) { val propBuilder = toBuilder.addProperty(parseToValidParamName(leafName)); propBuilder.setReadOnly(isReadOnly); @@ -1581,22 +1642,22 @@ public class BindingGeneratorImpl implements BindingGenerator { return false; } - /** - * Converts node leaf list schema node to getter method of - * typeBuilder. - * - * @param typeBuilder - * generated type builder to which is node added as - * getter method - * @param node - * leaf list schema node which is added to - * typeBuilder as getter method - * @return boolean value - *
    - *
  • true - if node, typeBuilder, - * nodeName equal null or node is added by uses
  • - *
  • false - other cases
  • - *
+ /** + * Converts node leaf list schema node to getter method of + * typeBuilder. + * + * @param typeBuilder + * generated type builder to which is node added as + * getter method + * @param node + * leaf list schema node which is added to + * typeBuilder as getter method + * @return boolean value + *
    + *
  • true - if node, typeBuilder, + * nodeName equal null or node is added by uses
  • + *
  • false - other cases
  • + *
*/ private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) { if ((node !== null) && (typeBuilder !== null)) { @@ -1606,28 +1667,28 @@ public class BindingGeneratorImpl implements BindingGenerator { nodeDesc = ""; } if (nodeName !== null && !node.isAddedByUses()) { - val TypeDefinition typeDef = node.type; - val parentModule = findParentModule(schemaContext, node); - - var Type returnType = null; - if (typeDef instanceof EnumTypeDefinition) { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node); - val enumTypeDef = typeDef as EnumTypeDefinition; - val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName, typeBuilder); - returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name); - (typeProvider as TypeProviderImpl).putReferencedType(node.path, returnType); - } else if (typeDef instanceof UnionType) { - val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule); - if (genTOBuilder !== null) { - returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule) + val TypeDefinition typeDef = node.type; + val parentModule = findParentModule(schemaContext, node); + + var Type returnType = null; + if (typeDef instanceof EnumTypeDefinition) { + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node); + val enumTypeDef = typeDef as EnumTypeDefinition; + val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName, typeBuilder); + returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name); + (typeProvider as TypeProviderImpl).putReferencedType(node.path, returnType); + } else if (typeDef instanceof UnionType) { + val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule); + if (genTOBuilder !== null) { + returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule) } - } else if (typeDef instanceof BitsTypeDefinition) { - val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule); - returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); - } else { - val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef); - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions); - } + } else if (typeDef instanceof BitsTypeDefinition) { + val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule); + returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); + } else { + val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef); + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions); + } val listType = Types.listTypeFor(returnType); constructGetter(typeBuilder, nodeName.localName, nodeDesc, listType); @@ -1636,7 +1697,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } return false; } - + private def Type createReturnTypeForUnion(GeneratedTOBuilder genTOBuilder, TypeDefinition typeDef, GeneratedTypeBuilder typeBuilder, Module parentModule) { val Type returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name); @@ -1644,7 +1705,7 @@ public class BindingGeneratorImpl implements BindingGenerator { genTOBuilder.setIsUnion(true); (typeProvider as TypeProviderImpl).addUnitsToGenTO(genTOBuilder, typeDef.getUnits()); - // union builder + // union builder val GeneratedTOBuilder unionBuilder = new GeneratedTOBuilderImpl(typeBuilder.getPackageName(), genTOBuilder.getName() + "Builder"); unionBuilder.setIsUnionBuilder(true); @@ -1662,38 +1723,38 @@ public class BindingGeneratorImpl implements BindingGenerator { types.add(unionBuilder.toInstance) } return returnType - } + } private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) { return addDefaultInterfaceDefinition(packageName, schemaNode, null); } - /** - * Instantiates generated type builder with packageName and - * schemaNode. - * - * The new builder always implements - * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.
- * If schemaNode is instance of GroupingDefinition it also - * implements {@link org.opendaylight.yangtools.yang.binding.Augmentable - * Augmentable}.
- * If schemaNode is instance of - * {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer - * DataNodeContainer} it can also implement nodes which are specified in - * uses. - * - * @param packageName - * string with the name of the package to which - * schemaNode belongs. - * @param schemaNode - * schema node for which is created generated type builder - * @param parent parent type (can be null) - * @return generated type builder schemaNode + /** + * Instantiates generated type builder with packageName and + * schemaNode. + * + * The new builder always implements + * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.
+ * If schemaNode is instance of GroupingDefinition it also + * implements {@link org.opendaylight.yangtools.yang.binding.Augmentable + * Augmentable}.
+ * If schemaNode is instance of + * {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer + * DataNodeContainer} it can also implement nodes which are specified in + * uses. + * + * @param packageName + * string with the name of the package to which + * schemaNode belongs. + * @param schemaNode + * schema node for which is created generated type builder + * @param parent parent type (can be null) + * @return generated type builder schemaNode */ private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode, Type parent) { - val it = addRawInterfaceDefinition(packageName, schemaNode, ""); - qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,schemaNode.QName); + val it = addRawInterfaceDefinition(packageName, schemaNode, ""); + qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,schemaNode.QName); if (parent === null) { addImplementsType(DATA_OBJECT); } else { @@ -1710,43 +1771,43 @@ public class BindingGeneratorImpl implements BindingGenerator { return it; } - /** - * Wraps the calling of the same overloaded method. - * - * @param packageName - * string with the package name to which returning generated type - * builder belongs - * @param schemaNode - * schema node which provide data about the schema node name - * @return generated type builder for schemaNode + /** + * Wraps the calling of the same overloaded method. + * + * @param packageName + * string with the package name to which returning generated type + * builder belongs + * @param schemaNode + * 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, ""); } - /** - * Returns reference to generated type builder for specified - * schemaNode with packageName. - * - * Firstly the generated type builder is searched in - * {@link BindingGeneratorImpl#genTypeBuilders genTypeBuilders}. If it isn't - * found it is created and added to genTypeBuilders. - * - * @param packageName - * string with the package name to which returning generated type - * builder belongs - * @param schemaNode - * schema node which provide data about the schema node name - * @param prefix return type name prefix - * @return generated type builder for schemaNode - * @throws IllegalArgumentException - *
    - *
  • if schemaNode equals null
  • - *
  • if packageName equals null
  • - *
  • if Q name of schema node is null
  • - *
  • if schema node name is null
  • - *
- * + /** + * Returns reference to generated type builder for specified + * schemaNode with packageName. + * + * Firstly the generated type builder is searched in + * {@link BindingGeneratorImpl#genTypeBuilders genTypeBuilders}. If it isn't + * found it is created and added to genTypeBuilders. + * + * @param packageName + * string with the package name to which returning generated type + * builder belongs + * @param schemaNode + * schema node which provide data about the schema node name + * @param prefix return type name prefix + * @return generated type builder for schemaNode + * @throws IllegalArgumentException + *
    + *
  • if schemaNode equals null
  • + *
  • if packageName equals null
  • + *
  • if Q name of schema node is null
  • + *
  • if schema node name is null
  • + *
+ * */ private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode, String prefix) { @@ -1763,7 +1824,7 @@ public class BindingGeneratorImpl implements BindingGenerator { genTypeName = prefix + BindingMapping.getClassName(schemaNodeName); } - //FIXME: Validation of name conflict + //FIXME: Validation of name conflict val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName); if (!genTypeBuilders.containsKey(packageName)) { val Map builders = new HashMap(); @@ -1778,14 +1839,14 @@ public class BindingGeneratorImpl implements BindingGenerator { return newType; } - /** - * Creates the name of the getter method from methodName. - * - * @param methodName - * string with the name of the getter method - * @param returnType return type - * @return string with the name of the getter method for - * methodName in JAVA method format + /** + * Creates the name of the getter method from methodName. + * + * @param methodName + * string with the name of the getter method + * @param returnType return type + * @return string with the name of the getter method for + * methodName in JAVA method format */ public static def String getterMethodName(String localName, Type returnType) { val method = new StringBuilder(); @@ -1798,26 +1859,26 @@ public class BindingGeneratorImpl implements BindingGenerator { return method.toString(); } - /** - * Created a method signature builder as part of - * interfaceBuilder. - * - * The method signature builder is created for the getter method of - * schemaNodeName. Also comment and - * returnType information are added to the builder. - * - * @param interfaceBuilder - * generated type builder for which the getter method should be - * created - * @param schemaNodeName - * string with schema node name. The name will be the part of the - * getter method name. - * @param comment - * string with comment for the getter method - * @param returnType - * type which represents the return type of the getter method - * @return method signature builder which represents the getter method of - * interfaceBuilder + /** + * Created a method signature builder as part of + * interfaceBuilder. + * + * The method signature builder is created for the getter method of + * schemaNodeName. Also comment and + * returnType information are added to the builder. + * + * @param interfaceBuilder + * generated type builder for which the getter method should be + * created + * @param schemaNodeName + * string with schema node name. The name will be the part of the + * getter method name. + * @param comment + * string with comment for the getter method + * @param returnType + * type which represents the return type of the getter method + * @return method signature builder which represents the getter method of + * interfaceBuilder */ private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName, String comment, Type returnType) { @@ -1827,28 +1888,28 @@ public class BindingGeneratorImpl implements BindingGenerator { return getMethod; } - /** - * Adds schemaNode to typeBuilder as getter method - * or to genTOBuilder as property. - * - * @param basePackageName - * string contains the module package name - * @param schemaNode - * data schema node which should be added as getter method to - * typeBuilder or as a property to - * genTOBuilder if is part of the list key - * @param typeBuilder - * generated type builder for the list schema node - * @param genTOBuilder - * generated TO builder for the list keys - * @param listKeys - * list of string which contains names of the list keys - * @param module current module - * @throws IllegalArgumentException - *
    - *
  • if schemaNode equals null
  • - *
  • if typeBuilder equals null
  • - *
+ /** + * Adds schemaNode to typeBuilder as getter method + * or to genTOBuilder as property. + * + * @param basePackageName + * string contains the module package name + * @param schemaNode + * data schema node which should be added as getter method to + * typeBuilder or as a property to + * genTOBuilder if is part of the list key + * @param typeBuilder + * generated type builder for the list schema node + * @param genTOBuilder + * generated TO builder for the list keys + * @param listKeys + * list of string which contains names of the list keys + * @param module current module + * @throws IllegalArgumentException + *
    + *
  • if schemaNode equals null
  • + *
  • if typeBuilder equals null
  • + *
*/ private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode, GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List listKeys, Module module) { @@ -1857,10 +1918,10 @@ public class BindingGeneratorImpl implements BindingGenerator { if (schemaNode instanceof LeafSchemaNode) { val leaf = schemaNode as LeafSchemaNode; - val leafName = leaf.QName.localName; + val leafName = leaf.QName.localName; resolveLeafSchemaNodeAsMethod(typeBuilder, leaf); if (listKeys.contains(leafName)) { - resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true); + resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true, module) } } else if (!schemaNode.addedByUses) { if (schemaNode instanceof LeafListSchemaNode) { @@ -1885,15 +1946,15 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * Selects the names of the list keys from list and returns - * them as the list of the strings - * - * @param list - * of string with names of the list keys - * @return list of string which represents names of the list keys. If the - * list contains no keys then the empty list is - * returned. + /** + * Selects the names of the list keys from list and returns + * them as the list of the strings + * + * @param list + * of string with names of the list keys + * @return list of string which represents names of the list keys. If the + * list contains no keys then the empty list is + * returned. */ private def listKeys(ListSchemaNode list) { val List listKeys = new ArrayList(); @@ -1907,17 +1968,17 @@ public class BindingGeneratorImpl implements BindingGenerator { return listKeys; } - /** - * Generates for the list which contains any list keys special - * generated TO builder. - * - * @param packageName - * string with package name to which the list belongs - * @param list - * list schema node which is source of data about the list name - * @return generated TO builder which represents the keys of the - * list or null if list is null or list of - * key definitions is null or empty. + /** + * Generates for the list which contains any list keys special + * generated TO builder. + * + * @param packageName + * string with package name to which the list belongs + * @param list + * list schema node which is source of data about the list name + * @return generated TO builder which represents the keys of the + * 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; @@ -1929,54 +1990,54 @@ public class BindingGeneratorImpl implements BindingGenerator { 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 - * BitsTypeDefinition} which are also added to typeBuilder as - * enclosing transfer object. - * - * If more then one generated TO builder is created for enclosing then all - * of the generated TO builders are added to typeBuilder as - * enclosing transfer objects. - * - * @param typeDef - * type definition which can be of type UnionType or - * BitsTypeDefinition - * @param typeBuilder - * generated type builder to which is added generated TO created - * from typeDef - * @param leafName - * string with name for generated TO builder - * @param leaf - * @param parentModule - * @return generated TO builder for typeDef + /** + * 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 + * BitsTypeDefinition} which are also added to typeBuilder as + * enclosing transfer object. + * + * If more then one generated TO builder is created for enclosing then all + * of the generated TO builders are added to typeBuilder as + * enclosing transfer objects. + * + * @param typeDef + * type definition which can be of type UnionType or + * BitsTypeDefinition + * @param typeBuilder + * generated type builder to which is added generated TO created + * from typeDef + * @param leafName + * string with name for generated TO builder + * @param leaf + * @param parentModule + * @return generated TO builder for typeDef */ private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition typeDef, GeneratedTypeBuilder typeBuilder, DataSchemaNode leaf, Module parentModule) { val classNameFromLeaf = BindingMapping.getClassName(leaf.QName); val List genTOBuilders = new ArrayList(); val packageName = typeBuilder.fullyQualifiedName; - if (typeDef instanceof UnionTypeDefinition) { - val List types = (typeProvider as TypeProviderImpl). - provideGeneratedTOBuildersForUnionTypeDef(packageName, (typeDef as UnionTypeDefinition), + if (typeDef instanceof UnionTypeDefinition) { + val List types = (typeProvider as TypeProviderImpl). + provideGeneratedTOBuildersForUnionTypeDef(packageName, (typeDef as UnionTypeDefinition), classNameFromLeaf, leaf); - genTOBuilders.addAll(types); - - - var GeneratedTOBuilder resultTOBuilder = null; - if (!types.isEmpty()) { - resultTOBuilder = types.remove(0); - for (GeneratedTOBuilder genTOBuilder : types) { - resultTOBuilder.addEnclosingTransferObject(genTOBuilder); - } - } - - val GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value"); - genPropBuilder.setReturnType(Types.primitiveType("char[]", null)); - resultTOBuilder.addEqualsIdentity(genPropBuilder); - resultTOBuilder.addHashIdentity(genPropBuilder); - resultTOBuilder.addToStringProperty(genPropBuilder); + genTOBuilders.addAll(types); + + + var GeneratedTOBuilder resultTOBuilder = null; + if (!types.isEmpty()) { + resultTOBuilder = types.remove(0); + for (GeneratedTOBuilder genTOBuilder : types) { + resultTOBuilder.addEnclosingTransferObject(genTOBuilder); + } + } + + val GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value"); + genPropBuilder.setReturnType(Types.primitiveType("char[]", null)); + resultTOBuilder.addEqualsIdentity(genPropBuilder); + resultTOBuilder.addHashIdentity(genPropBuilder); + resultTOBuilder.addToStringProperty(genPropBuilder); } else if (typeDef instanceof BitsTypeDefinition) { genTOBuilders.add( @@ -1993,21 +2054,21 @@ public class BindingGeneratorImpl implements BindingGenerator { } - /** - * Adds the implemented types to type builder. - * - * The method passes through the list of uses in - * {@code dataNodeContainer}. For every use is obtained corresponding - * generated type from {@link BindingGeneratorImpl#allGroupings - * allGroupings} which is added as implements type to - * builder - * - * @param dataNodeContainer - * element which contains the list of used YANG groupings - * @param builder - * builder to which are added implemented types according to - * dataNodeContainer - * @return generated type builder with all implemented types + /** + * Adds the implemented types to type builder. + * + * The method passes through the list of uses in + * {@code dataNodeContainer}. For every use is obtained corresponding + * generated type from {@link BindingGeneratorImpl#allGroupings + * allGroupings} which is added as implements type to + * builder + * + * @param dataNodeContainer + * element which contains the list of used YANG groupings + * @param builder + * builder to which are added implemented types according to + * dataNodeContainer + * @return generated type builder with all implemented types */ private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) { for (usesNode : dataNodeContainer.uses) { @@ -2052,16 +2113,16 @@ public class BindingGeneratorImpl implements BindingGenerator { } return null } - - private def Module getParentModule(SchemaNode node) { - val QName qname = node.getPath().getPath().get(0); - val URI namespace = qname.getNamespace(); - val Date revision = qname.getRevision(); - return schemaContext.findModuleByNamespaceAndRevision(namespace, revision); - } - - public def getModuleContexts() { - genCtx; - } - + + private def Module getParentModule(SchemaNode node) { + val QName qname = node.getPath().getPath().get(0); + val URI namespace = qname.getNamespace(); + val Date revision = qname.getRevision(); + return schemaContext.findModuleByNamespaceAndRevision(namespace, revision); + } + + public def getModuleContexts() { + genCtx; + } + }