From: Tomas Olvecky Date: Mon, 10 Mar 2014 12:17:05 +0000 (+0100) Subject: Add ability to get yang sources from SchemaContext. X-Git-Tag: release/helium~670 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8a22fe9a9294bf02c4c2829a547dfae02b434aea;p=yangtools.git Add ability to get yang sources from SchemaContext. SchemaContext should provide yang source code of parsed module files. To identify modules, move YANGModuleIdentifier from binding-generator-spi to yang-model-api: ModuleIdentifier. This interface can represent both modules and submodules in SchemaContext. Add methods to SchemaContext to iterate ove ModuleIdentifiers and get their source. In order to maintain backwards compatibility no new parsing method was created, so submodules cannot be supported now in new methods. Adding this functionality removes need for most methods defined in org.opendaylight.yangtools.yang.model.parser.api.YangModelParser . It is advised that after this change parser api would be refactored to have a method taking collection of input streams as input and returning SchemaContext. Other small changes: Externalize SimpleDateFormat wrapped in ThreadLocal Add toString to AbstractObjectRegistration Add guava dependency to yang-model-api for Optional goodness Add ModuleIdentifierImpl convenience class allowing users to seach source by module name. Change-Id: I8a46fa699bbd829e5d4a488ebc99012a66fc196d Signed-off-by: Tomas Olvecky --- 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 81ed99e6c1..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: - *
    - *
  • are generated from context schema nodes and
  • - *
  • are also part of some of the module in modules - * set
  • . - *
- * @throws IllegalArgumentException - *
    - *
  • if param context is null or
  • - *
  • if param modules is null
  • - *
- * @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: + *
    + *
  • are generated from context schema nodes and
  • + *
  • are also part of some of the module in modules + * set
  • . + *
+ * @throws IllegalArgumentException + *
    + *
  • if param context is null or
  • + *
  • if param modules is null
  • + *
+ * @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))); @@ -313,20 +315,20 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * 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."); @@ -343,21 +345,21 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - /** - * 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
  • - *
