import java.util.ArrayList;
import java.util.List;
-
-import javax.annotation.concurrent.Immutable;
-
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.antlr.v4.runtime.tree.ParseTree;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParserBaseListener;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+
+import javax.annotation.concurrent.Immutable;
@Immutable
public class YangStatementParserListenerImpl extends YangStatementParserBaseListener {
public YangStatementParserListenerImpl(String sourceName) {
this.sourceName = sourceName;
- // TODO
- // this.sourceName = Preconditions.checkNotNull(sourceName, "YangStatementParserListenerImpl#sourceName cannot "
- // + "be null");
}
public void setAttributes(StatementWriter writer, QNameToStatementDefinition stmtDef) {
@Override
public void enterStatement(YangStatementParser.StatementContext ctx) {
- final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine());
+ final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx
+ .getStart().getLine(), ctx.getStart().getCharPositionInLine());
boolean action = true;
QName identifier;
for (int i = 0; i < ctx.getChildCount(); i++) {
try {
identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
((YangStatementParser.KeywordContext) child).children.get(0).getText());
- if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier)
- && toBeSkipped.isEmpty()) {
+ if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
if (identifier.equals(Rfc6020Mapping.TYPE.getStatementName())) {
isType = true;
} else {
}
} else {
if (writer.getPhase().equals(ModelProcessingPhase.FULL_DECLARATION)) {
- throw new IllegalArgumentException(identifier.getLocalName() + " is not a YANG statement "
- + "or use of extension. Source: " + ref);
- }
- else {
+ throw new IllegalArgumentException(identifier.getLocalName() + " is not a YANG statement " +
+ "or use of extension. Source: " + ref);
+ } else {
action = false;
toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
}
try {
final String argument = Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child);
if (isType) {
- if (TypeUtils.isYangTypeBodyStmt(argument)) {
- writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, argument), ref);
- } else {
- writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, Rfc6020Mapping.TYPE
- .getStatementName().getLocalName()), ref);
- }
+ if (TypeUtils.isYangTypeBodyStmtString(argument)) {
+ writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, argument), ref);
+ } else {
+ writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, Rfc6020Mapping
+ .TYPE.getStatementName().getLocalName()), ref);
+ }
writer.argumentValue(argument, ref);
isType = false;
} else if (action) {
- writer.argumentValue(
- Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
+ writer.argumentValue(Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
} else {
action = true;
}
@Override
public void exitStatement(YangStatementParser.StatementContext ctx) {
- final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine());
+ final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(), ctx
+ .getStart().getCharPositionInLine());
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof YangStatementParser.KeywordContext) {
try {
String statementName = ((YangStatementParser.KeywordContext) child).children.get(0).getText();
QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE, statementName);
- if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier)
- && toBeSkipped.isEmpty()) {
+ if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
writer.endStatement(ref);
}
ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION, ADDED_BY_USES_AUGMENTATION
}
- TypeOfCopy getTypeOfCopy();
+ List<TypeOfCopy> getCopyHistory();
- void setTypeOfCopy(TypeOfCopy typeOfCopy);
+ void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList);
+
+ void addToCopyHistory(TypeOfCopy typeOfCopy);
StatementContextBase<?, ?, ?> getOriginalCtx();
boolean isRootContext();
+ void setOrder(int order);
+
+ int getOrder();
+
void setCompletedPhase(ModelProcessingPhase completedPhase);
ModelProcessingPhase getCompletedPhase();
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
+import org.opendaylight.yangtools.yang.common.QName;
import com.google.common.base.Splitter;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import java.util.HashSet;
+import java.util.Set;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
+import com.google.common.base.Predicate;
+import java.util.Collection;
+import com.google.common.base.Function;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
public final class StmtContextUtils {
public static final char LIST_KEY_SEPARATOR = ' ';
private static final Splitter KEY_SPLITTER = Splitter.on(LIST_KEY_SEPARATOR).omitEmptyStrings().trimResults();
- private static final Function<StmtContext<?, ?, ?>, DeclaredStatement<?>> BUILD_DECLARED = new Function<StmtContext<?, ?, ?>, DeclaredStatement<?>>() {
+ private static final Function<StmtContext<?, ?,?>, DeclaredStatement<?>> BUILD_DECLARED = new Function<StmtContext<?,?,?>, DeclaredStatement<?>>() {
@Override
public DeclaredStatement<?> apply(final StmtContext<?, ?, ?> input) {
return input.buildDeclared();
}
};
- private static final Function<StmtContext<?, ?, ?>, EffectiveStatement<?, ?>> BUILD_EFFECTIVE = new Function<StmtContext<?, ?, ?>, EffectiveStatement<?, ?>>() {
+ private static final Function<StmtContext<?, ?,?>, EffectiveStatement<?,?>> BUILD_EFFECTIVE = new Function<StmtContext<?,?,?>, EffectiveStatement<?,?>>() {
@Override
public EffectiveStatement<?, ?> apply(final StmtContext<?, ?, ?> input) {
return input.buildEffective();
}
};
- public static final Predicate<StmtContext<?, ?, ?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?, ?, ?>>() {
+ public static final Predicate<StmtContext<?, ?,?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?,?,?>>() {
@Override
public boolean apply(StmtContext<?, ?, ?> input) {
return input.isSupportedToBuildEffective();
@SuppressWarnings("unchecked")
public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
- final Iterable<? extends StmtContext<?, ?, ?>> contexts, final Class<DT> declaredType) {
+ final Iterable<? extends StmtContext<?, ?, ?>> contexts,
+ final Class<DT> declaredType) {
for (StmtContext<?, ?, ?> ctx : contexts) {
if (producesDeclared(ctx, declaredType)) {
return (AT) ctx.getStatementArgument();
}
@SuppressWarnings("unchecked")
- public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(final StmtContext<?, ?, ?> ctx,
- final Class<DT> declaredType) {
+ public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
+ final StmtContext<?, ?, ?> ctx, final Class<DT> declaredType) {
if (producesDeclared(ctx, declaredType)) {
return (AT) ctx.getStatementArgument();
}
@SuppressWarnings("unchecked")
- public static final <AT, DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
+ public static final <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
StmtContext<?, ?, ?> stmtContext, Class<DT> declaredType) {
- Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
- if (producesDeclared(subStmtContext, declaredType)) {
+ if (producesDeclared(subStmtContext,declaredType)) {
return (StmtContext<AT, ?, ?>) subStmtContext;
}
}
return null;
}
- public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(final StmtContext<?, ?, ?> stmtContext,
- int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
+ public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
+ final StmtContext<?, ?, ?> stmtContext, int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
if (startIndex >= types.length) {
return null;
}
- Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
- if (producesDeclared(subStmtContext, types[startIndex])) {
+ if (producesDeclared(subStmtContext,types[startIndex])) {
if (startIndex + 1 == types.length) {
return subStmtContext;
} else {
- return findFirstDeclaredSubstatement(subStmtContext, ++startIndex, types);
+ return findFirstDeclaredSubstatement(subStmtContext,
+ ++startIndex, types);
}
}
}
}
public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatementOnSublevel(
- final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType, int sublevel) {
- Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+ final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType,
+ int sublevel) {
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
- if (sublevel == 1 && producesDeclared(subStmtContext, declaredType)) {
+ if (sublevel == 1 && producesDeclared(subStmtContext,declaredType)) {
return subStmtContext;
} else {
if (sublevel > 1) {
- StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(subStmtContext, declaredType,
- --sublevel);
+ StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(
+ subStmtContext, declaredType, --sublevel);
if (result != null) {
return result;
}
public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findDeepFirstDeclaredSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
- if (producesDeclared(subStmtContext, declaredType)) {
+ if (producesDeclared(subStmtContext,declaredType)) {
return subStmtContext;
} else {
- StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(subStmtContext, declaredType);
+ StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(
+ subStmtContext, declaredType);
if (result != null) {
return result;
}
public static final boolean producesDeclared(final StmtContext<?, ?, ?> ctx,
final Class<? extends DeclaredStatement<?>> type) {
- return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
+ return type.isAssignableFrom(ctx.getPublicDefinition()
+ .getDeclaredRepresentationClass());
}
- public static boolean isInExtensionBody(StmtContext<?, ?, ?> stmtCtx) {
+ public static boolean isInExtensionBody(
+ StmtContext<?,?,?> stmtCtx) {
- StmtContext<?, ?, ?> current = stmtCtx;
- while (!current.getParentContext().isRootContext()) {
+ StmtContext<?,?,?> current = stmtCtx;
+ while(!current.getParentContext().isRootContext()) {
current = current.getParentContext();
- if (producesDeclared(current, UnknownStatementImpl.class)) {
+ if(producesDeclared(current, UnknownStatementImpl.class)) {
return true;
}
}
}
public static boolean isUnknownStatement(StmtContext<?, ?, ?> stmtCtx) {
- return producesDeclared(stmtCtx, UnknownStatementImpl.class);
- }
-
- public static Set<TypeOfCopy> getCopyTypesFromOriginal(StmtContext<?, ?, ?> ctx) {
-
- Set<TypeOfCopy> copyTypesFromOriginal = new HashSet<>();
- StmtContext<?, ?, ?> current = ctx;
-
- while (current.getOriginalCtx() != null) {
- copyTypesFromOriginal.add(current.getTypeOfCopy());
- current = current.getOriginalCtx();
+ if (producesDeclared(stmtCtx, UnknownStatementImpl.class)) {
+ return true;
+ } else {
+ return false;
}
-
- return copyTypesFromOriginal;
}
- public static Collection<SchemaNodeIdentifier> replaceModuleQNameForKey(
- StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx, QNameModule newQNameModule) {
+ public static Collection<SchemaNodeIdentifier> replaceModuleQNameForKey(StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx,
+ QNameModule newQNameModule) {
List<String> keyTokens = KEY_SPLITTER.splitToList(keyStmtCtx.rawStatementArgument());
for (String keyToken : keyTokens) {
QName keyQName = QName.create(newQNameModule, keyToken);
- SchemaNodeIdentifier keyIdentifier = SchemaNodeIdentifier.create(false, keyQName);
+ SchemaNodeIdentifier keyIdentifier = SchemaNodeIdentifier
+ .create(false, keyQName);
newKeys.add(keyIdentifier);
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.spi.source;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface StmtOrderingNamespace extends
+ IdentifierNamespace<Rfc6020Mapping, Integer> {
+
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
-import java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
import com.google.common.collect.ImmutableMap;
return context.buildEffective();
}
+ public SchemaContext buildEffective(List<InputStream> yangInputStreams) throws SourceException, ReactorException {
+
+ for(InputStream yangInputStream : yangInputStreams) {
+ addSource(new YangStatementSourceImpl(yangInputStream));
+ }
+
+ return buildEffective();
+ }
+
}
public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy) throws SourceException {
RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
- copy.setTypeOfCopy(typeOfCopy);
- copy.setOriginalCtx(this);
+
+ copy.addAllToCopyHistory(this.getCopyHistory());
+ copy.addToCopyHistory(typeOfCopy);
+
+ if(this.getOriginalCtx() != null) {
+ copy.setOriginalCtx(this.getOriginalCtx());
+ } else {
+ copy.setOriginalCtx(this);
+ }
+
return copy;
}
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.BinarySpecificationImpl;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import com.google.common.base.Preconditions;
return new StatementDefinitionContext<>(new IdentityRefSpecificationImpl.Definition());
case TypeUtils.INSTANCE_IDENTIFIER:
return new StatementDefinitionContext<>(new InstanceIdentifierSpecificationImpl.Definition());
- case TypeUtils.BINARY:
- return new StatementDefinitionContext<>(new BinarySpecificationImpl.Definition());
default:
return null;
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import java.util.LinkedList;
+
+import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.HashMultimap;
private final StatementDefinitionContext<A, D, E> definition;
private final StatementIdentifier identifier;
private final StatementSourceReference statementDeclSource;
+ private int order = 0;
private Map<StatementIdentifier, StatementContextBase<?, ?, ?>> substatements = new LinkedHashMap<>();
private E effectiveInstance;
private StatementContextBase<?, ?, ?> originalCtx;
- private TypeOfCopy typeOfCopy = TypeOfCopy.ORIGINAL;
+ private List<TypeOfCopy> copyHistory;
private boolean isSupportedToBuildEffective = true;
}
@Override
- public TypeOfCopy getTypeOfCopy() {
- return typeOfCopy;
+ public List<TypeOfCopy> getCopyHistory() {
+ return copyHistory;
+ }
+
+ @Override
+ public void addToCopyHistory(TypeOfCopy typeOfCopy) {
+ this.copyHistory.add(typeOfCopy);
}
@Override
- public void setTypeOfCopy(TypeOfCopy typeOfCopy) {
- this.typeOfCopy = typeOfCopy;
+ public void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList) {
+ this.copyHistory.addAll(typeOfCopyList);
}
@Override
this.originalCtx = originalCtx;
}
+ @Override
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ @Override
+ public int getOrder() {
+ return order;
+ }
+
@Override
public ModelProcessingPhase getCompletedPhase() {
return completedPhase;
this.identifier = builder.createIdentifier();
this.statementDeclSource = builder.getStamementSource();
this.completedPhase = null;
+ initCopyHistory();
}
StatementContextBase(StatementContextBase<A, D, E> original) {
this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource,
"Statement context statementDeclSource cannot be null");
this.completedPhase = null;
+ initCopyHistory();
+ }
+
+ private void initCopyHistory() {
+ this.copyHistory = new LinkedList<>();
+ this.copyHistory.add(TypeOfCopy.ORIGINAL);
}
/**
throws SourceException {
SubstatementContext<A, D, E> copy = new SubstatementContext<>(this,
newQNameModule, newParent, typeOfCopy);
- copy.setTypeOfCopy(typeOfCopy);
- copy.setOriginalCtx(this);
+
+ copy.addAllToCopyHistory(this.getCopyHistory());
+ copy.addToCopyHistory(typeOfCopy);
+
+ if(this.getOriginalCtx() != null) {
+ copy.setOriginalCtx(this.getOriginalCtx());
+ } else {
+ copy.setOriginalCtx(this);
+ }
+
return copy;
}
*/
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 java.util.Collection;
import org.slf4j.Logger;
StmtContext<?, ?, ?> ctx, String value) throws SourceException {
return SchemaNodeIdentifier.create(
AugmentUtils.parseAugmentPath(ctx, value),
- Utils.isXPathAbsolute(value));
+ Utils.isXPathAbsolute(ctx, value));
}
@Override
final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
throws SourceException {
- if(StmtContextUtils.isInExtensionBody(augmentNode)) {
+ if (StmtContextUtils.isInExtensionBody(augmentNode)) {
return;
}
.getAugmentTargetCtx(augmentNode);
if (augmentTargetCtx == null) {
- throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
+ throw new InferenceException(
+ "Augment target not found: "
+ + augmentNode.getStatementArgument(),
+ augmentNode.getStatementSourceReference());
}
if (StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
augmentNode.setIsSupportedToBuildEffective(false);
try {
AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
augmentTargetCtx);
- augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx);
+ augmentTargetCtx
+ .addEffectiveSubstatement(augmentSourceCtx);
+ updateAugmentOrder(augmentSourceCtx);
} catch (SourceException e) {
LOG.warn(e.getMessage(), e);
}
}
+ private void updateAugmentOrder(
+ final StatementContextBase<?, ?, ?> augmentSourceCtx) {
+ Integer currentOrder = augmentSourceCtx
+ .getFromNamespace(StmtOrderingNamespace.class,
+ Rfc6020Mapping.AUGMENT);
+ if (currentOrder == null) {
+ currentOrder = 1;
+ } else {
+ currentOrder++;
+ }
+ augmentSourceCtx.setOrder(currentOrder);
+ augmentSourceCtx.addToNs(StmtOrderingNamespace.class,
+ Rfc6020Mapping.AUGMENT, currentOrder);
+ }
+
@Override
public void prerequisiteFailed(
final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
throws InferenceException {
- throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
- augmentNode.getStatementSourceReference());
+ throw new InferenceException("Augment target not found: "
+ + augmentNode.getStatementArgument(), augmentNode
+ .getStatementSourceReference());
}
});
}
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
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.DerivedIdentitiesNamespace;
-import java.util.LinkedList;
-import java.util.List;
import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
final QName baseIdentityQName = baseStmtCtx.getStatementArgument();
ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(ModelProcessingPhase.STATEMENT_DEFINITION);
final Prerequisite<StmtContext<?, ?, ?>> requiresPrereq = baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName, ModelProcessingPhase.STATEMENT_DEFINITION);
- final Prerequisite<?> mutatesPrereq = baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
+ final Prerequisite<StmtContext.Mutable<?, ?, ?>> mutatesPrereq = baseIdentityAction.mutatesCtx
+ (baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
baseIdentityAction.apply( new InferenceAction() {
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-
-import javax.annotation.Nonnull;
-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.LengthStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
-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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
-
-public class BinarySpecificationImpl extends AbstractDeclaredStatement<String> implements
- TypeStatement.BinarySpecification {
-
- protected BinarySpecificationImpl(StmtContext<String, ?, ?> context) {
- super(context);
- }
-
- public static class Definition extends
- AbstractStatementSupport<String, BinarySpecification, EffectiveStatement<String, BinarySpecification>> {
-
- public Definition() {
- super(Rfc6020Mapping.TYPE);
- }
-
- @Override
- public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return value;
- }
-
- @Override
- public BinarySpecification createDeclared(StmtContext<String, BinarySpecification, ?> ctx) {
- return new BinarySpecificationImpl(ctx);
- }
-
- @Override
- public EffectiveStatement<String, BinarySpecification> createEffective(
- StmtContext<String, BinarySpecification, EffectiveStatement<String, BinarySpecification>> ctx) {
- return new BinaryEffectiveStatementImpl(ctx);
- }
- }
-
- @Nullable
- @Override
- public LengthStatement getLength() {
- return firstDeclared(LengthStatement.class);
- }
-
- @Nonnull
- @Override
- public String getName() {
- return argument();
- }
-}
@Override public SchemaNodeIdentifier parseArgumentValue(
StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+ return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
}
@Override public DeviationStatement createDeclared(
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
+import java.util.Set;
+
+import java.util.Map.Entry;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import com.google.common.base.Optional;
import java.net.URI;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ImportEffectiveStatementImpl;
-public class ImportStatementDefinition extends
+public class ImportStatementDefinition
+ extends
AbstractStatementSupport<String, ImportStatement, EffectiveStatement<String, ImportStatement>> {
public ImportStatementDefinition() {
}
@Override
- public ImportStatement createDeclared(StmtContext<String, ImportStatement, ?> ctx) {
+ public ImportStatement createDeclared(
+ StmtContext<String, ImportStatement, ?> ctx) {
return new ImportStatementImpl(ctx);
}
final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
throws SourceException {
final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt);
- ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
+ ModelActionBuilder importAction = stmt
+ .newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> imported;
final Prerequisite<Mutable<?, ?, ?>> linkageTarget;
- imported = importAction.requiresCtx(stmt, ModuleNamespace.class, impIdentifier, SOURCE_LINKAGE);
+ imported = importAction.requiresCtx(stmt, ModuleNamespace.class,
+ impIdentifier, SOURCE_LINKAGE);
linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
- String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
- stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, impIdentifier);
-
importAction.apply(new InferenceAction() {
@Override
public void apply() throws InferenceException {
- StmtContext<?, ?, ?> importedModule = imported.get();
- linkageTarget.get().addToNs(ImportedModuleContext.class, impIdentifier, importedModule);
+ StmtContext<?, ?, ?> importedModule = null;
+ ModuleIdentifier importedModuleIdentifier = null;
+ if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) {
+ Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> recentModuleEntry = findRecentModule(
+ impIdentifier,
+ stmt.getAllFromNamespace(ModuleNamespace.class));
+ if (recentModuleEntry != null) {
+ importedModuleIdentifier = recentModuleEntry.getKey();
+ importedModule = recentModuleEntry.getValue();
+ }
+ }
+
+ if(importedModule == null || importedModuleIdentifier == null) {
+ importedModule = imported.get();
+ importedModuleIdentifier = impIdentifier;
+ }
+
+ linkageTarget.get().addToNs(ImportedModuleContext.class,
+ importedModuleIdentifier, importedModule);
+ String impPrefix = firstAttributeOf(stmt.declaredSubstatements(),
+ PrefixStatement.class);
+ stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix,
+ importedModuleIdentifier);
+ }
+
+ private Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> findRecentModule(
+ ModuleIdentifier impIdentifier,
+ Map<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> allModules) {
+
+ ModuleIdentifier recentModuleIdentifier = impIdentifier;
+ Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> recentModuleEntry = null;
+
+ Set<Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>>> moduleEntrySet = allModules
+ .entrySet();
+ for (Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> moduleEntry : moduleEntrySet) {
+ if (moduleEntry.getKey().getName()
+ .equals(impIdentifier.getName())
+ && moduleEntry
+ .getKey()
+ .getRevision()
+ .compareTo(
+ recentModuleIdentifier
+ .getRevision()) > 0) {
+ recentModuleIdentifier = moduleEntry.getKey();
+ recentModuleEntry = moduleEntry;
+ }
+ }
+
+ return recentModuleEntry;
}
@Override
- public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
+ public void prerequisiteFailed(
+ Collection<? extends Prerequisite<?>> failed)
+ throws InferenceException {
if (failed.contains(imported)) {
- throw new InferenceException(String.format("Imported module [%s] was not found.", impIdentifier),
- stmt.getStatementSourceReference());
+ throw new InferenceException(String.format(
+ "Imported module [%s] was not found.",
+ impIdentifier), stmt.getStatementSourceReference());
}
}
});
}
- private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt)
- throws SourceException {
+ private static ModuleIdentifier getImportedModuleIdentifier(
+ Mutable<String, ImportStatement, ?> stmt) throws SourceException {
String moduleName = stmt.getStatementArgument();
- Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
+ Date revision = firstAttributeOf(stmt.declaredSubstatements(),
+ RevisionDateStatement.class);
if (revision == null) {
revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
}
- return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(), Optional.<Date> of(revision));
+ return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(),
+ Optional.<Date> of(revision));
}
}
\ No newline at end of file
@Override public RevisionAwareXPath parseArgumentValue(
StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+ return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
}
@Override public MustStatement createDeclared(
@Override
public RevisionAwareXPath parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+ return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
}
@Override
@Override
public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+ return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
}
@Override
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
+
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ExtendedTypeEffectiveStatementImpl;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
return new BooleanEffectiveStatementImpl(ctx);
case TypeUtils.EMPTY:
return new EmptyEffectiveStatementImpl(ctx);
+ case TypeUtils.BINARY:
+ return new BinaryEffectiveStatementImpl(ctx);
default:
// :FIXME try to resolve original typedef context here and
// return buildEffective of original typedef context
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
public static final String UINT64 = "uint64";
public static final String UNION = "union";
- private static final ImmutableSet<String> BUILT_IN_TYPES = initBuiltInTypesSet();
- private static final ImmutableSet<String> TYPE_BODY_STMTS = initTypeBodyStmtsSet();
- private static final ImmutableMap<String, TypeDefinition> BASE_TYPES_MAP = initBaseTypesMap();
+ private static final Set<String> BUILT_IN_TYPES = new HashSet<>();
+ public static final Set<String> TYPE_BODY_STMTS = new HashSet<>();
+ public static final Map<String, TypeDefinition<?>> PRIMITIVE_TYPES_MAP = new HashMap<>();
private static final Comparator<TypeDefinition<?>> TYPE_SORT_COMPARATOR = new Comparator<TypeDefinition<?>>() {
@Override
return 0;
}
};
-
- private static ImmutableSet<String> initBuiltInTypesSet() {
-
- final Set<String> builtInTypesInit = new HashSet<>();
- builtInTypesInit.add(BINARY);
- builtInTypesInit.add(BITS);
- builtInTypesInit.add(BOOLEAN);
- builtInTypesInit.add(DECIMAL64);
- builtInTypesInit.add(EMPTY);
- builtInTypesInit.add(ENUMERATION);
- builtInTypesInit.add(IDENTITY_REF);
- builtInTypesInit.add(INSTANCE_IDENTIFIER);
- builtInTypesInit.add(INT8);
- builtInTypesInit.add(INT16);
- builtInTypesInit.add(INT32);
- builtInTypesInit.add(INT64);
- builtInTypesInit.add(LEAF_REF);
- builtInTypesInit.add(STRING);
- builtInTypesInit.add(UINT8);
- builtInTypesInit.add(UINT16);
- builtInTypesInit.add(UINT32);
- builtInTypesInit.add(UINT64);
- builtInTypesInit.add(UNION);
-
- return ImmutableSet.copyOf(builtInTypesInit);
- }
-
- private static ImmutableSet<String> initTypeBodyStmtsSet() {
-
- final Set<String> typeBodyStmtsInit = new HashSet<>();
- typeBodyStmtsInit.add(DECIMAL64);
- typeBodyStmtsInit.add(ENUMERATION);
- typeBodyStmtsInit.add(LEAF_REF);
- typeBodyStmtsInit.add(IDENTITY_REF);
- typeBodyStmtsInit.add(INSTANCE_IDENTIFIER);
- typeBodyStmtsInit.add(BITS);
- typeBodyStmtsInit.add(UNION);
- typeBodyStmtsInit.add(BINARY);
-
- return ImmutableSet.copyOf(typeBodyStmtsInit);
- }
-
- private static ImmutableMap<String, TypeDefinition> initBaseTypesMap() {
-
- final Map<String, TypeDefinition> baseTypesMapInit = new HashMap<>();
- baseTypesMapInit.put(BINARY, BinaryType.getInstance());
- baseTypesMapInit.put(BOOLEAN, BooleanType.getInstance());
- baseTypesMapInit.put(EMPTY, EmptyType.getInstance());
- baseTypesMapInit.put(INT8, Int8.getInstance());
- baseTypesMapInit.put(INT16, Int16.getInstance());
- baseTypesMapInit.put(INT32, Int32.getInstance());
- baseTypesMapInit.put(INT64, Int64.getInstance());
- baseTypesMapInit.put(STRING, StringType.getInstance());
- baseTypesMapInit.put(UINT8, Uint8.getInstance());
- baseTypesMapInit.put(UINT16, Uint16.getInstance());
- baseTypesMapInit.put(UINT32, Uint32.getInstance());
- baseTypesMapInit.put(UINT64, Uint64.getInstance());
-
- return ImmutableMap.copyOf(baseTypesMapInit);
+ static {
+
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BINARY));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BITS));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BOOLEAN));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,DECIMAL64));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,EMPTY));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,ENUMERATION));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,IDENTITY_REF));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INSTANCE_IDENTIFIER));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT8));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT16));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT32));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT64));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,LEAF_REF));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,STRING));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT8));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT16));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT32));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT64));
+// BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UNION));
+
+ BUILT_IN_TYPES.add(BINARY);
+ BUILT_IN_TYPES.add(BITS);
+ BUILT_IN_TYPES.add(BOOLEAN);
+ BUILT_IN_TYPES.add(DECIMAL64);
+ BUILT_IN_TYPES.add(EMPTY);
+ BUILT_IN_TYPES.add(ENUMERATION);
+ BUILT_IN_TYPES.add(IDENTITY_REF);
+ BUILT_IN_TYPES.add(INSTANCE_IDENTIFIER);
+ BUILT_IN_TYPES.add(INT8);
+ BUILT_IN_TYPES.add(INT16);
+ BUILT_IN_TYPES.add(INT32);
+ BUILT_IN_TYPES.add(INT64);
+ BUILT_IN_TYPES.add(LEAF_REF);
+ BUILT_IN_TYPES.add(STRING);
+ BUILT_IN_TYPES.add(UINT8);
+ BUILT_IN_TYPES.add(UINT16);
+ BUILT_IN_TYPES.add(UINT32);
+ BUILT_IN_TYPES.add(UINT64);
+ BUILT_IN_TYPES.add(UNION);
+
+ TYPE_BODY_STMTS.add(DECIMAL64);
+ TYPE_BODY_STMTS.add(ENUMERATION);
+ TYPE_BODY_STMTS.add(LEAF_REF);
+ TYPE_BODY_STMTS.add(IDENTITY_REF);
+ TYPE_BODY_STMTS.add(INSTANCE_IDENTIFIER);
+ TYPE_BODY_STMTS.add(BITS);
+ TYPE_BODY_STMTS.add(UNION);
+
+ PRIMITIVE_TYPES_MAP.put(BINARY, BinaryType.getInstance());
+ PRIMITIVE_TYPES_MAP.put(BOOLEAN, BooleanType.getInstance());
+ PRIMITIVE_TYPES_MAP.put(EMPTY, EmptyType.getInstance());
+ PRIMITIVE_TYPES_MAP.put(INT8, Int8.getInstance());
+ PRIMITIVE_TYPES_MAP.put(INT16, Int16.getInstance());
+ PRIMITIVE_TYPES_MAP.put(INT32, Int32.getInstance());
+ PRIMITIVE_TYPES_MAP.put(INT64, Int64.getInstance());
+ PRIMITIVE_TYPES_MAP.put(STRING, StringType.getInstance());
+ PRIMITIVE_TYPES_MAP.put(UINT8, Uint8.getInstance());
+ PRIMITIVE_TYPES_MAP.put(UINT16, Uint16.getInstance());
+ PRIMITIVE_TYPES_MAP.put(UINT32, Uint32.getInstance());
+ PRIMITIVE_TYPES_MAP.put(UINT64, Uint64.getInstance());
}
private TypeUtils() {
}
}
- private static int compareNumbers(Number n1, Number n2) {
+ public static int compareNumbers(Number n1, Number n2) {
final BigDecimal num1 = yangConstraintToBigDecimal(n1);
final BigDecimal num2 = yangConstraintToBigDecimal(n2);
return rangeConstraints;
}
- public static boolean isYangBaseTypeString(String typeName) {
+ public static boolean isBuiltInType(TypeDefinition<?> o1) {
+ return BUILT_IN_TYPES.contains(o1.getQName().getLocalName());
+ }
+
+ public static boolean isYangBuiltInTypeString(String typeName) {
return BUILT_IN_TYPES.contains(typeName);
}
- public static boolean isYangTypeBodyStmt(String typeName) {
+ public static boolean isYangPrimitiveTypeString(String typeName) {
+ return PRIMITIVE_TYPES_MAP.containsKey(typeName);
+ }
+
+ public static boolean isYangTypeBodyStmtString(String typeName) {
return TYPE_BODY_STMTS.contains(typeName);
}
+ public static TypeDefinition<?> getYangPrimitiveTypeFromString(String typeName) {
+ if (PRIMITIVE_TYPES_MAP.containsKey(typeName)) {
+ return PRIMITIVE_TYPES_MAP.get(typeName);
+ }
+ return null;
+ }
+
public static TypeDefinition<?> getTypeFromEffectiveStatement(EffectiveStatement<?, ?> effectiveStatement) {
if (effectiveStatement instanceof TypeDefinitionEffectiveBuilder) {
TypeDefinitionEffectiveBuilder typeDefEffectiveBuilder = (TypeDefinitionEffectiveBuilder) effectiveStatement;
return typeDefEffectiveBuilder.buildType();
} else {
- final String typeName = ((TypeDefinition) effectiveStatement).getQName().getLocalName();
- return BASE_TYPES_MAP.get(typeName);
- }
- }
-
- public static TypeDefinition<?> getYangBaseTypeFromString(String typeName) {
-
- if (BASE_TYPES_MAP.containsKey(typeName)) {
- return BASE_TYPES_MAP.get(typeName);
+ final String typeName = ((TypeDefinition<?>) effectiveStatement).getQName().getLocalName();
+ return PRIMITIVE_TYPES_MAP.get(typeName);
}
-
- return null;
}
public static void sortTypes(List<TypeDefinition<?>> typesInit) {
Collections.sort(typesInit, TYPE_SORT_COMPARATOR);
}
- public static boolean isBuiltInType(TypeDefinition<?> o1) {
- return BUILT_IN_TYPES.contains(o1.getQName().getLocalName());
- }
}
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
+
import javax.annotation.Nullable;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+
import org.antlr.v4.runtime.tree.TerminalNode;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relative;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
- private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher
- .is('\'');
+ private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
public static final QName EMPTY_QNAME = QName.create("empty", "empty");
private Utils() {
}
- public static Collection<SchemaNodeIdentifier.Relative> transformKeysStringToKeyNodes(StmtContext<?, ?, ?> ctx, String
- value) {
+ public static Collection<SchemaNodeIdentifier.Relative> transformKeysStringToKeyNodes(StmtContext<?, ?, ?> ctx,
+ String value) {
Splitter keySplitter = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults();
List<String> keyTokens = keySplitter.splitToList(value);
for (String keyToken : keyTokens) {
- SchemaNodeIdentifier.Relative keyNode = (Relative) SchemaNodeIdentifier.Relative
- .create(false, Utils.qNameFromArgument(ctx, keyToken));
+ SchemaNodeIdentifier.Relative keyNode = (Relative) SchemaNodeIdentifier.Relative.create(false,
+ Utils.qNameFromArgument(ctx, keyToken));
keyNodes.add(keyNode);
}
public static List<String> splitPathToNodeNames(String path) {
- Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME)
- .omitEmptyStrings().trimResults();
+ Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
return keySplitter.splitToList(path);
}
- public static void validateXPath(String path) {
+ public static void validateXPath(final StmtContext<?, ?, ?> ctx, String path) {
final XPath xPath = XPathFactory.newInstance().newXPath();
try {
xPath.compile(path);
} catch (XPathExpressionException e) {
- throw new IllegalArgumentException(
- "Argument is not valid XPath string", e);
+ throw new IllegalArgumentException(String.format("Argument %s is not valid XPath string at %s", path, ctx
+ .getStatementSourceReference().toString()), e);
}
}
- public static boolean isXPathAbsolute(String path) {
+ private static String trimSingleLastSlashFromXPath(final String path) {
+ return path.replaceAll("/$", "");
+ }
- validateXPath(path);
+ public static boolean isXPathAbsolute(final StmtContext<?, ?, ?> ctx, String path) {
+
+ validateXPath(ctx, trimSingleLastSlashFromXPath(path));
return path.matches(REGEX_PATH_ABS);
}
return null;
}
- public static boolean isValidStatementDefinition(PrefixToModule prefixes,
- QNameToStatementDefinition stmtDef, QName identifier) {
+ public static boolean isValidStatementDefinition(PrefixToModule prefixes, QNameToStatementDefinition stmtDef,
+ QName identifier) {
if (stmtDef.get(identifier) != null) {
return true;
} else {
if (namesParts.length == 2) {
String prefix = namesParts[0];
String localName = namesParts[1];
- if (prefixes != null
- && prefixes.get(prefix) != null
- && stmtDef
- .get(new QName(
- YangConstants.RFC6020_YIN_NAMESPACE,
- localName)) != null) {
+ if (prefixes != null && prefixes.get(prefix) != null
+ && stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
return true;
} else {
- if (stmtDef.get(new QName(
- YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
+ if (stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
return true;
}
}
return false;
}
- public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx,
- String path) {
+ public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
+
+ String trimmedPath = trimSingleLastSlashFromXPath(path);
- validateXPath(path);
+ validateXPath(ctx, trimmedPath);
- List<String> nodeNames = splitPathToNodeNames(path);
+ List<String> nodeNames = splitPathToNodeNames(trimmedPath);
List<QName> qNames = new ArrayList<>();
for (String nodeName : nodeNames) {
return qNames;
}
- public static String stringFromStringContext(
- final YangStatementParser.ArgumentContext context) {
+ public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
StringBuilder sb = new StringBuilder();
List<TerminalNode> strings = context.STRING();
if (strings.isEmpty()) {
prefix = namesParts[0];
localName = namesParts[1];
qNameModule = getModuleQNameByPrefix(ctx, prefix);
- //in case of unknown statement argument, we're not going to parse it
- if (qNameModule == null && ctx.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom
- (UnknownStatementImpl.class)) {
+ // in case of unknown statement argument, we're not going to parse it
+ if (qNameModule == null
+ && ctx.getPublicDefinition().getDeclaredRepresentationClass()
+ .isAssignableFrom(UnknownStatementImpl.class)) {
localName = value;
qNameModule = getRootModuleQName(ctx);
}
- //:FIXME test and verify this...
- if(qNameModule == null && ctx.getTypeOfCopy() == StmtContext.TypeOfCopy.ADDED_BY_AUGMENTATION) {
+ if (qNameModule == null
+ && Iterables.getLast(ctx.getCopyHistory()) == StmtContext.TypeOfCopy.ADDED_BY_AUGMENTATION) {
ctx = ctx.getOriginalCtx();
qNameModule = getModuleQNameByPrefix(ctx, prefix);
}
}
if (qNameModule == null) {
- throw new IllegalArgumentException("Error in module '"
- + ctx.getRoot().rawStatementArgument()
+ throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument()
+ "': can not resolve QNameModule for '" + value + "'.");
}
- QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule
- .create(qNameModule.getNamespace(),
- SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
+ QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule.create(
+ qNameModule.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
return QName.create(resultQNameModule, localName);
}
- public static QNameModule getModuleQNameByPrefix(StmtContext<?, ?, ?> ctx,
- String prefix) {
+ public static QNameModule getModuleQNameByPrefix(StmtContext<?, ?, ?> ctx, String prefix) {
QNameModule qNameModule;
- ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(
- ImpPrefixToModuleIdentifier.class, prefix);
- qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class,
- impModIdentifier);
-
- if (qNameModule == null
- && StmtContextUtils.producesDeclared(ctx.getRoot(),
- SubmoduleStatement.class)) {
- String moduleName = ctx.getRoot().getFromNamespace(
- BelongsToPrefixToModuleName.class, prefix);
- qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class,
- moduleName);
+ ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(ImpPrefixToModuleIdentifier.class, prefix);
+ qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class, impModIdentifier);
+
+ if (qNameModule == null && StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
+ String moduleName = ctx.getRoot().getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
+ qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
}
return qNameModule;
}
QNameModule qNameModule = null;
if (StmtContextUtils.producesDeclared(rootCtx, ModuleStatement.class)) {
- qNameModule = rootCtx.getFromNamespace(
- ModuleCtxToModuleQName.class,
- rootCtx);
- } else if (StmtContextUtils.producesDeclared(rootCtx,
- SubmoduleStatement.class)) {
- String belongsToModuleName = firstAttributeOf(ctx.getRoot()
- .declaredSubstatements(), BelongsToStatement.class);
- qNameModule = rootCtx.getFromNamespace(
- ModuleNameToModuleQName.class, belongsToModuleName);
+ qNameModule = rootCtx.getFromNamespace(ModuleCtxToModuleQName.class, rootCtx);
+ } else if (StmtContextUtils.producesDeclared(rootCtx, SubmoduleStatement.class)) {
+ String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(),
+ BelongsToStatement.class);
+ qNameModule = rootCtx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
}
- return qNameModule.getRevision() == null ? QNameModule.create(
- qNameModule.getNamespace(),
+ return qNameModule.getRevision() == null ? QNameModule.create(qNameModule.getNamespace(),
SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
}
@Nullable
- public static StatementContextBase<?, ?, ?> findNode(
- StatementContextBase<?, ?, ?> rootStmtCtx,
+ public static StatementContextBase<?, ?, ?> findNode(StatementContextBase<?, ?, ?> rootStmtCtx,
final Iterable<QName> path) {
StatementContextBase<?, ?, ?> parent = rootStmtCtx;
Iterator<QName> pathIter = path.iterator();
while (pathIter.hasNext()) {
QName nextPathQName = pathIter.next();
- StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(
- parent, nextPathQName);
+ StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(parent, nextPathQName);
if (foundSubstatement == null) {
return null;
return null;
}
- public static StatementContextBase<?, ?, ?> getSubstatementByQName(
- StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
+ public static StatementContextBase<?, ?, ?> getSubstatementByQName(StatementContextBase<?, ?, ?> parent,
+ QName nextPathQName) {
- Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
- .declaredSubstatements();
- Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
- .effectiveSubstatements();
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent.declaredSubstatements();
+ Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent.effectiveSubstatements();
Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
allSubstatements.addAll(declaredSubstatement);
}
@Nullable
- public static StatementContextBase<?, ?, ?> findNode(
- StatementContextBase<?, ?, ?> rootStmtCtx,
+ public static StatementContextBase<?, ?, ?> findNode(StatementContextBase<?, ?, ?> rootStmtCtx,
final SchemaNodeIdentifier node) {
return findNode(rootStmtCtx, node.getPathFromRoot());
}
public static SchemaPath getSchemaPath(StmtContext<?, ?, ?> ctx) {
- if(ctx == null) {
+ if (ctx == null) {
return null;
}
- Iterator<StmtContext<?, ?, ?>> iteratorFromRoot = ctx
- .getStmtContextsFromRoot().iterator();
+ Iterator<StmtContext<?, ?, ?>> iteratorFromRoot = ctx.getStmtContextsFromRoot().iterator();
if (iteratorFromRoot.hasNext()) {
iteratorFromRoot.next(); // skip root argument
Object nextStmtArgument = nextStmtCtx.getStatementArgument();
if (nextStmtArgument instanceof QName) {
QName qname = (QName) nextStmtArgument;
- if (StmtContextUtils.producesDeclared(
- nextStmtCtx.getParentContext(), ChoiceStatement.class)
+ if (StmtContextUtils.producesDeclared(nextStmtCtx, UsesStatement.class)) {
+ continue;
+ }
+ if (StmtContextUtils.producesDeclared(nextStmtCtx.getParentContext(), ChoiceStatement.class)
&& isSupportedAsShorthandCase(nextStmtCtx)) {
qNamesFromRoot.add(qname);
}
} else if (nextStmtArgument instanceof String) {
final QName qName = qNameFromArgument(ctx, (String) nextStmtArgument);
qNamesFromRoot.add(qName);
- }
- else if (StmtContextUtils.producesDeclared(nextStmtCtx,
- AugmentStatement.class)
+ } else if (StmtContextUtils.producesDeclared(nextStmtCtx, AugmentStatement.class)
&& nextStmtArgument instanceof SchemaNodeIdentifier) {
- addQNamesFromSchemaNodeIdentifierToList(qNamesFromRoot,
- (SchemaNodeIdentifier) nextStmtArgument);
- } else if (nextStmtCtx.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom
- (UnknownStatementImpl.class)) {
+ addQNamesFromSchemaNodeIdentifierToList(qNamesFromRoot, (SchemaNodeIdentifier) nextStmtArgument);
+ } else if (nextStmtCtx.getPublicDefinition().getDeclaredRepresentationClass()
+ .isAssignableFrom(UnknownStatementImpl.class)) {
qNamesFromRoot.add(nextStmtCtx.getPublicDefinition().getStatementName());
} else {
return SchemaPath.SAME;
return schemaPath;
}
- private static boolean isSupportedAsShorthandCase(
- StmtContext<?, ?, ?> statementCtx) {
+ private static boolean isSupportedAsShorthandCase(StmtContext<?, ?, ?> statementCtx) {
- Collection<?> supportedCaseShorthands = statementCtx.getFromNamespace(
- ValidationBundlesNamespace.class,
+ Collection<?> supportedCaseShorthands = statementCtx.getFromNamespace(ValidationBundlesNamespace.class,
ValidationBundleType.SUPPORTED_CASE_SHORTHANDS);
- return supportedCaseShorthands == null
- || supportedCaseShorthands.contains(statementCtx
- .getPublicDefinition());
+ return supportedCaseShorthands == null || supportedCaseShorthands.contains(statementCtx.getPublicDefinition());
}
- private static void addQNamesFromSchemaNodeIdentifierToList(
- List<QName> qNamesFromRoot, SchemaNodeIdentifier augmentTargetPath) {
- Iterator<QName> augmentTargetPathIterator = augmentTargetPath
- .getPathFromRoot().iterator();
+ private static void addQNamesFromSchemaNodeIdentifierToList(List<QName> qNamesFromRoot,
+ SchemaNodeIdentifier augmentTargetPath) {
+ Iterator<QName> augmentTargetPathIterator = augmentTargetPath.getPathFromRoot().iterator();
while (augmentTargetPathIterator.hasNext()) {
qNamesFromRoot.add(augmentTargetPathIterator.next());
}
// suit this
String deviateUpper = deviate.toUpperCase();
if (Objects.equals(deviate, deviateUpper)) {
- throw new IllegalArgumentException(String.format(
- "String %s is not valid deviate argument", deviate));
+ throw new IllegalArgumentException(String.format("String %s is not valid deviate argument", deviate));
}
// but Java enum is uppercase so we cannot use lowercase here
try {
return Deviation.Deviate.valueOf(deviateUpper);
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(String.format(
- "String %s is not valid deviate argument", deviate), e);
+ throw new IllegalArgumentException(String.format("String %s is not valid deviate argument", deviate), e);
}
}
return status;
}
- public static SchemaPath SchemaNodeIdentifierToSchemaPath(
- SchemaNodeIdentifier identifier) {
- return SchemaPath.create(identifier.getPathFromRoot(),
- identifier.isAbsolute());
+ public static SchemaPath SchemaNodeIdentifierToSchemaPath(SchemaNodeIdentifier identifier) {
+ return SchemaPath.create(identifier.getPathFromRoot(), identifier.isAbsolute());
}
}
@Override public RevisionAwareXPath parseArgumentValue(
StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+ return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
}
@Override public WhenStatement createDeclared(
import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
import static org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
.addSupport(new FeatureStatementImpl.Definition())
.addSupport(new PositionStatementImpl.Definition())
.addSupport(new ValueStatementImpl.Definition())
+ .addSupport(global(StmtOrderingNamespace.class))
.build();
public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private YangStatementParser.StatementContext statementContext;
private ParseTreeWalker walker;
private String sourceName;
+// private String source;
+// private InputStream sourceStream;
private static final Logger LOG = LoggerFactory.getLogger(YangStatementSourceImpl.class);
public YangStatementSourceImpl(final String fileName, boolean isAbsolute) {
try {
statementContext = parseYangSource(loadFile(fileName, isAbsolute));
walker = new ParseTreeWalker();
- yangStatementModelParser = new YangStatementParserListenerImpl(fileName);
+ yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
}
}
}
+ public YangStatementSourceImpl(SourceIdentifier identifier, YangStatementParser.StatementContext statementContext) {
+ try {
+ this.statementContext = statementContext;
+ this.sourceName = identifier.getName();
+ walker = new ParseTreeWalker();
+ yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
+ } catch (Exception e) {
+ LOG.warn(e.getMessage(), e);
+ }
+ }
+
@Override
public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) throws SourceException {
yangStatementModelParser.setAttributes(writer, stmtDef);
walker.walk(yangStatementModelParser, statementContext);
}
- private FileInputStream loadFile(final String fileName, boolean isAbsolute) throws URISyntaxException, FileNotFoundException {
- return isAbsolute ? new FileInputStream(new File(fileName)) : new FileInputStream(new File(getClass().getResource(fileName).toURI()));
+ private NamedFileInputStream loadFile(final String fileName, boolean isAbsolute) throws URISyntaxException,
+ IOException {
+ //TODO: we need absolute path first!
+ return isAbsolute ? new NamedFileInputStream(new File(fileName), fileName) : new NamedFileInputStream(new File
+ (getClass().getResource(fileName).toURI()), fileName);
+
+// final File file = new File(fileName);
+// final ByteSource byteSource = BuilderUtils.fileToByteSource(file);
+// source = byteSource.asCharSource(Charsets.UTF_8).read();
+// return isAbsolute ? new NamedFileInputStream(file, fileName) : new NamedFileInputStream(new File
+// (getClass().getResource(fileName).toURI()), fileName);
}
- private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException, YangSyntaxErrorException {
+ private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException,
+ YangSyntaxErrorException {
final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final YangStatementParser parser = new YangStatementParser(tokens);
- sourceName = parser.getSourceName();
+
+ if(stream instanceof NamedFileInputStream) {
+ sourceName = stream.toString();
+ } else {
+ sourceName = null;
+ }
+
+// sourceStream = stream;
+// sourceName = parser.getSourceName();
+//
+// if (sourceName == null) {
+// sourceName = stream.toString();
+// }
+
return parser.statement();
}
+
+ public YangStatementParser.StatementContext getYangAST() {
+ return statementContext;
+ }
+
+// public InputStream getSourceStream() {
+// return sourceStream;
+// }
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.Collection;
import java.util.LinkedList;
AnyXmlSchemaNode original;
ConstraintDefinition constraintsDef;
boolean augmenting;
- boolean addedByUses;
+ private boolean addedByUses;
ImmutableList<UnknownSchemaNode> unknownNodes;
private void initCopyType(
StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
this.namespace = rootModuleQName.getNamespace();
this.revision = rootModuleQName.getRevision();
- this.order = 1;
+ this.order = ctx.getOrder();
initCopyOf(ctx);
initSubstatementCollections();
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.Collection;
import java.util.HashSet;
private void initCopyType(
StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import com.google.common.collect.ImmutableList;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import com.google.common.collect.Iterables;
import java.util.Collections;
import java.util.Arrays;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-public class CaseShorthandImpl implements ChoiceCaseNode {
+public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
private final DataSchemaNode caseShorthandNode;
private final QName qName;
private final SchemaPath path;
+ private final String description;
+ private final String reference;
+ private final Status status;
+
+ private final boolean augmenting;
+ private final boolean addedByUses;
+ ConstraintDefinition constraints;
+ private ChoiceCaseNode original;
+
+ ImmutableList<UnknownSchemaNode> unknownNodes;
+
public CaseShorthandImpl(DataSchemaNode caseShorthandNode) {
this.caseShorthandNode = caseShorthandNode;
this.qName = caseShorthandNode.getQName();
.create(Iterables.limit(pathFromRoot,
Iterables.size(pathFromRoot) - 1),
caseShorthandNodePath.isAbsolute());
+
+ this.description = caseShorthandNode.getDescription();
+ this.reference = caseShorthandNode.getReference();
+ this.status = caseShorthandNode.getStatus();
+
+ this.augmenting = caseShorthandNode.isAugmenting();
+ this.addedByUses = caseShorthandNode.isAddedByUses();
+ this.constraints = caseShorthandNode.getConstraints();
+ this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
}
@Override
public boolean isAugmenting() {
- return caseShorthandNode.isAugmenting();
+ return augmenting;
}
@Override
public boolean isAddedByUses() {
- return caseShorthandNode.isAddedByUses();
+ return addedByUses;
}
@Override
public boolean isConfiguration() {
- return caseShorthandNode.isConfiguration();
+ return false;
}
@Override
public ConstraintDefinition getConstraints() {
- return caseShorthandNode.getConstraints();
+ return constraints;
}
@Override
public QName getQName() {
- return caseShorthandNode.getQName();
+ return qName;
}
@Override
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- return caseShorthandNode.getUnknownSchemaNodes();
+ return unknownNodes;
}
@Override
public String getDescription() {
- return caseShorthandNode.getDescription();
+ return description;
}
@Override
public String getReference() {
- return caseShorthandNode.getReference();
+ return reference;
}
@Override
public Status getStatus() {
- return caseShorthandNode.getStatus();
+ return status;
}
@Override
public Set<AugmentationSchema> getAvailableAugmentations() {
return Collections.emptySet();
}
+
+ @Override
+ public Optional<? extends SchemaNode> getOriginal() {
+ return Optional.fromNullable(original);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qName == null) ? 0 : qName.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ CaseShorthandImpl other = (CaseShorthandImpl) obj;
+ if (qName == null) {
+ if (other.qName != null) {
+ return false;
+ }
+ } else if (!qName.equals(other.qName)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(
+ CaseShorthandImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("qname=");
+ sb.append(qName);
+ sb.append("]");
+ return sb.toString();
+ }
+
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.Collection;
import java.util.HashSet;
this.path = Utils.getSchemaPath(ctx);
this.constraints = new EffectiveConstraintDefinitionImpl(this);
- initSubstatementCollectionsAndFields();
initCopyType(ctx);
+ initSubstatementCollectionsAndFields();
}
private void initCopyType(
StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
}
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
+ if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
addedByUses = true;
}
- if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
+ if (copyTypesFromOriginal
+ .contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
- Set<ChoiceCaseNode> casesInit = new HashSet<>();
+ SortedSet<ChoiceCaseNode> casesInit = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
boolean configurationInit = false;
boolean defaultInit = false;
|| effectiveStatement instanceof ListSchemaNode
|| effectiveStatement instanceof LeafListSchemaNode
|| effectiveStatement instanceof LeafSchemaNode) {
+
+ DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
ChoiceCaseNode shorthandCase = new CaseShorthandImpl(
- (DataSchemaNode) effectiveStatement);
+ dataSchemaNode);
casesInit.add(shorthandCase);
+
+ if (dataSchemaNode.isAugmenting() == true
+ && this.augmenting == false) {
+ resetAugmenting(dataSchemaNode);
+ }
}
if (!configurationInit
&& effectiveStatement instanceof ConfigEffectiveStatementImpl) {
this.cases = ImmutableSet.copyOf(casesInit);
}
+ private void resetAugmenting(DataSchemaNode dataSchemaNode) {
+ if (dataSchemaNode instanceof LeafEffectiveStatementImpl) {
+ LeafEffectiveStatementImpl leaf = (LeafEffectiveStatementImpl) dataSchemaNode;
+ leaf.augmenting = false;
+ } else if (dataSchemaNode instanceof ContainerEffectiveStatementImpl) {
+ ContainerEffectiveStatementImpl container = (ContainerEffectiveStatementImpl) dataSchemaNode;
+ container.augmenting = false;
+ } else if (dataSchemaNode instanceof LeafListEffectiveStatementImpl) {
+ LeafListEffectiveStatementImpl leafList = (LeafListEffectiveStatementImpl) dataSchemaNode;
+ leafList.augmenting = false;
+ } else if (dataSchemaNode instanceof ListEffectiveStatementImpl) {
+ ListEffectiveStatementImpl list = (ListEffectiveStatementImpl) dataSchemaNode;
+ list.augmenting = false;
+ } else if (dataSchemaNode instanceof AnyXmlEffectiveStatementImpl) {
+ AnyXmlEffectiveStatementImpl anyXml = (AnyXmlEffectiveStatementImpl) dataSchemaNode;
+ anyXml.augmenting = false;
+ }
+ }
+
@Override
public QName getQName() {
return qname;
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
private final SchemaPath path;
private boolean presence;
- private boolean augmenting;
+ boolean augmenting;
private boolean addedByUses;
private boolean configuration = true;
private ContainerSchemaNode original;
private void initCopyType(
StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
+
import java.util.HashSet;
import com.google.common.collect.ImmutableList;
import java.util.List;
modulesInit.add(module);
}
}
- this.modules = ImmutableSet.copyOf(modulesInit);
+
+ Module[] moduleArray = new Module[modulesInit.size()];
+ List<Module> sortedModuleList = ModuleDependencySort.sort(modulesInit.toArray(moduleArray));
+ this.modules = ImmutableSet.copyOf(sortedModuleList);
final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
}
return result;
}
+
+ protected final <R> R firstSubstatementOfType(Class<?> type,
+ Class<R> returnType) {
+ R result = null;
+ try {
+ result = returnType.cast(Iterables.find(
+ substatements,
+ Predicates.and(Predicates.instanceOf(type),
+ Predicates.instanceOf(returnType))));
+ } catch (NoSuchElementException e) {
+ result = null;
+ }
+ return result;
+ }
+
}
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
TypeDefinition<?> baseType;
final QName baseTypeQName = Utils.qNameFromArgument(ctx, ctx.getStatementArgument());
- if (TypeUtils.isYangBaseTypeString(baseTypeQName.getLocalName())) {
- baseType = TypeUtils.getYangBaseTypeFromString(baseTypeQName.getLocalName());
+ if (TypeUtils.isYangPrimitiveTypeString(baseTypeQName.getLocalName())) {
+ baseType = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName.getLocalName());
} else {
StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
.getParentContext().getFromNamespace(TypeNamespace.class, baseTypeQName);
if (baseType instanceof IntegerTypeDefinition) {
final IntegerTypeDefinition intType = (IntegerTypeDefinition) TypeUtils
- .getYangBaseTypeFromString(baseTypeName);
+ .getYangPrimitiveTypeFromString(baseTypeName);
typeConstraints.addRanges(intType.getRangeConstraints());
} else if (baseType instanceof UnsignedIntegerTypeDefinition) {
final UnsignedIntegerTypeDefinition uintType = (UnsignedIntegerTypeDefinition) TypeUtils
- .getYangBaseTypeFromString(baseTypeName);
+ .getYangPrimitiveTypeFromString(baseTypeName);
typeConstraints.addRanges(uintType.getRangeConstraints());
} else if (baseType instanceof StringTypeDefinition) {
final StringTypeDefinition stringType = (StringTypeDefinition) TypeUtils
- .getYangBaseTypeFromString(baseTypeName);
+ .getYangPrimitiveTypeFromString(baseTypeName);
typeConstraints.addLengths(stringType.getLengthConstraints());
typeConstraints.addPatterns(stringType.getPatternConstraints());
- } else if (baseType instanceof DecimalTypeDefinition) {
- final DecimalTypeDefinition decimalType = (DecimalTypeDefinition) TypeUtils
- .getYangBaseTypeFromString(baseTypeName);
- typeConstraints.addRanges(decimalType.getRangeConstraints());
- typeConstraints.addFractionDigits(decimalType.getFractionDigits());
} else if (baseType instanceof BinaryTypeDefinition) {
final BinaryTypeDefinition binaryType = (BinaryTypeDefinition) TypeUtils
- .getYangBaseTypeFromString(baseTypeName);
+ .getYangPrimitiveTypeFromString(baseTypeName);
typeConstraints.addLengths(binaryType.getLengthConstraints());
} else if (baseType instanceof TypeDefEffectiveStatementImpl) {
typeConstraints.addRanges(((TypeDefEffectiveStatementImpl) baseType).getRangeConstraints());
typeConstraints.addLengths(((TypeDefEffectiveStatementImpl) baseType).getLengthConstraints());
typeConstraints.addPatterns(((TypeDefEffectiveStatementImpl) baseType).getPatternConstraints());
typeConstraints.addFractionDigits(((TypeDefEffectiveStatementImpl) baseType).getFractionDigits());
- } else if (baseType instanceof ExtendedTypeEffectiveStatementImpl) {
- typeConstraints.addRanges(((ExtendedTypeEffectiveStatementImpl) baseType).getRangeConstraints());
- typeConstraints.addLengths(((ExtendedTypeEffectiveStatementImpl) baseType).getLengthConstraints());
- typeConstraints.addPatterns(((ExtendedTypeEffectiveStatementImpl) baseType).getPatternConstraints());
- typeConstraints.addFractionDigits(((ExtendedTypeEffectiveStatementImpl) baseType).getFractionDigits());
}
+// else if (baseType instanceof DecimalTypeDefinition) {
+// final DecimalTypeDefinition decimalType = (DecimalTypeDefinition) TypeUtils
+// .getYangBaseTypeFromString(baseTypeName);
+// typeConstraints.addRanges(decimalType.getRangeConstraints());
+// typeConstraints.addFractionDigits(decimalType.getFractionDigits());
+// }
+// else if (baseType instanceof ExtendedTypeEffectiveStatementImpl) {
+// typeConstraints.addRanges(((ExtendedTypeEffectiveStatementImpl) baseType).getRangeConstraints());
+// typeConstraints.addLengths(((ExtendedTypeEffectiveStatementImpl) baseType).getLengthConstraints());
+// typeConstraints.addPatterns(((ExtendedTypeEffectiveStatementImpl) baseType).getPatternConstraints());
+// typeConstraints.addFractionDigits(((ExtendedTypeEffectiveStatementImpl) baseType).getFractionDigits());
+// }
return typeConstraints;
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
private void initCopyType(
StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
addedByUses = true;
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.HashSet;
import java.util.LinkedList;
private void initCopyType(
StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
private final QName qname;
private final SchemaPath path;
- private boolean augmenting;
+ boolean augmenting;
private boolean addedByUses;
private LeafSchemaNode original;
private boolean configuration = true;
private void initCopyType(
StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
private final QName qname;
private final SchemaPath path;
- private boolean augmenting;
+ boolean augmenting;
private boolean addedByUses;
private LeafListSchemaNode original;
private boolean configuration = true;
private void initCopyType(
StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (LeafListSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
private final SchemaPath path;
boolean augmenting;
- boolean addedByUses;
+ private boolean addedByUses;
ListSchemaNode original;
boolean configuration = true;
ConstraintDefinition constraints;
private void initCopyType(
StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import java.util.Map;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
import java.net.URI;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class ModuleEffectiveStatementImpl extends
- AbstractEffectiveDocumentedNode<String, ModuleStatement>
- implements Module, Immutable {
+ AbstractEffectiveDocumentedNode<String, ModuleStatement> implements
+ Module, Immutable {
private final QNameModule qNameModule;
private final String name;
- private String sourcePath; // TODO fill
+ private String sourcePath;
private String prefix;
private String yangVersion;
private String organization;
private ImmutableSet<IdentitySchemaNode> identities;
private ImmutableList<UnknownSchemaNode> unknownNodes;
private String source;
- private ImmutableList<EffectiveStatement<?,?>> substatementsOfSubmodules;
+ private ImmutableList<EffectiveStatement<?, ?>> substatementsOfSubmodules;
private ImmutableMap<QName, DataSchemaNode> childNodes;
private ImmutableSet<GroupingDefinition> groupings;
}
}
- // TODO init source, sourcePath
- source = ctx.getStatementSource().name();
+ if (yangVersion == null) {
+ yangVersion = "1";
+ }
+
+ sourcePath = ((DeclarationInTextSource) ctx
+ .getStatementSourceReference()).getSourceName();
+ // TODO source
+ // source =
initSubmodules(ctx);
initSubstatementCollections(ctx);
.values();
Set<Module> submodulesInit = new HashSet<>();
- List<EffectiveStatement<?,?>> substatementsOfSubmodulesInit = new LinkedList<>();
+ List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new LinkedList<>();
for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx = (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
.getFromNamespace(SubmoduleNamespace.class,
submoduleIdentifier);
- SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx.buildEffective();
+ SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
+ .buildEffective();
submodulesInit.add(submodule);
- substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
+ substatementsOfSubmodulesInit.addAll(submodule
+ .effectiveSubstatements());
}
this.submodules = ImmutableSet.copyOf(submodulesInit);
- this.substatementsOfSubmodules = ImmutableList.copyOf(substatementsOfSubmodulesInit);
+ this.substatementsOfSubmodules = ImmutableList
+ .copyOf(substatementsOfSubmodulesInit);
}
- private void initSubstatementCollections(StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ private void initSubstatementCollections(
+ StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
effectiveSubstatements.addAll(effectiveSubstatements());
dataSchemaNode);
mutablePublicChildNodes.add(dataSchemaNode);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof UsesNode) {
if (!mutableUses.contains(usesNode)) {
mutableUses.add(usesNode);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
if (!mutableTypeDefinitions.contains(extendedType)) {
mutableTypeDefinitions.add(extendedType);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
if (effectiveStatement instanceof GroupingDefinition) {
if (!mutableGroupings.contains(grp)) {
mutableGroupings.add(grp);
} else {
- throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+ throw EffectiveStmtUtils
+ .createNameCollisionSourceException(ctx,
+ effectiveStatement);
}
}
}
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- this.imports = ImmutableSet.copyOf(importsInit);
+ this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,
+ ctx));
this.notifications = ImmutableSet.copyOf(notificationsInit);
this.rpcs = ImmutableSet.copyOf(rpcsInit);
this.deviations = ImmutableSet.copyOf(deviationsInit);
this.uses = ImmutableSet.copyOf(mutableUses);
}
+ private Set<ModuleImport> resolveModuleImports(
+ Set<ModuleImport> importsInit,
+ StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+ for (ModuleImport moduleImport : importsInit) {
+ if (moduleImport.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+ QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
+ moduleImport.getPrefix());
+ if (!impModuleQName.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+ ModuleImport resolvedModuleImport = new ModuleImportImpl(
+ moduleImport.getModuleName(),
+ impModuleQName.getRevision(),
+ moduleImport.getPrefix());
+ resolvedModuleImports.add(resolvedModuleImport);
+ }
+ } else {
+ resolvedModuleImports.add(moduleImport);
+ }
+ }
+ return resolvedModuleImports;
+ }
+
@Override
public String getModuleSourcePath() {
return sourcePath;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(ModuleEffectiveStatementImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(
+ ModuleEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("name=").append(name);
sb.append(", namespace=").append(getNamespace());
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.HashSet;
import java.util.LinkedList;
private void initCopyType(
StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import com.google.common.collect.ImmutableMap;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
import java.net.URI;
import java.util.Collection;
}
}
- //:TODO init source, sourcePath
- source = ctx.getStatementSource().name();
+ //:TODO init source
+// source = ctx.getStatementSource().name();
+ sourcePath = ((DeclarationInTextSource) ctx.getStatementSourceReference()).getSourceName();
initSubmodules(ctx);
initSubstatementCollections(ctx);
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
- this.imports = ImmutableSet.copyOf(importsInit);
+ this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,ctx));
this.notifications = ImmutableSet.copyOf(notificationsInit);
this.rpcs = ImmutableSet.copyOf(rpcsInit);
this.deviations = ImmutableSet.copyOf(deviationsInit);
this.uses = ImmutableSet.copyOf(mutableUses);
}
+ private Set<ModuleImport> resolveModuleImports(
+ Set<ModuleImport> importsInit,
+ StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
+ Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+ for (ModuleImport moduleImport : importsInit) {
+ if (moduleImport.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+ QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
+ moduleImport.getPrefix());
+ if (!impModuleQName.getRevision().equals(
+ SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+ ModuleImport resolvedModuleImport = new ModuleImportImpl(
+ moduleImport.getModuleName(),
+ impModuleQName.getRevision(),
+ moduleImport.getPrefix());
+ resolvedModuleImports.add(resolvedModuleImport);
+ }
+ } else {
+ resolvedModuleImports.add(moduleImport);
+ }
+ }
+ return resolvedModuleImports;
+ }
+
@Override
public String getModuleSourcePath() {
return sourcePath;
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl;
+import java.util.ArrayList;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LengthEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.RangeEffectiveStatementImpl;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.TypeDefinitionEffectiveBuilder;
-public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName, TypedefStatement> implements
+public class TypeDefEffectiveStatementImpl extends
+ EffectiveStatementBase<QName, TypedefStatement> implements
TypeDefinition<TypeDefinition<?>>, TypeDefinitionEffectiveBuilder {
private final QName qName;
private ExtendedType extendedType = null;
- public TypeDefEffectiveStatementImpl(StmtContext<QName, TypedefStatement, ?> ctx) {
+ public TypeDefEffectiveStatementImpl(
+ StmtContext<QName, TypedefStatement, ?> ctx) {
super(ctx);
qName = ctx.getStatementArgument();
path = Utils.getSchemaPath(ctx);
+ baseType = parseBaseTypeFromCtx(ctx);
+
+ EffectiveStatementBase<?, ?> typeEffectiveStmt = firstSubstatementOfType(
+ TypeDefinition.class, EffectiveStatementBase.class);
+
+ ranges = initRanges(typeEffectiveStmt);
+ lengths = initLengths(typeEffectiveStmt);
+ patterns = initPatterns(typeEffectiveStmt);
- ExtendedTypeEffectiveStatementImpl type = null;
+ //due to compatibility problems with original yang parser
+ //:FIXME try to find out better solution
+ if (typeEffectiveStmt.argument().equals(TypeUtils.DECIMAL64)
+ && ranges.isEmpty()) {
+ fractionDigits = null;
+ } else {
+ fractionDigits = initFractionDigits(typeEffectiveStmt);
+ }
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
- if (effectiveStatement instanceof ExtendedTypeEffectiveStatementImpl) {
- type = ((ExtendedTypeEffectiveStatementImpl) effectiveStatement);
- }
if (effectiveStatement instanceof DefaultEffectiveStatementImpl) {
- defaultValue = ((DefaultEffectiveStatementImpl) effectiveStatement).argument();
+ defaultValue = ((DefaultEffectiveStatementImpl) effectiveStatement)
+ .argument();
}
if (effectiveStatement instanceof UnitsEffectiveStatementImpl) {
- units = ((UnitsEffectiveStatementImpl) effectiveStatement).argument();
+ units = ((UnitsEffectiveStatementImpl) effectiveStatement)
+ .argument();
}
if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
- description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
+ description = ((DescriptionEffectiveStatementImpl) effectiveStatement)
+ .argument();
}
if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
- reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
+ reference = ((ReferenceEffectiveStatementImpl) effectiveStatement)
+ .argument();
}
if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
- status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
+ status = ((StatusEffectiveStatementImpl) effectiveStatement)
+ .argument();
}
}
+ }
- if (type != null) {
+ private TypeDefinition<?> parseBaseTypeFromCtx(
+ final StmtContext<QName, TypedefStatement, ?> ctx) {
- ranges = ImmutableList.copyOf(type.getRangeConstraints());
- lengths = ImmutableList.copyOf(type.getLengthConstraints());
- patterns = ImmutableList.copyOf(type.getPatternConstraints());
- fractionDigits = type.getFractionDigits();
- } else {
+ TypeDefinition<?> baseType;
- ranges = Collections.emptyList();
- lengths = Collections.emptyList();
- patterns = Collections.emptyList();
- fractionDigits = null;
+ QName baseTypeQName = Utils.qNameFromArgument(ctx, StmtContextUtils
+ .firstAttributeOf(ctx.declaredSubstatements(),
+ TypeStatement.class));
+
+ if (TypeUtils.isYangBuiltInTypeString(baseTypeQName.getLocalName())) {
+ baseType = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName
+ .getLocalName());
+ if (baseType == null) {
+ baseType = firstSubstatementOfType(TypeDefinition.class);
+
+ //due to compatibility problems with original yang parser
+ //:FIXME try to find out better solution
+ if(baseType instanceof Decimal64SpecificationEffectiveStatementImpl) {
+ Decimal64SpecificationEffectiveStatementImpl decimal64 = (Decimal64SpecificationEffectiveStatementImpl) baseType;
+ if(decimal64.isExtended()) {
+ baseType = decimal64.getBaseType();
+ }
+ }
+ }
+ } else {
+ StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
+ .getParentContext().getFromNamespace(TypeNamespace.class,
+ baseTypeQName);
+ baseType = (TypeDefEffectiveStatementImpl) baseTypeCtx
+ .buildEffective();
}
- baseType = parseBaseTypeFromCtx(ctx);
+ return baseType;
}
- private TypeDefinition<?> parseBaseTypeFromCtx(final StmtContext<QName, TypedefStatement, ?> ctx) {
+ protected Integer initFractionDigits(
+ EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+ final FractionDigitsEffectiveStatementImpl fractionDigitsEffStmt = typeEffectiveStmt
+ .firstEffective(FractionDigitsEffectiveStatementImpl.class);
+ return fractionDigitsEffStmt != null ? fractionDigitsEffStmt.argument()
+ : null;
+ }
- TypeDefinition<?> baseType;
+ protected List<RangeConstraint> initRanges(
+ EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+ final RangeEffectiveStatementImpl rangeConstraints = typeEffectiveStmt
+ .firstEffective(RangeEffectiveStatementImpl.class);
+ return rangeConstraints != null ? rangeConstraints.argument()
+ : Collections.<RangeConstraint> emptyList();
+ }
- QName baseTypeQName = Utils.qNameFromArgument(ctx,
- StmtContextUtils.firstAttributeOf(ctx.declaredSubstatements(), TypeStatement.class));
+ protected List<LengthConstraint> initLengths(
+ EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+ final LengthEffectiveStatementImpl lengthConstraints = typeEffectiveStmt
+ .firstEffective(LengthEffectiveStatementImpl.class);
+ return lengthConstraints != null ? lengthConstraints.argument()
+ : Collections.<LengthConstraint> emptyList();
+ }
- if (TypeUtils.isYangBaseTypeString(baseTypeQName.getLocalName())) {
- baseType = TypeUtils.getYangBaseTypeFromString(baseTypeQName.getLocalName());
- } else {
- StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
- .getParentContext().getFromNamespace(TypeNamespace.class, baseTypeQName);
- baseType = (TypeDefEffectiveStatementImpl) baseTypeCtx.buildEffective();
- }
+ protected List<PatternConstraint> initPatterns(
+ EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+ final List<PatternConstraint> patternConstraints = new ArrayList<>();
- if (baseType == null) {
- baseType = firstSubstatementOfType(TypeDefinition.class);
+ for (final EffectiveStatement<?, ?> effectiveStatement : typeEffectiveStmt
+ .effectiveSubstatements()) {
+ if (effectiveStatement instanceof PatternEffectiveStatementImpl) {
+ final PatternConstraint pattern = ((PatternEffectiveStatementImpl) effectiveStatement)
+ .argument();
+
+ if (pattern != null) {
+ patternConstraints.add(pattern);
+ }
+ }
}
- return baseType;
+ return !patternConstraints.isEmpty() ? ImmutableList
+ .copyOf(patternConstraints) : Collections
+ .<PatternConstraint> emptyList();
}
@Override
Builder extendedTypeBuilder;
if (baseType instanceof TypeDefinitionEffectiveBuilder) {
TypeDefinitionEffectiveBuilder typeDefBaseType = (TypeDefinitionEffectiveBuilder) baseType;
- extendedTypeBuilder = ExtendedType.builder(qName, typeDefBaseType.buildType(),
- Optional.fromNullable(description), Optional.fromNullable(reference), path);
+ extendedTypeBuilder = ExtendedType.builder(qName,
+ typeDefBaseType.buildType(),
+ Optional.fromNullable(description),
+ Optional.fromNullable(reference), path);
} else {
- extendedTypeBuilder = ExtendedType.builder(qName, baseType, Optional.fromNullable(description),
+ extendedTypeBuilder = ExtendedType.builder(qName, baseType,
+ Optional.fromNullable(description),
Optional.fromNullable(reference), path);
}
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.yangtools.yang.common.QName;
nodeType = extension.getQName();
nodeParameter = argument();
- qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : null;
+ qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : extension.getQName();
path = Utils.getSchemaPath(ctx);
// TODO init other fields (see Bug1412Test)
private void initCopyType(
final StmtContext<String, UnknownStatement<String>, ?> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
augmenting = true;
addedByUses = augmenting = true;
}
- if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+ if (ctx.getOriginalCtx() != null) {
original = (UnknownSchemaNode) ctx.getOriginalCtx().buildEffective();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
private void initCopyType(
StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
- Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+ List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
addedByUses = true;
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class BinaryEffectiveStatementImpl extends
- EffectiveStatementBase<String, TypeStatement.BinarySpecification> implements
+ EffectiveStatementBase<String, TypeStatement> implements
BinaryTypeDefinition {
private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
private final List<LengthConstraint> lengthConstraints;
public BinaryEffectiveStatementImpl(
- final StmtContext<String, TypeStatement.BinarySpecification, EffectiveStatement<String, TypeStatement.BinarySpecification>> ctx) {
+ final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
super(ctx);
final LengthConstraint lengthConstraint = new LengthConstraintEffectiveImpl(
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
-
import org.opendaylight.yangtools.yang.model.util.Decimal64;
import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
import com.google.common.base.Optional;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.FractionDigitsEffectiveStatementImpl;
public class Decimal64SpecificationEffectiveStatementImpl extends
- EffectiveStatementBase<String, TypeStatement.Decimal64Specification> implements DecimalTypeDefinition, TypeDefinitionEffectiveBuilder {
+ EffectiveStatementBase<String, TypeStatement.Decimal64Specification>
+ implements DecimalTypeDefinition, TypeDefinitionEffectiveBuilder {
private static final String UNITS = "";
private static final BigDecimal DEFAULT_VALUE = null;
- private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, TypeUtils.DECIMAL64);
+ private static final QName QNAME = QName.create(
+ YangConstants.RFC6020_YANG_MODULE, TypeUtils.DECIMAL64);
private static final String DESCRIPTION = "The decimal64 type represents a subset of the real numbers, which can "
+ "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
+ "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";
private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.3";
- private static final BigDecimal MIN_VALUE = new BigDecimal("-922337203685477580.8");
- private static final BigDecimal MAX_VALUE = new BigDecimal("922337203685477580.7");
+ private static final BigDecimal MIN_VALUE = new BigDecimal(
+ "-922337203685477580.8");
+ private static final BigDecimal MAX_VALUE = new BigDecimal(
+ "922337203685477580.7");
private List<RangeConstraint> rangeConstraints;
private Integer fractionDigits;
private SchemaPath path;
+ private QName extendedTypeQName;
- public Decimal64SpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
- super(ctx);
+ private ExtendedType extendedType;
+ private final boolean isExtended;
- path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
+ public Decimal64SpecificationEffectiveStatementImpl(
+ StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
+ super(ctx);
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
if (effectiveStatement instanceof FractionDigitsEffectiveStatementImpl) {
- fractionDigits = ((FractionDigitsEffectiveStatementImpl) effectiveStatement).argument();
+ fractionDigits = ((FractionDigitsEffectiveStatementImpl) effectiveStatement)
+ .argument();
+ }
+ }
+
+ List<RangeConstraint> initRanges = initRanges();
+
+ if (!initRanges.isEmpty() && validateRanges(initRanges)) {
+ isExtended = true;
+ rangeConstraints = ImmutableList.copyOf(initRanges);
+ SchemaPath parentPath = Utils.getSchemaPath(ctx.getParentContext());
+ extendedTypeQName = QName.create(parentPath.getLastComponent().getModule(), QNAME.getLocalName());
+ path = parentPath.createChild(extendedTypeQName);
+ } else {
+ isExtended = false;
+ rangeConstraints = defaultRangeStatements();
+ path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
+ }
+ }
+
+ private boolean validateRanges(List<RangeConstraint> initRanges) {
+ for (RangeConstraint rangeConstraint : initRanges) {
+
+ String maxValueString = rangeConstraint.getMax().toString();
+ String minValueString = rangeConstraint.getMin().toString();
+
+ if ((!maxValueString.equals("max") && new BigDecimal(maxValueString)
+ .compareTo(MAX_VALUE) > 0)
+ || (!minValueString.equals("min") && new BigDecimal(
+ minValueString).compareTo(MIN_VALUE) < 0)) {
+ return false;
}
}
-
- rangeConstraints = defaultRangeStatements();
+ return true;
+ }
+
+ protected List<RangeConstraint> initRanges() {
+ final RangeEffectiveStatementImpl rangeConstraints = firstEffective(RangeEffectiveStatementImpl.class);
+ return rangeConstraints != null ? rangeConstraints.argument()
+ : Collections.<RangeConstraint> emptyList();
}
private List<RangeConstraint> defaultRangeStatements() {
final List<RangeConstraint> rangeStmts = new ArrayList<>();
- final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + MAX_VALUE + ", inclusively.";
+ final String rangeDescription = "Integer values between " + MIN_VALUE
+ + " and " + MAX_VALUE + ", inclusively.";
final String rangeReference = RangeConstraintEffectiveImpl.DEFAULT_REFERENCE;
- rangeStmts.add(new RangeConstraintEffectiveImpl(MIN_VALUE, MAX_VALUE, Optional.of(rangeDescription), Optional
- .of(rangeReference)));
+ rangeStmts.add(new RangeConstraintEffectiveImpl(MIN_VALUE, MAX_VALUE,
+ Optional.of(rangeDescription), Optional.of(rangeReference)));
return ImmutableList.copyOf(rangeStmts);
}
+ public boolean isExtended() {
+ return isExtended;
+ }
+
@Override
public List<RangeConstraint> getRangeConstraints() {
return rangeConstraints;
@Override
public DecimalTypeDefinition getBaseType() {
- return null;
+ if(isExtended) {
+ if (decimal64Instance == null) {
+ decimal64Instance = Decimal64.create(path, fractionDigits);
+ }
+ return decimal64Instance;
+ } else {
+ return null;
+ }
}
@Override
@Override
public String toString() {
- return Decimal64SpecificationEffectiveStatementImpl.class.getSimpleName() + "[qName=" + QNAME
- + ", fractionDigits=" + fractionDigits + "]";
+ return Decimal64SpecificationEffectiveStatementImpl.class
+ .getSimpleName()
+ + "[qName="
+ + QNAME
+ + ", fractionDigits="
+ + fractionDigits + "]";
}
private Decimal64 decimal64Instance = null;
@Override
- public Decimal64 buildType() {
+ public TypeDefinition<?> buildType() {
- if (decimal64Instance != null) {
+ if (decimal64Instance == null) {
+ decimal64Instance = Decimal64.create(path, fractionDigits);
+ }
+
+ if(!isExtended) {
return decimal64Instance;
}
- decimal64Instance = Decimal64.create(path, fractionDigits);
- return decimal64Instance;
+ if (extendedType != null) {
+ return extendedType;
+ }
+
+ Builder extendedTypeBuilder = ExtendedType.builder(path.getLastComponent(), decimal64Instance, Optional.<String>absent(),
+ Optional.<String>absent(), path);
+
+ extendedTypeBuilder.fractionDigits(fractionDigits);
+ extendedTypeBuilder.ranges(rangeConstraints);
+
+ extendedType = extendedTypeBuilder.build();
+
+ return extendedType;
}
}
*/
public final class ModuleDependencySort {
- private static final Date DEFAULT_REVISION = new Date(0);
+ private static final Date DEFAULT_REVISION = SimpleDateFormatUtil.DEFAULT_DATE_REV;
private static final Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
private static final Function<Node, Module> TOPOLOGY_FUNCTION = new Function<TopologicalSort.Node, Module>() {
@Override
assertTrue(id.isAugmenting());
}
+ @Test
+ public void caseShortHandAugmentingTest() throws Exception {
+ modules = TestUtils.loadModules(getClass().getResource("/choice-case-type-test-models").toURI());
+
+ Module findModule = TestUtils.findModule(modules, "choice-monitoring");
+
+ ContainerSchemaNode netconf = (ContainerSchemaNode) findModule.getDataChildByName("netconf-state");
+ ContainerSchemaNode datastores = (ContainerSchemaNode) netconf.getDataChildByName("datastores");
+ ListSchemaNode datastore = (ListSchemaNode) datastores.getDataChildByName("datastore");
+ ContainerSchemaNode locks = (ContainerSchemaNode) datastore.getDataChildByName("locks");
+ ChoiceSchemaNode lockType = (ChoiceSchemaNode)locks.getDataChildByName("lock-type");
+
+ ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+ assertTrue(leafAugCase.isAugmenting());
+ DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case");
+ assertFalse(leafAug.isAugmenting());
+ }
+
}
assertNotNull(foundNode);
assertEquals(testNode, foundNode);
- GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+ GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
.getDataChildByName("my-leaf-in-grouping");
assertNull(testNode);
assertNull(foundNode);
- GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+ GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
.getDataChildByName("no-leaf-in-grouping");
assertNotNull(foundNode);
assertEquals(testNode, foundNode);
- testNode = myModule.getGroupings().iterator().next();
+ testNode = getGroupingByName(myModule,"my-grouping");
path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
QName.parseRevision("2014-10-07"));
- GroupingDefinition grouping = module.getGroupings().iterator().next();
+ GroupingDefinition grouping = getGroupingByName(module,"my-grouping");
SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt.retest;
+
+import static org.junit.Assert.assertNotNull;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+import java.io.File;
+import org.junit.Test;
+
+public class Bug2291Test {
+
+ @Test
+ public void testRevisionWithExt() throws Exception {
+ File extdef = new File(getClass().getResource("/bugs/bug2291/bug2291-ext.yang").toURI());
+ File bug = new File(getClass().getResource("/bugs/bug2291/bug2291.yang").toURI());
+ File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI());
+
+ SchemaContext context = TestUtils.parseYangSources(extdef, bug, inet);
+ assertNotNull(context);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt.retest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+
+public class SchemaContextUtilTest {
+ @Mock
+ private SchemaContext mockSchemaContext;
+ @Mock
+ private Module mockModule;
+
+ @Test
+ public void testFindDummyData() {
+ MockitoAnnotations.initMocks(this);
+
+ QName qName = QName.create("TestQName");
+ SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
+
+ RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
+ assertEquals("Should be null. Module bookstore not found", null,
+ SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
+
+ SchemaNode schemaNode = Int32.getInstance();
+ RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
+ assertEquals("Should be null, Module prefix not found", null,
+ SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,
+ xPathRelative));
+
+ assertEquals("Should be null. Module TestQName not found", null,
+ SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
+
+ assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-leaf-in-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ RpcDefinition rpc = getRpcByName(myModule,"my-rpc");
+ testNode = rpc.getInput().getDataChildByName("my-input-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "my-input-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ rpc = getRpcByName(myModule,"my-rpc");
+ testNode = rpc.getOutput().getDataChildByName("my-output-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "output"),
+ QName.create(myModule.getQNameModule(), "my-output-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ NotificationDefinition notification = myModule.getNotifications().iterator().next();
+ testNode = notification.getDataChildByName("my-notification-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "my-notification-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
+ testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+ .getDataChildByName("my-leaf-in-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-grouping"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+ "my-choice-leaf-one");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("my-leaf-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-leaf-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("my-leaf-list-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-leaf-list-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-leaf-not-in-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-leaf-not-in-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ RpcDefinition rpc = getRpcByName(myModule,"my-rpc");
+ testNode = rpc.getInput().getDataChildByName("no-input-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "no-input-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ NotificationDefinition notification = myModule.getNotifications().iterator().next();
+ testNode = notification.getDataChildByName("no-notification-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "no-notification-leaf"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
+ testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+ .getDataChildByName("no-leaf-in-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+ QName.create(myModule.getQNameModule(), "no-leaf-in-grouping"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ testNode = ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+ "no-choice-leaf");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "no-choice-leaf"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("no-leaf-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "no-leaf-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+
+ testNode = listNode.getDataChildByName("no-leaf-list-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "no-leaf-list-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = myModule.getDataChildByName("my-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = getRpcByName(myModule,"my-rpc");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getNotifications().iterator().next();
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = getGroupingByName(myModule,"my-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = myModule.getDataChildByName("my-choice");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container")).getDataChildByName("my-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findParentModuleTest() throws URISyntaxException, IOException, SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ DataSchemaNode node = myModule.getDataChildByName("my-container");
+
+ Module foundModule = SchemaContextUtil.findParentModule(context, node);
+
+ assertEquals(myModule, foundModule);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findParentModuleIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaContextUtil.findParentModule(mockContext, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findParentModuleIllegalArgumentTest2() {
+
+ SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+ SchemaContextUtil.findParentModule(null, mockSchemaNode);
+
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void findParentModuleIllegalStateTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+ Mockito.when(mockSchemaNode.getPath()).thenReturn(null);
+ SchemaContextUtil.findParentModule(mockContext, mockSchemaNode);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ SchemaContextUtil.findDataSchemaNode(mockContext, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeIllegalArgumentTest2() {
+
+ SchemaPath mockSchemaPath = Mockito.mock(SchemaPath.class);
+ SchemaContextUtil.findDataSchemaNode(null, mockSchemaPath);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeTest() throws URISyntaxException, IOException, SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+ Module importedModule = context.findModuleByNamespaceAndRevision(new URI("uri:imported-module"),
+ QName.parseRevision("2014-10-07"));
+
+ SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName("my-imported-container"))
+ .getDataChildByName("my-imported-leaf");
+
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("imp:my-imported-container/imp:my-imported-leaf", true);
+
+ SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+ assertNotNull(foundNode);
+ assertNotNull(testNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ GroupingDefinition grouping = getGroupingByName(module,"my-grouping");
+ SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
+
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+ assertNotNull(foundNode);
+ assertNotNull(testNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, module, null);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest2() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, null, xpath);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest3() {
+
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+ SchemaContextUtil.findDataSchemaNode(null, module, xpath);
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void findDataSchemaNodeFromXPathIllegalArgumentTest4() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping[@con='NULL']/my:my-leaf-in-gouping2",
+ true);
+
+ SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath);
+
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathNullTest() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = Mockito.mock(RevisionAwareXPath.class);
+
+ Mockito.when(xpath.toString()).thenReturn(null);
+ assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+ }
+
+ @Test
+ public void findDataSchemaNodeFromXPathNullTest2() {
+
+ SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+ Module module = Mockito.mock(Module.class);
+ RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", false);
+
+ assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextGroupingsTest() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ // find grouping in container
+ DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName("my-container");
+ SchemaNode testNode = getGroupingByName(dataContainer, "my-grouping-in-container");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-container"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-container");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-container"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in list
+ dataContainer = (DataNodeContainer) ((DataNodeContainer) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-list");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-list"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-list");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-list"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in grouping
+ dataContainer = getGroupingByName(myModule, "my-grouping");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-grouping");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-grouping"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-grouping");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-grouping"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in rpc
+ RpcDefinition rpc = getRpcByName(myModule, "my-rpc");
+ for (GroupingDefinition grouping : rpc.getGroupings()) {
+ if (grouping.getQName().getLocalName().equals("my-grouping-in-rpc")) {
+ testNode = grouping;
+ }
+ }
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-rpc"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-rpc");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-rpc"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in output
+ dataContainer = getRpcByName(myModule, "my-rpc").getOutput();
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-output");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "output"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-output"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-output");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-output"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in input
+ dataContainer = getRpcByName(myModule, "my-rpc").getInput();
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-input");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-input"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-input");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-input"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in notification
+ dataContainer = getNotificationByName(myModule, "my-notification");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-notification");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-notification"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-notification");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-notification"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ // find grouping in case
+ dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName(
+ "one").getDataChildByName("my-container-in-case");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-case");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "my-container-in-case"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-case"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-case");
+ path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-case"));
+
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+ @Test
+ public void findNodeInSchemaContextGroupingsTest2() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ // find grouping in container
+ DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName("my-container");
+ SchemaNode testNode = getGroupingByName(dataContainer, "my-grouping-in-container2");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-container2"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in list
+ dataContainer = (DataNodeContainer) ((DataNodeContainer) myModule.getDataChildByName("my-container"))
+ .getDataChildByName("my-list");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-list2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+ QName.create(myModule.getQNameModule(), "my-list"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-list2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in grouping
+ dataContainer = getGroupingByName(myModule, "my-grouping");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-grouping2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-grouping2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in rpc
+ RpcDefinition rpc = getRpcByName(myModule, "my-rpc");
+ for (GroupingDefinition grouping : rpc.getGroupings()) {
+ if (grouping.getQName().getLocalName().equals("my-grouping-in-rpc2")) {
+ testNode = grouping;
+ }
+ }
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-rpc2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in output
+ dataContainer = getRpcByName(myModule, "my-rpc").getOutput();
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-output2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "output"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-output2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in input
+ dataContainer = getRpcByName(myModule, "my-rpc").getInput();
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-input2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-input2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in notification
+ dataContainer = getNotificationByName(myModule, "my-notification");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-notification2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-notification2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ // find grouping in case
+ dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName(
+ "one").getDataChildByName("my-container-in-case");
+ testNode = getGroupingByName(dataContainer, "my-grouping-in-case2");
+
+ path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "one"),
+ QName.create(myModule.getQNameModule(), "my-container-in-case"),
+ QName.create(myModule.getQNameModule(), "my-grouping-in-case2"));
+ foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNull(testNode);
+ assertNull(foundNode);
+
+ }
+
+ private static GroupingDefinition getGroupingByName(final DataNodeContainer dataNodeContainer, final String name) {
+ for (GroupingDefinition grouping : dataNodeContainer.getGroupings()) {
+ if (grouping.getQName().getLocalName().equals(name)) {
+ return grouping;
+ }
+ }
+ return null;
+ }
+
+ private static RpcDefinition getRpcByName(final Module module, final String name) {
+ for (RpcDefinition rpc : module.getRpcs()) {
+ if (rpc.getQName().getLocalName().equals(name)) {
+ return rpc;
+ }
+ }
+ return null;
+ }
+
+ private static NotificationDefinition getNotificationByName(final Module module, final String name) {
+ for (NotificationDefinition notification : module.getNotifications()) {
+ if (notification.getQName().getLocalName().equals(name)) {
+ return notification;
+ }
+ }
+ return null;
+ }
+
+ @Test
+ public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException,
+ SourceException, ReactorException {
+
+ SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+ Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+ QName.parseRevision("2014-10-07"));
+
+ ChoiceSchemaNode choice = (ChoiceSchemaNode)getRpcByName(myModule,"my-name").getInput().getDataChildByName("my-choice");
+ SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName("two");
+
+ SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
+ QName.create(myModule.getQNameModule(), "input"),
+ QName.create(myModule.getQNameModule(), "my-choice"),
+ QName.create(myModule.getQNameModule(), "case-two"),
+ QName.create(myModule.getQNameModule(), "two"));
+ SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+ assertNotNull(testNode);
+ assertNotNull(foundNode);
+ assertEquals(testNode, foundNode);
+
+ }
+
+}
\ No newline at end of file
package org.opendaylight.yangtools.yang.stmt.retest;
import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
+import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
+
import java.io.File;
import java.io.InputStream;
import java.net.URI;
private TestUtils() {
}
- public static Set<Module> loadModules(final URI resourceDirectory) throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ public static Set<Module> loadModules(final URI resourceDirectory)
+ throws SourceException, ReactorException {
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
File[] files = new File(resourceDirectory).listFiles();
for (File file : files) {
- addSources(reactor, new YangStatementSourceImpl(file.getPath(), true));
+ addSources(reactor, new YangStatementSourceImpl(file.getPath(),
+ true));
}
EffectiveSchemaContext ctx = reactor.buildEffective();
return ctx.getModules();
}
- public static Set<Module> loadModules(final List<InputStream> streams) throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ public static Set<Module> loadModules(final List<InputStream> streams)
+ throws SourceException, ReactorException {
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
for (InputStream inputStream : streams) {
addSources(reactor, new YangStatementSourceImpl(inputStream));
}
return ctx.getModules();
}
- public static Module loadModule(final InputStream stream) throws SourceException, ReactorException {
- final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ public static Module loadModule(final InputStream stream)
+ throws SourceException, ReactorException {
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
addSources(reactor, new YangStatementSourceImpl(stream));
EffectiveSchemaContext ctx = reactor.buildEffective();
return ctx.getModules().iterator().next();
}
- public static Module findModule(final Set<Module> modules, final String moduleName) {
+ public static Module findModule(final Set<Module> modules,
+ final String moduleName) {
Module result = null;
for (Module module : modules) {
if (module.getName().equals(moduleName)) {
return result;
}
- public static ModuleImport findImport(final Set<ModuleImport> imports, final String prefix) {
+ public static ModuleImport findImport(final Set<ModuleImport> imports,
+ final String prefix) {
ModuleImport result = null;
for (ModuleImport moduleImport : imports) {
if (moduleImport.getPrefix().equals(prefix)) {
return result;
}
- public static TypeDefinition<?> findTypedef(final Set<TypeDefinition<?>> typedefs, final String name) {
+ public static TypeDefinition<?> findTypedef(
+ final Set<TypeDefinition<?>> typedefs, final String name) {
TypeDefinition<?> result = null;
for (TypeDefinition<?> td : typedefs) {
if (td.getQName().getLocalName().equals(name)) {
return result;
}
- public static SchemaPath createPath(final boolean absolute, final URI namespace, final Date revision,
- final String prefix, final String... names) {
+ public static SchemaPath createPath(final boolean absolute,
+ final URI namespace, final Date revision, final String prefix,
+ final String... names) {
List<QName> path = new ArrayList<>();
for (String name : names) {
path.add(QName.create(namespace, revision, name));
}
/**
- * Test if node has augmenting flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
- * child nodes/case nodes too.
+ * Test if node has augmenting flag set to expected value. In case this is
+ * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
*
* @param node
* node to check
* @param expected
* expected value
*/
- public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+ public static void checkIsAugmenting(final DataSchemaNode node,
+ final boolean expected) {
assertEquals(expected, node.isAugmenting());
if (node instanceof DataNodeContainer) {
- for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+ for (DataSchemaNode child : ((DataNodeContainer) node)
+ .getChildNodes()) {
checkIsAugmenting(child, expected);
}
} else if (node instanceof ChoiceSchemaNode) {
}
/**
- * Check if node has addedByUses flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
- * child nodes/case nodes too.
+ * Check if node has addedByUses flag set to expected value. In case this is
+ * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
*
* @param node
* node to check
* @param expected
* expected value
*/
- public static void checkIsAddedByUses(final DataSchemaNode node, final boolean expected) {
+ public static void checkIsAddedByUses(final DataSchemaNode node,
+ final boolean expected) {
assertEquals(expected, node.isAddedByUses());
if (node instanceof DataNodeContainer) {
- for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+ for (DataSchemaNode child : ((DataNodeContainer) node)
+ .getChildNodes()) {
checkIsAddedByUses(child, expected);
}
} else if (node instanceof ChoiceSchemaNode) {
}
}
- public static void checkIsAddedByUses(final GroupingDefinition node, final boolean expected) {
+ public static void checkIsAddedByUses(final GroupingDefinition node,
+ final boolean expected) {
assertEquals(expected, node.isAddedByUses());
for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
checkIsAddedByUses(child, expected);
}
}
- public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
+ public static List<Module> findModules(final Set<Module> modules,
+ final String moduleName) {
List<Module> result = new ArrayList<>();
for (Module module : modules) {
if (module.getName().equals(moduleName)) {
return result;
}
- private static void addSources(CrossSourceStatementReactor.BuildAction reactor, YangStatementSourceImpl... sources) {
+ private static void addSources(
+ CrossSourceStatementReactor.BuildAction reactor,
+ YangStatementSourceImpl... sources) {
for (YangStatementSourceImpl source : sources) {
reactor.addSource(source);
}
}
+ public static SchemaContext parseYangSources(
+ StatementStreamSource... sources) throws SourceException,
+ ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ reactor.addSources(sources);
+
+ return reactor.buildEffective();
+ }
+
+ public static SchemaContext parseYangSources(File... files)
+ throws SourceException, ReactorException, FileNotFoundException {
+
+ StatementStreamSource[] sources = new StatementStreamSource[files.length];
+
+ for (int i = 0; i < files.length; i++) {
+ sources[i] = new YangStatementSourceImpl(new FileInputStream(
+ files[i]));
+ }
+
+ return parseYangSources(sources);
+ }
+
+ public static SchemaContext parseYangSources(Collection<File> files)
+ throws SourceException, ReactorException, FileNotFoundException {
+ return parseYangSources(files.toArray(new File[files.size()]));
+ }
+
+ public static SchemaContext parseYangSources(String yangSourcesDirectoryPath)
+ throws SourceException, ReactorException, FileNotFoundException,
+ URISyntaxException {
+
+ URL resourceDir = StmtTestUtils.class
+ .getResource(yangSourcesDirectoryPath);
+ File testSourcesDir = new File(resourceDir.toURI());
+
+ return parseYangSources(testSourcesDir.listFiles());
+ }
+
+ public static SchemaContext parseYangSource(String yangSourceFilePath)
+ throws SourceException, ReactorException, FileNotFoundException,
+ URISyntaxException {
+
+ URL resourceFile = StmtTestUtils.class
+ .getResource(yangSourceFilePath);
+ File testSourcesFile = new File(resourceFile.toURI());
+
+ return parseYangSources(testSourcesFile);
+ }
+
}
package org.opendaylight.yangtools.yang.stmt.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.net.URISyntaxException;
+
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import java.io.FileNotFoundException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import com.google.common.collect.ImmutableList;
import java.net.URI;
import org.junit.Test;
reactor.addSource(source);
}
}
+
+ @Test
+ public void caseShortHandAugmentingTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+
+ SchemaContext context = StmtTestUtils.parseYangSources("/choice-case-type-test-models");
+
+ assertNotNull(context);
+
+ ContainerSchemaNode netconf = (ContainerSchemaNode) context.getDataChildByName("netconf-state");
+ ContainerSchemaNode datastores = (ContainerSchemaNode) netconf.getDataChildByName("datastores");
+ ListSchemaNode datastore = (ListSchemaNode) datastores.getDataChildByName("datastore");
+ ContainerSchemaNode locks = (ContainerSchemaNode) datastore.getDataChildByName("locks");
+ ChoiceSchemaNode lockType = (ChoiceSchemaNode)locks.getDataChildByName("lock-type");
+
+ ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+ assertTrue(leafAugCase.isAugmenting());
+ DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case");
+ assertFalse(leafAug.isAugmenting());
+ }
+
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.util.Set;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Module;
.newBuild();
reactor.addSources(TED_20130712, TED_20131021, ISIS_20130712,
- ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES, NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
+ ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES,
+ NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
EffectiveSchemaContext result = reactor.buildEffective();
assertNotNull(result);
}
+ @Test
+ public void multipleRevisionsTest() throws SourceException,
+ ReactorException, FileNotFoundException, URISyntaxException {
+ for (int i = 0; i < 25; i++) {
+ SchemaContext context = StmtTestUtils
+ .parseYangSources("/semantic-statement-parser/multiple-revisions");
+ assertNotNull(context);
+ }
+ }
+
}
package org.opendaylight.yangtools.yang.stmt.test;
+import java.net.URISyntaxException;
+
+import java.net.URL;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import java.util.ArrayList;
import java.util.List;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
public class StmtTestUtils {
- private static final Logger LOG = LoggerFactory.getLogger(StmtTestUtils.class);
+ private static final Logger LOG = LoggerFactory
+ .getLogger(StmtTestUtils.class);
private StmtTestUtils() {
}
}
- public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
+ public static List<Module> findModules(final Set<Module> modules,
+ final String moduleName) {
List<Module> result = new ArrayList<>();
for (Module module : modules) {
if (module.getName().equals(moduleName)) {
String indent) {
for (DataSchemaNode child : childNodes) {
- LOG.debug(indent + "Child "
- + child.getQName().getLocalName());
+ LOG.debug(indent + "Child " + child.getQName().getLocalName());
if (child instanceof DataNodeContainer) {
printChilds(((DataNodeContainer) child).getChildNodes(), indent
+ " ");
}
}
}
+
+ public static SchemaContext parseYangSources(
+ StatementStreamSource... sources) throws SourceException,
+ ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ reactor.addSources(sources);
+
+ return reactor.buildEffective();
+ }
+
+ public static SchemaContext parseYangSources(File... files)
+ throws SourceException, ReactorException, FileNotFoundException {
+
+ StatementStreamSource[] sources = new StatementStreamSource[files.length];
+
+ for (int i = 0; i < files.length; i++) {
+ sources[i] = new YangStatementSourceImpl(new FileInputStream(
+ files[i]));
+ }
+
+ return parseYangSources(sources);
+ }
+
+ public static SchemaContext parseYangSources(Collection<File> files)
+ throws SourceException, ReactorException, FileNotFoundException {
+ return parseYangSources(files.toArray(new File[files.size()]));
+ }
+
+ public static SchemaContext parseYangSources(String yangSourcesDirectoryPath)
+ throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
+
+ URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
+ File testSourcesDir = new File(resourceDir.toURI());
+
+ return parseYangSources(testSourcesDir.listFiles());
+ }
}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
+import org.opendaylight.yangtools.yang.model.util.Decimal64;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.junit.Test;
+
+public class TypedefConstraintsTest {
+
+ @Test
+ public void decimalRangeConstraintsTest() throws SourceException,
+ FileNotFoundException, ReactorException, URISyntaxException {
+ SchemaContext context = StmtTestUtils
+ .parseYangSources("/stmt-test/constraints");
+
+ assertNotNull(context);
+
+ Set<TypeDefinition<?>> typeDefinitions = context.getTypeDefinitions();
+ assertNotNull(typeDefinitions);
+ assertEquals(1, typeDefinitions.size());
+
+ TypeDefinition<?> myDecimal = typeDefinitions.iterator().next();
+
+ assertNotNull(myDecimal);
+ assertTrue(myDecimal instanceof ExtendedType);
+
+ List<RangeConstraint> rangeConstraints = ((ExtendedType) myDecimal)
+ .getRangeConstraints();
+
+ assertNotNull(rangeConstraints);
+ assertEquals(1, rangeConstraints.size());
+
+ DataSchemaNode dataNode = context.getDataChildByName("id-decimal64");
+ assertNotNull(dataNode);
+ assertTrue(dataNode instanceof LeafSchemaNode);
+
+ LeafSchemaNode leafDecimal = (LeafSchemaNode) dataNode;
+ TypeDefinition<?> type = leafDecimal.getType();
+
+ assertTrue(type instanceof ExtendedType);
+ ExtendedType decType = (ExtendedType) type;
+
+ List<RangeConstraint> decRangeConstraints = decType.getRangeConstraints();
+
+ assertEquals(1, decRangeConstraints.size());
+
+ RangeConstraint range = decRangeConstraints.iterator().next();
+ assertEquals(new BigDecimal(1.5), range.getMin());
+ assertEquals(new BigDecimal(5.5), range.getMax());
+
+ assertTrue(decType.getQName().getModule().equals(leafDecimal.getQName().getModule()));
+ assertTrue(decType.getQName().getLocalName().equals(TypeUtils.DECIMAL64));
+ assertTrue(decType.getBaseType() instanceof Decimal64);
+ }
+
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+
import java.net.URI;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.util.BooleanType;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
import org.opendaylight.yangtools.yang.model.util.Int16;
import org.opendaylight.yangtools.yang.model.util.Int32;
import org.opendaylight.yangtools.yang.model.util.Int64;
final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(lfDecimal);
assertNotNull(lfDecimalNode);
- final Decimal64 lfDecimalNodeType = (Decimal64) lfDecimalNode.getType();
- assertEquals(Decimal64.class, lfDecimalNodeType.getClass());
+ final ExtendedType lfDecimalNodeType = (ExtendedType) lfDecimalNode.getType();
+ assertEquals(ExtendedType.class, lfDecimalNodeType.getClass());
assertEquals(2, lfDecimalNodeType.getFractionDigits().intValue());
final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(lfInt8);
--- /dev/null
+module augment-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:augment-monitoring";
+ prefix "amon";
+
+ import choice-monitoring { prefix nm; }
+
+ revision "2013-07-01" {
+ reference "NO REF";
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" {
+
+ case anonymous-lock {
+ leaf lock-time {
+ type uint32;
+ }
+ }
+
+ leaf leaf-aug-case {
+ type string;
+ }
+ }
+
+}
--- /dev/null
+module choice-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:choice-monitoring";
+ prefix "ncm";
+
+ revision 2013-07-01 {
+ }
+
+ container netconf-state {
+ config false;
+
+ container datastores {
+ list datastore {
+ key name;
+
+ leaf name {
+ type string;
+ }
+ container locks {
+ choice lock-type {
+
+ case original-lock {
+ }
+
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module importedrevtest {
+ yang-version 1;
+ namespace "urn:imprevtst:yang";
+ prefix "imprevtst";
+
+ description "This is a test module";
+
+ revision 2015-07-02;
+
+ typedef date-and-time {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module importedrevtest {
+ yang-version 1;
+ namespace "urn:imprevtst:yang";
+ prefix "imprevtst";
+
+ description "This is a test module";
+
+ revision 2015-05-02;
+
+ typedef date-and-time {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module importedrevtest {
+ yang-version 1;
+ namespace "urn:imprevtst:yang";
+ prefix "imprevtst";
+
+ description "This is a test module";
+
+ revision 2015-06-02;
+
+ typedef date-and-time {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module importedrevtest {
+ yang-version 1;
+ namespace "urn:imprevtst:yang";
+ prefix "imprevtst";
+
+ description "This is a test module";
+
+ revision 2015-08-02;
+
+ typedef date-and-time {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module importedrevtest {
+ yang-version 1;
+ namespace "urn:imprevtst:yang";
+ prefix "imprevtst";
+
+ description "This is a test module";
+
+ revision 2015-09-02;
+
+ typedef date-and-time {
+ type string;
+ }
+}
\ No newline at end of file
--- /dev/null
+module testrev {
+ yang-version 1;
+ namespace "urn:tstrev:yang";
+ prefix "tstrev";
+
+ import importedrevtest {
+ prefix "imprevtst";
+ }
+
+ description "This is a test module";
+
+ revision 2015-07-02;
+
+ container mycontainer {
+ leaf myleaf {
+ type imprevtst:date-and-time;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+module foo {
+ yang-version 1;
+ namespace "urn:opendaylight.foo";
+ prefix "foo";
+
+ revision "2013-10-08" {
+ }
+
+ typedef my-decimal-type {
+ type decimal64 {
+ fraction-digits 6;
+ range "1.5..5.5";
+ }
+ }
+
+ leaf id-decimal64 {
+ type decimal64 {
+ fraction-digits 4;
+ range "1.5..5.5";
+ }
+ }
+}