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
82 import java.util.TreeSet
83 import org.opendaylight.yangtools.yang.binding.BaseIdentity
85 public class BindingGeneratorImpl implements BindingGenerator {
87 private final Map<Module, ModuleContext> genCtx = new HashMap()
90 * Outer key represents the package name. Outer value represents map of
91 * all builders in the same package. Inner key represents the schema node
92 * name (in JAVA class/interface name format). Inner value represents
93 * instance of builder for schema node specified in key part.
95 private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
98 * Provide methods for converting YANG types to JAVA types.
100 private var TypeProvider typeProvider;
103 * Holds reference to schema context to resolve data of augmented element
104 * when creating augmentation builder
106 private var SchemaContext schemaContext;
109 * Constant with the concrete name of namespace.
111 private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
114 * Constant with the concrete name of identifier.
116 private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier";
119 * Resolves generated types from <code>context</code> schema nodes of all
122 * Generated types are created for modules, groupings, types, containers,
123 * lists, choices, augments, rpcs, notification, identities.
126 * schema context which contains data about all schema nodes
128 * @return list of types (usually <code>GeneratedType</code>
129 * <code>GeneratedTransferObject</code>which are generated from
130 * <code>context</code> data.
131 * @throws IllegalArgumentException
132 * if param <code>context</code> is null
133 * @throws IllegalStateException
134 * if <code>context</code> contain no modules
136 override generateTypes(SchemaContext context) {
137 checkArgument(context !== null, "Schema Context reference cannot be NULL.");
138 checkState(context.modules !== null, "Schema Context does not contain defined modules.");
139 schemaContext = context;
140 typeProvider = new TypeProviderImpl(context);
141 val Set<Module> modules = context.modules;
142 return generateTypes(context, modules);
146 * Resolves generated types from <code>context</code> schema nodes only for
147 * modules specified in <code>modules</code>
149 * Generated types are created for modules, groupings, types, containers,
150 * lists, choices, augments, rpcs, notification, identities.
153 * schema context which contains data about all schema nodes
156 * set of modules for which schema nodes should be generated
158 * @return list of types (usually <code>GeneratedType</code> or
159 * <code>GeneratedTransferObject</code>) which:
161 * <li>are generated from <code>context</code> schema nodes and</li>
162 * <li>are also part of some of the module in <code>modules</code>
165 * @throws IllegalArgumentException
167 * <li>if param <code>context</code> is null or</li>
168 * <li>if param <code>modules</code> is null</li>
170 * @throws IllegalStateException
171 * if <code>context</code> contain no modules
173 override generateTypes(SchemaContext context, Set<Module> modules) {
174 checkArgument(context !== null, "Schema Context reference cannot be NULL.");
175 checkState(context.modules !== null, "Schema Context does not contain defined modules.");
176 checkArgument(modules !== null, "Set of Modules cannot be NULL.");
178 schemaContext = context;
179 typeProvider = new TypeProviderImpl(context);
180 val contextModules = ModuleDependencySort.sort(context.modules);
181 genTypeBuilders = new HashMap();
183 for (contextModule : contextModules) {
184 moduleToGenTypes(contextModule, context);
186 for (contextModule : contextModules) {
187 allAugmentsToGenTypes(contextModule);
190 val List<Type> filteredGenTypes = new ArrayList();
191 for (Module m : modules) {
192 val ctx = checkNotNull(genCtx.get(m), "Module context not found for module %s", m)
193 filteredGenTypes.addAll(ctx.generatedTypes);
194 val Set<Type> additionalTypes = (typeProvider as TypeProviderImpl).additionalTypes.get(m)
195 if (additionalTypes != null) {
196 filteredGenTypes.addAll(additionalTypes)
200 return filteredGenTypes;
203 private def void moduleToGenTypes(Module m, SchemaContext context) {
204 genCtx.put(m, new ModuleContext)
205 allTypeDefinitionsToGenTypes(m)
206 groupingsToGenTypes(m, m.groupings)
207 rpcMethodsToGenType(m)
208 allIdentitiesToGenTypes(m, context)
209 notificationsToGenType(m)
211 if (!m.childNodes.isEmpty()) {
212 val moduleType = moduleToDataType(m)
213 genCtx.get(m).addModuleNode(moduleType)
214 val basePackageName = moduleNamespaceToPackageName(m);
215 resolveDataSchemaNodes(m, basePackageName, moduleType, moduleType, m.childNodes)
220 * Converts all extended type definitions of module to the list of
221 * <code>Type</code> objects.
224 * module from which is obtained set of type definitions
225 * @throws IllegalArgumentException
227 * <li>if module equals null</li>
228 * <li>if name of module equals null</li>
229 * <li>if type definitions of module equal null</li>
233 private def void allTypeDefinitionsToGenTypes(Module module) {
234 checkArgument(module !== null, "Module reference cannot be NULL.");
235 checkArgument(module.name !== null, "Module name cannot be NULL.");
236 val it = new DataNodeIterator(module);
237 val List<TypeDefinition<?>> typeDefinitions = it.allTypedefs;
238 checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.''');
240 for (TypeDefinition<?> typedef : typeDefinitions) {
241 if (typedef !== null) {
242 val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef);
244 genCtx.get(module).addTypedefType(typedef.path, type)
250 private def GeneratedTypeBuilder processDataSchemaNode(Module module, String basePackageName,
251 GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, DataSchemaNode node) {
252 if (node.augmenting || node.addedByUses) {
255 val packageName = packageNameForGeneratedType(basePackageName, node.path)
256 val genType = addDefaultInterfaceDefinition(packageName, node, childOf)
257 genType.addComment(node.getDescription());
258 if (node instanceof DataNodeContainer) {
259 genCtx.get(module).addChildNodeType(node.path, genType)
260 groupingsToGenTypes(module, (node as DataNodeContainer).groupings)
261 processUsesAugments(node as DataNodeContainer, module)
266 private def void containerToGenType(Module module, String basePackageName, GeneratedTypeBuilder parent,
267 GeneratedTypeBuilder childOf, ContainerSchemaNode node) {
268 val genType = processDataSchemaNode(module, basePackageName, parent, childOf, node)
269 if (genType != null) {
270 constructGetter(parent, node.QName.localName, node.description, genType)
271 resolveDataSchemaNodes(module, basePackageName, genType, genType, node.childNodes)
275 private def void listToGenType(Module module, String basePackageName, GeneratedTypeBuilder parent,
276 GeneratedTypeBuilder childOf, ListSchemaNode node) {
277 val genType = processDataSchemaNode(module, basePackageName, parent, childOf, node)
278 if (genType != null) {
279 constructGetter(parent, node.QName.localName, node.description, Types.listTypeFor(genType))
281 val List<String> listKeys = listKeys(node);
282 val packageName = packageNameForGeneratedType(basePackageName, (node).path)
283 val genTOBuilder = resolveListKeyTOBuilder(packageName, node);
284 if (genTOBuilder !== null) {
285 val identifierMarker = IDENTIFIER.parameterizedTypeFor(genType);
286 val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder);
287 genTOBuilder.addImplementsType(identifierMarker);
288 genType.addImplementsType(identifiableMarker);
291 for (schemaNode : node.childNodes) {
292 if (!schemaNode.augmenting) {
293 addSchemaNodeToListBuilders(basePackageName, schemaNode, genType, genTOBuilder, listKeys, module);
298 if (genTOBuilder !== null) {
299 val GeneratedPropertyBuilder prop = new GeneratedPropertyBuilderImpl("serialVersionUID");
300 prop.setValue(Long.toString(computeDefaultSUID(genTOBuilder)));
301 genTOBuilder.setSUID(prop);
304 typeBuildersToGenTypes(module, genType, genTOBuilder);
308 private def void processUsesAugments(DataNodeContainer node, Module module) {
309 val basePackageName = moduleNamespaceToPackageName(module);
310 for (usesNode : node.uses) {
311 for (augment : usesNode.augmentations) {
312 usesAugmentationToGenTypes(basePackageName, augment, module, usesNode, node);
313 processUsesAugments(augment, module);
319 * Converts all <b>augmentation</b> of the module to the list
320 * <code>Type</code> objects.
323 * module from which is obtained list of all augmentation objects
324 * to iterate over them
325 * @throws IllegalArgumentException
327 * <li>if the module equals null</li>
328 * <li>if the name of module equals null</li>
329 * <li>if the set of child nodes equals null</li>
333 private def void allAugmentsToGenTypes(Module module) {
334 checkArgument(module !== null, "Module reference cannot be NULL.");
335 checkArgument(module.name !== null, "Module name cannot be NULL.");
336 if (module.childNodes === null) {
337 throw new IllegalArgumentException(
338 "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL.");
341 val basePackageName = moduleNamespaceToPackageName(module);
342 val List<AugmentationSchema> augmentations = resolveAugmentations(module);
343 for (augment : augmentations) {
344 augmentationToGenTypes(basePackageName, augment, module);
349 * Returns list of <code>AugmentationSchema</code> objects. The objects are
350 * sorted according to the length of their target path from the shortest to
354 * module from which is obtained list of all augmentation objects
355 * @return list of sorted <code>AugmentationSchema</code> objects obtained
356 * from <code>module</code>
357 * @throws IllegalArgumentException
359 * <li>if the module equals null</li>
360 * <li>if the set of augmentation equals null</li>
364 private def List<AugmentationSchema> resolveAugmentations(Module module) {
365 checkArgument(module !== null, "Module reference cannot be NULL.");
366 checkState(module.augmentations !== null, "Augmentations Set cannot be NULL.");
368 val Set<AugmentationSchema> augmentations = module.augmentations;
369 var List<AugmentationSchema> sortedAugmentations = getSortedOrNull(augmentations)
370 if (sortedAugmentations != null) {
371 return sortedAugmentations
373 sortedAugmentations = new ArrayList(augmentations);
374 Collections.sort(sortedAugmentations,
375 [ augSchema1, augSchema2 |
376 val Iterator<QName> thisIt = augSchema1.targetPath.getPath().iterator();
377 val Iterator<QName> otherIt = augSchema2.getTargetPath().getPath().iterator();
378 while (thisIt.hasNext()) {
379 if (otherIt.hasNext()) {
380 val int comp = thisIt.next().compareTo(otherIt.next());
388 if (otherIt.hasNext()) {
393 return sortedAugmentations;
396 private def List<AugmentationSchema> getSortedOrNull(Collection<AugmentationSchema> collection) {
397 val TreeSet<AugmentationSchema> set = new TreeSet()
398 for (e : collection) {
399 if (e instanceof Comparable<?>) {
405 return new ArrayList(set.toArray)
409 * Converts whole <b>module</b> to <code>GeneratedType</code> object.
410 * Firstly is created the module builder object from which is vally
411 * obtained reference to <code>GeneratedType</code> object.
414 * module from which are obtained the module name, child nodes,
415 * uses and is derived package name
416 * @return <code>GeneratedType</code> which is internal representation of
418 * @throws IllegalArgumentException
419 * if the module equals null
422 private def GeneratedTypeBuilder moduleToDataType(Module module) {
423 checkArgument(module !== null, "Module reference cannot be NULL.");
425 val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
426 addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
427 moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
428 moduleDataTypeBuilder.addComment(module.getDescription());
429 return moduleDataTypeBuilder;
433 * Converts all <b>rpcs</b> inputs and outputs substatements of the module
434 * to the list of <code>Type</code> objects. In addition are to containers
435 * and lists which belong to input or output also part of returning list.
438 * module from which is obtained set of all rpc objects to
440 * @throws IllegalArgumentException
442 * <li>if the module equals null</li>
443 * <li>if the name of module equals null</li>
444 * <li>if the set of child nodes equals null</li>
448 private def void rpcMethodsToGenType(Module module) {
449 checkArgument(module !== null, "Module reference cannot be NULL.");
450 checkArgument(module.name !== null, "Module name cannot be NULL.");
451 checkArgument(module.childNodes !== null,
452 "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL.");
454 val basePackageName = moduleNamespaceToPackageName(module);
455 val Set<RpcDefinition> rpcDefinitions = module.rpcs;
456 if (rpcDefinitions.isEmpty()) {
460 val interfaceBuilder = moduleTypeBuilder(module, "Service");
461 interfaceBuilder.addImplementsType(Types.typeForClass(RpcService));
462 for (rpc : rpcDefinitions) {
464 val rpcName = BindingMapping.getClassName(rpc.QName);
465 val rpcMethodName = parseToValidParamName(rpcName);
466 val rpcComment = rpc.getDescription();
467 val method = interfaceBuilder.addMethod(rpcMethodName);
469 val input = rpc.input;
470 val output = rpc.output;
472 if (input !== null) {
473 val inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
474 addImplementedInterfaceFromUses(input, inType);
475 inType.addImplementsType(DATA_OBJECT);
476 inType.addImplementsType(augmentable(inType));
477 resolveDataSchemaNodes(module, basePackageName, inType, inType, input.childNodes);
478 genCtx.get(module).addChildNodeType(input.path, inType)
479 val inTypeInstance = inType.toInstance();
480 method.addParameter(inTypeInstance, "input");
483 var Type outTypeInstance = VOID;
484 if (output !== null) {
485 val outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
486 addImplementedInterfaceFromUses(output, outType);
487 outType.addImplementsType(DATA_OBJECT);
488 outType.addImplementsType(augmentable(outType));
489 resolveDataSchemaNodes(module, basePackageName, outType, outType, output.childNodes);
490 genCtx.get(module).addChildNodeType(output.path, outType)
491 outTypeInstance = outType.toInstance();
494 val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance);
495 method.setComment(rpcComment);
496 method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes));
501 genCtx.get(module).addTopLevelNodeType(interfaceBuilder)
505 * Converts all <b>notifications</b> of the module to the list of
506 * <code>Type</code> objects. In addition are to this list added containers
507 * and lists which are part of this notification.
510 * module from which is obtained set of all notification objects
511 * to iterate over them
512 * @throws IllegalArgumentException
514 * <li>if the module equals null</li>
515 * <li>if the name of module equals null</li>
516 * <li>if the set of child nodes equals null</li>
520 private def void notificationsToGenType(Module module) {
521 checkArgument(module !== null, "Module reference cannot be NULL.");
522 checkArgument(module.name !== null, "Module name cannot be NULL.");
524 if (module.childNodes === null) {
525 throw new IllegalArgumentException(
526 "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL.");
528 val notifications = module.notifications;
529 if(notifications.empty) return;
531 val listenerInterface = moduleTypeBuilder(module, "Listener");
532 listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
533 val basePackageName = moduleNamespaceToPackageName(module);
535 for (notification : notifications) {
536 if (notification !== null) {
537 processUsesAugments(notification, module);
539 val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification,
540 BindingTypes.DATA_OBJECT);
541 notificationInterface.addImplementsType(NOTIFICATION);
542 genCtx.get(module).addChildNodeType(notification.path, notificationInterface)
544 // Notification object
545 resolveDataSchemaNodes(module, basePackageName, notificationInterface, notificationInterface,
546 notification.childNodes);
548 listenerInterface.addMethod("on" + notificationInterface.name) //
549 .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification").
550 setComment(notification.getDescription()).setReturnType(Types.VOID);
554 genCtx.get(module).addTopLevelNodeType(listenerInterface)
558 * Converts all <b>identities</b> of the module to the list of
559 * <code>Type</code> objects.
562 * module from which is obtained set of all identity objects to
565 * schema context only used as input parameter for method
566 * {@link identityToGenType}
569 private def void allIdentitiesToGenTypes(Module module, SchemaContext context) {
570 val Set<IdentitySchemaNode> schemaIdentities = module.identities;
571 val basePackageName = moduleNamespaceToPackageName(module);
573 if (schemaIdentities !== null && !schemaIdentities.isEmpty()) {
574 for (identity : schemaIdentities) {
575 identityToGenType(module, basePackageName, identity, context);
581 * Converts the <b>identity</b> object to GeneratedType. Firstly it is
582 * created transport object builder. If identity contains base identity then
583 * reference to base identity is added to superior identity as its extend.
584 * If identity doesn't contain base identity then only reference to abstract
585 * class {@link org.opendaylight.yangtools.yang.model.api.BaseIdentity
586 * BaseIdentity} is added
588 * @param module current module
589 * @param basePackageName
590 * string contains the module package name
592 * IdentitySchemaNode which contains data about identity
594 * SchemaContext which is used to get package and name
595 * information about base of identity
598 private def void identityToGenType(Module module, String basePackageName, IdentitySchemaNode identity,
599 SchemaContext context) {
600 if (identity === null) {
603 val packageName = packageNameForGeneratedType(basePackageName, identity.path);
604 val genTypeName = BindingMapping.getClassName(identity.QName);
605 val newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
606 val baseIdentity = identity.baseIdentity;
607 if (baseIdentity === null) {
608 val GeneratedTOBuilderImpl gto = new GeneratedTOBuilderImpl(BaseIdentity.package.name,
609 BaseIdentity.simpleName);
610 newType.setExtendsType(gto.toInstance);
612 val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
613 val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
614 val returnTypeName = BindingMapping.getClassName(baseIdentity.QName);
615 val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
616 newType.setExtendsType(gto);
618 newType.setAbstract(true);
619 newType.addComment(identity.getDescription());
620 val qname = identity.QName;
622 newType.qnameConstant(BindingMapping.QNAME_STATIC_FIELD_NAME,qname);
624 genCtx.get(module).addIdentityType(identity.QName,newType)
627 private static def qnameConstant(GeneratedTypeBuilderBase<?> toBuilder, String constantName, QName name) {
628 toBuilder.addConstant(QName.typeForClass,constantName,'''
629 org.opendaylight.yangtools.yang.common.QName.create("«name.namespace»","«name.formattedRevision»","«name.localName»")
634 * Converts all <b>groupings</b> of the module to the list of
635 * <code>Type</code> objects. Firstly are groupings sorted according mutual
636 * dependencies. At least dependent (independent) groupings are in the list
637 * saved at first positions. For every grouping the record is added to map
638 * {@link BindingGeneratorImpl#allGroupings allGroupings}
642 * @param collection of groupings from which types will be generated
645 private def void groupingsToGenTypes(Module module, Collection<GroupingDefinition> groupings) {
646 val basePackageName = moduleNamespaceToPackageName(module);
647 val List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort(
649 for (grouping : groupingsSortedByDependencies) {
650 groupingToGenType(basePackageName, grouping, module);
655 * Converts individual grouping to GeneratedType. Firstly generated type
656 * builder is created and every child node of grouping is resolved to the
659 * @param basePackageName
660 * string contains the module package name
662 * GroupingDefinition which contains data about grouping
663 * @param module current module
664 * @return GeneratedType which is generated from grouping (object of type
665 * <code>GroupingDefinition</code>)
667 private def void groupingToGenType(String basePackageName, GroupingDefinition grouping, Module module) {
668 val packageName = packageNameForGeneratedType(basePackageName, grouping.path);
669 val genType = addDefaultInterfaceDefinition(packageName, grouping);
670 genCtx.get(module).addGroupingType(grouping.path, genType)
671 resolveDataSchemaNodes(module, basePackageName, genType, genType, grouping.childNodes);
672 groupingsToGenTypes(module, grouping.groupings);
673 processUsesAugments(grouping, module);
677 * Tries to find EnumTypeDefinition in <code>typeDefinition</code>. If base
678 * type of <code>typeDefinition</code> is of the type ExtendedType then this
679 * method is recursively called with this base type.
681 * @param typeDefinition
682 * TypeDefinition in which should be EnumTypeDefinition found as
684 * @return EnumTypeDefinition if it is found inside
685 * <code>typeDefinition</code> or <code>null</code> in other case
687 private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition<?> typeDefinition) {
688 if (typeDefinition !== null) {
689 if (typeDefinition.baseType instanceof EnumTypeDefinition) {
690 return typeDefinition.baseType as EnumTypeDefinition;
691 } else if (typeDefinition.baseType instanceof ExtendedType) {
692 return enumTypeDefFromExtendedType(typeDefinition.baseType);
699 * Adds enumeration builder created from <code>enumTypeDef</code> to
700 * <code>typeBuilder</code>.
702 * Each <code>enumTypeDef</code> item is added to builder with its name and
706 * EnumTypeDefinition contains enum data
708 * string contains name which will be assigned to enumeration
711 * GeneratedTypeBuilder to which will be enum builder assigned
712 * @return enumeration builder which contains data from
713 * <code>enumTypeDef</code>
715 private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, QName enumName,
716 GeneratedTypeBuilder typeBuilder) {
717 if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) &&
718 (enumTypeDef.QName.localName !== null)) {
719 val enumerationName = BindingMapping.getClassName(enumName);
720 val enumBuilder = typeBuilder.addEnumeration(enumerationName);
721 enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
728 * Generates type builder for <code>module</code>.
731 * Module which is source of package name for generated type
734 * string which is added to the module class name representation
736 * @return instance of GeneratedTypeBuilder which represents
737 * <code>module</code>.
738 * @throws IllegalArgumentException
739 * if <code>module</code> equals null
741 private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) {
742 checkArgument(module !== null, "Module reference cannot be NULL.");
743 val packageName = moduleNamespaceToPackageName(module);
744 val moduleName = BindingMapping.getClassName(module.name) + postfix;
745 return new GeneratedTypeBuilderImpl(packageName, moduleName);
749 * Converts <code>augSchema</code> to list of <code>Type</code> which
750 * contains generated type for augmentation. In addition there are also
751 * generated types for all containers, list and choices which are child of
752 * <code>augSchema</code> node or a generated types for cases are added if
753 * augmented node is choice.
755 * @param augmentPackageName
756 * string with the name of the package to which the augmentation
759 * AugmentationSchema which is contains data about augmentation
760 * (target path, childs...)
761 * @param module current module
762 * @param parentUsesNode parent uses node of this augment (can be null if this augment is not defined under uses statement)
763 * @throws IllegalArgumentException
765 * <li>if <code>augmentPackageName</code> equals null</li>
766 * <li>if <code>augSchema</code> equals null</li>
767 * <li>if target path of <code>augSchema</code> equals null</li>
770 private def void augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module) {
771 checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
772 checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
773 checkState(augSchema.targetPath !== null,
774 "Augmentation Schema does not contain Target Path (Target Path is NULL).");
776 processUsesAugments(augSchema, module);
777 val targetPath = augSchema.targetPath;
778 var SchemaNode targetSchemaNode = null
780 targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
781 if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
782 targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode, schemaContext);
783 if (targetSchemaNode == null) {
784 throw new NullPointerException(
785 "Failed to find target node from grouping in augmentation " + augSchema + " in module " +
789 if (targetSchemaNode == null) {
790 throw new IllegalArgumentException("augment target not found: " + targetPath)
793 var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
794 if (targetTypeBuilder === null) {
795 targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
797 if (targetTypeBuilder === null) {
798 throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
801 if (!(targetSchemaNode instanceof ChoiceNode)) {
802 var packageName = augmentPackageName;
803 val targetType = new ReferencedTypeImpl(targetTypeBuilder.packageName,targetTypeBuilder.name);
804 addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,targetType, augSchema);
807 generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
808 targetSchemaNode as ChoiceNode, augSchema.childNodes);
812 private def void usesAugmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema, Module module,
813 UsesNode usesNode, DataNodeContainer usesNodeParent) {
814 checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
815 checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
816 checkState(augSchema.targetPath !== null,
817 "Augmentation Schema does not contain Target Path (Target Path is NULL).");
819 processUsesAugments(augSchema, module);
820 val targetPath = augSchema.targetPath;
821 var SchemaNode targetSchemaNode = null
822 targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode);
823 if (targetSchemaNode == null) {
824 throw new IllegalArgumentException("augment target not found: " + targetPath)
827 var targetTypeBuilder = findChildNodeByPath(targetSchemaNode.path)
828 if (targetTypeBuilder === null) {
829 targetTypeBuilder = findCaseByPath(targetSchemaNode.path)
831 if (targetTypeBuilder === null) {
832 throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
835 if (!(targetSchemaNode instanceof ChoiceNode)) {
836 var packageName = augmentPackageName;
837 if (usesNodeParent instanceof SchemaNode) {
838 packageName = packageNameForGeneratedType(augmentPackageName, (usesNodeParent as SchemaNode).path, true)
840 addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
841 targetTypeBuilder.toInstance, augSchema);
843 generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance,
844 targetSchemaNode as ChoiceNode, augSchema.childNodes);
849 * Convenient method to find node added by uses statement.
851 private def DataSchemaNode findOriginalTargetFromGrouping(SchemaPath targetPath, UsesNode parentUsesNode) {
852 var SchemaNode targetGrouping = findNodeInSchemaContext(schemaContext, parentUsesNode.groupingPath.path);
853 if (!(targetGrouping instanceof GroupingDefinition)) {
854 throw new IllegalArgumentException("Failed to generate code for augment in " + parentUsesNode);
857 var grouping = targetGrouping as GroupingDefinition;
858 var SchemaNode result = grouping;
859 val List<QName> path = targetPath.path
861 // finding by local name is valid, grouping cannot contain nodes with same name and different namespace
862 if (result instanceof DataNodeContainer) {
863 result = (result as DataNodeContainer).getDataChildByName(node.localName)
864 } else if (result instanceof ChoiceNode) {
865 result = (result as ChoiceNode).getCaseNodeByName(node.localName)
868 if (result == null) {
872 var boolean fromUses = (result as DataSchemaNode).addedByUses
873 var Iterator<UsesNode> groupingUses = grouping.uses.iterator;
874 while (groupingUses.hasNext && fromUses) {
875 result = findOriginalTargetFromGrouping(targetPath, groupingUses.next);
876 if (result != null) {
877 fromUses = (result as DataSchemaNode).addedByUses
881 throw new NullPointerException("Failed to generate code for augment in " + parentUsesNode);
884 return result as DataSchemaNode
888 * Returns a generated type builder for an augmentation.
890 * The name of the type builder is equal to the name of augmented node with
891 * serial number as suffix.
893 * @param module current module
894 * @param augmentPackageName
895 * string with contains the package name to which the augment
897 * @param basePackageName
898 * string with the package name to which the augmented node
900 * @param targetTypeRef
903 * augmentation schema which contains data about the child nodes
904 * and uses of augment
905 * @return generated type builder for augment
907 private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(Module module, String augmentPackageName,
908 String basePackageName, Type targetTypeRef, AugmentationSchema augSchema) {
909 var Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
910 if (augmentBuilders === null) {
911 augmentBuilders = new HashMap();
912 genTypeBuilders.put(augmentPackageName, augmentBuilders);
914 val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes);
916 val augTypeName = if (augIdentifier !== null) {
917 BindingMapping.getClassName(augIdentifier)
919 augGenTypeName(augmentBuilders, targetTypeRef.name);
922 val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
924 augTypeBuilder.addImplementsType(DATA_OBJECT);
925 augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
926 addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
928 augSchemaNodeToMethods(module, basePackageName, augTypeBuilder, augTypeBuilder, augSchema.childNodes);
929 augmentBuilders.put(augTypeName, augTypeBuilder);
931 genCtx.get(module).addTargetToAugmentation(targetTypeRef,augTypeBuilder);
932 genCtx.get(module).addAugmentType(augTypeBuilder);
933 genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
934 return augTypeBuilder;
939 * @param unknownSchemaNodes
940 * @return nodeParameter of UnknownSchemaNode
942 private def String getAugmentIdentifier(List<UnknownSchemaNode> unknownSchemaNodes) {
943 for (unknownSchemaNode : unknownSchemaNodes) {
944 val nodeType = unknownSchemaNode.nodeType;
945 if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) &&
946 YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) {
947 return unknownSchemaNode.nodeParameter;
954 * Returns first unique name for the augment generated type builder. The
955 * generated type builder name for augment consists from name of augmented
956 * node and serial number of its augmentation.
959 * map of builders which were created in the package to which the
960 * augmentation belongs
962 * string with name of augmented node
963 * @return string with unique name for augmentation builder
965 private def String augGenTypeName(Map<String, GeneratedTypeBuilder> builders, String genTypeName) {
967 while ((builders !== null) && builders.containsKey(genTypeName + index)) {
970 return genTypeName + index;
974 * Adds the methods to <code>typeBuilder</code> which represent subnodes of
975 * node for which <code>typeBuilder</code> was created.
977 * The subnodes aren't mapped to the methods if they are part of grouping or
978 * augment (in this case are already part of them).
980 * @param module current module
981 * @param basePackageName
982 * string contains the module package name
984 * generated type builder which represents any node. The subnodes
985 * of this node are added to the <code>typeBuilder</code> as
986 * methods. The subnode can be of type leaf, leaf-list, list,
988 * @param childOf parent type
990 * set of data schema nodes which are the children of the node
991 * for which <code>typeBuilder</code> was created
992 * @return generated type builder which is the same builder as input
993 * parameter. The getter methods (representing child nodes) could be
996 private def GeneratedTypeBuilder resolveDataSchemaNodes(Module module, String basePackageName,
997 GeneratedTypeBuilder parent, GeneratedTypeBuilder childOf, Set<DataSchemaNode> schemaNodes) {
998 if ((schemaNodes !== null) && (parent !== null)) {
999 for (schemaNode : schemaNodes) {
1000 if (!schemaNode.augmenting && !schemaNode.addedByUses) {
1001 addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, parent, childOf, module);
1009 * Adds the methods to <code>typeBuilder</code> what represents subnodes of
1010 * node for which <code>typeBuilder</code> was created.
1012 * @param module current module
1013 * @param basePackageName
1014 * string contains the module package name
1015 * @param typeBuilder
1016 * generated type builder which represents any node. The subnodes
1017 * of this node are added to the <code>typeBuilder</code> as
1018 * methods. The subnode can be of type leaf, leaf-list, list,
1019 * container, choice.
1020 * @param childOf parent type
1021 * @param schemaNodes
1022 * set of data schema nodes which are the children of the node
1023 * for which <code>typeBuilder</code> was created
1024 * @return generated type builder which is the same object as the input
1025 * parameter <code>typeBuilder</code>. The getter method could be
1028 private def GeneratedTypeBuilder augSchemaNodeToMethods(Module module, String basePackageName,
1029 GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Set<DataSchemaNode> schemaNodes) {
1030 if ((schemaNodes !== null) && (typeBuilder !== null)) {
1031 for (schemaNode : schemaNodes) {
1032 if (!schemaNode.isAugmenting()) {
1033 addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder, childOf, module);
1041 * Adds to <code>typeBuilder</code> a method which is derived from
1042 * <code>schemaNode</code>.
1044 * @param basePackageName
1045 * string with the module package name
1047 * data schema node which is added to <code>typeBuilder</code> as
1049 * @param typeBuilder
1050 * generated type builder to which is <code>schemaNode</code>
1051 * added as a method.
1052 * @param childOf parent type
1053 * @param module current module
1055 private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node,
1056 GeneratedTypeBuilder typeBuilder, GeneratedTypeBuilder childOf, Module module) {
1057 if (node !== null && typeBuilder !== null) {
1059 case node instanceof LeafSchemaNode:
1060 resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode)
1061 case node instanceof LeafListSchemaNode:
1062 resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode)
1063 case node instanceof ContainerSchemaNode:
1064 containerToGenType(module, basePackageName, typeBuilder, childOf, node as ContainerSchemaNode)
1065 case node instanceof ListSchemaNode:
1066 listToGenType(module, basePackageName, typeBuilder, childOf, node as ListSchemaNode)
1067 case node instanceof ChoiceNode:
1068 choiceToGeneratedType(module, basePackageName, typeBuilder, node as ChoiceNode)
1074 * Converts <code>choiceNode</code> to the list of generated types for
1075 * choice and its cases.
1077 * The package names for choice and for its cases are created as
1078 * concatenation of the module package (<code>basePackageName</code>) and
1079 * names of all parents node.
1081 * @param module current module
1082 * @param basePackageName
1083 * string with the module package name
1084 * @param parent parent type
1085 * @param childOf concrete parent for case child nodes
1087 * choice node which is mapped to generated type. Also child
1088 * nodes - cases are mapped to generated types.
1089 * @throws IllegalArgumentException
1091 * <li>if <code>basePackageName</code> equals null</li>
1092 * <li>if <code>choiceNode</code> equals null</li>
1096 private def void choiceToGeneratedType(Module module, String basePackageName, GeneratedTypeBuilder parent,
1097 ChoiceNode choiceNode) {
1098 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1099 checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
1101 if (!choiceNode.addedByUses) {
1102 val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
1103 val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
1104 constructGetter(parent, choiceNode.QName.localName, choiceNode.description, choiceTypeBuilder);
1105 choiceTypeBuilder.addImplementsType(DataContainer.typeForClass);
1106 genCtx.get(module).addChildNodeType(choiceNode.path, choiceTypeBuilder)
1107 generateTypesFromChoiceCases(module, basePackageName, parent, choiceTypeBuilder.toInstance, choiceNode);
1112 * Converts <code>caseNodes</code> set to list of corresponding generated
1115 * For every <i>case</i> which isn't added through augment or <i>uses</i> is
1116 * created generated type builder. The package names for the builder is
1117 * created as concatenation of the module package (
1118 * <code>basePackageName</code>) and names of all parents nodes of the
1119 * concrete <i>case</i>. There is also relation "<i>implements type</i>"
1120 * between every case builder and <i>choice</i> type
1122 * @param basePackageName
1123 * string with the module package name
1124 * @param refChoiceType
1125 * type which represents superior <i>case</i>
1127 * set of choice case nodes which are mapped to generated types
1128 * @return list of generated types for <code>caseNodes</code>.
1129 * @throws IllegalArgumentException
1131 * <li>if <code>basePackageName</code> equals null</li>
1132 * <li>if <code>refChoiceType</code> equals null</li>
1133 * <li>if <code>caseNodes</code> equals null</li>
1137 private def void generateTypesFromChoiceCases(Module module, String basePackageName,
1138 GeneratedTypeBuilder choiceParent, Type refChoiceType, ChoiceNode choiceNode) {
1139 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1140 checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
1141 checkArgument(choiceNode !== null, "ChoiceNode cannot be NULL.");
1143 val Set<ChoiceCaseNode> caseNodes = choiceNode.cases;
1144 if (caseNodes == null) {
1148 for (caseNode : caseNodes) {
1149 if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
1150 val packageName = packageNameForGeneratedType(basePackageName, caseNode.path)
1151 val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode)
1152 caseTypeBuilder.addImplementsType(refChoiceType)
1153 genCtx.get(module).addCaseType(caseNode.path, caseTypeBuilder)
1154 genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder,caseNode)
1155 val Set<DataSchemaNode> caseChildNodes = caseNode.childNodes
1156 if (caseChildNodes !== null) {
1157 var Object parentNode = null
1158 val SchemaPath nodeSp = choiceNode.path
1159 val List<QName> nodeNames = nodeSp.path
1160 val List<QName> nodeNewNames = new ArrayList(nodeNames)
1161 nodeNewNames.remove(nodeNewNames.size - 1)
1162 val SchemaPath nodeNewSp = SchemaPath.create(nodeNewNames, nodeSp.absolute)
1163 parentNode = findDataSchemaNode(schemaContext, nodeNewSp)
1165 var SchemaNode parent
1166 if (parentNode instanceof AugmentationSchema) {
1167 val augSchema = parentNode as AugmentationSchema;
1168 val targetPath = augSchema.targetPath;
1169 var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath)
1170 if (targetSchemaNode instanceof DataSchemaNode &&
1171 (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
1172 targetSchemaNode = findOriginal(targetSchemaNode as DataSchemaNode, schemaContext);
1173 if (targetSchemaNode == null) {
1174 throw new NullPointerException(
1175 "Failed to find target node from grouping for augmentation " + augSchema +
1176 " in module " + module.name);
1179 parent = targetSchemaNode
1181 val SchemaPath sp = choiceNode.path
1182 val List<QName> names = sp.path
1183 val List<QName> newNames = new ArrayList(names)
1184 newNames.remove(newNames.size - 1)
1185 val SchemaPath newSp = SchemaPath.create(newNames, sp.absolute)
1186 parent = findDataSchemaNode(schemaContext, newSp)
1188 var GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.path)
1189 resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes)
1193 processUsesAugments(caseNode, module);
1198 * Generates list of generated types for all the cases of a choice which are
1199 * added to the choice through the augment.
1202 * @param basePackageName
1203 * string contains name of package to which augment belongs. If
1204 * an augmented choice is from an other package (pcg1) than an
1205 * augmenting choice (pcg2) then case's of the augmenting choice
1206 * will belong to pcg2.
1207 * @param refChoiceType
1208 * Type which represents the choice to which case belongs. Every
1209 * case has to contain its choice in extend part.
1211 * set of choice case nodes for which is checked if are/aren't
1212 * added to choice through augmentation
1213 * @return list of generated types which represents augmented cases of
1214 * choice <code>refChoiceType</code>
1215 * @throws IllegalArgumentException
1217 * <li>if <code>basePackageName</code> equals null</li>
1218 * <li>if <code>refChoiceType</code> equals null</li>
1219 * <li>if <code>caseNodes</code> equals null</li>
1222 private def void generateTypesFromAugmentedChoiceCases(Module module, String basePackageName, Type targetType,
1223 ChoiceNode targetNode, Set<DataSchemaNode> augmentedNodes) {
1224 checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
1225 checkArgument(targetType !== null, "Referenced Choice Type cannot be NULL.");
1226 checkArgument(augmentedNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
1228 for (caseNode : augmentedNodes) {
1229 if (caseNode !== null) {
1230 val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
1231 val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
1232 caseTypeBuilder.addImplementsType(targetType);
1234 var SchemaNode parent = null
1235 val SchemaPath nodeSp = targetNode.path
1236 val List<QName> nodeNames = nodeSp.path
1237 val List<QName> nodeNewNames = new ArrayList(nodeNames)
1238 nodeNewNames.remove(nodeNewNames.size - 1)
1239 val SchemaPath nodeNewSp = SchemaPath.create(nodeNewNames, nodeSp.absolute)
1240 parent = findDataSchemaNode(schemaContext, nodeNewSp)
1242 var GeneratedTypeBuilder childOfType = null;
1243 if (parent instanceof Module) {
1244 childOfType = genCtx.get(parent as Module).moduleNode
1245 } else if (parent instanceof ChoiceCaseNode) {
1246 childOfType = findCaseByPath(parent.path)
1247 } else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
1248 childOfType = findChildNodeByPath(parent.path)
1249 } else if (parent instanceof GroupingDefinition) {
1250 childOfType = findGroupingByPath(parent.path);
1253 if (childOfType == null) {
1254 throw new IllegalArgumentException("Failed to find parent type of choice " + targetNode);
1257 var ChoiceCaseNode node = null;
1258 if (caseNode instanceof ChoiceCaseNode) {
1259 node = caseNode as ChoiceCaseNode;
1261 node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName());
1263 val Set<DataSchemaNode> childNodes = node.childNodes;
1264 if (childNodes !== null) {
1265 resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
1267 genCtx.get(module).addCaseType(caseNode.path, caseTypeBuilder)
1268 genCtx.get(module).addChoiceToCaseMapping(targetType, caseTypeBuilder,node);
1275 * Converts <code>leaf</code> to the getter method which is added to
1276 * <code>typeBuilder</code>.
1278 * @param typeBuilder
1279 * generated type builder to which is added getter method as
1280 * <code>leaf</code> mapping
1282 * leaf schema node which is mapped as getter method which is
1283 * added to <code>typeBuilder</code>
1284 * @return boolean value
1286 * <li>false - if <code>leaf</code> or <code>typeBuilder</code> are
1288 * <li>true - in other cases</li>
1291 private def Type resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) {
1292 var Type returnType = null;
1293 if ((leaf !== null) && (typeBuilder !== null)) {
1294 val leafName = leaf.QName.localName;
1295 var String leafDesc = leaf.description;
1296 if (leafDesc === null) {
1300 val parentModule = findParentModule(schemaContext, leaf);
1301 if (leafName !== null && !leaf.isAddedByUses()) {
1302 val TypeDefinition<?> typeDef = leaf.type;
1304 var GeneratedTOBuilder genTOBuilder;
1305 if (typeDef instanceof EnumTypeDefinition) {
1306 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
1307 val enumTypeDef = typeDef as EnumTypeDefinition;
1308 val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.QName, typeBuilder);
1310 if (enumBuilder !== null) {
1311 returnType = enumBuilder.toInstance(typeBuilder)
1313 (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType);
1314 } else if (typeDef instanceof UnionType) {
1315 genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
1316 if (genTOBuilder !== null) {
1317 returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule)
1319 } else if (typeDef instanceof BitsTypeDefinition) {
1320 genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
1321 if (genTOBuilder !== null) {
1322 returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
1325 val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
1326 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions);
1328 if (returnType !== null) {
1329 val MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType);
1330 processContextRefExtension(leaf, getter, parentModule);
1337 private def void processContextRefExtension(LeafSchemaNode leaf, MethodSignatureBuilder getter, Module module) {
1338 for (node : leaf.unknownSchemaNodes) {
1339 val nodeType = node.nodeType;
1340 if ("context-reference".equals(nodeType.localName)) {
1341 val nodeParam = node.nodeParameter;
1342 var IdentitySchemaNode identity = null;
1343 var String basePackageName = null;
1344 val String[] splittedElement = nodeParam.split(":");
1345 if (splittedElement.length == 1) {
1346 identity = findIdentityByName(module.identities, splittedElement.get(0));
1347 basePackageName = moduleNamespaceToPackageName(module);
1348 } else if (splittedElement.length == 2) {
1349 var prefix = splittedElement.get(0);
1350 val Module dependentModule = findModuleFromImports(module.imports, prefix)
1351 if (dependentModule == null) {
1352 throw new IllegalArgumentException(
1353 "Failed to process context-reference: unknown prefix " + prefix);
1355 identity = findIdentityByName(dependentModule.identities, splittedElement.get(1));
1356 basePackageName = moduleNamespaceToPackageName(dependentModule);
1358 throw new IllegalArgumentException(
1359 "Failed to process context-reference: unknown identity " + nodeParam);
1361 if (identity == null) {
1362 throw new IllegalArgumentException(
1363 "Failed to process context-reference: unknown identity " + nodeParam);
1366 val Class<RoutingContext> clazz = typeof(RoutingContext);
1367 val AnnotationTypeBuilder rc = getter.addAnnotation(clazz.package.name, clazz.simpleName);
1368 val packageName = packageNameForGeneratedType(basePackageName, identity.path);
1369 val genTypeName = BindingMapping.getClassName(identity.QName.localName);
1370 rc.addParameter("value", packageName + "." + genTypeName + ".class");
1375 private def IdentitySchemaNode findIdentityByName(Set<IdentitySchemaNode> identities, String name) {
1376 for (id : identities) {
1377 if (id.QName.localName.equals(name)) {
1384 private def Module findModuleFromImports(Set<ModuleImport> imports, String prefix) {
1385 for (imp : imports) {
1386 if (imp.prefix.equals(prefix)) {
1387 return schemaContext.findModuleByName(imp.moduleName, imp.revision);
1393 private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf,
1394 boolean isReadOnly, Module module) {
1395 if ((leaf !== null) && (toBuilder !== null)) {
1396 val leafName = leaf.QName.localName;
1397 var String leafDesc = leaf.description;
1398 if (leafDesc === null) {
1402 if (leafName !== null) {
1403 var Type returnType = null;
1404 val TypeDefinition<?> typeDef = leaf.type;
1405 if (typeDef instanceof UnionTypeDefinition) {
1406 // GeneratedType for this type definition should be already created
1407 var qname = typeDef.QName
1408 var Module unionModule = null
1409 if (qname.prefix == null || qname.prefix.empty) {
1410 unionModule = module
1412 unionModule = findModuleFromImports(module.imports, qname.prefix)
1414 val ModuleContext mc = genCtx.get(unionModule)
1415 returnType = mc.typedefs.get(typeDef.path)
1417 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
1419 return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly)
1426 * Converts <code>leaf</code> schema node to property of generated TO
1430 * generated TO builder to which is <code>leaf</code> added as
1433 * leaf schema node which is added to <code>toBuilder</code> as
1435 * @param returnType property type
1437 * boolean value which says if leaf property is|isn't read only
1438 * @return boolean value
1440 * <li>false - if <code>leaf</code>, <code>toBuilder</code> or leaf
1441 * name equals null or if leaf is added by <i>uses</i>.</li>
1442 * <li>true - other cases</li>
1445 private def resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf, Type returnType,
1446 boolean isReadOnly) {
1447 if (returnType == null) {
1450 val leafName = leaf.QName.localName
1451 val leafDesc = leaf.description
1452 val propBuilder = toBuilder.addProperty(parseToValidParamName(leafName));
1453 propBuilder.setReadOnly(isReadOnly);
1454 propBuilder.setReturnType(returnType);
1455 propBuilder.setComment(leafDesc);
1456 toBuilder.addEqualsIdentity(propBuilder);
1457 toBuilder.addHashIdentity(propBuilder);
1458 toBuilder.addToStringProperty(propBuilder);
1463 * Converts <code>node</code> leaf list schema node to getter method of
1464 * <code>typeBuilder</code>.
1466 * @param typeBuilder
1467 * generated type builder to which is <code>node</code> added as
1470 * leaf list schema node which is added to
1471 * <code>typeBuilder</code> as getter method
1472 * @return boolean value
1474 * <li>true - if <code>node</code>, <code>typeBuilder</code>,
1475 * nodeName equal null or <code>node</code> is added by <i>uses</i></li>
1476 * <li>false - other cases</li>
1479 private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) {
1480 if ((node !== null) && (typeBuilder !== null)) {
1481 val nodeName = node.QName;
1482 var String nodeDesc = node.description;
1483 if (nodeDesc === null) {
1486 if (nodeName !== null && !node.isAddedByUses()) {
1487 val TypeDefinition<?> typeDef = node.type;
1488 val parentModule = findParentModule(schemaContext, node);
1490 var Type returnType = null;
1491 if (typeDef instanceof EnumTypeDefinition) {
1492 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node);
1493 val enumTypeDef = typeDef as EnumTypeDefinition;
1494 val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName, typeBuilder);
1495 returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name);
1496 (typeProvider as TypeProviderImpl).putReferencedType(node.path, returnType);
1497 } else if (typeDef instanceof UnionType) {
1498 val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule);
1499 if (genTOBuilder !== null) {
1500 returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule)
1502 } else if (typeDef instanceof BitsTypeDefinition) {
1503 val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, node, parentModule);
1504 returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
1506 val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
1507 returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions);
1510 val listType = Types.listTypeFor(returnType);
1511 constructGetter(typeBuilder, nodeName.localName, nodeDesc, listType);
1518 private def Type createReturnTypeForUnion(GeneratedTOBuilder genTOBuilder, TypeDefinition<?> typeDef,
1519 GeneratedTypeBuilder typeBuilder, Module parentModule) {
1520 val GeneratedTOBuilderImpl returnType = new GeneratedTOBuilderImpl(genTOBuilder.packageName, genTOBuilder.name)
1521 genTOBuilder.setTypedef(true);
1522 genTOBuilder.setIsUnion(true);
1523 (typeProvider as TypeProviderImpl).addUnitsToGenTO(genTOBuilder, typeDef.getUnits());
1526 val GeneratedTOBuilder unionBuilder = new GeneratedTOBuilderImpl(typeBuilder.getPackageName(),
1527 genTOBuilder.getName() + "Builder");
1528 unionBuilder.setIsUnionBuilder(true);
1529 val MethodSignatureBuilder method = unionBuilder.addMethod("getDefaultInstance");
1530 method.setReturnType(returnType);
1531 method.addParameter(Types.STRING, "defaultValue");
1532 method.setAccessModifier(AccessModifier.PUBLIC);
1533 method.setStatic(true);
1535 val Set<Type> types = (typeProvider as TypeProviderImpl).additionalTypes.get(parentModule);
1536 if (types == null) {
1537 (typeProvider as TypeProviderImpl).additionalTypes.put(parentModule,
1538 Sets.newHashSet(unionBuilder.toInstance))
1540 types.add(unionBuilder.toInstance)
1542 return returnType.toInstance
1545 private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) {
1546 return addDefaultInterfaceDefinition(packageName, schemaNode, null);
1550 * Instantiates generated type builder with <code>packageName</code> and
1551 * <code>schemaNode</code>.
1553 * The new builder always implements
1554 * {@link org.opendaylight.yangtools.yang.binding.DataObject DataObject}.<br />
1555 * If <code>schemaNode</code> is instance of GroupingDefinition it also
1556 * implements {@link org.opendaylight.yangtools.yang.binding.Augmentable
1557 * Augmentable}.<br />
1558 * If <code>schemaNode</code> is instance of
1559 * {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer
1560 * DataNodeContainer} it can also implement nodes which are specified in
1563 * @param packageName
1564 * string with the name of the package to which
1565 * <code>schemaNode</code> belongs.
1567 * schema node for which is created generated type builder
1568 * @param parent parent type (can be null)
1569 * @return generated type builder <code>schemaNode</code>
1571 private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode,
1573 val it = addRawInterfaceDefinition(packageName, schemaNode, "");
1574 if (parent === null) {
1575 addImplementsType(DATA_OBJECT);
1577 addImplementsType(BindingTypes.childOf(parent));
1579 if (!(schemaNode instanceof GroupingDefinition)) {
1580 addImplementsType(augmentable(it));
1583 if (schemaNode instanceof DataNodeContainer) {
1584 addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, it);
1591 * Wraps the calling of the same overloaded method.
1593 * @param packageName
1594 * string with the package name to which returning generated type
1597 * schema node which provide data about the schema node name
1598 * @return generated type builder for <code>schemaNode</code>
1600 private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) {
1601 return addRawInterfaceDefinition(packageName, schemaNode, "");
1605 * Returns reference to generated type builder for specified
1606 * <code>schemaNode</code> with <code>packageName</code>.
1608 * Firstly the generated type builder is searched in
1609 * {@link BindingGeneratorImpl#genTypeBuilders genTypeBuilders}. If it isn't
1610 * found it is created and added to <code>genTypeBuilders</code>.
1612 * @param packageName
1613 * string with the package name to which returning generated type
1616 * schema node which provide data about the schema node name
1617 * @param prefix return type name prefix
1618 * @return generated type builder for <code>schemaNode</code>
1619 * @throws IllegalArgumentException
1621 * <li>if <code>schemaNode</code> equals null</li>
1622 * <li>if <code>packageName</code> equals null</li>
1623 * <li>if Q name of schema node is null</li>
1624 * <li>if schema node name is null</li>
1628 private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode,
1630 checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
1631 checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL.");
1632 checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL.");
1633 val schemaNodeName = schemaNode.QName.localName;
1634 checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL.");
1636 var String genTypeName;
1637 if (prefix === null) {
1638 genTypeName = BindingMapping.getClassName(schemaNodeName);
1640 genTypeName = prefix + BindingMapping.getClassName(schemaNodeName);
1643 //FIXME: Validation of name conflict
1644 val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
1645 qnameConstant(newType,BindingMapping.QNAME_STATIC_FIELD_NAME,schemaNode.QName);
1646 newType.addComment(schemaNode.getDescription());
1647 if (!genTypeBuilders.containsKey(packageName)) {
1648 val Map<String, GeneratedTypeBuilder> builders = new HashMap();
1649 builders.put(genTypeName, newType);
1650 genTypeBuilders.put(packageName, builders);
1652 val Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
1653 if (!builders.containsKey(genTypeName)) {
1654 builders.put(genTypeName, newType);
1661 * Creates the name of the getter method name from <code>localName</code>.
1664 * string with the name of the getter method
1665 * @param returnType return type
1666 * @return string with the name of the getter method for
1667 * <code>methodName</code> in JAVA method format
1669 public static def String getterMethodName(String localName, Type returnType) {
1670 val method = new StringBuilder();
1671 if (BOOLEAN.equals(returnType)) {
1672 method.append("is");
1674 method.append("get");
1676 method.append(BindingMapping.getPropertyName(localName).toFirstUpper);
1677 return method.toString();
1681 * Created a method signature builder as part of
1682 * <code>interfaceBuilder</code>.
1684 * The method signature builder is created for the getter method of
1685 * <code>schemaNodeName</code>. Also <code>comment</code> and
1686 * <code>returnType</code> information are added to the builder.
1688 * @param interfaceBuilder
1689 * generated type builder for which the getter method should be
1691 * @param schemaNodeName
1692 * string with schema node name. The name will be the part of the
1693 * getter method name.
1695 * string with comment for the getter method
1697 * type which represents the return type of the getter method
1698 * @return method signature builder which represents the getter method of
1699 * <code>interfaceBuilder</code>
1701 private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName,
1702 String comment, Type returnType) {
1703 val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType));
1704 getMethod.setComment(comment);
1705 getMethod.setReturnType(returnType);
1710 * Adds <code>schemaNode</code> to <code>typeBuilder</code> as getter method
1711 * or to <code>genTOBuilder</code> as property.
1713 * @param basePackageName
1714 * string contains the module package name
1716 * data schema node which should be added as getter method to
1717 * <code>typeBuilder</code> or as a property to
1718 * <code>genTOBuilder</code> if is part of the list key
1719 * @param typeBuilder
1720 * generated type builder for the list schema node
1721 * @param genTOBuilder
1722 * generated TO builder for the list keys
1724 * list of string which contains names of the list keys
1725 * @param module current module
1726 * @throws IllegalArgumentException
1728 * <li>if <code>schemaNode</code> equals null</li>
1729 * <li>if <code>typeBuilder</code> equals null</li>
1732 private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode,
1733 GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List<String> listKeys, Module module) {
1734 checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
1735 checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
1737 if (schemaNode instanceof LeafSchemaNode) {
1738 val leaf = schemaNode as LeafSchemaNode;
1739 val leafName = leaf.QName.localName;
1740 val Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
1741 if (listKeys.contains(leafName)) {
1743 resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true, module)
1745 resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, type, true)
1748 } else if (!schemaNode.addedByUses) {
1749 if (schemaNode instanceof LeafListSchemaNode) {
1750 resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode);
1751 } else if (schemaNode instanceof ContainerSchemaNode) {
1752 containerToGenType(module, basePackageName, typeBuilder, typeBuilder, schemaNode as ContainerSchemaNode);
1753 } else if (schemaNode instanceof ChoiceNode) {
1754 choiceToGeneratedType(module, basePackageName, typeBuilder, schemaNode as ChoiceNode);
1755 } else if (schemaNode instanceof ListSchemaNode) {
1756 listToGenType(module, basePackageName, typeBuilder, typeBuilder, schemaNode as ListSchemaNode);
1761 private def typeBuildersToGenTypes(Module module, GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
1762 checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
1764 if (genTOBuilder !== null) {
1765 val genTO = genTOBuilder.toInstance();
1766 constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO);
1767 genCtx.get(module).addGeneratedTOBuilder(genTOBuilder)
1772 * Selects the names of the list keys from <code>list</code> and returns
1773 * them as the list of the strings
1776 * of string with names of the list keys
1777 * @return list of string which represents names of the list keys. If the
1778 * <code>list</code> contains no keys then the empty list is
1781 private def listKeys(ListSchemaNode list) {
1782 val List<String> listKeys = new ArrayList();
1784 if (list.keyDefinition !== null) {
1785 val keyDefinitions = list.keyDefinition;
1786 for (keyDefinition : keyDefinitions) {
1787 listKeys.add(keyDefinition.localName);
1794 * Generates for the <code>list</code> which contains any list keys special
1795 * generated TO builder.
1797 * @param packageName
1798 * string with package name to which the list belongs
1800 * list schema node which is source of data about the list name
1801 * @return generated TO builder which represents the keys of the
1802 * <code>list</code> or null if <code>list</code> is null or list of
1803 * key definitions is null or empty.
1805 private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) {
1806 var GeneratedTOBuilder genTOBuilder = null;
1807 if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) {
1808 val listName = list.QName.localName + "Key";
1809 val String genTOName = BindingMapping.getClassName(listName);
1810 genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName);
1812 return genTOBuilder;
1816 * Builds generated TO builders for <code>typeDef</code> of type
1817 * {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or
1818 * {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
1819 * BitsTypeDefinition} which are also added to <code>typeBuilder</code> as
1820 * enclosing transfer object.
1822 * If more then one generated TO builder is created for enclosing then all
1823 * of the generated TO builders are added to <code>typeBuilder</code> as
1824 * enclosing transfer objects.
1827 * type definition which can be of type <code>UnionType</code> or
1828 * <code>BitsTypeDefinition</code>
1829 * @param typeBuilder
1830 * generated type builder to which is added generated TO created
1831 * from <code>typeDef</code>
1833 * string with name for generated TO builder
1835 * @param parentModule
1836 * @return generated TO builder for <code>typeDef</code>
1838 private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition<?> typeDef, GeneratedTypeBuilder typeBuilder,
1839 DataSchemaNode leaf, Module parentModule) {
1840 val classNameFromLeaf = BindingMapping.getClassName(leaf.QName);
1841 val List<GeneratedTOBuilder> genTOBuilders = new ArrayList();
1842 val packageName = typeBuilder.fullyQualifiedName;
1843 if (typeDef instanceof UnionTypeDefinition) {
1844 val List<GeneratedTOBuilder> types = (typeProvider as TypeProviderImpl).
1845 provideGeneratedTOBuildersForUnionTypeDef(packageName, (typeDef as UnionTypeDefinition),
1846 classNameFromLeaf, leaf);
1847 genTOBuilders.addAll(types);
1850 var GeneratedTOBuilder resultTOBuilder = null;
1851 if (!types.isEmpty()) {
1852 resultTOBuilder = types.remove(0);
1853 for (GeneratedTOBuilder genTOBuilder : types) {
1854 resultTOBuilder.addEnclosingTransferObject(genTOBuilder);
1858 val GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value");
1859 genPropBuilder.setReturnType(Types.primitiveType("char[]", null));
1860 resultTOBuilder.addEqualsIdentity(genPropBuilder);
1861 resultTOBuilder.addHashIdentity(genPropBuilder);
1862 resultTOBuilder.addToStringProperty(genPropBuilder);
1864 } else if (typeDef instanceof BitsTypeDefinition) {
1866 ((typeProvider as TypeProviderImpl) ).
1867 provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf));
1869 if (genTOBuilders !== null && !genTOBuilders.isEmpty()) {
1870 for (genTOBuilder : genTOBuilders) {
1871 typeBuilder.addEnclosingTransferObject(genTOBuilder);
1873 return genTOBuilders.get(0);
1880 * Adds the implemented types to type builder.
1882 * The method passes through the list of <i>uses</i> in
1883 * {@code dataNodeContainer}. For every <i>use</i> is obtained corresponding
1884 * generated type from {@link BindingGeneratorImpl#allGroupings
1885 * allGroupings} which is added as <i>implements type</i> to
1886 * <code>builder</code>
1888 * @param dataNodeContainer
1889 * element which contains the list of used YANG groupings
1891 * builder to which are added implemented types according to
1892 * <code>dataNodeContainer</code>
1893 * @return generated type builder with all implemented types
1895 private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) {
1896 for (usesNode : dataNodeContainer.uses) {
1897 if (usesNode.groupingPath !== null) {
1898 val genType = findGroupingByPath(usesNode.groupingPath).toInstance
1899 if (genType === null) {
1900 throw new IllegalStateException(
1901 "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name);
1903 builder.addImplementsType(genType);
1904 builder.addComment(genType.getComment());
1910 private def GeneratedTypeBuilder findChildNodeByPath(SchemaPath path) {
1911 for (ctx : genCtx.values) {
1912 var result = ctx.getChildNode(path)
1913 if (result !== null) {
1920 private def GeneratedTypeBuilder findGroupingByPath(SchemaPath path) {
1921 for (ctx : genCtx.values) {
1922 var result = ctx.getGrouping(path)
1923 if (result !== null) {
1930 private def GeneratedTypeBuilder findCaseByPath(SchemaPath path) {
1931 for (ctx : genCtx.values) {
1932 var result = ctx.getCase(path)
1933 if (result !== null) {
1940 public def getModuleContexts() {