if (!module.getChildNodes().isEmpty()) {
final GeneratedTypeBuilder moduleType = moduleToDataType(context);
context.addModuleNode(moduleType);
- resolveDataSchemaNodes(context, moduleType, moduleType, module.getChildNodes());
+ resolveDataSchemaNodes(context, moduleType, moduleType, module.getChildNodes(), false);
}
return context;
}
}
private GeneratedTypeBuilder processDataSchemaNode(final ModuleContext context, final Type baseInterface,
- final DataSchemaNode node) {
+ final DataSchemaNode node, final boolean inGrouping) {
if (node.isAugmenting() || node.isAddedByUses()) {
return null;
}
if (node instanceof DataNodeContainer) {
context.addChildNodeType(node, genType);
groupingsToGenTypes(context, ((DataNodeContainer) node).getGroupings());
- processUsesAugments((DataNodeContainer) node, context);
+ processUsesAugments((DataNodeContainer) node, context, inGrouping);
}
return genType;
}
private void containerToGenType(final ModuleContext context, final GeneratedTypeBuilder parent,
- final Type baseInterface, final ContainerSchemaNode node) {
- final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, node);
+ final Type baseInterface, final ContainerSchemaNode node, final boolean inGrouping) {
+ final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, node, inGrouping);
if (genType != null) {
constructGetter(parent, genType, node);
- resolveDataSchemaNodes(context, genType, genType, node.getChildNodes());
- actionsToGenType(context, genType, node, null);
+ resolveDataSchemaNodes(context, genType, genType, node.getChildNodes(), inGrouping);
+ actionsToGenType(context, genType, node, null, inGrouping);
}
}
private void listToGenType(final ModuleContext context, final GeneratedTypeBuilder parent,
- final Type baseInterface, final ListSchemaNode node) {
- final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, node);
+ final Type baseInterface, final ListSchemaNode node, final boolean inGrouping) {
+ final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, node, inGrouping);
if (genType != null) {
final ParameterizedType listType = listTypeFor(genType);
constructGetter(parent, listType, node);
genType.addImplementsType(identifiableMarker);
}
- actionsToGenType(context, genType, node, genTOBuilder);
+ actionsToGenType(context, genType, node, genTOBuilder, inGrouping);
for (final DataSchemaNode schemaNode : node.getChildNodes()) {
if (!schemaNode.isAugmenting()) {
- addSchemaNodeToListBuilders(context, schemaNode, genType, genTOBuilder, listKeys);
+ addSchemaNodeToListBuilders(context, schemaNode, genType, genTOBuilder, listKeys, inGrouping);
}
}
}
}
- private void processUsesAugments(final DataNodeContainer node, final ModuleContext context) {
+ private void processUsesAugments(final DataNodeContainer node, final ModuleContext context,
+ final boolean inGrouping) {
for (final UsesNode usesNode : node.getUses()) {
for (final AugmentationSchemaNode augment : usesNode.getAugmentations()) {
- usesAugmentationToGenTypes(context, augment, usesNode, node);
- processUsesAugments(augment, context);
+ usesAugmentationToGenTypes(context, augment, usesNode, node, inGrouping);
+ processUsesAugments(augment, context, inGrouping);
}
}
}
}
private <T extends DataNodeContainer & ActionNodeContainer> void actionsToGenType(final ModuleContext context,
- final Type parent, final T parentSchema, final Type keyType) {
+ final Type parent, final T parentSchema, final Type keyType, final boolean inGrouping) {
for (final ActionDefinition action : parentSchema.getActions()) {
final GeneratedType input;
final GeneratedType output;
input = context.getChildNode(orig.getInput().getPath()).build();
output = context.getChildNode(orig.getOutput().getPath()).build();
} else {
- input = actionContainer(context, RPC_INPUT, action.getInput());
- output = actionContainer(context, RPC_OUTPUT, action.getOutput());
+ input = actionContainer(context, RPC_INPUT, action.getInput(), inGrouping);
+ output = actionContainer(context, RPC_OUTPUT, action.getOutput(), inGrouping);
}
if (!(parentSchema instanceof GroupingDefinition)) {
}
private GeneratedType actionContainer(final ModuleContext context, final Type baseInterface,
- final ContainerSchemaNode schema) {
- final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, schema);
- resolveDataSchemaNodes(context, genType, genType, schema.getChildNodes());
+ final ContainerSchemaNode schema, final boolean inGrouping) {
+ final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, schema, inGrouping);
+ resolveDataSchemaNodes(context, genType, genType, schema.getChildNodes(), inGrouping);
return genType.build();
}
private Type createRpcContainer(final ModuleContext context, final String rpcName, final RpcDefinition rpc,
final ContainerSchemaNode schema, final Type type) {
- processUsesAugments(schema, context);
+ processUsesAugments(schema, context, false);
final GeneratedTypeBuilder outType = addRawInterfaceDefinition(
JavaTypeName.create(context.modulePackageName(), rpcName + BindingMapping.getClassName(schema.getQName())),
schema);
outType.addImplementsType(augmentable(outType));
defaultImplementedInterace(outType);
annotateDeprecatedIfNecessary(rpc.getStatus(), outType);
- resolveDataSchemaNodes(context, outType, outType, schema.getChildNodes());
+ resolveDataSchemaNodes(context, outType, outType, schema.getChildNodes(), false);
context.addChildNodeType(schema, outType);
return outType.build();
}
for (final NotificationDefinition notification : notifications) {
if (notification != null) {
- processUsesAugments(notification, context);
+ processUsesAugments(notification, context, false);
final GeneratedTypeBuilder notificationInterface = addDefaultInterfaceDefinition(
context.modulePackageName(), notification, DATA_OBJECT, context);
// Notification object
resolveDataSchemaNodes(context, notificationInterface, notificationInterface,
- notification.getChildNodes());
+ notification.getChildNodes(), false);
addComment(listenerInterface.addMethod("on" + notificationInterface.getName())
.setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
narrowImplementedInterface(genType);
annotateDeprecatedIfNecessary(grouping.getStatus(), genType);
context.addGroupingType(grouping, genType);
- resolveDataSchemaNodes(context, genType, genType, grouping.getChildNodes());
+ resolveDataSchemaNodes(context, genType, genType, grouping.getChildNodes(), true);
groupingsToGenTypes(context, grouping.getGroupings());
- processUsesAugments(grouping, context);
- actionsToGenType(context, genType, grouping, null);
+ processUsesAugments(grouping, context, true);
+ actionsToGenType(context, genType, grouping, null, true);
}
}
checkState(augSchema.getTargetPath() != null,
"Augmentation Schema does not contain Target Path (Target Path is NULL).");
- processUsesAugments(augSchema, context);
+ processUsesAugments(augSchema, context, false);
final SchemaPath targetPath = augSchema.getTargetPath();
SchemaNode targetSchemaNode = null;
if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
final Type targetType = new ReferencedTypeImpl(targetTypeBuilder.getIdentifier());
- addRawAugmentGenTypeDefinition(context, targetType, augSchema);
+ addRawAugmentGenTypeDefinition(context, targetType, augSchema, false);
} else {
generateTypesFromAugmentedChoiceCases(context, targetTypeBuilder.build(),
- (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(), null);
+ (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(), null, false);
}
}
private void usesAugmentationToGenTypes(final ModuleContext context, final AugmentationSchemaNode augSchema,
- final UsesNode usesNode, final DataNodeContainer usesNodeParent) {
+ final UsesNode usesNode, final DataNodeContainer usesNodeParent, final boolean inGrouping) {
checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
checkState(augSchema.getTargetPath() != null,
"Augmentation Schema does not contain Target Path (Target Path is NULL).");
- processUsesAugments(augSchema, context);
+ processUsesAugments(augSchema, context, inGrouping);
final SchemaPath targetPath = augSchema.getTargetPath();
final SchemaNode targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode);
if (targetSchemaNode == null) {
addRawAugmentGenTypeDefinition(context,
packageNameForAugmentedGeneratedType(context.modulePackageName(),
((SchemaNode) usesNodeParent).getPath()),
- targetTypeBuilder.build(), augSchema);
+ targetTypeBuilder.build(), augSchema, inGrouping);
} else {
- addRawAugmentGenTypeDefinition(context, targetTypeBuilder.build(), augSchema);
+ addRawAugmentGenTypeDefinition(context, targetTypeBuilder.build(), augSchema, inGrouping);
}
} else {
generateTypesFromAugmentedChoiceCases(context, targetTypeBuilder.build(),
- (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(), usesNodeParent);
+ (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes(), usesNodeParent, inGrouping);
}
}
*/
private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(final ModuleContext context,
final String augmentPackageName, final Type targetTypeRef,
- final AugmentationSchemaNode augSchema) {
+ final AugmentationSchemaNode augSchema, final boolean inGrouping) {
Map<String, GeneratedTypeBuilder> augmentBuilders =
genTypeBuilders.computeIfAbsent(augmentPackageName, k -> new HashMap<>());
final String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes());
annotateDeprecatedIfNecessary(augSchema.getStatus(), augTypeBuilder);
addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
- augSchemaNodeToMethods(context, augTypeBuilder, augSchema.getChildNodes());
+ augSchemaNodeToMethods(context, augTypeBuilder, augSchema.getChildNodes(), inGrouping);
augmentBuilders.put(augTypeName, augTypeBuilder);
if (!augSchema.getChildNodes().isEmpty()) {
}
private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(final ModuleContext context, final Type targetTypeRef,
- final AugmentationSchemaNode augSchema) {
- return addRawAugmentGenTypeDefinition(context, context.modulePackageName(), targetTypeRef, augSchema);
+ final AugmentationSchemaNode augSchema, final boolean inGrouping) {
+ return addRawAugmentGenTypeDefinition(context, context.modulePackageName(), targetTypeRef, augSchema,
+ inGrouping);
}
private static String getAugmentIdentifier(final List<UnknownSchemaNode> unknownSchemaNodes) {
* child nodes) could be added to it.
*/
private GeneratedTypeBuilder resolveDataSchemaNodes(final ModuleContext context, final GeneratedTypeBuilder parent,
- final @Nullable Type childOf, final Iterable<DataSchemaNode> schemaNodes) {
+ final @Nullable Type childOf, final Iterable<DataSchemaNode> schemaNodes, final boolean inGrouping) {
if (schemaNodes != null && parent != null) {
final Type baseInterface = childOf == null ? DATA_OBJECT : childOf(childOf);
for (final DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
- addSchemaNodeToBuilderAsMethod(context, schemaNode, parent, baseInterface);
+ addSchemaNodeToBuilderAsMethod(context, schemaNode, parent, baseInterface, inGrouping);
}
}
}
* The getter method could be added to it.
*/
private GeneratedTypeBuilder augSchemaNodeToMethods(final ModuleContext context,
- final GeneratedTypeBuilder typeBuilder, final Iterable<DataSchemaNode> schemaNodes) {
+ final GeneratedTypeBuilder typeBuilder, final Iterable<DataSchemaNode> schemaNodes,
+ final boolean inGrouping) {
if (schemaNodes != null && typeBuilder != null) {
final Type baseInterface = childOf(typeBuilder);
for (final DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting()) {
- addSchemaNodeToBuilderAsMethod(context, schemaNode, typeBuilder, baseInterface);
+ addSchemaNodeToBuilderAsMethod(context, schemaNode, typeBuilder, baseInterface, inGrouping);
}
}
}
* @param module current module
*/
private void addSchemaNodeToBuilderAsMethod(final ModuleContext context, final DataSchemaNode node,
- final GeneratedTypeBuilder typeBuilder, final Type baseInterface) {
+ final GeneratedTypeBuilder typeBuilder, final Type baseInterface, final boolean inGrouping) {
if (node != null && typeBuilder != null) {
if (node instanceof LeafSchemaNode) {
- resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) node, context);
+ resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) node, context, inGrouping);
} else if (node instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node, context);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) node, context, inGrouping);
} else if (node instanceof ContainerSchemaNode) {
- containerToGenType(context, typeBuilder, baseInterface, (ContainerSchemaNode) node);
+ containerToGenType(context, typeBuilder, baseInterface, (ContainerSchemaNode) node, inGrouping);
} else if (node instanceof ListSchemaNode) {
- listToGenType(context, typeBuilder, baseInterface, (ListSchemaNode) node);
+ listToGenType(context, typeBuilder, baseInterface, (ListSchemaNode) node, inGrouping);
} else if (node instanceof ChoiceSchemaNode) {
- choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) node);
+ choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) node, inGrouping);
} else {
// TODO: anyxml not yet supported
LOG.debug("Unable to add schema node {} as method in {}: unsupported type of node.", node.getClass(),
* </ul>
*/
private void choiceToGeneratedType(final ModuleContext context, final GeneratedTypeBuilder parent,
- final ChoiceSchemaNode choiceNode) {
+ final ChoiceSchemaNode choiceNode, final boolean inGrouping) {
checkArgument(choiceNode != null, "Choice Schema Node cannot be NULL.");
if (!choiceNode.isAddedByUses()) {
context.addChildNodeType(choiceNode, choiceTypeBuilder);
final GeneratedType choiceType = choiceTypeBuilder.build();
- generateTypesFromChoiceCases(context, choiceType, choiceNode);
+ generateTypesFromChoiceCases(context, choiceType, choiceNode, inGrouping);
constructGetter(parent, choiceType, choiceNode);
}
* </ul>
*/
private void generateTypesFromChoiceCases(final ModuleContext context, final Type refChoiceType,
- final ChoiceSchemaNode choiceNode) {
+ final ChoiceSchemaNode choiceNode, final boolean inGrouping) {
checkArgument(refChoiceType != null, "Referenced Choice Type cannot be NULL.");
checkArgument(choiceNode != null, "ChoiceNode cannot be NULL.");
if (childOfType == null) {
childOfType = findGroupingByPath(parent.getPath());
}
- resolveDataSchemaNodes(context, caseTypeBuilder, childOfType, caseChildNodes);
+ resolveDataSchemaNodes(context, caseTypeBuilder, childOfType, caseChildNodes, inGrouping);
} else {
- resolveDataSchemaNodes(context, caseTypeBuilder, moduleToDataType(context), caseChildNodes);
+ resolveDataSchemaNodes(context, caseTypeBuilder, moduleToDataType(context), caseChildNodes,
+ inGrouping);
}
}
}
- processUsesAugments(caseNode, context);
+ processUsesAugments(caseNode, context, inGrouping);
}
}
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private void generateTypesFromAugmentedChoiceCases(final ModuleContext context,
final Type targetType, final ChoiceSchemaNode targetNode, final Iterable<DataSchemaNode> augmentedNodes,
- final DataNodeContainer usesNodeParent) {
+ final DataNodeContainer usesNodeParent, final boolean inGrouping) {
checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
}
final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
if (childNodes != null) {
- resolveDataSchemaNodes(context, caseTypeBuilder, findChildOfType(targetNode), childNodes);
+ resolveDataSchemaNodes(context, caseTypeBuilder, findChildOfType(targetNode), childNodes,
+ inGrouping);
}
context.addCaseType(caseNode.getPath(), caseTypeBuilder);
context.addChoiceToCaseMapping(targetType, caseTypeBuilder, node);
* </ul>
*/
private Type resolveLeafSchemaNodeAsMethod(final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf,
- final ModuleContext context) {
+ final ModuleContext context, final boolean inGrouping) {
if (leaf == null || typeBuilder == null || leaf.isAddedByUses()) {
return null;
}
final TypeDefinition<?> typeDef = CompatUtils.compatLeafType(leaf);
if (isInnerType(leaf, typeDef)) {
if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, inGrouping);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
typeBuilder, context);
// and apply restrictions from leaf type
final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
returnType = typeProvider.javaTypeForSchemaDefinitionType(getBaseOrDeclaredType(typeDef), leaf,
- restrictions);
+ restrictions, inGrouping);
addPatternConstant(typeBuilder, leaf.getQName().getLocalName(), restrictions.getPatternConstraints());
}
} else {
final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions, inGrouping);
addPatternConstant(typeBuilder, leaf.getQName().getLocalName(), restrictions.getPatternConstraints());
}
* </ul>
*/
private boolean resolveLeafListSchemaNode(final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node,
- final ModuleContext context) {
+ final ModuleContext context, final boolean inGrouping) {
if (node == null || typeBuilder == null || node.isAddedByUses()) {
return false;
}
Type returnType = null;
if (typeDef.getBaseType() == null) {
if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, inGrouping);
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, nodeName,
typeBuilder, context);
returnType = genTOBuilder.build();
} else {
final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions, inGrouping);
addPatternConstant(typeBuilder, node.getQName().getLocalName(), restrictions.getPatternConstraints());
}
} else {
final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, node, restrictions, inGrouping);
addPatternConstant(typeBuilder, node.getQName().getLocalName(), restrictions.getPatternConstraints());
}
*/
private void addSchemaNodeToListBuilders(final ModuleContext context, final DataSchemaNode schemaNode,
final GeneratedTypeBuilder typeBuilder, final GeneratedTOBuilder genTOBuilder,
- final List<String> listKeys) {
+ final List<String> listKeys, final boolean inGrouping) {
checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
checkArgument(typeBuilder != null, "Generated Type Builder cannot be NULL.");
if (schemaNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) schemaNode;
final String leafName = leaf.getQName().getLocalName();
- Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf, context);
+ Type type = resolveLeafSchemaNodeAsMethod(typeBuilder, leaf, context, inGrouping);
if (listKeys.contains(leafName)) {
if (type == null) {
resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
}
} else if (!schemaNode.isAddedByUses()) {
if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode, context);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode, context, inGrouping);
} else if (schemaNode instanceof ContainerSchemaNode) {
containerToGenType(context, typeBuilder, childOf(typeBuilder),
- (ContainerSchemaNode) schemaNode);
+ (ContainerSchemaNode) schemaNode, inGrouping);
} else if (schemaNode instanceof ChoiceSchemaNode) {
- choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) schemaNode);
+ choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) schemaNode, inGrouping);
} else if (schemaNode instanceof ListSchemaNode) {
- listToGenType(context, typeBuilder, childOf(typeBuilder), (ListSchemaNode) schemaNode);
+ listToGenType(context, typeBuilder, childOf(typeBuilder), (ListSchemaNode) schemaNode, inGrouping);
}
}
}
*/
package org.opendaylight.mdsal.binding.yang.types;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.TYPE_OBJECT;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
}
@Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
- return javaTypeForSchemaDefinitionType(typeDefinition, parentNode, null);
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
+ final boolean lenientRelativeLeafrefs) {
+ return javaTypeForSchemaDefinitionType(typeDefinition, parentNode, null, lenientRelativeLeafrefs);
}
/**
*/
@Override
public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
- final Restrictions restrictions) {
+ final Restrictions restrictions, final boolean lenientRelativeLeafrefs) {
Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
Preconditions.checkArgument(typeDefinition.getQName() != null,
"Type Definition cannot have non specified QName (QName cannot be NULL!)");
// a base type which holds these constraints.
if (typeDefinition instanceof DecimalTypeDefinition) {
final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition,
- parentNode, restrictions);
+ parentNode, restrictions, lenientRelativeLeafrefs);
if (ret != null) {
return ret;
}
}
// Deal with leafrefs/identityrefs
- Type ret = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode);
+ Type ret = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode, lenientRelativeLeafrefs);
if (ret != null) {
return ret;
}
return ret;
}
- Type returnType = javaTypeForExtendedType(typeDefinition);
+ Type returnType = javaTypeForExtendedType(typeDefinition, lenientRelativeLeafrefs);
if (restrictions != null && returnType instanceof GeneratedTransferObject) {
final GeneratedTransferObject gto = (GeneratedTransferObject) returnType;
final Module module = findParentModule(schemaContext, parentNode);
* @param typeDefinition type definition which is converted to JAVA <code>Type</code>
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
- private Type javaTypeForLeafrefOrIdentityRef(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
+ private Type javaTypeForLeafrefOrIdentityRef(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
+ final boolean inGrouping) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
Preconditions.checkArgument(!isLeafRefSelfReference(leafref, parentNode),
"Leafref %s is referencing itself, incoming StackOverFlowError detected.", leafref);
- return provideTypeForLeafref(leafref, parentNode);
+ return provideTypeForLeafref(leafref, parentNode, inGrouping);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
return provideTypeForIdentityref((IdentityrefTypeDefinition) typeDefinition);
}
* @param typeDefinition type definition which is converted to JAVA <code>Type</code>
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
- private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition) {
+ private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition, final boolean lenient) {
final String typedefName = typeDefinition.getQName().getLocalName();
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
- Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition);
+ Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition, lenient);
if (returnType == null) {
if (baseTypeDef instanceof EnumTypeDefinition) {
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
}
if (returnType == null) {
returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
- baseTypeDef, typeDefinition, r);
+ baseTypeDef, typeDefinition, r, lenient);
}
}
}
* to find referenced node and its <code>Type</code> is returned.
*
* @param leafrefType leafref type definition for which is the type sought
+ * @param parentNode parent node of the leaf being resolved
+ * @param inGrouping true if we are resolving the type within a grouping.
* @return JAVA <code>Type</code> of data schema node which is referenced in <code>leafrefType</code>
* @throws IllegalArgumentException
* <ul>
* <li>if <code>leafrefType</code> equal null</li>
* <li>if path statement of <code>leafrefType</code> equal null</li>
* </ul>
- *
*/
- public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode) {
+ public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode,
+ final boolean inGrouping) {
Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
- Preconditions.checkArgument(leafrefType.getPathStatement() != null,
- "The Path Statement for Leafref Type Definition cannot be NULL!");
final RevisionAwareXPath xpath = leafrefType.getPathStatement();
- final String strXPath = xpath.toString();
- Type returnType = null;
+ Preconditions.checkArgument(xpath != null, "The Path Statement for Leafref Type Definition cannot be NULL!");
- if (strXPath != null) {
- if (strXPath.indexOf('[') == -1) {
- final Module module = findParentModule(schemaContext, parentNode);
- Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
+ final String strXPath = verifyNotNull(xpath.toString());
+ if (strXPath.indexOf('[') != -1) {
+ // XXX: why are we special-casing this?
+ return Types.objectType();
+ }
- final SchemaNode dataNode;
- if (xpath.isAbsolute()) {
- dataNode = findDataSchemaNode(schemaContext, module, xpath);
- } else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
- }
- Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
- strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule());
-
- // FIXME: this block seems to be some weird magic hack. Analyze and refactor it.
- if (leafContainsEnumDefinition(dataNode)) {
- returnType = referencedTypes.get(dataNode.getPath());
- } else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
- }
- if (returnType == null) {
- returnType = resolveTypeFromDataSchemaNode(dataNode);
- }
- } else {
- returnType = Types.objectType();
+ final Module module = findParentModule(schemaContext, parentNode);
+ Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
+
+ final SchemaNode dataNode;
+ if (xpath.isAbsolute()) {
+ dataNode = findDataSchemaNode(schemaContext, module, xpath);
+ } else {
+ dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+ if (dataNode == null && inGrouping) {
+ // Relative path within a grouping may end up being unresolvable because it may refer outside
+ // the grouping, in which case it is polymorphic based on instantiation, for example:
+ //
+ // grouping foo {
+ // leaf foo {
+ // type leafref {
+ // path "../../bar";
+ // }
+ // }
+ // }
+ //
+ // container one {
+ // leaf bar {
+ // type string;
+ // }
+ // uses foo;
+ // }
+ //
+ // container two {
+ // leaf bar {
+ // type uint16;
+ // }
+ // uses foo;
+ // }
+ LOG.debug("Leafref type {} not found in parent {}, assuming polymorphic object", leafrefType,
+ parentNode);
+ return Types.objectType();
}
}
+ Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
+ strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule());
+
+ // FIXME: this block seems to be some weird magic hack. Analyze and refactor it.
+ Type returnType = null;
+ if (leafContainsEnumDefinition(dataNode)) {
+ returnType = referencedTypes.get(dataNode.getPath());
+ } else if (leafListContainsEnumDefinition(dataNode)) {
+ returnType = Types.listTypeFor(referencedTypes.get(dataNode.getPath()));
+ }
+ if (returnType == null) {
+ returnType = resolveTypeFromDataSchemaNode(dataNode);
+ }
Preconditions.checkArgument(returnType != null, "Failed to find leafref target: %s in module %s (%s)",
strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule(), this);
return returnType;