import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate;
import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import org.opendaylight.yangtools.yang.model.util.UnionType;
import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
processUsesAugments(notification, module);
final GeneratedTypeBuilder notificationInterface = addDefaultInterfaceDefinition(basePackageName,
- notification, BindingTypes.DATA_OBJECT, module);
+ notification, null, module);
notificationInterface.addImplementsType(NOTIFICATION);
genCtx.get(module).addChildNodeType(notification, notificationInterface);
* builder
* @param typeBuilder
* GeneratedTypeBuilder to which will be enum builder assigned
+ * @param module
+ * Module in which type should be generated
* @return enumeration builder which contains data from
* <code>enumTypeDef</code>
*/
private EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final QName enumName,
- final GeneratedTypeBuilder typeBuilder) {
+ final GeneratedTypeBuilder typeBuilder, Module module) {
if ((enumTypeDef != null) && (typeBuilder != null) && (enumTypeDef.getQName() != null)
&& (enumTypeDef.getQName().getLocalName() != null)) {
final String enumerationName = BindingMapping.getClassName(enumName);
final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);
enumBuilder.setDescription(enumTypeDef.getDescription());
enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
+ ModuleContext ctx = genCtx.get(module);
+ ctx.addInnerTypedefType(enumTypeDef.getPath(), enumBuilder);
return enumBuilder;
}
return null;
final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf, final Module module) {
if (node != null && typeBuilder != null) {
if (node instanceof LeafSchemaNode) {
- resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) node);
+ resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) node, module);
} else if (node instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node,module);
} else if (node instanceof ContainerSchemaNode) {
containerToGenType(module, basePackageName, typeBuilder, childOf, (ContainerSchemaNode) node);
} else if (node instanceof ListSchemaNode) {
genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
if (caseChildNodes != null) {
- final SchemaPath nodeSp = choiceNode.getPath();
- final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
-
- SchemaNode parent;
- if (parentNode instanceof AugmentationSchema) {
- final AugmentationSchema augSchema = (AugmentationSchema) parentNode;
- final SchemaPath targetPath = augSchema.getTargetPath();
- SchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
- if (targetSchemaNode instanceof DataSchemaNode
- && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
- if (targetSchemaNode instanceof DerivableSchemaNode) {
- targetSchemaNode = ((DerivableSchemaNode) targetSchemaNode).getOriginal().orNull();
- }
- if (targetSchemaNode == null) {
- throw new IllegalStateException(
- "Failed to find target node from grouping for augmentation " + augSchema
- + " in module " + module.getName());
+ final SchemaPath choiceNodeParentPath = choiceNode.getPath().getParent();
+
+ if (!Iterables.isEmpty(choiceNodeParentPath.getPathFromRoot())) {
+ SchemaNode parent = findDataSchemaNode(schemaContext, choiceNodeParentPath);
+
+ if (parent instanceof AugmentationSchema) {
+ final AugmentationSchema augSchema = (AugmentationSchema) parent;
+ final SchemaPath targetPath = augSchema.getTargetPath();
+ SchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
+ if (targetSchemaNode instanceof DataSchemaNode
+ && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
+ if (targetSchemaNode instanceof DerivableSchemaNode) {
+ targetSchemaNode = ((DerivableSchemaNode) targetSchemaNode).getOriginal().orNull();
+ }
+ if (targetSchemaNode == null) {
+ throw new IllegalStateException(
+ "Failed to find target node from grouping for augmentation " + augSchema
+ + " in module " + module.getName());
+ }
}
+ parent = targetSchemaNode;
}
- parent = targetSchemaNode;
- } else {
- final SchemaPath sp = choiceNode.getPath();
- parent = findDataSchemaNode(schemaContext, sp.getParent());
- }
- Preconditions.checkState(parent != null, "Could not find Choice node parent "+choiceNode.getPath().getParent());
- GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
- if (childOfType == null) {
- childOfType = findGroupingByPath(parent.getPath());
- }
- resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
- }
+
+ Preconditions.checkState(parent != null, "Could not find Choice node parent %s",
+ choiceNodeParentPath);
+ GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
+ if (childOfType == null) {
+ childOfType = findGroupingByPath(parent.getPath());
+ }
+ resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
+ } else
+ resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, moduleToDataType(module),
+ caseChildNodes);
+ }
}
processUsesAugments(caseNode, module);
}
* @param leaf
* leaf schema node which is mapped as getter method which is
* added to <code>typeBuilder</code>
+ * @param module
+ * Module in which type was defined
* @return boolean value
* <ul>
* <li>false - if <code>leaf</code> or <code>typeBuilder</code> are
* <li>true - in other cases</li>
* </ul>
*/
- private Type resolveLeafSchemaNodeAsMethod(final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) {
+ private Type resolveLeafSchemaNodeAsMethod(final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf, Module module) {
Type returnType = null;
if ((leaf != null) && (typeBuilder != null)) {
final String leafName = leaf.getQName().getLocalName();
returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
- typeBuilder);
+ typeBuilder,module);
if (enumBuilder != null) {
returnType = enumBuilder.toInstance(typeBuilder);
if (leafDesc == null) {
leafDesc = "";
}
-
- if (leafName != null) {
- Type returnType = null;
- final TypeDefinition<?> typeDef = leaf.getType();
- if (typeDef instanceof UnionTypeDefinition) {
- // GeneratedType for this type definition should be already
- // created
- final QName qname = typeDef.getQName();
- final Module unionModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
- qname.getRevision());
- final ModuleContext mc = genCtx.get(unionModule);
- returnType = mc.getTypedefs().get(typeDef.getPath());
- } else {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
- }
- return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly);
+ Type returnType = null;
+ final TypeDefinition<?> typeDef = leaf.getType();
+ if (typeDef instanceof UnionTypeDefinition) {
+ // GeneratedType for this type definition should be already
+ // created
+ final QName qname = typeDef.getQName();
+ final Module unionModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
+ qname.getRevision());
+ final ModuleContext mc = genCtx.get(unionModule);
+ returnType = mc.getTypedefs().get(typeDef.getPath());
+ } else if (typeDef instanceof EnumTypeDefinition && BaseTypes.ENUMERATION_QNAME.equals(typeDef.getQName())) {
+ // Annonymous enumeration (already generated, since it is inherited via uses).
+ LeafSchemaNode originalLeaf = (LeafSchemaNode) SchemaNodeUtils.getRootOriginalIfPossible(leaf);
+ QName qname = originalLeaf.getQName();
+ final Module enumModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
+ qname.getRevision());
+ returnType = genCtx.get(enumModule).getInnerType(originalLeaf.getType().getPath());
+ } else {
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
}
+ return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly);
}
return false;
}
* @param node
* leaf list schema node which is added to
* <code>typeBuilder</code> as getter method
+ * @param module
* @return boolean value
* <ul>
* <li>true - if <code>node</code>, <code>typeBuilder</code>,
* <li>false - other cases</li>
* </ul>
*/
- private boolean resolveLeafListSchemaNode(final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node) {
+ private boolean resolveLeafListSchemaNode(final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node, Module module) {
if ((node != null) && (typeBuilder != null)) {
final QName nodeName = node.getQName();
returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName,
- typeBuilder);
+ typeBuilder,module);
returnType = new ReferencedTypeImpl(enumBuilder.getPackageName(), enumBuilder.getName());
((TypeProviderImpl) typeProvider).putReferencedType(node.getPath(), returnType);
} else if (typeDef instanceof UnionType) {
if (schemaNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) schemaNode;
final String leafName = leaf.getQName().getLocalName();
- final Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
+ final Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf,module);
if (listKeys.contains(leafName)) {
if (type == null) {
resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true, module);
}
} else if (!schemaNode.isAddedByUses()) {
if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode, module);
} else if (schemaNode instanceof ContainerSchemaNode) {
containerToGenType(module, basePackageName, typeBuilder, typeBuilder, (ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ChoiceSchemaNode) {