- * + /** + * 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,27 +711,27 @@ 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) { checkArgument(augmentPackageName !== null, "Package Name cannot be NULL."); @@ -760,7 +762,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } if (targetTypeBuilder === null) { throw new NullPointerException("Target type not yet generated: " + targetSchemaNode); - } + } if (!(targetSchemaNode instanceof ChoiceNode)) { var packageName = augmentPackageName; @@ -773,7 +775,7 @@ public class BindingGeneratorImpl implements BindingGenerator { 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."); @@ -795,7 +797,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } if (targetTypeBuilder === null) { throw new NullPointerException("Target type not yet generated: " + targetSchemaNode); - } + } if (!(targetSchemaNode instanceof ChoiceNode)) { var packageName = augmentPackageName; @@ -810,10 +812,10 @@ public class BindingGeneratorImpl implements BindingGenerator { 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); @@ -833,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 } } @@ -861,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; @@ -877,7 +879,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } } - if (result.addedByUses) { + if (result.addedByUses) { result = findCorrectTargetFromAugmentGrouping(result, augment, tmpTree); } @@ -886,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 @@ -924,17 +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); - if (parent instanceof DataNodeContainer) { - 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) { @@ -951,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)) { @@ -1004,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) { @@ -1018,12 +1020,12 @@ public class BindingGeneratorImpl implements BindingGenerator { Collections.reverse(tmpPath); tmpPath.remove(0); - for (name : tmpPath) { - // searching by local name is must, because node has different namespace in its original location - if (newParent instanceof DataNodeContainer) { - newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName); - } else { - newParent = (newParent as ChoiceNode).getCaseNodeByName(name.localName); + for (name : tmpPath) { + // searching by local name is must, because node has different namespace in its original location + if (newParent instanceof DataNodeContainer) { + newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName); + } else { + newParent = (newParent as ChoiceNode).getCaseNodeByName(name.localName); } } if (newParent != null && newParent.addedByUses) { @@ -1031,11 +1033,11 @@ public class BindingGeneratorImpl implements BindingGenerator { } return newParent; } - } + } - /** - * Convenient method to find node added by uses statement. + /** + * Convenient method to find node added by uses statement. */ private def DataSchemaNode findOriginalTargetFromGrouping(SchemaPath targetPath, UsesNode parentUsesNode) { var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, parentUsesNode.groupingPath.path); @@ -1043,11 +1045,11 @@ public class BindingGeneratorImpl implements BindingGenerator { throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode); } - var grouping = targetGrouping as GroupingDefinition; - var SchemaNode result = grouping; - val List path = targetPath.path + var grouping = targetGrouping as GroupingDefinition; + 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 + // 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) { @@ -1056,8 +1058,8 @@ public class BindingGeneratorImpl implements BindingGenerator { } if (result == null) { return null; - } - + } + val String targetSchemaNodeName = result.QName.localName; var boolean fromUses = (result as DataSchemaNode).addedByUses var Iterator groupingUses = grouping.uses.iterator; @@ -1074,25 +1076,25 @@ public class BindingGeneratorImpl implements BindingGenerator { 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) { @@ -1120,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) { @@ -1136,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; @@ -1156,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) { @@ -1191,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) { @@ -1223,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) { @@ -1256,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) { @@ -1294,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) { @@ -1339,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) { @@ -1363,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) @@ -1379,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) { @@ -1416,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) { @@ -1459,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)) { @@ -1500,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); @@ -1579,24 +1581,24 @@ 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, Module module) { @@ -1607,22 +1609,22 @@ public class BindingGeneratorImpl implements BindingGenerator { leafDesc = ""; } - if (leafName !== null) { + 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); + 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); } if (returnType !== null) { @@ -1640,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)) { @@ -1665,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); @@ -1695,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); @@ -1703,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); @@ -1721,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 { @@ -1769,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) { @@ -1822,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(); @@ -1837,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(); @@ -1857,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) { @@ -1886,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) { @@ -1916,7 +1918,7 @@ 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, module) @@ -1944,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(); @@ -1966,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; @@ -1988,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( @@ -2052,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) { @@ -2111,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; + } + } diff --git a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProviderFactory.java b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProviderFactory.java index 0091d36697..d0aa79bc9b 100644 --- a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProviderFactory.java +++ b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProviderFactory.java @@ -1,13 +1,16 @@ -/* - * 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.spi; - -public interface TypeProviderFactory { - - TypeProvider providerFor(YANGModuleIdentifier module); -} +/* + * 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.spi; + +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; + +//FIXME not implemented anywhere +public interface TypeProviderFactory { + + TypeProvider providerFor(ModuleIdentifier module); +} diff --git a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/YANGModuleIdentifier.java b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/YANGModuleIdentifier.java deleted file mode 100644 index d948cdeb90..0000000000 --- a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/YANGModuleIdentifier.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.sal.binding.generator.spi; - -import java.net.URI; -import java.util.Date; - - -public class YANGModuleIdentifier { - private String name; - private URI namespace; - private Date revision; - - /** - * Returns name. - * - * @return string with name - */ - public String getName() { - return this.name; - } - - /** - * Returns URI namespace. - * - * @return URI with namespace - */ - public URI getNamespace() { - return this.namespace; - } - - /** - * Returns the revision date. - * - * @return date of revision - */ - public Date getRevision() { - return this.revision; - } -} diff --git a/concepts/pom.xml b/concepts/pom.xml index f062b66784..7c9df45b4d 100644 --- a/concepts/pom.xml +++ b/concepts/pom.xml @@ -17,7 +17,7 @@ bundle 4.0.0 concepts - Concepts + ${project.artifactId} Java binding for YANG diff --git a/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractObjectRegistration.java b/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractObjectRegistration.java index 7c322ac3e2..8854863e55 100644 --- a/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractObjectRegistration.java +++ b/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractObjectRegistration.java @@ -24,5 +24,13 @@ public abstract class AbstractObjectRegistration extends AbstractRegistration public final T getInstance() { return instance; } + + + @Override + public String toString() { + return "AbstractObjectRegistration{" + + "instance=" + instance + + '}'; + } } diff --git a/pom.xml b/pom.xml index a661458631..37399eff88 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,8 @@ terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html --> - + 4.0.0 yangtools @@ -183,13 +184,19 @@ plexus-slf4j-logging 1.1 + + commons-io + commons-io + 2.4 + - - - ${project.groupId} - concepts - ${project.version} - + + + + ${project.groupId} + concepts + ${project.version} + @@ -249,9 +256,9 @@ ${project.groupId}.${project.artifactId} - + @@ -301,7 +308,7 @@ - + diff --git a/restconf/pom.xml b/restconf/pom.xml index c22dd7ca01..be73c40916 100644 --- a/restconf/pom.xml +++ b/restconf/pom.xml @@ -104,11 +104,6 @@ concepts ${project.version} - - org.apache.commons - commons-io - 1.3.2 - org.glassfish.jersey.ext jersey-proxy-client @@ -131,11 +126,6 @@ 1.1.1 - - commons-io - commons-io - 2.4 - org.opendaylight.yangtools yang-model-util diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java index 379c1f7cdb..00aaccc1ff 100644 --- a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java +++ b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java @@ -7,19 +7,20 @@ */ package org.opendaylight.yangtools.yang.common; +import org.opendaylight.yangtools.concepts.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.opendaylight.yangtools.concepts.Immutable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat; /** * The QName from XML consists of local name of element and XML namespace, but @@ -47,17 +48,7 @@ public final class QName implements Immutable,Serializable { protected static final Logger LOGGER = LoggerFactory.getLogger(QName.class); - private static final ThreadLocal REVISION_FORMAT = new ThreadLocal() { - - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd"); - }; - - public void set(SimpleDateFormat value) { - throw new UnsupportedOperationException(); - }; - }; static final String QNAME_REVISION_DELIMITER = "?revision="; static final String QNAME_LEFT_PARENTHESIS = "("; static final String QNAME_RIGHT_PARENTHESIS = ")"; @@ -92,7 +83,7 @@ public final class QName implements Immutable,Serializable { this.revision = revision; this.prefix = prefix; if(revision != null) { - this.formattedRevision = REVISION_FORMAT.get().format(revision); + this.formattedRevision = getRevisionFormat().format(revision); } else { this.formattedRevision = null; } @@ -157,7 +148,7 @@ public final class QName implements Immutable,Serializable { if (nsAndRev.contains("?")) { String[] splitted = nsAndRev.split("\\?"); this.namespace = URI.create(splitted[0]); - revision = REVISION_FORMAT.get().parse(splitted[1]); + revision = getRevisionFormat().parse(splitted[1]); } else { this.namespace = URI.create(nsAndRev); } @@ -166,7 +157,7 @@ public final class QName implements Immutable,Serializable { this.revision = revision; this.prefix = null; if (revision != null) { - this.formattedRevision = REVISION_FORMAT.get().format(revision); + this.formattedRevision = getRevisionFormat().format(revision); } else { this.formattedRevision = null; } @@ -315,7 +306,7 @@ public final class QName implements Immutable,Serializable { sb.append(QNAME_LEFT_PARENTHESIS + namespace); if (revision != null) { - sb.append(QNAME_REVISION_DELIMITER + REVISION_FORMAT.get().format(revision)); + sb.append(QNAME_REVISION_DELIMITER + getRevisionFormat().format(revision)); } sb.append(QNAME_RIGHT_PARENTHESIS); } @@ -365,7 +356,7 @@ public final class QName implements Immutable,Serializable { public static Date parseRevision(String formatedDate) { try { - return REVISION_FORMAT.get().parse(formatedDate); + return getRevisionFormat().parse(formatedDate); } catch (ParseException| RuntimeException e) { throw new IllegalArgumentException("Revision is not in supported format:" + formatedDate,e); } @@ -375,7 +366,7 @@ public final class QName implements Immutable,Serializable { if(revision == null) { return null; } - return REVISION_FORMAT.get().format(revision); + return getRevisionFormat().format(revision); } public boolean isEqualWithoutRevision(QName other) { diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java new file mode 100644 index 0000000000..fd50c95ab8 --- /dev/null +++ b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/SimpleDateFormatUtil.java @@ -0,0 +1,30 @@ +/* + * 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.common; + +import java.text.SimpleDateFormat; + +public class SimpleDateFormatUtil { + + private static final ThreadLocal REVISION_FORMAT = new ThreadLocal() { + + protected SimpleDateFormat initialValue() { + return new SimpleDateFormat("yyyy-MM-dd"); + }; + + public void set(SimpleDateFormat value) { + throw new UnsupportedOperationException(); + }; + + }; + + public static SimpleDateFormat getRevisionFormat() { + return REVISION_FORMAT.get(); + } +} diff --git a/yang/yang-maven-plugin/pom.xml b/yang/yang-maven-plugin/pom.xml index c66c21a80a..8ffa8204c2 100644 --- a/yang/yang-maven-plugin/pom.xml +++ b/yang/yang-maven-plugin/pom.xml @@ -73,7 +73,6 @@ commons-io commons-io - 2.4 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 9efe633ffa..fa0fa27e41 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 @@ -7,18 +7,8 @@ */ package org.opendaylight.yangtools.yang2sources.plugin; -import java.io.Closeable; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.Maps; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -36,8 +26,19 @@ import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator; import org.sonatype.plexus.build.incremental.BuildContext; import org.sonatype.plexus.build.incremental.DefaultBuildContext; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; class YangToSourcesProcessor { static final String LOG_PREFIX = "yang-to-sources:"; @@ -148,7 +149,8 @@ class YangToSourcesProcessor { projectYangModules = new HashSet<>(); for (InputStream inProject : yangsInProject) { - projectYangModules.add(allYangModules.get(inProject)); + Module module = checkNotNull(allYangModules.get(inProject), "Cannot find module by %s", inProject); + projectYangModules.add(module); } } finally { diff --git a/yang/yang-model-api/pom.xml b/yang/yang-model-api/pom.xml index 8b9915e209..8f16814a37 100644 --- a/yang/yang-model-api/pom.xml +++ b/yang/yang-model-api/pom.xml @@ -25,5 +25,9 @@ ${project.groupId} yang-common + + com.google.guava + guava + diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java index d6c4966c70..16fda82ed4 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java @@ -7,8 +7,6 @@ */ package org.opendaylight.yangtools.yang.model.api; -import java.net.URI; -import java.util.Date; import java.util.List; import java.util.Set; @@ -57,33 +55,8 @@ import java.util.Set; */ -public interface Module extends DataNodeContainer, SourceStreamAware { +public interface Module extends DataNodeContainer, SourceStreamAware, ModuleIdentifier { - /** - * Returns the namespace of the module which is specified as argument of - * YANG {@link Module namespace} - * keyword. - * - * @return URI format of the namespace of the module - */ - URI getNamespace(); - - /** - * Returns the name of the module which is specified as argument of YANG - * {@link Module module} keyword - * - * @return string with the name of the module - */ - String getName(); - - /** - * Returns the revision date for the module. - * - * @return date of the module revision which is specified as argument of - * YANG {@link Module revison} - * keyword - */ - Date getRevision(); /** * Returns the prefix of the module diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java new file mode 100644 index 0000000000..a1e8b433c0 --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java @@ -0,0 +1,42 @@ +/* + * 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.net.URI; +import java.util.Date; + + +public interface ModuleIdentifier { + + /** + * Returns the namespace of the module which is specified as argument of + * YANG {@link Module namespace} + * keyword. + * + * @return URI format of the namespace of the module + */ + URI getNamespace(); + + /** + * Returns the name of the module which is specified as argument of YANG + * {@link Module module} keyword + * + * @return string with the name of the module + */ + String getName(); + + /** + * Returns the revision date for the module. + * + * @return date of the module revision which is specified as argument of + * YANG {@link Module revison} + * keyword + */ + Date getRevision(); +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java index e51e468432..ecafe233a4 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java @@ -7,12 +7,13 @@ */ package org.opendaylight.yangtools.yang.model.api; +import com.google.common.base.Optional; +import org.opendaylight.yangtools.yang.common.QName; + import java.net.URI; import java.util.Date; import java.util.Set; -import org.opendaylight.yangtools.yang.common.QName; - /** * The interface contains the methods for manipulating all the top level context * data (data from all red modules) like YANG notifications, extensions, @@ -104,4 +105,20 @@ public interface SchemaContext extends ContainerSchemaNode { */ Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision); + + /** + * Get yang source code represented as string for matching + * {@link org.opendaylight.yangtools.yang.model.api.ModuleIdentifier}. + * @param moduleIdentifier must provide a non-null + * {@link org.opendaylight.yangtools.yang.model.api.ModuleIdentifier#getName()}, + * other methods might return null. + * @return value iif matching module is found in schema context. + */ + Optional getModuleSource(ModuleIdentifier moduleIdentifier); + + /** + * Get all module and submodule identifiers. + */ + Set getAllModuleIdentifiers(); + } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SourceStreamAware.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SourceStreamAware.java index 4ed6617eeb..a05a3a15c4 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SourceStreamAware.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SourceStreamAware.java @@ -7,8 +7,12 @@ */ package org.opendaylight.yangtools.yang.model.api; +// TODO: merge into Module, makes no sense as standalone interface public interface SourceStreamAware { + /** + * Get descriptive source path (usually file path) from which this module was parsed. + */ String getModuleSourcePath(); } 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 0ab1a29f30..02d488d420 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 @@ -7,21 +7,22 @@ */ package org.opendaylight.yangtools.yang.model.parser.api; +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; + import java.io.File; import java.io.InputStream; import java.util.List; import java.util.Map; 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. * */ +// refactor methods returning input streams, after introducing public interface YangModelParser { /** @@ -107,6 +108,8 @@ public interface YangModelParser { * yang streams to parse * @return Map of Yang Modules */ + //TODO: when working with input streams do not swallow IOException, it should be propagated without having to wrap it in a runtime exception + //FIXME: it is not defined in which state are the returning streams. Map parseYangModelsFromStreamsMapped(final List yangModelStreams); /** diff --git a/yang/yang-parser-impl/pom.xml b/yang/yang-parser-impl/pom.xml index fae3b6ebd2..0231aa80c6 100644 --- a/yang/yang-parser-impl/pom.xml +++ b/yang/yang-parser-impl/pom.xml @@ -64,6 +64,10 @@ ${project.groupId} concepts + + commons-io + commons-io + diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java index e21e9f0483..4350692632 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java @@ -7,17 +7,48 @@ */ package org.opendaylight.yangtools.yang.parser.builder.impl; -import java.net.URI; -import java.util.*; - import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.*; -import org.opendaylight.yangtools.yang.parser.builder.api.*; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Deviation; +import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; +import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; +import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; +import org.opendaylight.yangtools.yang.model.api.RpcDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +import org.opendaylight.yangtools.yang.model.api.UsesNode; +import org.opendaylight.yangtools.yang.parser.builder.api.AbstractDataNodeContainerBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.Builder; +import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; import org.opendaylight.yangtools.yang.parser.util.Comparators; import org.opendaylight.yangtools.yang.parser.util.ModuleImportImpl; import org.opendaylight.yangtools.yang.parser.util.RefineHolder; import org.opendaylight.yangtools.yang.parser.util.YangParseException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Deque; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + /** * Builder of Module object. If this module is dependent on external * module/modules, these dependencies must be resolved before module is built, @@ -80,6 +111,8 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { private final List allLists = new ArrayList(); + private String source; + public ModuleBuilder(final String name, final String sourcePath) { this(name, false, sourcePath); } @@ -207,6 +240,8 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP); instance.setUnknownSchemaNodes(unknownNodes); + instance.setSource(source); + return instance; } @@ -885,7 +920,11 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return "module " + name; } - private static final class ModuleImpl implements Module { + public void setSource(String source) { + this.source = source; + } + + public static final class ModuleImpl implements Module { private URI namespace; private final String name; private final String sourcePath; @@ -909,6 +948,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { private final List extensionNodes = new ArrayList<>(); private final Set identities = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); private final List unknownNodes = new ArrayList<>(); + private String source; private ModuleImpl(String name, String sourcePath) { this.name = name; @@ -1151,6 +1191,15 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return getChildNode(childNodes, name); } + void setSource(String source){ + this.source = source; + } + + public String getSource() { + return source; + } + + // FIXME: prefix should not be taken into consideration, perhaps namespace too @Override public int hashCode() { final int prime = 31; @@ -1402,4 +1451,5 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return true; } + } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java new file mode 100644 index 0000000000..02f6abb780 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java @@ -0,0 +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.parser.builder.impl; + +import com.google.common.base.Optional; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; + +import java.net.URI; +import java.util.Date; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * ModuleIdentifier that can be used for indexing/searching by name. + * Name is only non-null attribute. + * Equality check on namespace and revision is only triggered if they are non-null + */ +public class ModuleIdentifierImpl implements ModuleIdentifier { + private final String name; + private final Optional namespace; + private final Optional revision; + + public ModuleIdentifierImpl(String name, Optional namespace, Optional revision) { + this.name = checkNotNull(name); + this.namespace = checkNotNull(namespace); + this.revision = checkNotNull(revision); + } + + @Override + public Date getRevision() { + return revision.orNull(); + } + + @Override + public String getName() { + return name; + } + + @Override + public URI getNamespace() { + return namespace.orNull(); + } + + @Override + public String toString() { + return "ModuleIdentifierImpl{" + + "name='" + name + '\'' + + ", namespace=" + namespace + + ", revision=" + revision + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || (o instanceof ModuleIdentifier == false)) { + return false; + } + + ModuleIdentifier that = (ModuleIdentifier) o; + + if (!name.equals(that.getName())) { + return false; + } + // only fail if this namespace is non-null + if (namespace.isPresent() && namespace.get().equals(that.getNamespace()) == false) { + return false; + } + // only fail if this revision is non-null + if (revision.isPresent() && revision.get().equals(that.getRevision()) == false) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return name.hashCode(); + } +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java index 73b2cb637e..6f81e7adaf 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java @@ -7,16 +7,7 @@ */ package org.opendaylight.yangtools.yang.parser.impl; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeMap; - +import com.google.common.base.Optional; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; @@ -24,6 +15,7 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -34,11 +26,24 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + final class SchemaContextImpl implements SchemaContext { private final Set modules; + private final Map identifiersToSources; - SchemaContextImpl(final Set modules) { + SchemaContextImpl(final Set modules, Map identifiersToSources) { this.modules = modules; + this.identifiersToSources = identifiersToSources; } @Override @@ -257,4 +262,15 @@ final class SchemaContextImpl implements SchemaContext { return Collections.emptySet(); } + //FIXME: should work for submodules too + @Override + public Set getAllModuleIdentifiers() { + return identifiersToSources.keySet(); + } + + @Override + public Optional getModuleSource(ModuleIdentifier moduleIdentifier) { + String maybeSource = identifiersToSources.get(moduleIdentifier); + return Optional.fromNullable(maybeSource); + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java index 591d5c4f5c..fe57b76dab 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java @@ -7,29 +7,27 @@ */ package org.opendaylight.yangtools.yang.parser.impl; -import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.*; -import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveType; -import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeUnion; -import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeUnionWithContext; -import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeWithContext; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.*; - +import com.google.common.base.Preconditions; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeWalker; +import org.apache.commons.io.IOUtils; import org.opendaylight.yangtools.antlrv4.code.gen.YangLexer; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.YangContext; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.*; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; +import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.yangtools.yang.parser.builder.api.Builder; @@ -40,19 +38,66 @@ import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder; import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.*; +import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.DeviationBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.ExtensionBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder.ModuleImpl; +import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder; import org.opendaylight.yangtools.yang.parser.util.Comparators; import org.opendaylight.yangtools.yang.parser.util.GroupingSort; import org.opendaylight.yangtools.yang.parser.util.GroupingUtils; import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.opendaylight.yangtools.yang.parser.util.NamedByteArrayInputStream; +import org.opendaylight.yangtools.yang.parser.util.NamedInputStream; import org.opendaylight.yangtools.yang.parser.util.ParserUtils; import org.opendaylight.yangtools.yang.parser.util.YangParseException; import org.opendaylight.yangtools.yang.validator.YangModelBasicValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.fillAugmentTarget; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findBaseIdentity; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findBaseIdentityFromContext; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromBuilders; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findModuleFromContext; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findSchemaNode; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.findSchemaNodeInModule; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.processAugmentation; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.setNodeAddedByUses; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.wrapChildNode; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.wrapChildNodes; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.wrapGroupings; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.wrapTypedefs; +import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.wrapUnknownNodes; +import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveType; +import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeUnion; +import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeUnionWithContext; +import static org.opendaylight.yangtools.yang.parser.util.TypeUtils.resolveTypeWithContext; public final class YangParserImpl implements YangModelParser { @@ -68,7 +113,7 @@ public final class YangParserImpl implements YangModelParser { final String yangFileName = yangFile.getName(); final String[] fileList = directory.list(); - Preconditions.checkNotNull(fileList, directory + " not found"); + checkNotNull(fileList, directory + " not found"); FileInputStream yangFileStream = null; LinkedHashMap streamToFileMap = new LinkedHashMap<>(); @@ -221,30 +266,84 @@ public final class YangParserImpl implements YangModelParser { return result; } + // TODO: fix exception handling @Override public Map parseYangModelsFromStreamsMapped(final List yangModelStreams) { if (yangModelStreams == null) { return Collections.emptyMap(); } - Map builderToStreamMap = new HashMap<>(); - Map> modules = resolveModuleBuilders(yangModelStreams, builderToStreamMap, + + // copy input streams so that they can be read more than once + Map arrayBackedToOriginalInputStreams = new HashMap<>(); + for (final InputStream originalIS : yangModelStreams) { + InputStream arrayBackedIs; + try { + arrayBackedIs = NamedByteArrayInputStream.create(originalIS); + } catch (IOException e) { + // FIXME: throw IOException here + throw new IllegalStateException("Can not get yang as String from " + originalIS, e); + } + arrayBackedToOriginalInputStreams.put(arrayBackedIs, originalIS); + } + + // it would be better if all code from here used string representation of yang sources instead of input streams + Map builderToStreamMap = new HashMap<>(); // FIXME: do not modify input parameter + Map> modules = resolveModuleBuilders(new ArrayList<>(arrayBackedToOriginalInputStreams.keySet()), + builderToStreamMap, null); - Map result = new LinkedHashMap<>(); + + + // TODO move deeper + for(TreeMap value : modules.values()) { + Collection values = value.values(); + for(ModuleBuilder builder: values) { + InputStream is = builderToStreamMap.get(builder); + try { + is.reset(); + } catch (IOException e) { + // this cannot happen because it is ByteArrayInputStream + throw new IllegalStateException("Possible error in code", e); + } + String content; + try { + content = IOUtils.toString(is); + } catch (IOException e) { + // this cannot happen because it is ByteArrayInputStream + throw new IllegalStateException("Possible error in code", e); + } + builder.setSource(content); + } + } + + Map builderToModuleMap = build(modules); + Set keyset = builderToModuleMap.keySet(); List sorted = ModuleDependencySort.sort(keyset.toArray(new ModuleBuilder[keyset.size()])); + Map result = new LinkedHashMap<>(); for (ModuleBuilder key : sorted) { - result.put(builderToStreamMap.get(key), builderToModuleMap.get(key)); + Module value = checkNotNull(builderToModuleMap.get(key), "Cannot get module for %s", key); + InputStream arrayBackedIS = checkNotNull(builderToStreamMap.get(key), "Cannot get is for %s", key); + InputStream originalIS = arrayBackedToOriginalInputStreams.get(arrayBackedIS); + result.put(originalIS, value); } return result; } @Override public SchemaContext resolveSchemaContext(final Set modules) { - return new SchemaContextImpl(modules); + // after merging parse method with this one, add support for getting submodule sources. + Map identifiersToSources = new HashMap<>(); + for(Module module: modules) { + ModuleImpl moduleImpl = (ModuleImpl) module; + identifiersToSources.put(module, moduleImpl.getSource()); + } + return new SchemaContextImpl(modules, identifiersToSources); } + // FIXME: why a list is required? + // FIXME: streamToBuilderMap is output of this method, not input private Map parseModuleBuilders(List inputStreams, Map streamToBuilderMap) { Map modules = parseBuilders(inputStreams, streamToBuilderMap); @@ -252,6 +351,8 @@ public final class YangParserImpl implements YangModelParser { return result; } + // FIXME: why a list is required? + // FIXME: streamToBuilderMap is output of this method, not input private Map parseBuilders(List inputStreams, Map streamToBuilderMap) { final ParseTreeWalker walker = new ParseTreeWalker(); @@ -265,15 +366,15 @@ public final class YangParserImpl implements YangModelParser { for (Map.Entry entry : trees.entrySet()) { InputStream is = entry.getKey(); String path = null; - if (is instanceof NamedFileInputStream) { - NamedFileInputStream nis = (NamedFileInputStream)is; - path = nis.getFileDestination(); + if (is instanceof NamedInputStream) { + path = is.toString(); } yangModelParser = new YangParserListenerImpl(path); walker.walk(yangModelParser, entry.getValue()); ModuleBuilder moduleBuilder = yangModelParser.getModuleBuilder(); // We expect the order of trees and streams has to be the same + // FIXME: input parameters should be treated as immutable streamToBuilderMap.put(moduleBuilder, entry.getKey()); builders.put(entry.getKey(), moduleBuilder); @@ -359,6 +460,8 @@ public final class YangParserImpl implements YangModelParser { module.getAllUnknownNodes().addAll(submodule.getAllUnknownNodes()); } + // FIXME: why a list is required? + // FIXME: streamToBuilderMap is output of this method, not input private Map> resolveModuleBuilders(final List yangFileStreams, final Map streamToBuilderMap, final SchemaContext context) { Map parsedBuilders = parseModuleBuilders(yangFileStreams, streamToBuilderMap); @@ -440,6 +543,7 @@ public final class YangParserImpl implements YangModelParser { } } + // FIXME: why a list is required? private Map parseStreams(final List yangStreams) { final Map trees = new HashMap<>(); for (InputStream yangStream : yangStreams) { @@ -461,6 +565,7 @@ public final class YangParserImpl implements YangModelParser { result = parser.yang(); errorListener.validate(); } catch (IOException e) { + // TODO: fix this ASAP LOG.warn("Exception while reading yang file: " + yangStream, e); } return result; diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedByteArrayInputStream.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedByteArrayInputStream.java new file mode 100644 index 0000000000..fd5bd9d2d8 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedByteArrayInputStream.java @@ -0,0 +1,37 @@ +/* + * 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.parser.util; + +import org.apache.commons.io.IOUtils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NamedByteArrayInputStream extends ByteArrayInputStream implements NamedInputStream { + private final String toString; + private NamedByteArrayInputStream(byte[] buf, String toString) { + super(buf); + this.toString = toString; + } + + public static ByteArrayInputStream create(InputStream originalIS) throws IOException { + String content = IOUtils.toString(originalIS); + if (originalIS instanceof NamedInputStream) { + return new NamedByteArrayInputStream(content.getBytes(), originalIS.toString()); + } else { + return new ByteArrayInputStream(content.getBytes()); + } + } + + @Override + public String toString() { + return toString; + } +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedFileInputStream.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedFileInputStream.java index c2d1d24d21..e78db8e271 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedFileInputStream.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedFileInputStream.java @@ -11,7 +11,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -public class NamedFileInputStream extends FileInputStream { +public class NamedFileInputStream extends FileInputStream implements NamedInputStream { private final String fileDestination; public NamedFileInputStream(File file, String fileDestination) throws FileNotFoundException { @@ -23,4 +23,8 @@ public class NamedFileInputStream extends FileInputStream { return fileDestination; } + @Override + public String toString() { + return fileDestination; + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedInputStream.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedInputStream.java new file mode 100644 index 0000000000..4f56d947d2 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/NamedInputStream.java @@ -0,0 +1,17 @@ +/* + * 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.parser.util; + +public interface NamedInputStream { + + /** + * @return name of resource from which this input stream is derived, typically file path. + */ + String toString(); +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java index 0d2f1dffc9..9002afdcd2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java @@ -7,7 +7,43 @@ */ package org.opendaylight.yangtools.yang.parser.impl; -import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; +import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; +import org.opendaylight.yangtools.yang.model.api.ChoiceNode; +import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Deviation; +import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate; +import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; +import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; +import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; +import org.opendaylight.yangtools.yang.model.api.RpcDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.Status; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; +import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; +import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; +import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; +import org.opendaylight.yangtools.yang.model.util.Decimal64; +import org.opendaylight.yangtools.yang.model.util.ExtendedType; +import org.opendaylight.yangtools.yang.model.util.Int16; +import org.opendaylight.yangtools.yang.model.util.Int32; +import org.opendaylight.yangtools.yang.model.util.StringType; +import org.opendaylight.yangtools.yang.model.util.Uint32; +import org.opendaylight.yangtools.yang.model.util.UnionType; import java.io.File; import java.io.FileInputStream; @@ -20,6 +56,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.LinkedHashSet; @@ -27,22 +64,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.*; -import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate; -import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; -import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser; -import org.opendaylight.yangtools.yang.model.util.Decimal64; -import org.opendaylight.yangtools.yang.model.util.ExtendedType; -import org.opendaylight.yangtools.yang.model.util.Int16; -import org.opendaylight.yangtools.yang.model.util.Int32; -import org.opendaylight.yangtools.yang.model.util.StringType; -import org.opendaylight.yangtools.yang.model.util.Uint32; -import org.opendaylight.yangtools.yang.model.util.UnionType; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; public class YangParserTest { public static final String FS = File.separator; @@ -826,7 +853,7 @@ public class YangParserTest { File dependenciesDir = new File(getClass().getResource("/sorting-test").toURI()); YangModelParser parser = new YangParserImpl(); modules = parser.parseYangModels(yangFile, dependenciesDir); - SchemaContext ctx = new SchemaContextImpl(modules); + SchemaContext ctx = new SchemaContextImpl(modules, Collections.emptyMap()); checkOrder(modules); assertSetEquals(modules, ctx.getModules()); @@ -843,12 +870,12 @@ public class YangParserTest { } Set newModules = parser.parseYangModels(testFiles); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); // ########## newModules = parser.parseYangModels(testFiles, null); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); // ########## List streams = new ArrayList<>(); @@ -857,7 +884,7 @@ public class YangParserTest { } newModules = parser.parseYangModelsFromStreams(streams); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); // ########## streams.clear(); @@ -866,13 +893,13 @@ public class YangParserTest { } newModules = parser.parseYangModelsFromStreams(streams, null); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); // ########## Map mapped = parser.parseYangModelsMapped(testFiles); newModules = new LinkedHashSet<>(mapped.values()); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); // ########## streams.clear(); @@ -882,7 +909,7 @@ public class YangParserTest { Map mappedStreams = parser.parseYangModelsFromStreamsMapped(streams); newModules = new LinkedHashSet<>(mappedStreams.values()); assertSetEquals(newModules, modules); - ctx = new SchemaContextImpl(newModules); + ctx = new SchemaContextImpl(newModules, Collections.emptyMap()); assertSetEquals(newModules, ctx.getModules()); }