These paths are not full XPaths, but rather SchemaNodeIdentifier paths.
Do not attempt to compile them, as we validate them by splitting and
look up of individual components.
Change-Id: If472ff6a2c795ce810794ad64dc643bf10a24199
Signed-off-by: Robert Varga <rovarga@cisco.com>
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import com.google.common.base.Preconditions;
import java.util.Collection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class AugmentStatementImpl extends
- AbstractDeclaredStatement<SchemaNodeIdentifier> implements
- AugmentStatement {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(AugmentStatementImpl.class);
+public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
+ private static final Logger LOG = LoggerFactory.getLogger(AugmentStatementImpl.class);
+ private static final Pattern PATH_REL_PATTERN1 = Pattern.compile("\\.\\.?\\s*/(.+)");
+ private static final Pattern PATH_REL_PATTERN2 = Pattern.compile("//.*");
- protected AugmentStatementImpl(
- StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
+ protected AugmentStatementImpl(final StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
super(context);
}
- public static class Definition
- extends
+ public static class Definition extends
AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
public Definition() {
}
@Override
- public SchemaNodeIdentifier parseArgumentValue(
- StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return SchemaNodeIdentifier.create(
- AugmentUtils.parseAugmentPath(ctx, value),
- Utils.isXPathAbsolute(ctx, value));
+ public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ Preconditions.checkArgument(!PATH_REL_PATTERN1.matcher(value).matches()
+ && !PATH_REL_PATTERN2.matcher(value).matches(),
+ "An argument for augment can be only absolute path; or descendant if used in uses");
+
+ return Utils.nodeIdentifierFromPath(ctx, value);
}
@Override
public AugmentStatement createDeclared(
- StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
+ final StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
return new AugmentStatementImpl(ctx);
}
@Override
public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
- StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
+ final StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
return new AugmentEffectiveStatementImpl(ctx);
}
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
public final class AugmentUtils {
private static final Logger LOG = LoggerFactory.getLogger(AugmentUtils.class);
- private static final Pattern PATH_REL_PATTERN1 = Pattern.compile("\\.\\.?\\s*/(.+)");
- private static final Pattern PATH_REL_PATTERN2 = Pattern.compile("//.*");
private AugmentUtils() {
throw new UnsupportedOperationException();
}
- public static Iterable<QName> parseAugmentPath(final StmtContext<?, ?, ?> ctx, final String path) {
- Preconditions.checkArgument(!PATH_REL_PATTERN1.matcher(path).matches()
- && !PATH_REL_PATTERN2.matcher(path).matches(),
- "An argument for augment can be only absolute path; or descendant if used in uses");
-
- return Utils.parseXPath(ctx, path);
- }
-
public static void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceCtx,
final StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviationEffectiveStatementImpl;
-
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviationEffectiveStatementImpl;
public class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements DeviationStatement {
- protected DeviationStatementImpl(
- StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
+ protected DeviationStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
super(context);
}
super(Rfc6020Mapping.DEVIATION);
}
- @Override public SchemaNodeIdentifier parseArgumentValue(
- StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
+ @Override
+ public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ return Utils.nodeIdentifierFromPath(ctx, value);
}
- @Override public DeviationStatement createDeclared(
- StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+ @Override
+ public DeviationStatement createDeclared(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
return new DeviationStatementImpl(ctx);
}
- @Override public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
- StmtContext<SchemaNodeIdentifier, DeviationStatement, EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
+ @Override
+ public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
+ final StmtContext<SchemaNodeIdentifier, DeviationStatement, EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
return new DeviationEffectiveStatementImpl(ctx);
}
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RefineEffectiveStatementImpl;
-
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RefineEffectiveStatementImpl;
public class RefineStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements RefineStatement {
- protected RefineStatementImpl(
- StmtContext<SchemaNodeIdentifier, RefineStatement, ?> context) {
+ protected RefineStatementImpl(final StmtContext<SchemaNodeIdentifier, RefineStatement, ?> context) {
super(context);
}
}
@Override
- public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
- return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
+ public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ return Utils.nodeIdentifierFromPath(ctx, value);
}
@Override
- public RefineStatement createDeclared(StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
+ public RefineStatement createDeclared(final StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
return new RefineStatementImpl(ctx);
}
@Override
- public EffectiveStatement<SchemaNodeIdentifier, RefineStatement> createEffective(StmtContext<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> ctx) {
+ public EffectiveStatement<SchemaNodeIdentifier, RefineStatement> createEffective(
+ final StmtContext<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> ctx) {
return new RefineEffectiveStatementImpl(ctx);
}
}
return keyNodes;
}
- public static List<String> splitPathToNodeNames(final String path) {
- return SLASH_SPLITTER.splitToList(path);
- }
-
private static void compileXPath(final StmtContext<?, ?, ?> ctx, final String path) {
final XPath xPath = XPATH_FACTORY.get().newXPath();
return false;
}
- public static Iterable<QName> parseXPath(final StmtContext<?, ?, ?> ctx, final String path) {
-
- String trimmedPath = trimSingleLastSlashFromXPath(path);
-
- compileXPath(ctx, trimmedPath);
-
- List<String> nodeNames = splitPathToNodeNames(trimmedPath);
- List<QName> qNames = new ArrayList<>(nodeNames.size());
-
- for (String nodeName : nodeNames) {
+ static SchemaNodeIdentifier nodeIdentifierFromPath(final StmtContext<?, ?, ?> ctx, final String path) {
+ // FIXME: is the path trimming really necessary??
+ final List<QName> qNames = new ArrayList<>();
+ for (String nodeName : SLASH_SPLITTER.split(trimSingleLastSlashFromXPath(path))) {
try {
final QName qName = Utils.qNameFromArgument(ctx, nodeName);
qNames.add(qName);
} catch (Exception e) {
- throw new IllegalArgumentException(e);
+ throw new IllegalArgumentException(
+ String.format("Failed to parse node '%s' in path '%s'", nodeName, path), e);
}
}
- return qNames;
+ return SchemaNodeIdentifier.create(qNames, PATH_ABS.matcher(path).matches());
}
public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {