2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.sal.binding.generator.impl;
10 import static com.google.common.base.Preconditions.*;
11 import static extension org.opendaylight.yangtools.binding.generator.util.Types.*;
12 import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*;
13 import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*;
14 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*;
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.List;
22 import java.util.Iterator
23 import java.util.Collection
24 import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
25 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
26 import org.opendaylight.yangtools.binding.generator.util.Types;
27 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
28 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
29 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
30 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
31 import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
32 import org.opendaylight.yangtools.sal.binding.model.api.Type;
33 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.EnumBuilder;
34 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
35 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
36 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
37 import org.opendaylight.yangtools.sal.binding.yang.types.GroupingDefinitionDependencySort;
38 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
39 import org.opendaylight.yangtools.yang.binding.RpcService;
40 import org.opendaylight.yangtools.yang.common.RpcResult;
41 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
42 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
43 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
44 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
45 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
46 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
47 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
48 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
50 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
51 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
52 import org.opendaylight.yangtools.yang.model.api.Module;
53 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
54 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
55 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
56 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
57 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
58 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
59 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
60 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
61 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
62 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
63 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
64 import org.opendaylight.yangtools.yang.model.util.UnionType;
65 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort
66 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
67 import org.opendaylight.yangtools.yang.model.api.UsesNode
68 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext
69 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder
70 import org.opendaylight.yangtools.yang.model.api.ModuleImport
71 import org.opendaylight.yangtools.yang.binding.DataContainer
72 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
73 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
74 import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
75 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder
76 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl
77 import org.opendaylight.yangtools.yang.common.QName
78 import org.opendaylight.yangtools.yang.binding.BindingMapping
79 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilderBase
81 import com.google.common.collect.Sets
83 public class BindingGeneratorImpl implements BindingGenerator {
85 private final Map<Module, ModuleContext> genCtx = new HashMap()
88 * Outer key represents the package name. Outer value represents map of
89 * all builders in the same package. Inner key represents the schema node
90 * name (in JAVA class/interface name format). Inner value represents
91 * instance of builder for schema node specified in key part.
93 private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
96 * Provide methods for converting YANG types to JAVA types.
98 private var TypeProvider typeProvider;
101 * Holds reference to schema context to resolve data of augmented element
102 * when creating augmentation builder
104 private var SchemaContext schemaContext;
107 * Constant with the concrete name of namespace.
109 private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
112 * Constant with the concrete name of identifier.
114 private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier";
117 * Resolves generated types from <code>context</code> schema nodes of all
120 * Generated types are created for modules, groupings, types, containers,
121 * lists, choices, augments, rpcs, notification, identities.
124 * schema context which contains data about all schema nodes
126 * @return list of types (usually <code>GeneratedType</code>
127 * <code>GeneratedTransferObject</code>which are generated from
128 * <code>context</code> data.
129 * @throws IllegalArgumentException
130 * if param <code>context</code> is null
131 * @throws IllegalStateException
132 * if <code>context</code> contain no modules
134 override generateTypes(SchemaContext context) {
135 checkArgument(context !== null, "Schema Context reference cannot be NULL.");
136 checkState(context.modules !== null, "Schema Context does not contain defined modules.");
137 schemaContext = context;
138 typeProvider = new TypeProviderImpl(context);
139 val Set<Module> modules = context.modules;
140 return generateTypes(context, modules);
144 * Resolves generated types from <code>context</code> schema nodes only for
145 * modules specified in <code>modules</code>
147 * Generated types are created for modules, groupings, types, containers,
148 * lists, choices, augments, rpcs, notification, identities.
151 * schema context which contains data about all schema nodes
154 * set of modules for which schema nodes should be generated
156 * @return list of types (usually <code>GeneratedType</code> or
157 * <code>GeneratedTransferObject</code>) which:
159 * <li>are generated from <code>context</code> schema nodes and</li>
160 * <li>are also part of some of the module in <code>modules</code>
163 * @throws IllegalArgumentException
165 * <li>if param <code>context</code> is null or</li>
166 * <li>if param <code>modules</code> is null</li>
168 * @throws IllegalStateException
169 * if <code>context</code> contain no modules
171 override generateTypes(SchemaContext context, Set<Module> modules) {
172 checkArgument(context !== null, "Schema Context reference cannot be NULL.");
173 checkState(context.modules !== null, "Schema Context does not contain defined modules.");
174 checkArgument(modules !== null, "Set of Modules cannot be NULL.");
176 schemaContext = context;
177 typeProvider = new TypeProviderImpl(context);
178 val contextModules = ModuleDependencySort.sort(context.modules);
179 genTypeBuilders = new HashMap();
181 for (contextModule : contextModules) {
182 moduleToGenTypes(contextModule, context);
184 for (contextModule : contextModules) {
185 allAugmentsToGenTypes(contextModule);
188 val List<Type> filteredGenTypes = new ArrayList();
189 for (Module m : modules) {
190 val ctx = checkNotNull(genCtx.get(m), "Module context not found for module %s", m)
191 filteredGenTypes.addAll(ctx.generatedTypes);
192 val Set<Type> additionalTypes = (typeProvider as TypeProviderImpl).additionalTypes.get(m)
193 if (additionalTypes != null) {
194 filteredGenTypes.addAll(additionalTypes)
198 return filteredGenTypes;
201 private def void moduleToGenTypes(Module m, SchemaContext context) {
202 genCtx.put(m, new ModuleContext)
203 allTypeDefinitionsToGenTypes(m)
204 groupingsToGenTypes(m, m.groupings)
205 rpcMethodsToGenType(m)
206 allIdentitiesToGenTypes(m, context)
207 notificationsToGenType(m)
209 if (!m.childNodes.isEmpty()) {
210 val moduleType = moduleToDataType(m)
211 genCtx.get(m).addModuleNode(moduleType)
212 val basePackageName = moduleNamespaceToPackageName(m);
213 resolveDataSchemaNodes(m, basePackageName, moduleType, moduleType, m.childNodes)
218 * Converts all extended type definitions of module to the list of
219 * <code>Type</code> objects.
222 * module from which is obtained set of type definitions
223 * @throws IllegalArgumentException
225 * <li>if module equals null</li>
226 * <li>if name of module equals null</li>
227 * <li>if type definitions of module equal null</li>
231 private def void allTypeDefinitionsToGenTypes(Module module) {
232 checkArgument(module !== null, "Module reference cannot be NULL.");
233 checkArgument(module.name !== null, "Module name cannot be NULL.");
234 val it = new DataNodeIterator(module);
235 val List<TypeDefinition<?>> typeDefinitions = it.allTypedefs;
236 checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.''');
238 for (TypeDefinition<?> typedef : typeDefinitions) {
239 if (typedef !== null) {
240 val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef);
242 genCtx.get(module).addTypedefType(typedef.path, type)
248 private def GeneratedTypeBuilder processDataSchemaNode(Module module, String basePackageName,
249 GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, DataSchemaNode node) {
250 if (node.augmenting || node.addedByUses) {
253 val packageName = packageNameForGeneratedType(basePackageName, node.path)
254 val genType = addDefaultInterfaceDefinition(packageName, node, childOf)
255 if (node instanceof DataNodeContainer) {
256 genCtx.get(module).addChildNodeType(node.path, genType)
257 groupingsToGenTypes(module, (node as DataNodeContainer).groupings)
258 processUsesAugments(node as DataNodeContainer, module)
263 private def void containerToGenType(Module module, String basePackageName, GeneratedTypeBuilder parent,
264 GeneratedTypeBuilder childOf, ContainerSchemaNode node) {
265 val genType = processDataSchemaNode(module, basePackageName, parent, childOf, node)
266 if (genType != null) {
267 constructGetter(parent, node.QName.localName, node.description, genType)
268 resolveDataSchemaNodes(module, basePackageName, genType, genType, node.childNodes)
272 private def void listToGenType(Module module, String basePackageName, GeneratedTypeBuilder parent,
273 GeneratedTypeBuilder childOf, ListSchemaNode node) {
274 val genType = processDataSchemaNode(module, basePackageName, parent, childOf, node)
275 if (genType != null) {
276 constructGetter(parent, node.QName.localName, node.description, Types.listTypeFor(genType))
278 val List<String> listKeys = listKeys(node);
279 val packageName = packageNameForGeneratedType(basePackageName, (node).path)
280 val genTOBuilder = resolveListKeyTOBuilder(packageName, node);
281 if (genTOBuilder !== null) {
282 val identifierMarker = IDENTIFIER.parameterizedTypeFor(genType);
283 val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder);
284 genTOBuilder.addImplementsType(identifierMarker);
285 genType.addImplementsType(identifiableMarker);
288 for (schemaNode : node.childNodes) {
289 if (!schemaNode.augmenting) {
290 addSchemaNodeToListBuilders(basePackageName, schemaNode, genType, genTOBuilder, listKeys, module);
295 if (genTOBuilder !== null) {
296 val GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
297 prop.setValue(Long.toString(computeDefaultSUID(genTOBuilder as GeneratedTOBuilderImpl)));
298 genTOBuilder.setSUID(prop);
301 typeBuildersToGenTypes(module, genType, genTOBuilder);
305 private def void processUsesAugments(DataNodeContainer node, Module module) {
306 val basePackageName = moduleNamespaceToPackageName(module);
307 for (usesNode : node.uses) {
308 for (augment : usesNode.augmentations) {
309 usesAugmentationToGenTypes(basePackageName, augment, module, usesNode, node);
310 processUsesAugments(augment, module);
316 * Converts all <b>augmentation</b> of the module to the list
317 * <code>Type</code> objects.
320 * module from which is obtained list of all augmentation objects
321 * to iterate over them
322 * @throws IllegalArgumentException
324 * <li>if the module equals null</li>
325 * <li>if the name of module equals null</li>
326 * <li>if the set of child nodes equals null</li>
330 private def void allAugmentsToGenTypes(Module module) {
331 checkArgument(module !== null, "Module reference cannot be NULL.");
332 checkArgument(module.name !== null, "Module name cannot be NULL.");
333 if (module.childNodes === null) {
334 throw new IllegalArgumentException(
335 "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL.");
338 val basePackageName = moduleNamespaceToPackageName(module);
339 val List<AugmentationSchema> augmentations = resolveAugmentations(module);
340 for (augment : augmentations) {
341 augmentationToGenTypes(basePackageName, augment, module);
346 * Returns list of <code>AugmentationSchema</code> objects. The objects are
347 * sorted according to the length of their target path from the shortest to
351 * module from which is obtained list of all augmentation objects
352 * @return list of sorted <code>AugmentationSchema</code> objects obtained
353 * from <code>module</code>
354 * @throws IllegalArgumentException
356 * <li>if the module equals null</li>
357 * <li>if the set of augmentation equals null</li>
361 private def List<AugmentationSchema> resolveAugmentations(Module module) {
362 checkArgument(module !== null, "Module reference cannot be NULL.");
363 checkState(module.augmentations !== null, "Augmentations Set cannot be NULL.");
365 val Set<AugmentationSchema> augmentations = module.augmentations;
366 val List<AugmentationSchema> sortedAugmentations = new ArrayList(augmentations);
367 Collections.sort(sortedAugmentations,
368 [ augSchema1, augSchema2 |
369 if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) {
371 } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) {
376 return sortedAugmentations;
380 * Converts whole <b>module</b> to <code>GeneratedType</code> object.
381 * Firstly is created the module builder object from which is vally
382 * obtained reference to <code>GeneratedType</code> object.
385 * module from which are obtained the module name, child nodes,
386 * uses and is derived package name
387 * @return <code>GeneratedType</code> which is internal representation of
389 * @throws IllegalArgumentException
390 * if the module equals null
393 private def GeneratedTypeBuilder moduleToDataType(Module module) {
394 checkArgument(module !== null, "Module reference cannot be NULL.");
396 val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
397 addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
398 moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
399 return moduleDataTypeBuilder;
403 * Converts all <b>rpcs</b> inputs and outputs substatements of the module
404 * to the list of <code>Type</code> objects. In addition are to containers
405 * and lists which belong to input or output also part of returning list.
408 * module from which is obtained set of all rpc objects to
410 * @throws IllegalArgumentException
412 * <li>if the module equals null</li>
413 * <li>if the name of module equals null</li>
414 * <li>if the set of child nodes equals null</li>
418 private def void rpcMethodsToGenType(Module module) {
419 checkArgument(module !== null, "Module reference cannot be NULL.");
420 checkArgument(module.name !== null, "Module name cannot be NULL.");
421 checkArgument(module.childNodes !== null,
422 "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL.");
424 val basePackageName = moduleNamespaceToPackageName(module);
425 val Set<RpcDefinition> rpcDefinitions = module.rpcs;
426 if (rpcDefinitions.isEmpty()) {
430 val interfaceBuilder = moduleTypeBuilder(module, "Service");
431 interfaceBuilder.addImplementsType(Types.typeForClass(RpcService));
432 for (rpc : rpcDefinitions) {
434 val rpcName = BindingMapping.getClassName(rpc.QName);
435 val rpcMethodName = parseToValidParamName(rpcName);
436 val method = interfaceBuilder.addMethod(rpcMethodName);
437 val input = rpc.input;
438 val output = rpc.output;
440 if (input !== null) {
441 val inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
442 addImplementedInterfaceFromUses(input, inType);
443 inType.addImplementsType(DATA_OBJECT);
444 inType.addImplementsType(augmentable(inType));
445 resolveDataSchemaNodes(module, basePackageName, inType, inType, input.childNodes);
446 genCtx.get(module).addChildNodeType(input.path, inType)
447 val inTypeInstance = inType.toInstance();
448 method.addParameter(inTypeInstance, "input");
451 var Type outTypeInstance = VOID;
452 if (output !== null) {
453 val outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
454 addImplementedInterfaceFromUses(output, outType);
455 outType.addImplementsType(DATA_OBJECT);
456 outType.addImplementsType(augmentable(outType));
457 resolveDataSchemaNodes(module, basePackageName, outType, outType, output.childNodes);
458 genCtx.get(module).addChildNodeType(output.path, outType)
459 outTypeInstance = outType.toInstance();
462 val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance);
463 method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes));
467 genCtx.get(module).addTopLevelNodeType(interfaceBuilder)
471 * Converts all <b>notifications</b> of the module to the list of
472 * <code>Type</code> objects. In addition are to this list added containers
473 * and lists which are part of this notification.
476 * module from which is obtained set of all notification objects
477 * to iterate over them
478 * @throws IllegalArgumentException
480 * <li>if the module equals null</li>
481 * <li>if the name of module equals null</li>
482 * <li>if the set of child nodes equals null</li>
486 private def void notificationsToGenType(Module module) {
487 checkArgument(module !== null, "Module reference cannot be NULL.");
488 checkArgument(module.name !== null, "Module name cannot be NULL.");
490 if (module.childNodes === null) {
491 throw new IllegalArgumentException(
492 "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL.");
494 val notifications = module.notifications;
495 if(notifications.empty) return;
497 val listenerInterface = moduleTypeBuilder(module, "Listener");
498 listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
499 val basePackageName = moduleNamespaceToPackageName(module);
501 for (notification : notifications) {
502 if (notification !== null) {
503 processUsesAugments(notification, module);
505 val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification,
506 BindingTypes.DATA_OBJECT);
507 notificationInterface.addImplementsType(NOTIFICATION);
508 genCtx.get(module).addChildNodeType(notification.path, notificationInterface)
510 // Notification object
511 resolveDataSchemaNodes(module, basePackageName, notificationInterface, notificationInterface,
512 notification.childNodes);
514 listenerInterface.addMethod("on" + notificationInterface.name) //
515 .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification").
516 setReturnType(Types.VOID);
520 genCtx.get(module).addTopLevelNodeType(listenerInterface)
524 * Converts all <b>identities</b> of the module to the list of
525 * <code>Type</code> objects.
528 * module from which is obtained set of all identity objects to
531 * schema context only used as input parameter for method
532 * {@link identityToGenType}
535 private def void allIdentitiesToGenTypes(Module module, SchemaContext context) {
536 val Set<IdentitySchemaNode> schemaIdentities = module.identities;
537 val basePackageName = moduleNamespaceToPackageName(module);
539 if (schemaIdentities !== null && !schemaIdentities.isEmpty()) {
540 for (identity : schemaIdentities) {
541 identityToGenType(module, basePackageName, identity, context);
547 * Converts the <b>identity</b> object to GeneratedType. Firstly it is
548 * created transport object builder. If identity contains base identity then
549 * reference to base identity is added to superior identity as its extend.
550 * If identity doesn't contain base identity then only reference to abstract
551 * class {@link org.opendaylight.yangtools.yang.model.api.BaseIdentity
552 * BaseIdentity} is added
554 * @param module current module
555 * @param basePackageName
556 * string contains the module package name
558 * IdentitySchemaNode which contains data about identity
560 * SchemaContext which is used to get package and name
561 * information about base of identity
564 private def void identityToGenType(Module module, String basePackageName, IdentitySchemaNode identity,
565 SchemaContext context) {
566 if (identity === null) {
569 val packageName = packageNameForGeneratedType(basePackageName, identity.path);
570 val genTypeName = BindingMapping.getClassName(identity.QName);
571 val newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
572 val baseIdentity = identity.baseIdentity;
573 if (baseIdentity === null) {
574 newType.setExtendsType(Types.baseIdentityTO);
576 val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
577 val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
578 val returnTypeName = BindingMapping.getClassName(baseIdentity.QName);
579 val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
580 newType.setExtendsType(gto);
582 newType.setAbstract(true);
583 val qname = identity.QName;
585 newType.qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,qname);
587 genCtx.get(module).addIdentityType(identity.QName,newType)
590 private static def qnameConstant(GeneratedTypeBuilderBase<?> toBuilder, String constantName, QName name) {
591 toBuilder.addConstant(QName.typeForClass,constantName,'''
592 org.opendaylight.yangtools.yang.common.QName.create("«name.namespace»","«name.formattedRevision»","«name.localName»")
597 * Converts all <b>groupings</b> of the module to the list of
598 * <code>Type</code> objects. Firstly are groupings sorted according mutual
599 * dependencies. At least dependent (independent) groupings are in the list
600 * saved at first positions. For every grouping the record is added to map
601 * {@link BindingGeneratorImpl#allGroupings allGroupings}
605 * @param collection of groupings from which types will be generated
608 private def void groupingsToGenTypes(Module module, Collection<GroupingDefinition> groupings) {
609 val basePackageName = moduleNamespaceToPackageName(module);
610 val List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort(
612 for (grouping : groupingsSortedByDependencies) {
613 groupingToGenType(basePackageName, grouping, module);
618 * Converts individual grouping to GeneratedType. Firstly generated type
619 * builder is created and every child node of grouping is resolved to the
622 * @param basePackageName
623 * string contains the module package name
625 * GroupingDefinition which contains data about grouping
626 * @param module current module
627 * @return GeneratedType which is generated from grouping (object of type
628 * <code>GroupingDefinition</code>)
630 private def void groupingToGenType(String basePackageName, GroupingDefinition grouping, Module module) {
631 val packageName = packageNameForGeneratedType(basePackageName, grouping.path);
632 val genType = addDefaultInterfaceDefinition(packageName, grouping);
633 genCtx.get(module).addGroupingType(grouping.path, genType)
634 resolveDataSchemaNodes(module, basePackageName, genType, genType, grouping.childNodes);
635 groupingsToGenTypes(module, grouping.groupings);
636 processUsesAugments(grouping, module);
640 * Tries to find EnumTypeDefinition in <code>typeDefinition</code>. If base
641 * type of <code>typeDefinition</code> is of the type ExtendedType then this
642 * method is recursively called with this base type.
644 * @param typeDefinition
645 * TypeDefinition in which should be EnumTypeDefinition found as
647 * @return EnumTypeDefinition if it is found inside
648 * <code>typeDefinition</code> or <code>null</code> in other case
650 private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition<?> typeDefinition) {
651 if (typeDefinition !== null) {
652 if (typeDefinition.baseType instanceof EnumTypeDefinition) {
653 return typeDefinition.baseType as EnumTypeDefinition;
654 } else if (typeDefinition.baseType instanceof ExtendedType) {
655 return enumTypeDefFromExtendedType(typeDefinition.baseType);
662 * Adds enumeration builder created from <code>enumTypeDef</code> to
663 * <code>typeBuilder</code>.
665 * Each <code>enumTypeDef</code> item is added to builder with its name and
669 * EnumTypeDefinition contains enum data
671 * string contains name which will be assigned to enumeration
674 * GeneratedTypeBuilder to which will be enum builder assigned
675 * @return enumeration builder which contains data from
676 * <code>enumTypeDef</code>
678 private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, QName enumName,
679 GeneratedTypeBuilder typeBuilder) {
680 if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) &&
681 (enumTypeDef.QName.localName !== null)) {
682 val enumerationName = BindingMapping.getClassName(enumName);
683 val enumBuilder = typeBuilder.addEnumeration(enumerationName);
684 enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
691 * Generates type builder for <code>module</code>.
694 * Module which is source of package name for generated type
697 * string which is added to the module class name representation
699 * @return instance of GeneratedTypeBuilder which represents
700 * <code>module</code>.
701 * @throws IllegalArgumentException
702 * if <code>module</code> equals null
704 private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) {
705 checkArgument(module !== null, "Module reference cannot be NULL.");
706 val packageName = moduleNamespaceToPackageName(module);
707 val moduleName = BindingMapping.getClassName(module.name) + postfix;
708 return new GeneratedTypeBuilderImpl(packageName, moduleName);
712 * Converts <code>augSchema</code> to list of <code>Type</code> which
713 * contains generated type for augmentation. In addition there are also
714 * generated types for all containers, list and choices which are child of
715 * <code>augSchema</code> node or a generated types for cases are added if
716 * augmented node is choice.
718 * @param augmentPackageName
719 * string with the name of the package to which the augmentation
722 * AugmentationSchema which is contains data about augmentation
723 * (target path, childs...)
724 * @param module current module
725 * @param parentUsesNode parent uses node of this augment (can be null if this augment is not defined under uses statement)
726 * @throws IllegalArgumentException
728 * <li>if <code>augmentPackageName</code> equals null</li>
729 * <li>if <code>augSchema</code> equals null</li>
730 * <li>if target path of <code>augSchema</code> equals null</li>
733 private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module) {
734 checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
735 checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
736 checkState(augSchema.targetPath !== null,
737 "Augmentation Schema does not contain Target Path (Target Path is NULL).");
739 processUsesAugments(augSchema, module);
740 val targetPath = augSchema.targetPath;
741 var SchemaNode targetSchemaNode = null
743 targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
744 if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
745 targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode, schemaContext);
746 if (targetSchemaNode == null) {
747 throw new NullPointerException(
748 "Failed to find target node from grouping in augmentation " + augSchema + " in module " +
752 if (targetSchemaNode == null) {
753 throw new IllegalArgumentException("augment target not found: " + targetPath)
756 var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
757 if (targetTypeBuilder === null) {
758 targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
760 if (targetTypeBuilder === null) {
761 throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
764 if (!(targetSchemaNode instanceof ChoiceNode)) {
765 var packageName = augmentPackageName;
766 val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
767 targetTypeBuilder.toInstance, augSchema);
768 genCtx.get(module).addAugmentType(augTypeBuilder)
769 genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
771 generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
772 targetSchemaNode as ChoiceNode, augSchema.childNodes);
776 private def void usesAugmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module,
777 UsesNode usesNode, DataNodeContainer usesNodeParent) {
778 checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
779 checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
780 checkState(augSchema.targetPath !== null,
781 "Augmentation Schema does not contain Target Path (Target Path is NULL).");
783 processUsesAugments(augSchema, module);
784 val targetPath = augSchema.targetPath;
785 var SchemaNode targetSchemaNode = null
786 targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode);
787 if (targetSchemaNode == null) {
788 throw new IllegalArgumentException("augment target not found: " + targetPath)
791 var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
792 if (targetTypeBuilder === null) {
793 targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
795 if (targetTypeBuilder === null) {
796 throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
799 if (!(targetSchemaNode instanceof ChoiceNode)) {
800 var packageName = augmentPackageName;
801 if (usesNodeParent instanceof SchemaNode) {
802 packageName = packageNameForGeneratedType(augmentPackageName, (usesNodeParent as SchemaNode).path, true)
804 val augTypeBuilder = addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
805 targetTypeBuilder.toInstance, augSchema);
806 genCtx.get(module).addAugmentType(augTypeBuilder)
807 genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
809 generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
810 targetSchemaNode as ChoiceNode, augSchema.childNodes);
815 * Convenient method to find node added by uses statement.
817 private def DataSchemaNode findOriginalTargetFromGrouping(SchemaPath targetPath, UsesNode parentUsesNode) {
818 var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, parentUsesNode.groupingPath.path);
819 if (!(targetGrouping instanceof GroupingDefinition)) {
820 throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode);
823 var grouping = targetGrouping as GroupingDefinition;
824 var SchemaNode result = grouping;
825 val List<QName> path = targetPath.path
827 // finding by local name is valid, grouping cannot contain nodes with same name and different namespace
828 if (result instanceof DataNodeContainer) {
829 result = (result as DataNodeContainer).getDataChildByName(node.localName)
830 } else if (result instanceof ChoiceNode) {
831 result = (result as ChoiceNode).getCaseNodeByName(node.localName)
834 if (result == null) {
838 val String targetSchemaNodeName = result.QName.localName;
839 var boolean fromUses = (result as DataSchemaNode).addedByUses
840 var Iterator<UsesNode> groupingUses = grouping.uses.iterator;
842 if (groupingUses.hasNext()) {
843 grouping = findNodeInSchemaContext(schemaContext, groupingUses.next().groupingPath.path) as GroupingDefinition;
844 result = grouping.getDataChildByName(targetSchemaNodeName);
845 fromUses = (result as DataSchemaNode).addedByUses;
847 throw new NullPointerException("Failed to generate code for augment in " + parentUsesNode);
851 return result as DataSchemaNode
855 * Returns a generated type builder for an augmentation.
857 * The name of the type builder is equal to the name of augmented node with
858 * serial number as suffix.
860 * @param module current module
861 * @param augmentPackageName
862 * string with contains the package name to which the augment
864 * @param basePackageName
865 * string with the package name to which the augmented node
867 * @param targetTypeRef
870 * augmentation schema which contains data about the child nodes
871 * and uses of augment
872 * @return generated type builder for augment
874 private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(Module module, String augmentPackageName,
875 String basePackageName, Type targetTypeRef, AugmentationSchema augSchema) {
876 var Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
877 if (augmentBuilders === null) {
878 augmentBuilders = new HashMap();
879 genTypeBuilders.put(augmentPackageName, augmentBuilders);
881 val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes);
883 val augTypeName = if (augIdentifier !== null) {
884 BindingMapping.getClassName(augIdentifier)
886 augGenTypeName(augmentBuilders, targetTypeRef.name);
889 val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
891 augTypeBuilder.addImplementsType(DATA_OBJECT);
892 augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
893 addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
895 augSchemaNodeToMethods(module, basePackageName, augTypeBuilder, augTypeBuilder, augSchema.childNodes);
896 augmentBuilders.put(augTypeName, augTypeBuilder);
897 return augTypeBuilder;
902 * @param unknownSchemaNodes
903 * @return nodeParameter of UnknownSchemaNode
905 private def String getAugmentIdentifier(List<UnknownSchemaNode> unknownSchemaNodes) {
906 for (unknownSchemaNode : unknownSchemaNodes) {
907 val nodeType = unknownSchemaNode.nodeType;
908 if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) &&
909 YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) {
910 return unknownSchemaNode.nodeParameter;
917 * Returns first unique name for the augment generated type builder. The
918 * generated type builder name for augment consists from name of augmented
919 * node and serial number of its augmentation.
922 * map of builders which were created in the package to which the
923 * augmentation belongs
925 * string with name of augmented node
926 * @return string with unique name for augmentation builder
928 private def String augGenTypeName(Map<String, GeneratedTypeBuilder> builders, String genTypeName) {
930 while ((builders !== null) && builders.containsKey(genTypeName + index)) {
933 return genTypeName + index;
937 * Adds the methods to <code>typeBuilder</code> which represent subnodes of
938 * node for which <code>typeBuilder</code> was created.
940 * The subnodes aren't mapped to the methods if they are part of grouping or
941 * augment (in this case are already part of them).
943 * @param module current module
944 * @param basePackageName
945 * string contains the module package name
947 * generated type builder which represents any node. The subnodes
948 * of this node are added to the <code>typeBuilder</code> as
949 * methods. The subnode can be of type leaf, leaf-list, list,
951 * @param childOf parent type
953 * set of data schema nodes which are the children of the node
954 * for which <code>typeBuilder</code> was created
955 * @return generated type builder which is the same builder as input
956 * parameter. The getter methods (representing child nodes) could be
959 private def GeneratedTypeBuilder resolveDataSchemaNodes(Module module, String basePackageName,
960 GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, Set<DataSchemaNode> schemaNodes) {
961 if ((schemaNodes !== null) && (parent !== null)) {
962 for (schemaNode : schemaNodes) {
963 if (!schemaNode.augmenting && !schemaNode.addedByUses) {
964 addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, parent, childOf, module);
972 * Adds the methods to <code>typeBuilder</code> what represents subnodes of
973 * node for which <code>typeBuilder</code> was created.
975 * @param module current module
976 * @param basePackageName
977 * string contains the module package name
979 * generated type builder which represents any node. The subnodes
980 * of this node are added to the <code>typeBuilder</code> as
981 * methods. The subnode can be of type leaf, leaf-list, list,
983 * @param childOf parent type
985 * set of data schema nodes which are the children of the node
986 * for which <code>typeBuilder</code> was created
987 * @return generated type builder which is the same object as the input
988 * parameter <code>typeBuilder</code>. The getter method could be
991 private def GeneratedTypeBuilder augSchemaNodeToMethods(Module module, String basePackageName,
992 GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Set<DataSchemaNode> schemaNodes) {
993 if ((schemaNodes !== null) && (typeBuilder !== null)) {
994 for (schemaNode : schemaNodes) {
995 if (!schemaNode.isAugmenting()) {
996 addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder, childOf, module);
1004 * Adds to <code>typeBuilder</code> a method which is derived from
1005 * <code>schemaNode</code>.
1007 * @param basePackageName
1008 * string with the module package name
1010 * data schema node which is added to <code>typeBuilder</code> as
1012 * @param typeBuilder
1013 * generated type builder to which is <code>schemaNode</code>
1014 * added as a method.
1015 * @param childOf parent type
1016 * @param module current module
1018 private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node,
1019 GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Module module) {
1020 if (node !== null && typeBuilder !== null) {
1022 case node instanceof LeafSchemaNode:
1023 resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode)
1024 case node instanceof LeafListSchemaNode:
1025 resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode)
1026 case node instanceof ContainerSchemaNode:
1027 containerToGenType(module, basePackageName, typeBuilder, childOf, node as ContainerSchemaNode)
1028 case node instanceof ListSchemaNode:
1029 listToGenType(module, basePackageName, typeBuilder, childOf, node as ListSchemaNode)
1030 case node instanceof ChoiceNode:
1031 choiceToGeneratedType(module, basePackageName, typeBuilder, node as ChoiceNode)
1037 * Converts <code>choiceNode</code> to the list of generated types for
1038 * choice and its cases.
1040 * The package names for choice and for its cases are created as
1041 * concatenation of the module package (<code>basePackageName</code>) and
1042 * names of all parents node.
1044 * @param module current module
1045 * @param basePackageName
1046 * string with the module package name
1047 * @param parent parent type
1048 * @param childOf concrete parent for case child nodes
1050 * choice node which is mapped to generated type. Also child
1051 * nodes - cases are mapped to generated types.
1052 * @throws IllegalArgumentException
1054 * <li>if <code>basePackageName</code> equals null</li>
1055 * <li>if <code>choiceNode</code> equals null</li>
1059 private def void choiceToGeneratedType(Module module, String basePackageName, GeneratedTypeBuilder parent,
1060 ChoiceNode choiceNode) {
1061 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1062 checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
1064 if (!choiceNode.addedByUses) {
1065 val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
1066 val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
1067 constructGetter(parent, choiceNode.QName.localName, choiceNode.description, choiceTypeBuilder);
1068 choiceTypeBuilder.addImplementsType(DataContainer.typeForClass);
1069 genCtx.get(module).addChildNodeType(choiceNode.path, choiceTypeBuilder)
1070 generateTypesFromChoiceCases(module, basePackageName, parent, choiceTypeBuilder.toInstance, choiceNode);
1075 * Converts <code>caseNodes</code> set to list of corresponding generated
1078 * For every <i>case</i> which isn't added through augment or <i>uses</i> is
1079 * created generated type builder. The package names for the builder is
1080 * created as concatenation of the module package (
1081 * <code>basePackageName</code>) and names of all parents nodes of the
1082 * concrete <i>case</i>. There is also relation "<i>implements type</i>"
1083 * between every case builder and <i>choice</i> type
1085 * @param basePackageName
1086 * string with the module package name
1087 * @param refChoiceType
1088 * type which represents superior <i>case</i>
1090 * set of choice case nodes which are mapped to generated types
1091 * @return list of generated types for <code>caseNodes</code>.
1092 * @throws IllegalArgumentException
1094 * <li>if <code>basePackageName</code> equals null</li>
1095 * <li>if <code>refChoiceType</code> equals null</li>
1096 * <li>if <code>caseNodes</code> equals null</li>
1100 private def void generateTypesFromChoiceCases(Module module, String basePackageName,
1101 GeneratedTypeBuilder choiceParent, Type refChoiceType, ChoiceNode choiceNode) {
1102 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1103 checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
1104 checkArgument(choiceNode !== null, "ChoiceNode cannot be NULL.");
1106 val Set<ChoiceCaseNode> caseNodes = choiceNode.cases;
1107 if (caseNodes == null) {
1111 for (caseNode : caseNodes) {
1112 if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
1113 val packageName = packageNameForGeneratedType(basePackageName, caseNode.path)
1114 val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode)
1115 caseTypeBuilder.addImplementsType(refChoiceType)
1116 genCtx.get(module).addCaseType(caseNode.path, caseTypeBuilder)
1117 val Set<DataSchemaNode> caseChildNodes = caseNode.childNodes
1118 if (caseChildNodes !== null) {
1119 var Object parentNode = null
1120 val SchemaPath nodeSp = choiceNode.path
1121 val List<QName> nodeNames = nodeSp.path
1122 val List<QName> nodeNewNames = new ArrayList(nodeNames)
1123 nodeNewNames.remove(nodeNewNames.size - 1)
1124 val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute)
1125 parentNode = findDataSchemaNode(schemaContext, nodeNewSp)
1127 var SchemaNode parent
1128 if (parentNode instanceof AugmentationSchema) {
1129 val augSchema = parentNode as AugmentationSchema;
1130 val targetPath = augSchema.targetPath;
1131 var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath)
1132 if (targetSchemaNode instanceof DataSchemaNode &&
1133 (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
1134 targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode, schemaContext);
1135 if (targetSchemaNode == null) {
1136 throw new NullPointerException(
1137 "Failed to find target node from grouping for augmentation " + augSchema +
1138 " in module " + module.name);
1141 parent = targetSchemaNode
1143 val SchemaPath sp = choiceNode.path
1144 val List<QName> names = sp.path
1145 val List<QName> newNames = new ArrayList(names)
1146 newNames.remove(newNames.size - 1)
1147 val SchemaPath newSp = new SchemaPath(newNames, sp.absolute)
1148 parent = findDataSchemaNode(schemaContext, newSp)
1150 var GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.path)
1151 resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes)
1155 processUsesAugments(caseNode, module);
1160 * Generates list of generated types for all the cases of a choice which are
1161 * added to the choice through the augment.
1164 * @param basePackageName
1165 * string contains name of package to which augment belongs. If
1166 * an augmented choice is from an other package (pcg1) than an
1167 * augmenting choice (pcg2) then case's of the augmenting choice
1168 * will belong to pcg2.
1169 * @param refChoiceType
1170 * Type which represents the choice to which case belongs. Every
1171 * case has to contain its choice in extend part.
1173 * set of choice case nodes for which is checked if are/aren't
1174 * added to choice through augmentation
1175 * @return list of generated types which represents augmented cases of
1176 * choice <code>refChoiceType</code>
1177 * @throws IllegalArgumentException
1179 * <li>if <code>basePackageName</code> equals null</li>
1180 * <li>if <code>refChoiceType</code> equals null</li>
1181 * <li>if <code>caseNodes</code> equals null</li>
1184 private def void generateTypesFromAugmentedChoiceCases(Module module, String basePackageName, Type targetType,
1185 ChoiceNode targetNode, Set<DataSchemaNode> augmentedNodes) {
1186 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1187 checkArgument(targetType !== null, "Referenced Choice Type cannot be NULL.");
1188 checkArgument(augmentedNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
1190 for (caseNode : augmentedNodes) {
1191 if (caseNode !== null) {
1192 val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
1193 val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
1194 caseTypeBuilder.addImplementsType(targetType);
1196 var SchemaNode parent = null
1197 val SchemaPath nodeSp = targetNode.path
1198 val List<QName> nodeNames = nodeSp.path
1199 val List<QName> nodeNewNames = new ArrayList(nodeNames)
1200 nodeNewNames.remove(nodeNewNames.size - 1)
1201 val SchemaPath nodeNewSp = new SchemaPath(nodeNewNames, nodeSp.absolute)
1202 parent = findDataSchemaNode(schemaContext, nodeNewSp)
1204 var GeneratedTypeBuilder childOfType = null;
1205 if (parent instanceof Module) {
1206 childOfType = genCtx.get(parent as Module).moduleNode
1207 } else if (parent instanceof ChoiceCaseNode) {
1208 childOfType = findCaseByPath(parent.path)
1209 } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
1210 childOfType = findChildNodeByPath(parent.path)
1211 } else if (parent instanceof GroupingDefinition) {
1212 childOfType = findGroupingByPath(parent.path);
1215 if (childOfType == null) {
1216 throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
1219 if (caseNode instanceof DataNodeContainer) {
1220 val DataNodeContainer dataNodeCase = caseNode as DataNodeContainer;
1221 val Set<DataSchemaNode> childNodes = dataNodeCase.childNodes;
1222 if (childNodes !== null) {
1223 resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
1226 val ChoiceCaseNode node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName());
1227 val Set<DataSchemaNode> childNodes = node.childNodes;
1228 if (childNodes !== null) {
1229 resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
1233 genCtx.get(module).addCaseType(caseNode.path, caseTypeBuilder)
1240 * Converts <code>leaf</code> to the getter method which is added to
1241 * <code>typeBuilder</code>.
1243 * @param typeBuilder
1244 * generated type builder to which is added getter method as
1245 * <code>leaf</code> mapping
1247 * leaf schema node which is mapped as getter method which is
1248 * added to <code>typeBuilder</code>
1249 * @return boolean value
1251 * <li>false - if <code>leaf</code> or <code>typeBuilder</code> are
1253 * <li>true - in other cases</li>
1256 private def Type resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) {
1257 var Type returnType = null;
1258 if ((leaf !== null) && (typeBuilder !== null)) {
1259 val leafName = leaf.QName.localName;
1260 var String leafDesc = leaf.description;
1261 if (leafDesc === null) {
1265 val parentModule = findParentModule(schemaContext, leaf);
1266 if (leafName !== null && !leaf.isAddedByUses()) {
1267 val TypeDefinition<?> typeDef = leaf.type;
1269 var GeneratedTOBuilder genTOBuilder;
1270 if (typeDef instanceof EnumTypeDefinition) {
1271 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
1272 val enumTypeDef = typeDef as EnumTypeDefinition;
1273 val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.QName, typeBuilder);
1275 if (enumBuilder !== null) {
1276 returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name);
1278 (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType);
1279 } else if (typeDef instanceof UnionType) {
1280 genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
1281 if (genTOBuilder !== null) {
1282 returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule)
1284 } else if (typeDef instanceof BitsTypeDefinition) {
1285 genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
1286 if (genTOBuilder !== null) {
1287 returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
1290 val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
1291 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions);
1293 if (returnType !== null) {
1294 val MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType);
1295 processContextRefExtension(leaf, getter, parentModule);
1302 private def void processContextRefExtension(LeafSchemaNode leaf, MethodSignatureBuilder getter, Module module) {
1303 for (node : leaf.unknownSchemaNodes) {
1304 val nodeType = node.nodeType;
1305 if ("context-reference".equals(nodeType.localName)) {
1306 val nodeParam = node.nodeParameter;
1307 var IdentitySchemaNode identity = null;
1308 var String basePackageName = null;
1309 val String[] splittedElement = nodeParam.split(":");
1310 if (splittedElement.length == 1) {
1311 identity = findIdentityByName(module.identities, splittedElement.get(0));
1312 basePackageName = moduleNamespaceToPackageName(module);
1313 } else if (splittedElement.length == 2) {
1314 var prefix = splittedElement.get(0);
1315 val Module dependentModule = findModuleFromImports(module.imports, prefix)
1316 if (dependentModule == null) {
1317 throw new IllegalArgumentException(
1318 "Failed to process context-reference: unknown prefix " + prefix);
1320 identity = findIdentityByName(dependentModule.identities, splittedElement.get(1));
1321 basePackageName = moduleNamespaceToPackageName(dependentModule);
1323 throw new IllegalArgumentException(
1324 "Failed to process context-reference: unknown identity " + nodeParam);
1326 if (identity == null) {
1327 throw new IllegalArgumentException(
1328 "Failed to process context-reference: unknown identity " + nodeParam);
1331 val Class<RoutingContext> clazz = typeof(RoutingContext);
1332 val AnnotationTypeBuilder rc = getter.addAnnotation(clazz.package.name, clazz.simpleName);
1333 val packageName = packageNameForGeneratedType(basePackageName, identity.path);
1334 val genTypeName = BindingMapping.getClassName(identity.QName.localName);
1335 rc.addParameter("value", packageName + "." + genTypeName + ".class");
1340 private def IdentitySchemaNode findIdentityByName(Set<IdentitySchemaNode> identities, String name) {
1341 for (id : identities) {
1342 if (id.QName.localName.equals(name)) {
1349 private def Module findModuleFromImports(Set<ModuleImport> imports, String prefix) {
1350 for (imp : imports) {
1351 if (imp.prefix.equals(prefix)) {
1352 return schemaContext.findModuleByName(imp.moduleName, imp.revision);
1358 private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf,
1359 boolean isReadOnly, Module module) {
1360 if ((leaf !== null) && (toBuilder !== null)) {
1361 val leafName = leaf.QName.localName;
1362 var String leafDesc = leaf.description;
1363 if (leafDesc === null) {
1367 if (leafName !== null) {
1368 var Type returnType = null;
1369 val TypeDefinition<?> typeDef = leaf.type;
1370 if (typeDef instanceof UnionTypeDefinition) {
1371 // GeneratedType for this type definition should be already created
1372 var qname = typeDef.QName
1373 var Module unionModule = null
1374 if (qname.prefix == null || qname.prefix.empty) {
1375 unionModule = module
1377 unionModule = findModuleFromImports(module.imports, qname.prefix)
1379 val ModuleContext mc = genCtx.get(unionModule)
1380 returnType = mc.typedefs.get(typeDef.path)
1382 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
1384 return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly)
1391 * Converts <code>leaf</code> schema node to property of generated TO
1395 * generated TO builder to which is <code>leaf</code> added as
1398 * leaf schema node which is added to <code>toBuilder</code> as
1400 * @param returnType property type
1402 * boolean value which says if leaf property is|isn't read only
1403 * @return boolean value
1405 * <li>false - if <code>leaf</code>, <code>toBuilder</code> or leaf
1406 * name equals null or if leaf is added by <i>uses</i>.</li>
1407 * <li>true - other cases</li>
1410 private def resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf, Type returnType,
1411 boolean isReadOnly) {
1412 if (returnType == null) {
1415 val leafName = leaf.QName.localName
1416 val leafDesc = leaf.description
1417 val propBuilder = toBuilder.addProperty(parseToValidParamName(leafName));
1418 propBuilder.setReadOnly(isReadOnly);
1419 propBuilder.setReturnType(returnType);
1420 propBuilder.setComment(leafDesc);
1421 toBuilder.addEqualsIdentity(propBuilder);
1422 toBuilder.addHashIdentity(propBuilder);
1423 toBuilder.addToStringProperty(propBuilder);
1428 * Converts <code>node</code> leaf list schema node to getter method of
1429 * <code>typeBuilder</code>.
1431 * @param typeBuilder
1432 * generated type builder to which is <code>node</code> added as
1435 * leaf list schema node which is added to
1436 * <code>typeBuilder</code> as getter method
1437 * @return boolean value
1439 * <li>true - if <code>node</code>, <code>typeBuilder</code>,
1440 * nodeName equal null or <code>node</code> is added by <i>uses</i></li>
1441 * <li>false - other cases</li>
1444 private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) {
1445 if ((node !== null) && (typeBuilder !== null)) {
1446 val nodeName = node.QName;
1447 var String nodeDesc = node.description;
1448 if (nodeDesc === null) {
1451 if (nodeName !== null && !node.isAddedByUses()) {
1452 val TypeDefinition<?> typeDef = node.type;
1453 val parentModule = findParentModule(schemaContext, node);
1455 var Type returnType = null;
1456 if (typeDef instanceof EnumTypeDefinition) {
1457 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node);
1458 val enumTypeDef = typeDef as EnumTypeDefinition;
1459 val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName, typeBuilder);
1460 returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name);
1461 (typeProvider as TypeProviderImpl).putReferencedType(node.path, returnType);
1462 } else if (typeDef instanceof UnionType) {
1463 val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule);
1464 if (genTOBuilder !== null) {
1465 returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule)
1467 } else if (typeDef instanceof BitsTypeDefinition) {
1468 val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule);
1469 returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
1471 val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
1472 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions);
1475 val listType = Types.listTypeFor(returnType);
1476 constructGetter(typeBuilder, nodeName.localName, nodeDesc, listType);
1483 private def Type createReturnTypeForUnion(GeneratedTOBuilder genTOBuilder, TypeDefinition<?> typeDef,
1484 GeneratedTypeBuilder typeBuilder, Module parentModule) {
1485 val Type returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
1486 genTOBuilder.setTypedef(true);
1487 genTOBuilder.setIsUnion(true);
1488 (typeProvider as TypeProviderImpl).addUnitsToGenTO(genTOBuilder, typeDef.getUnits());
1491 val GeneratedTOBuilder unionBuilder = new GeneratedTOBuilderImpl(typeBuilder.getPackageName(),
1492 genTOBuilder.getName() + "Builder");
1493 unionBuilder.setIsUnionBuilder(true);
1494 val MethodSignatureBuilder method = unionBuilder.addMethod("getDefaultInstance");
1495 method.setReturnType(returnType);
1496 method.addParameter(Types.STRING, "defaultValue");
1497 method.setAccessModifier(AccessModifier.PUBLIC);
1498 method.setStatic(true);
1500 val Set<Type> types = (typeProvider as TypeProviderImpl).additionalTypes.get(parentModule);
1501 if (types == null) {
1502 (typeProvider as TypeProviderImpl).additionalTypes.put(parentModule,
1503 Sets.newHashSet(unionBuilder.toInstance))
1505 types.add(unionBuilder.toInstance)
1510 private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) {
1511 return addDefaultInterfaceDefinition(packageName, schemaNode, null);
1515 * Instantiates generated type builder with <code>packageName</code> and
1516 * <code>schemaNode</code>.
1518 * The new builder always implements
1519 * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.<br />
1520 * If <code>schemaNode</code> is instance of GroupingDefinition it also
1521 * implements {@link org.opendaylight.yangtools.yang.binding.Augmentable
1522 * Augmentable}.<br />
1523 * If <code>schemaNode</code> is instance of
1524 * {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer
1525 * DataNodeContainer} it can also implement nodes which are specified in
1528 * @param packageName
1529 * string with the name of the package to which
1530 * <code>schemaNode</code> belongs.
1532 * schema node for which is created generated type builder
1533 * @param parent parent type (can be null)
1534 * @return generated type builder <code>schemaNode</code>
1536 private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode,
1538 val it = addRawInterfaceDefinition(packageName, schemaNode, "");
1539 qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,schemaNode.QName);
1540 if (parent === null) {
1541 addImplementsType(DATA_OBJECT);
1543 addImplementsType(BindingTypes.childOf(parent));
1545 if (!(schemaNode instanceof GroupingDefinition)) {
1546 addImplementsType(augmentable(it));
1549 if (schemaNode instanceof DataNodeContainer) {
1550 addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, it);
1557 * Wraps the calling of the same overloaded method.
1559 * @param packageName
1560 * string with the package name to which returning generated type
1563 * schema node which provide data about the schema node name
1564 * @return generated type builder for <code>schemaNode</code>
1566 private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) {
1567 return addRawInterfaceDefinition(packageName, schemaNode, "");
1571 * Returns reference to generated type builder for specified
1572 * <code>schemaNode</code> with <code>packageName</code>.
1574 * Firstly the generated type builder is searched in
1575 * {@link BindingGeneratorImpl#genTypeBuilders genTypeBuilders}. If it isn't
1576 * found it is created and added to <code>genTypeBuilders</code>.
1578 * @param packageName
1579 * string with the package name to which returning generated type
1582 * schema node which provide data about the schema node name
1583 * @param prefix return type name prefix
1584 * @return generated type builder for <code>schemaNode</code>
1585 * @throws IllegalArgumentException
1587 * <li>if <code>schemaNode</code> equals null</li>
1588 * <li>if <code>packageName</code> equals null</li>
1589 * <li>if Q name of schema node is null</li>
1590 * <li>if schema node name is null</li>
1594 private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode,
1596 checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
1597 checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL.");
1598 checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL.");
1599 val schemaNodeName = schemaNode.QName.localName;
1600 checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL.");
1602 var String genTypeName;
1603 if (prefix === null) {
1604 genTypeName = BindingMapping.getClassName(schemaNodeName);
1606 genTypeName = prefix + BindingMapping.getClassName(schemaNodeName);
1609 //FIXME: Validation of name conflict
1610 val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
1611 if (!genTypeBuilders.containsKey(packageName)) {
1612 val Map<String, GeneratedTypeBuilder> builders = new HashMap();
1613 builders.put(genTypeName, newType);
1614 genTypeBuilders.put(packageName, builders);
1616 val Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
1617 if (!builders.containsKey(genTypeName)) {
1618 builders.put(genTypeName, newType);
1625 * Creates the name of the getter method from <code>methodName</code>.
1628 * string with the name of the getter method
1629 * @param returnType return type
1630 * @return string with the name of the getter method for
1631 * <code>methodName</code> in JAVA method format
1633 public static def String getterMethodName(String localName, Type returnType) {
1634 val method = new StringBuilder();
1635 if (BOOLEAN.equals(returnType)) {
1636 method.append("is");
1638 method.append("get");
1640 method.append(BindingMapping.getPropertyName(localName).toFirstUpper);
1641 return method.toString();
1645 * Created a method signature builder as part of
1646 * <code>interfaceBuilder</code>.
1648 * The method signature builder is created for the getter method of
1649 * <code>schemaNodeName</code>. Also <code>comment</code> and
1650 * <code>returnType</code> information are added to the builder.
1652 * @param interfaceBuilder
1653 * generated type builder for which the getter method should be
1655 * @param schemaNodeName
1656 * string with schema node name. The name will be the part of the
1657 * getter method name.
1659 * string with comment for the getter method
1661 * type which represents the return type of the getter method
1662 * @return method signature builder which represents the getter method of
1663 * <code>interfaceBuilder</code>
1665 private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName,
1666 String comment, Type returnType) {
1667 val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType));
1668 getMethod.setComment(comment);
1669 getMethod.setReturnType(returnType);
1674 * Adds <code>schemaNode</code> to <code>typeBuilder</code> as getter method
1675 * or to <code>genTOBuilder</code> as property.
1677 * @param basePackageName
1678 * string contains the module package name
1680 * data schema node which should be added as getter method to
1681 * <code>typeBuilder</code> or as a property to
1682 * <code>genTOBuilder</code> if is part of the list key
1683 * @param typeBuilder
1684 * generated type builder for the list schema node
1685 * @param genTOBuilder
1686 * generated TO builder for the list keys
1688 * list of string which contains names of the list keys
1689 * @param module current module
1690 * @throws IllegalArgumentException
1692 * <li>if <code>schemaNode</code> equals null</li>
1693 * <li>if <code>typeBuilder</code> equals null</li>
1696 private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode,
1697 GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List<String> listKeys, Module module) {
1698 checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
1699 checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
1701 if (schemaNode instanceof LeafSchemaNode) {
1702 val leaf = schemaNode as LeafSchemaNode;
1703 val leafName = leaf.QName.localName;
1704 val Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
1705 if (listKeys.contains(leafName)) {
1707 resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true, module)
1709 resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, type, true)
1712 } else if (!schemaNode.addedByUses) {
1713 if (schemaNode instanceof LeafListSchemaNode) {
1714 resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode);
1715 } else if (schemaNode instanceof ContainerSchemaNode) {
1716 containerToGenType(module, basePackageName, typeBuilder, typeBuilder, schemaNode as ContainerSchemaNode);
1717 } else if (schemaNode instanceof ChoiceNode) {
1718 choiceToGeneratedType(module, basePackageName, typeBuilder, schemaNode as ChoiceNode);
1719 } else if (schemaNode instanceof ListSchemaNode) {
1720 listToGenType(module, basePackageName, typeBuilder, typeBuilder, schemaNode as ListSchemaNode);
1725 private def typeBuildersToGenTypes(Module module, GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
1726 checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
1728 if (genTOBuilder !== null) {
1729 val genTO = genTOBuilder.toInstance();
1730 constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO);
1731 genCtx.get(module).addGeneratedTOBuilder(genTOBuilder)
1736 * Selects the names of the list keys from <code>list</code> and returns
1737 * them as the list of the strings
1740 * of string with names of the list keys
1741 * @return list of string which represents names of the list keys. If the
1742 * <code>list</code> contains no keys then the empty list is
1745 private def listKeys(ListSchemaNode list) {
1746 val List<String> listKeys = new ArrayList();
1748 if (list.keyDefinition !== null) {
1749 val keyDefinitions = list.keyDefinition;
1750 for (keyDefinition : keyDefinitions) {
1751 listKeys.add(keyDefinition.localName);
1758 * Generates for the <code>list</code> which contains any list keys special
1759 * generated TO builder.
1761 * @param packageName
1762 * string with package name to which the list belongs
1764 * list schema node which is source of data about the list name
1765 * @return generated TO builder which represents the keys of the
1766 * <code>list</code> or null if <code>list</code> is null or list of
1767 * key definitions is null or empty.
1769 private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) {
1770 var GeneratedTOBuilder genTOBuilder = null;
1771 if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) {
1772 val listName = list.QName.localName + "Key";
1773 val String genTOName = BindingMapping.getClassName(listName);
1774 genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName);
1776 return genTOBuilder;
1780 * Builds generated TO builders for <code>typeDef</code> of type
1781 * {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or
1782 * {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
1783 * BitsTypeDefinition} which are also added to <code>typeBuilder</code> as
1784 * enclosing transfer object.
1786 * If more then one generated TO builder is created for enclosing then all
1787 * of the generated TO builders are added to <code>typeBuilder</code> as
1788 * enclosing transfer objects.
1791 * type definition which can be of type <code>UnionType</code> or
1792 * <code>BitsTypeDefinition</code>
1793 * @param typeBuilder
1794 * generated type builder to which is added generated TO created
1795 * from <code>typeDef</code>
1797 * string with name for generated TO builder
1799 * @param parentModule
1800 * @return generated TO builder for <code>typeDef</code>
1802 private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition<?> typeDef, GeneratedTypeBuilder typeBuilder,
1803 DataSchemaNode leaf, Module parentModule) {
1804 val classNameFromLeaf = BindingMapping.getClassName(leaf.QName);
1805 val List<GeneratedTOBuilder> genTOBuilders = new ArrayList();
1806 val packageName = typeBuilder.fullyQualifiedName;
1807 if (typeDef instanceof UnionTypeDefinition) {
1808 val List<GeneratedTOBuilder> types = (typeProvider as TypeProviderImpl).
1809 provideGeneratedTOBuildersForUnionTypeDef(packageName, (typeDef as UnionTypeDefinition),
1810 classNameFromLeaf, leaf);
1811 genTOBuilders.addAll(types);
1814 var GeneratedTOBuilder resultTOBuilder = null;
1815 if (!types.isEmpty()) {
1816 resultTOBuilder = types.remove(0);
1817 for (GeneratedTOBuilder genTOBuilder : types) {
1818 resultTOBuilder.addEnclosingTransferObject(genTOBuilder);
1822 val GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value");
1823 genPropBuilder.setReturnType(Types.primitiveType("char[]", null));
1824 resultTOBuilder.addEqualsIdentity(genPropBuilder);
1825 resultTOBuilder.addHashIdentity(genPropBuilder);
1826 resultTOBuilder.addToStringProperty(genPropBuilder);
1828 } else if (typeDef instanceof BitsTypeDefinition) {
1830 ((typeProvider as TypeProviderImpl) ).
1831 provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf));
1833 if (genTOBuilders !== null && !genTOBuilders.isEmpty()) {
1834 for (genTOBuilder : genTOBuilders) {
1835 typeBuilder.addEnclosingTransferObject(genTOBuilder);
1837 return genTOBuilders.get(0);
1844 * Adds the implemented types to type builder.
1846 * The method passes through the list of <i>uses</i> in
1847 * {@code dataNodeContainer}. For every <i>use</i> is obtained corresponding
1848 * generated type from {@link BindingGeneratorImpl#allGroupings
1849 * allGroupings} which is added as <i>implements type</i> to
1850 * <code>builder</code>
1852 * @param dataNodeContainer
1853 * element which contains the list of used YANG groupings
1855 * builder to which are added implemented types according to
1856 * <code>dataNodeContainer</code>
1857 * @return generated type builder with all implemented types
1859 private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) {
1860 for (usesNode : dataNodeContainer.uses) {
1861 if (usesNode.groupingPath !== null) {
1862 val genType = findGroupingByPath(usesNode.groupingPath).toInstance
1863 if (genType === null) {
1864 throw new IllegalStateException(
1865 "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name);
1867 builder.addImplementsType(genType);
1873 private def GeneratedTypeBuilder findChildNodeByPath(SchemaPath path) {
1874 for (ctx : genCtx.values) {
1875 var result = ctx.getChildNode(path)
1876 if (result !== null) {
1883 private def GeneratedTypeBuilder findGroupingByPath(SchemaPath path) {
1884 for (ctx : genCtx.values) {
1885 var result = ctx.getGrouping(path)
1886 if (result !== null) {
1893 private def GeneratedTypeBuilder findCaseByPath(SchemaPath path) {
1894 for (ctx : genCtx.values) {
1895 var result = ctx.getCase(path)
1896 if (result !== null) {
1903 public def getModuleContexts() {