*/
package org.opendaylight.yangtools.yang.data.impl.leafref;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.PathExpression;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
this.schemaContext = schemaContext;
}
- LeafRefContext buildLeafRefContextTree() throws IOException, LeafRefYangSyntaxErrorException {
+ LeafRefContext buildLeafRefContextTree() throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder rootBuilder = new LeafRefContextBuilder(schemaContext.getQName(),
schemaContext.getPath(), schemaContext);
return rootBuilder.build();
}
- private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule)
- throws IOException, LeafRefYangSyntaxErrorException {
+ private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final Module currentModule) {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
}
} else if (node instanceof TypedDataSchemaNode) {
- final TypeDefinition<?> type = ((TypedDataSchemaNode) node).getType();
+ final TypedDataSchemaNode typedNode = (TypedDataSchemaNode) node;
+ final TypeDefinition<?> type = typedNode.getType();
// FIXME: fix case when type is e.g. typedef -> typedef -> leafref
if (type instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
- final String leafRefPathString = leafrefType.getPathStatement().toString();
+ final PathExpression path = leafrefType.getPathStatement();
+ final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
+ final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(path);
- currentLeafRefContextBuilder.setLeafRefTargetPathString(leafRefPathString);
+ currentLeafRefContextBuilder.setLeafRefTargetPathString(path.getOriginalString());
currentLeafRefContextBuilder.setReferencing(true);
-
- final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(schemaContext,
- checkNotNull(getBaseTypeModule(leafrefType), "Unable to find base module for leafref %s", node),
- node);
-
- final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPathSourceToSchemaPath(
- new ByteArrayInputStream(leafRefPathString.getBytes(StandardCharsets.UTF_8)));
-
currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
return currentLeafRefContextBuilder.build();
}
- private Module getBaseTypeModule(final LeafrefTypeDefinition leafrefType) {
- /*
- * Find the first definition of supplied leafref type and return the
- * module which contains this definition.
- */
- LeafrefTypeDefinition baseLeafRefType = leafrefType;
- while (baseLeafRefType.getBaseType() != null) {
- baseLeafRefType = baseLeafRefType.getBaseType();
- }
- return schemaContext.findModule(baseLeafRefType.getQName().getModule()).orElse(null);
- }
-
private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule)
- throws IOException,LeafRefYangSyntaxErrorException {
+ throws LeafRefYangSyntaxErrorException {
final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(),
node.getPath(), schemaContext);
if (node instanceof DataNodeContainer) {