package org.opendaylight.yangtools.yang.common;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Date;
public final class SimpleDateFormatUtil {
+ private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
+ private static final String DEFAULT_DATE = "1970-01-01";
+
+ public static Date DEFAULT_DATE_REV;
+ public static Date DEFAULT_DATE_IMP;
+
+ static {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(REVISION_SIMPLE_DATE);
+
+ try {
+ DEFAULT_DATE_REV = simpleDateFormat.parse(DEFAULT_DATE);
+ DEFAULT_DATE_IMP = simpleDateFormat.parse(DEFAULT_DATE);
+ } catch (ParseException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
private SimpleDateFormatUtil() {
throw new UnsupportedOperationException("Utility class should not be instantiated");
}
@Override
protected SimpleDateFormat initialValue() {
- return new SimpleDateFormat("yyyy-MM-dd");
+ return new SimpleDateFormat(REVISION_SIMPLE_DATE);
}
@Override
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
/**
- * Anyxml normalizedNode.
+ * AN normalizedNode.
*/
public interface AnyXmlNode extends AttributesContainer, DataContainerChild<NodeIdentifier, DOMSource> {
* {@link #endNode()}. Leaf list entries are emmited using
* {@link #leafSetEntryNode(Object)}.
*
- * <li><code>anyxml - Anyxml node event is emitted using
+ * <li><code>anyxml - AN node event is emitted using
* {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emitted
* for anyxml node.</code></li>
*
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YinElementStatement;
+
@Beta
public enum Rfc6020Mapping implements StatementDefinition {
ANYXML(AnyxmlStatement.class, "anyxml", "name"),
*
*
*/
+ //<K, V, N extends IdentifierNamespace<? super K, ? extends V>> V
@Nullable
- <K, V, N extends IdentifierNamespace<? super K, ? extends V>> V get(@Nonnull Class<N> namespace,@Nonnull K identifier);
+ public <K,V,N extends IdentifierNamespace<K, V>> V get(@Nonnull Class<N> namespace,@Nonnull K identifier);
/**
*
@Rfc6020AbnfRule("argument-stmt")
public interface ArgumentStatement extends DeclaredStatement<QName> {
- @Nonnull String getName();
+ @Nonnull QName getName();
@Nullable YinElementStatement getYinElement();
public interface IdentityStatement extends DeclaredStatement<QName>, DocumentationGroup.WithStatus {
- @Nonnull String getName();
+ @Nonnull QName getName();
@Nullable BaseStatement getBase();
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface MandatoryStatement extends DeclaredStatement<String> {
+public interface MandatoryStatement extends DeclaredStatement<Boolean> {
- @Nonnull String getValue();
+ @Nonnull Boolean getValue();
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface NotificationStatement extends DeclaredStatement<QName> {
+public interface NotificationStatement extends DeclaredStatement<QName>, DataDefinitionContainer.WithReusableDefinitions, DocumentationGroup.WithStatus {
@Nonnull QName getName();
}
public interface RequireInstanceStatement extends DeclaredStatement<Boolean> {
- @Nonnull String getValue();
+ @Nonnull Boolean getValue();
}
*/
package org.opendaylight.yangtools.yang.model.api.stmt;
+import java.util.Date;
+
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface RevisionStatement extends DeclaredStatement<String>, DocumentationGroup {
+public interface RevisionStatement extends DeclaredStatement<Date>, DocumentationGroup {
- String getDate();
+ Date getDate();
}
*/
package org.opendaylight.yangtools.yang.model.api.stmt;
+import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface RpcStatement extends DeclaredStatement<QName> {
+public interface RpcStatement extends DeclaredStatement<QName>, DocumentationGroup.WithStatus, ConditionalFeature {
- String getName();
+ QName getName();
+
+ Collection<? extends TypedefStatement> getTypedefs();
+
+ Collection<? extends GroupingStatement> getGroupings();
+
+ InputStatement getInput();
+
+ OutputStatement getOutput();
}
import java.util.Collection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
@Rfc6020AbnfRule("type-stmt")
-public interface TypeStatement extends DeclaredStatement<QName> {
+public interface TypeStatement extends DeclaredStatement<String> {
@Nonnull String getName();
public interface TypedefStatement extends DeclaredStatement<QName>,DocumentationGroup.WithStatus, TypeGroup {
- @Nonnull String getName();
+ @Nonnull QName getName();
}
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import javax.annotation.Nonnull;
+
public interface YangVersionStatement extends DeclaredStatement<String> {
+ @Nonnull String getValue();
}
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface YinElementStatement extends DeclaredStatement<String> {
+public interface YinElementStatement extends DeclaredStatement<Boolean> {
- @Nonnull String getValue();
+ @Nonnull Boolean getValue();
}
fragment UNICODE : 'u' HEX HEX HEX HEX;
fragment HEX : [0-9a-fA-F] ;
-STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | ':' | '/' | '=' | '[' | ']' )~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | ':' | '/' | '=' | '[' | ']')* ) | SUB_STRING );
+STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | ':' | '/' | '=' | '[' | ']' | '+' )~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | ':' | '/' | '=' | '[' | ']')* ) | SUB_STRING );
mode BLOCK_COMMENT_MODE;
END_BLOCK_COMMENT : '*/' -> popMode, skip;
statement : SEP? keyword SEP? (argument)? SEP? (SEMICOLON | LEFT_BRACE SEP? (statement)* SEP? RIGHT_BRACE SEP?) SEP?;
keyword : (IDENTIFIER COLON)? IDENTIFIER;
-argument : STRING | IDENTIFIER | STRING (SEP? PLUS SEP? STRING)*;
\ No newline at end of file
+argument : STRING (SEP? PLUS SEP? STRING)* | IDENTIFIER;
\ No newline at end of file
import static com.google.common.base.Preconditions.checkNotNull;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+
import com.google.common.base.Optional;
import java.net.URI;
import java.util.Date;
if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) {
return false;
}
+
+ Date defaultRev = SimpleDateFormatUtil.DEFAULT_DATE_REV;
+ Date defaultImp = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
+
+ // if revision is in import only, spec says that it is undefined which
+ // revision to take
+ if (getRevision() == defaultImp ^ that.getRevision() == defaultImp) {
+ return true;
+ }
+
+ // default and none revisions taken as equal
+ if ((defaultRev.equals(getRevision()) && that.getRevision() == null)
+ || (defaultRev.equals(that.getRevision()) && getRevision() == null)) {
+ return true;
+ }
+
+ // else if none of them is default and one null
+ if (getRevision() == null ^ that.getRevision() == null) {
+ return false;
+ }
+
// only fail if this revision is non-null
- if (getRevision() != null && !getRevision().equals(that.getRevision())) {
+ if (getRevision() != null && that.getRevision() != null && !getRevision().equals(that.getRevision())) {
return false;
}
--- /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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.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.Utils;
+
+public class YangStatementParserListenerImpl extends YangStatementParserBaseListener {
+
+ private StatementWriter writer;
+ private StatementSourceReference ref;
+ private QNameToStatementDefinition stmtDef;
+ private PrefixToModule prefixes;
+ private List<String> toBeSkipped = new ArrayList<>();
+
+ public YangStatementParserListenerImpl(StatementSourceReference ref) {
+ this.ref = ref;
+ }
+
+ public void setAttributes(StatementWriter writer, QNameToStatementDefinition stmtDef) {
+ this.writer = writer;
+ this.stmtDef = stmtDef;
+ }
+
+ public void setAttributes(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) {
+ this.writer = writer;
+ this.stmtDef = stmtDef;
+ this.prefixes = prefixes;
+ }
+
+ @Override
+ public void enterStatement(YangStatementParser.StatementContext ctx) {
+ boolean action = true;
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ ParseTree child = ctx.getChild(i);
+ if (child instanceof YangStatementParser.KeywordContext) {
+ try {
+ QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
+ ((YangStatementParser.KeywordContext) child).children.get(0).getText());
+ if (stmtDef != null && stmtDef.get(identifier) != null && toBeSkipped.isEmpty()) {
+ writer.startStatement(identifier, ref);
+ } else {
+ action = false;
+ toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
+ }
+ } catch (SourceException e) {
+ e.printStackTrace();
+ }
+ } else if (child instanceof YangStatementParser.ArgumentContext) {
+ try {
+ if (action)
+ writer.argumentValue(
+ Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
+ else
+ action = true;
+ } catch (SourceException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }
+
+ @Override
+ public void exitStatement(YangStatementParser.StatementContext ctx) {
+ 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 && stmtDef.get(identifier) != null && toBeSkipped.isEmpty()) {
+ writer.endStatement(ref);
+ }
+
+ if (toBeSkipped.contains(statementName)) {
+ toBeSkipped.remove(statementName);
+ }
+ } catch (SourceException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
@Nullable <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(Class<N> type, K key);
+ //<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromLocalStorage(Class<N> type);
+
@Nullable <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(Class<N> type, K key, V value);
}
}
public abstract V getFrom(NamespaceStorageNode storage, K key);
+
+ //public abstract Map<K, V> getAllFrom(NamespaceStorageNode storage);
+
public abstract void addTo(NamespaceStorageNode storage,K key,V value);
@Override
return storage.getFromLocalStorage(getIdentifier(), key);
}
+// protected final Map<K, V> getAllFromLocalStorage(NamespaceStorageNode storage) {
+// return storage.getAllFromLocalStorage(getIdentifier());
+// }
+
protected final void addToStorage(NamespaceStorageNode storage,K key,V value) {
storage.addToLocalStorage(getIdentifier(),key,value);
}
@Override
public V getFrom(final NamespaceStorageNode storage, final K key) {
NamespaceStorageNode current = storage;
- while(current.getParentNamespaceStorage() != null) {
+ while(current.getStorageNodeType() != storageType) {
current = current.getParentNamespaceStorage();
}
return getFromLocalStorage(current,key);
}
+// @Override
+// public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+// NamespaceStorageNode current = storage;
+// while(current.getStorageNodeType() != storageType) {
+// current = current.getParentNamespaceStorage();
+// }
+// return getAllFromLocalStorage(current);
+// }
+
@Override
public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, K key, V value) {
NamespaceStorageNode current = storage;
return null;
}
+// @Override
+// public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+// NamespaceStorageNode current = storage;
+// while(current != null) {
+// final Map<K, V> val = getAllFromLocalStorage(current);
+// if(val != null) {
+// return val;
+// }
+// current = current.getParentNamespaceStorage();
+// }
+// return null;
+// }
+
@Override
public void addTo(NamespaceStorageNode storage,K key, V value) {
addToStorage(storage, key, value);
private final ImmutableMap<QName, StatementSupport<?,?,?>> definitions;
private final ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaceDefinitions;
+ public ImmutableMap<QName, StatementSupport<?, ?, ?>> getDefinitions() {
+ return definitions;
+ }
+
private StatementSupportBundle(StatementSupportBundle parent,
ImmutableMap<QName, StatementSupport<?, ?, ?>> statements,
ImmutableMap<Class<?>, NamespaceBehaviour<?, ?, ?>> namespaces) {
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+import java.util.Map;
+
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import java.util.Collection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Nullable A getStatementArgument();
- @Nonnull <K,VT, V extends VT,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key) throws NamespaceNotAvailableException;
+ //<K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
+ // <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key)
+ @Nonnull <K,V,N extends IdentifierNamespace<K, V>> V getFromNamespace(Class<N> type, K key) throws NamespaceNotAvailableException;
+
+ <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(Class<N> type);
@Nonnull StmtContext<?,?,?> getRoot();
- @Nonnull Collection<? extends StmtContext<?,?,?>> declaredSubstatements();
+ @Nonnull Collection<StatementContextBase<?,?,?>> declaredSubstatements();
+
+ public Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
D buildDeclared();
E buildEffective();
+ public StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,StatementContextBase<?, ?, ?> newParent) throws SourceException;
+
interface Mutable<A,D extends DeclaredStatement<A>,E extends EffectiveStatement<A, D>> extends StmtContext<A,D,E> {
@Override
StmtContext.Mutable<?,?,?> getParentContext();
+ //<K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value)
<K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value) throws NamespaceNotAvailableException;
@Override
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
+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;
private static final Function<StmtContext<?, ?,?>, DeclaredStatement<?>> BUILD_DECLARED = new Function<StmtContext<?,?,?>, DeclaredStatement<?>>() {
@Override
- public DeclaredStatement<?> apply(StmtContext<?,?,?> input) {
+ public DeclaredStatement<?> apply(StmtContext<?, ?, ?> input) {
return input.buildDeclared();
}
};
private static final Function<StmtContext<?, ?,?>, EffectiveStatement<?,?>> BUILD_EFFECTIVE = new Function<StmtContext<?,?,?>, EffectiveStatement<?,?>>() {
@Override
- public EffectiveStatement<?,?> apply(StmtContext<?,?,?> input) {
+ public EffectiveStatement<?, ?> apply(StmtContext<?, ?, ?> input) {
return input.buildEffective();
}
};
}
@SuppressWarnings("unchecked")
- public static <E extends EffectiveStatement<?,?>> Function<StmtContext<?, ?,? extends E>, E> buildEffective() {
+
+ public static final <E extends EffectiveStatement<?, ?>> Function<StmtContext<?, ?, ? extends E>, E> buildEffective() {
return Function.class.cast(BUILD_EFFECTIVE);
}
@SuppressWarnings("unchecked")
- public static <AT,DT extends DeclaredStatement<AT>> AT firstAttributeOf(Iterable<? extends StmtContext<?,?,?>> contexts, Class<DT> declaredType) {
- for(StmtContext<?, ?, ?> ctx : contexts) {
- if(producesDeclared(ctx,declaredType)) {
+ public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
+ Iterable<? extends StmtContext<?, ?, ?>> contexts,
+ Class<DT> declaredType) {
+ for (StmtContext<?, ?, ?> ctx : contexts) {
+ if (producesDeclared(ctx, declaredType)) {
return (AT) ctx.getStatementArgument();
}
}
return null;
}
- public static boolean producesDeclared(StmtContext<?, ?, ?> ctx, Class<? extends DeclaredStatement<?>> type) {
- return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
+ @SuppressWarnings("unchecked")
+ public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
+ StmtContext<?, ?, ?> ctx, Class<DT> declaredType) {
+
+ if (producesDeclared(ctx, declaredType)) {
+ return (AT) ctx.getStatementArgument();
+ }
+
+ return null;
+ }
+
+ public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
+ StmtContext<?, ?, ?> stmtContext, Class<DT> declaredType) {
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
+ for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
+ if (producesDeclared(subStmtContext,declaredType)) {
+ return subStmtContext;
+ }
+ }
+ return null;
+ }
+
+ public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
+ StmtContext<?, ?, ?> stmtContext, int startIndex, Class<? extends DeclaredStatement<?>>... types) {
+
+ if (startIndex >= types.length)
+ return null;
+
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
+ for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
+ if (producesDeclared(subStmtContext,types[startIndex])) {
+ if (startIndex + 1 == types.length)
+ return subStmtContext;
+ else
+ return findFirstDeclaredSubstatement(subStmtContext,
+ ++startIndex, types);
+ }
+ }
+ return null;
+ }
+
+ public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatementOnSublevel(
+ StmtContext<?, ?, ?> stmtContext, Class<DT> declaredType,
+ int sublevel) {
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
+ for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
+ if (sublevel == 1 && producesDeclared(subStmtContext,declaredType)) {
+ return subStmtContext;
+ } else {
+ if (sublevel > 1) {
+ StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(
+ subStmtContext, declaredType, --sublevel);
+ if (result != null)
+ return result;
+ }
+ }
+ }
+ return null;
+ }
+
+ public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findDeepFirstDeclaredSubstatement(
+ StmtContext<?, ?, ?> stmtContext, Class<DT> declaredType) {
+
+ Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+ .declaredSubstatements();
+
+ for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
+ if (producesDeclared(subStmtContext,declaredType)) {
+ return subStmtContext;
+ } else {
+ StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(
+ subStmtContext, declaredType);
+ if (result != null)
+ return result;
+
+ }
+ }
+ return null;
+ }
+
+ public static final boolean producesDeclared(StmtContext<?, ?, ?> ctx,
+ Class<? extends DeclaredStatement<?>> type) {
+ return type.isAssignableFrom(ctx.getPublicDefinition()
+ .getDeclaredRepresentationClass());
}
}
--- /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.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface BelongsToPrefixToModuleName extends IdentifierNamespace<String, String> {
+
+
+}
--- /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.ModuleIdentifier;
+
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface ImpPrefixToModuleIdentifier extends IdentifierNamespace<String, ModuleIdentifier> {
+
+
+}
--- /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.common.QNameModule;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface ModuleIdentifierToModuleQName extends IdentifierNamespace<ModuleIdentifier, QNameModule> {
+
+
+}
--- /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.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface ModuleNameToModuleQName extends IdentifierNamespace<String, QNameModule> {
+
+
+
+}
--- /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.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface ModuleQNameToModuleName extends IdentifierNamespace<QNameModule,String> {
+
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.spi.source;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+
+public class QNameToStatementDefinitionMap implements QNameToStatementDefinition{
+
+ private Map<QName, StatementDefinition> qNameToStmtDefMap = new HashMap<>();
+
+ public void put(QName qName, StatementDefinition stDef ) {
+ qNameToStmtDefMap.put(qName, stDef);
+ }
+
+ @Nullable @Override
+ public StatementDefinition get(@Nonnull QName identifier) {
+ return qNameToStmtDefMap.get(identifier);
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
this.supports = supports;
}
+ public StatementSupportBundle getSupportsForPhase(ModelProcessingPhase currentPhase) {
+ return supports.get(currentPhase);
+ }
+
public void addSource(@Nonnull StatementStreamSource source) {
sources.add(new SourceSpecificContext(this,source));
}
return new EffectiveModelContext(rootStatements);
}
+ public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
+ for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
+ startPhase(phase);
+ loadPhaseStatements();
+ completePhaseActions();
+ endPhase(phase);
+ }
+ return transformEffective();
+ }
+
+ private EffectiveSchemaContext transformEffective() {
+ Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+ List<DeclaredStatement<?>> rootStatements = new ArrayList<>();
+ List<EffectiveStatement<?,?>> rootEffectiveStatements = new ArrayList<>();
+
+ for(SourceSpecificContext source : sources) {
+ DeclaredStatement<?> root = source.getRoot().buildDeclared();
+ rootStatements.add(root);
+
+ EffectiveStatement<?,?> rootEffective = source.getRoot().buildEffective();
+ rootEffectiveStatements.add(rootEffective);
+ }
+
+ return new EffectiveSchemaContext(rootStatements,rootEffectiveStatements);
+ }
+
private void startPhase(ModelProcessingPhase phase) {
Preconditions.checkState(Objects.equals(finishedPhase, phase.getPreviousPhase()));
for(SourceSpecificContext source : sources) {
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
import com.google.common.collect.ImmutableMap;
import java.util.EnumMap;
import java.util.Map;
return context.build();
}
-
+ public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
+ return context.buildEffective();
+ }
}
public ImmutableList<DeclaredStatement<?>> getRootStatements() {
return rootStatements;
}
-
}
@Override
public <D extends DeclaredStatement<?>> Prerequisite<D> requiresDeclared(StmtContext<?, ? extends D, ?> context) {
- return requiresCtxImpl(context,FULL_DECLARATION).transform(StmtContextUtils.<D>buildDeclared());
+ return requiresCtxImpl(context, FULL_DECLARATION).transform(StmtContextUtils.<D>buildDeclared());
}
@Override
public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>> AbstractPrerequisite<StmtContext<?, D, ?>> requiresDeclaredCtx(
StmtContext<?, ?, ?> context, Class<N> namespace, K key) {
- return requiresCtxImpl(context, namespace, key,FULL_DECLARATION);
+ return requiresCtxImpl(context, namespace, key, FULL_DECLARATION);
}
@Override
public <K, D extends DeclaredStatement<?>, N extends StatementNamespace<K, ? extends D, ?>> Prerequisite<D> requiresDeclared(
StmtContext<?, ?, ?> context, Class<N> namespace, K key) {
- final AbstractPrerequisite<StmtContext<?,D,?>> rawContext = requiresCtxImpl(context, namespace, key,FULL_DECLARATION);
+ final AbstractPrerequisite<StmtContext<?,D,?>> rawContext = requiresCtxImpl(context, namespace, key, FULL_DECLARATION);
return rawContext.transform(StmtContextUtils.<D>buildDeclared());
}
@Override
public <E extends EffectiveStatement<?, ?>> Prerequisite<E> requiresEffective(StmtContext<?, ?, ? extends E> stmt) {
- return requiresCtxImpl(stmt,EFFECTIVE_MODEL).transform(StmtContextUtils.<E>buildEffective());
+ return requiresCtxImpl(stmt, EFFECTIVE_MODEL).transform(StmtContextUtils.<E>buildEffective());
}
@Override
public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> AbstractPrerequisite<StmtContext<?, ?, E>> requiresEffectiveCtx(
StmtContext<?, ?, ?> context, Class<N> namespace, K key) {
- return requiresCtxImpl(contextImpl(context),namespace,key,EFFECTIVE_MODEL);
+ return requiresCtxImpl(contextImpl(context),namespace,key, EFFECTIVE_MODEL);
}
@Override
public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> Prerequisite<E> requiresEffective(
StmtContext<?, ?, ?> context, Class<N> namespace, K key) {
- final AbstractPrerequisite<StmtContext<?,?,E>> rawContext = requiresCtxImpl(context, namespace, key,EFFECTIVE_MODEL);
+ final AbstractPrerequisite<StmtContext<?,?,E>> rawContext = requiresCtxImpl(context, namespace, key, EFFECTIVE_MODEL);
return rawContext.transform(StmtContextUtils.<E>buildEffective());
}
// NOOP
}
- public final <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key)
+ //<K,V,N extends IdentifierNamespace<K, V>> V
+ //public final <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key)
+ public final <K,V,N extends IdentifierNamespace<K, V>> V getFromNamespace(Class<N> type, K key)
throws NamespaceNotAvailableException {
return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this,key);
}
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(Class<N> type){
+ return namespaces.get(type);
+ }
+
public final <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value)
throws NamespaceNotAvailableException {
getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value);
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import java.util.Collection;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-
class RootStatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
- extends StatementContextBase<A, D,E> {
-
+ extends StatementContextBase<A, D, E> {
private final SourceSpecificContext sourceContext;
+ private final A argument;
- RootStatementContext(ContextBuilder<A, D,E> builder, SourceSpecificContext sourceContext) throws SourceException {
+ RootStatementContext(ContextBuilder<A, D, E> builder,
+ SourceSpecificContext sourceContext) throws SourceException {
super(builder);
this.sourceContext = sourceContext;
+ this.argument = builder.getDefinition().parseArgumentValue(this,
+ builder.getRawArgument());
+ }
+
+ RootStatementContext(RootStatementContext<A, D, E> original,
+ QNameModule newQNameModule) throws SourceException {
+ super(original);
+
+ sourceContext = original.sourceContext;
+ this.argument = original.argument;
+
+ copyDeclaredStmts(original, newQNameModule);
+
+ copyEffectiveStmts(original, newQNameModule);
+
+ }
+
+ private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
+ QNameModule newQNameModule) throws SourceException {
+ Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
+ .declaredSubstatements();
+ for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ this.addEffectiveSubstatement(stmtContext
+ .createCopy(newQNameModule,this));
+ }
+ }
+
+ private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
+ QNameModule newQNameModule) throws SourceException {
+ Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
+ .effectiveSubstatements();
+ for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
+ this.addEffectiveSubstatement(stmtContext
+ .createCopy(newQNameModule,this));
+ }
}
@Override
- public StatementContextBase<?,?, ?> getParentContext() {
+ public StatementContextBase<?, ?, ?> getParentContext() {
return null;
}
}
@Override
- public RootStatementContext<?,?,?> getRoot() {
+ public RootStatementContext<?, ?, ?> getRoot() {
return this;
}
return sourceContext;
}
+ @Override
+ public A getStatementArgument() {
+ return argument;
+ }
+
+ @Override
+ public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
+ throws SourceException {
+ StatementContextBase<A, D, E> copy = new RootStatementContext<A, D, E>(
+ this, newQNameModule);
+ return copy;
+ }
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Mutable;
import org.opendaylight.yangtools.yang.common.QName;
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.meta.IdentifierNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
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.QNameToStatementDefinitionMap;
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.StatementStreamSource;
private ModelProcessingPhase inProgressPhase;
private ModelProcessingPhase finishedPhase;
+ private QNameToStatementDefinitionMap qNameToStmtDefMap = new QNameToStatementDefinitionMap();
SourceSpecificContext(BuildGlobalContext currentContext,StatementStreamSource source) {
if(current == null) {
return createDeclaredRoot(def,ref);
}
- return current.substatementBuilder(def,ref);
+ return current.substatementBuilder(def, ref);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
if(root == null) {
root = new RootStatementContext(this, SourceSpecificContext.this);
} else {
- Preconditions.checkState(root.getIdentifier().equals(getIdentifier()), "Root statement was already defined.");
+ Preconditions.checkState(root.getIdentifier().equals(getIdentifier()), "Root statement was already defined as %s.", root.getIdentifier());
}
root.resetLists();
return root;
return root.buildDeclared();
}
- EffectiveStatement<?,?> build() {
+ EffectiveStatement<?,?> buildEffective() {
return root.buildEffective();
}
PhaseCompletionProgress tryToCompletePhase(ModelProcessingPhase phase) throws SourceException {
Collection<ModifierImpl> currentPhaseModifiers = modifiers.get(phase);
+
+ boolean hasProgressed = hasProgress(currentPhaseModifiers);
+
+ boolean phaseCompleted = root.tryToCompletePhase(phase);
+
+ hasProgressed = hasProgress(currentPhaseModifiers);
+
+ if(phaseCompleted && (currentPhaseModifiers.isEmpty())) {
+ finishedPhase = phase;
+ return PhaseCompletionProgress.FINISHED;
+
+ }
+ if(hasProgressed) {
+ return PhaseCompletionProgress.PROGRESS;
+ }
+ return PhaseCompletionProgress.NO_PROGRESS;
+ }
+
+
+ private boolean hasProgress(Collection<ModifierImpl> currentPhaseModifiers) {
+
Iterator<ModifierImpl> modifier = currentPhaseModifiers.iterator();
boolean hasProgressed = false;
while(modifier.hasNext()) {
hasProgressed = true;
}
}
- if(root.tryToCompletePhase(phase) && currentPhaseModifiers.isEmpty()) {
- finishedPhase = phase;
- return PhaseCompletionProgress.FINISHED;
- }
- if(hasProgressed) {
- return PhaseCompletionProgress.PROGRESS;
- }
- return PhaseCompletionProgress.NO_PROGRESS;
+ return hasProgressed;
+
}
ModelActionBuilder newInferenceAction(ModelProcessingPhase phase) {
break;
case STATEMENT_DEFINITION:
source.writeLinkageAndStatementDefinitions(new StatementContextWriter(this, inProgressPhase), stmtDef(), prefixes());
+ break;
case FULL_DECLARATION:
source.writeFull(new StatementContextWriter(this, inProgressPhase), stmtDef(), prefixes());
-
+ break;
default:
break;
}
}
private QNameToStatementDefinition stmtDef() {
- // TODO Auto-generated method stub
- return null;
+ ImmutableMap<QName, StatementSupport<?, ?, ?>> definitions = currentContext.getSupportsForPhase(
+ inProgressPhase).getDefinitions();
+ for (Map.Entry<QName, StatementSupport<?,?,?>> entry : definitions.entrySet()) {
+ qNameToStmtDefMap.put(entry.getKey(), entry.getValue());
+ }
+ return qNameToStmtDefMap;
}
-
}
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
-abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
+public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
NamespaceStorageSupport implements StmtContext.Mutable<A, D, E>, Identifiable<StatementIdentifier> {
interface OnNamespaceItemAdded extends EventListener{
private final StatementDefinitionContext<A, D, E> definition;
private final StatementIdentifier identifier;
private final StatementSourceReference statementDeclSource;
- private final A argument;
private LinkedHashMap<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
this.definition = builder.getDefinition();
this.identifier = builder.getIdentifier();
this.statementDeclSource = builder.getStamementSource();
- this.argument = definition.parseArgumentValue(this, this.rawStatementArgument());
+ this.completedPhase = null;
+ }
+
+ StatementContextBase(StatementContextBase<A,D,E> original) {
+ this.definition = original.definition;
+ this.identifier = original.identifier;
+ this.statementDeclSource = original.statementDeclSource;
this.completedPhase = null;
}
}
@Override
- public A getStatementArgument() {
- return argument;
+ public Collection<StatementContextBase<?, ?, ?>> declaredSubstatements() {
+ return Collections.unmodifiableCollection(declared);
}
@Override
- public Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements() {
- return Collections.unmodifiableCollection(declared);
+ public Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements() {
+ return Collections.unmodifiableCollection(effective);
+ }
+
+ public void addEffectiveSubstatement(StatementContextBase<?, ?, ?> substatement){
+ effective.add(substatement);
+ }
+
+ public void addDeclaredSubstatement(StatementContextBase<?, ?, ?> substatement){
+ declared.add(substatement);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
};
}
+
+
@Override
public StorageNodeType getStorageNodeType() {
return StorageNodeType.STATEMENT_LOCAL;
for(StatementContextBase<?, ?, ?> child: declared) {
finished &= child.tryToCompletePhase(phase);
}
+ for(StatementContextBase<?, ?, ?> child: effective) {
+ finished &= child.tryToCompletePhase(phase);
+ }
if(finished) {
onPhaseCompleted(phase);
return true;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-class StatementDefinitionContext<A,D extends DeclaredStatement<A>,E extends EffectiveStatement<A,D>> {
+public class StatementDefinitionContext<A,D extends DeclaredStatement<A>,E extends EffectiveStatement<A,D>> {
private final StatementSupport<A,D,E> support;
public StatementDefinitionContext(StatementSupport<A,D,E> support) {
this.support= support;
break;
case STATEMENT_DEFINITION:
support.onStatementDefinitionDeclared(statement);
+ break;
case FULL_DECLARATION:
support.onFullDefinitionDeclared(statement);
+ break;
default:
break;
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.GroupingUtils;
+
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.common.QName;
import com.google.common.base.Preconditions;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
extends StatementContextBase<A,D,E> {
private final StatementContextBase<?,?,?> parent;
+ private final A argument;
SubstatementContext(StatementContextBase<?,?,?> parent,ContextBuilder<A,D,E> builder) throws SourceException {
+ //super(builder, builder.getDefinition().parseArgumentValue(parent, builder.getRawArgument()));
super(builder);
this.parent = Preconditions.checkNotNull(parent, "Parent must not be null");
+ this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
+ }
+
+ SubstatementContext(SubstatementContext<A,D,E> original, QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
+ super(original);
+ this.parent = newParent;
+
+ if(newQNameModule != null && original.argument instanceof QName) {
+ QName originalQName = (QName) original.argument;
+ this.argument = (A) QName.create(newQNameModule,originalQName.getLocalName());
+ } else {
+ this.argument = original.argument;
+ }
+
+ copyDeclaredStmts(original, newQNameModule);
+
+ copyEffectiveStmts(original, newQNameModule);
+ }
+
+ private void copyDeclaredStmts(SubstatementContext<A, D, E> original,
+ QNameModule newQNameModule) throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
+ .declaredSubstatements();
+ for (StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ if (GroupingUtils.needToCopyByUses(stmtContext)) {
+ StatementContextBase<?, ?, ?> copy = stmtContext
+ .createCopy(newQNameModule,this);
+ this.addEffectiveSubstatement(copy);
+ } else if (GroupingUtils.isReusedByUses(stmtContext)) {
+ this.addEffectiveSubstatement(stmtContext);
+ }
+ }
+ }
+
+ private void copyEffectiveStmts(SubstatementContext<A, D, E> original,
+ QNameModule newQNameModule) throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
+ .effectiveSubstatements();
+ for (StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
+ if (GroupingUtils.needToCopyByUses(stmtContext)) {
+ StatementContextBase<?, ?, ?> copy = stmtContext
+ .createCopy(newQNameModule,this);
+ this.addEffectiveSubstatement(copy);
+ } else if (GroupingUtils.isReusedByUses(stmtContext)) {
+ this.addEffectiveSubstatement(stmtContext);
+ }
+ }
}
@Override
return parent.getRoot();
}
+
+ @Override
+ public A getStatementArgument() {
+ return argument;
+ }
+
+ @Override
+ public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
+ StatementContextBase<A,D,E> copy = new SubstatementContext<A,D,E>(this,newQNameModule, newParent);
+ return copy;
+ }
}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.common.QName;
+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.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.AnyxmlStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+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;
+
+public class AnyxmlStatementImpl extends AbstractDeclaredStatement<QName> implements AnyxmlStatement {
+
+ protected AnyxmlStatementImpl(StmtContext<QName, AnyxmlStatement,?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<QName,AnyxmlStatement,EffectiveStatement<QName,AnyxmlStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ANYXML);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?,?,?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx,value);
+ }
+
+ @Override
+ public AnyxmlStatement createDeclared(StmtContext<QName, AnyxmlStatement,?> ctx) {
+ return new AnyxmlStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName,AnyxmlStatement> createEffective(StmtContext<QName,AnyxmlStatement,EffectiveStatement<QName,AnyxmlStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Override
+ public Collection<? extends MustStatement> getMusts() {
+ return allDeclared(MustStatement.class);
+ }
+
+ @Override
+ public ConfigStatement getConfig() {
+ return firstDeclared(ConfigStatement.class);
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public MandatoryStatement getMandatory() {
+ return firstDeclared(MandatoryStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.YinElementStatement;
+
+import org.opendaylight.yangtools.yang.common.QName;
+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.ArgumentStatement;
+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;
+
+public class ArgumentStatementImpl extends AbstractDeclaredStatement<QName>
+ implements ArgumentStatement {
+
+ protected ArgumentStatementImpl(
+ StmtContext<QName, ArgumentStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, ArgumentStatement, EffectiveStatement<QName, ArgumentStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ARGUMENT);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public ArgumentStatement createDeclared(
+ StmtContext<QName, ArgumentStatement, ?> ctx) {
+ return new ArgumentStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, ArgumentStatement> createEffective(
+ StmtContext<QName, ArgumentStatement, EffectiveStatement<QName, ArgumentStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public YinElementStatement getYinElement() {
+ return firstDeclared(YinElementStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+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;
+
+public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
+
+ protected AugmentStatementImpl(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.AUGMENT);
+ }
+
+ @Override
+ public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return SchemaNodeIdentifier.create(Utils.parseAugmentPath(ctx, value), Utils.isXPathAbsolute(value));
+ }
+
+ @Override
+ public AugmentStatement createDeclared(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
+ return new AugmentStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<SchemaNodeIdentifier, AugmentStatement> createEffective(
+ StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull
+ @Override
+ public SchemaNodeIdentifier getTargetNode() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.common.QName;
+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.BaseStatement;
+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;
+
+public class BaseStatementImpl extends AbstractDeclaredStatement<QName>
+ implements BaseStatement {
+
+ protected BaseStatementImpl(StmtContext<QName, BaseStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, BaseStatement, EffectiveStatement<QName, BaseStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.BASE);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public BaseStatement createDeclared(
+ StmtContext<QName, BaseStatement, ?> ctx) {
+ return new BaseStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, BaseStatement> createEffective(
+ StmtContext<QName, BaseStatement, EffectiveStatement<QName, BaseStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+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.BelongsToStatement;
+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;
+
+public class BelongsToStatementImpl extends AbstractDeclaredStatement<String>
+ implements BelongsToStatement {
+
+ protected BelongsToStatementImpl(
+ StmtContext<String, BelongsToStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.BELONGS_TO);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public BelongsToStatement createDeclared(
+ StmtContext<String, BelongsToStatement, ?> ctx) {
+ return new BelongsToStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, BelongsToStatement> createEffective(
+ StmtContext<String, BelongsToStatement, EffectiveStatement<String, BelongsToStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getModule() {
+ return argument();
+ }
+
+ @Override
+ public PrefixStatement getPrefix() {
+ return firstDeclared(PrefixStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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.BitStatement;
+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;
+
+public class BitStatementImpl extends AbstractDeclaredStatement<String>
+ implements BitStatement {
+
+ protected BitStatementImpl(
+ StmtContext<String, BitStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, BitStatement, EffectiveStatement<String, BitStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.BIT);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public BitStatement createDeclared(
+ StmtContext<String, BitStatement, ?> ctx) {
+ return new BitStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, BitStatement> createEffective(
+ StmtContext<String, BitStatement, EffectiveStatement<String, BitStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public PositionStatement getPosition() {
+ return firstDeclared(PositionStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class BitsSpecificationImpl extends AbstractDeclaredStatement<String>
+ implements TypeStatement.BitsSpecification {
+
+ protected BitsSpecificationImpl(
+ StmtContext<String, TypeStatement.BitsSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.BitsSpecification, EffectiveStatement<String, TypeStatement.BitsSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.TYPE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.BitsSpecification createDeclared(
+ StmtContext<String, TypeStatement.BitsSpecification, ?> ctx) {
+ return new BitsSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.BitsSpecification> createEffective(
+ StmtContext<String, TypeStatement.BitsSpecification, EffectiveStatement<String, TypeStatement.BitsSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends BitStatement> getBits() {
+ return allDeclared(BitStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import org.opendaylight.yangtools.yang.common.QName;
+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.CaseStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+public class CaseStatementImpl extends AbstractDeclaredStatement<QName> implements CaseStatement {
+
+ protected CaseStatementImpl(
+ StmtContext<QName, CaseStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<QName,CaseStatement,EffectiveStatement<QName,CaseStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.CASE);
+ }
+
+ @Override public QName parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override public CaseStatement createDeclared(
+ StmtContext<QName, CaseStatement, ?> ctx) {
+ return new CaseStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<QName, CaseStatement> createEffective(
+ StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Nonnull @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+
+ @Nullable @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.common.QName;
+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.CaseStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DefaultStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+public class ChoiceStatementImpl extends AbstractDeclaredStatement<QName>
+ implements ChoiceStatement {
+
+ protected ChoiceStatementImpl(StmtContext<QName, ChoiceStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.CHOICE);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public ChoiceStatement createDeclared(
+ StmtContext<QName, ChoiceStatement, ?> ctx) {
+ return new ChoiceStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, ChoiceStatement> createEffective(
+ StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Nullable
+ @Override
+ public DefaultStatement getDefault() {
+ return firstDeclared(DefaultStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ConfigStatement getConfig() {
+ return firstDeclared(ConfigStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public MandatoryStatement getMandatory() {
+ return firstDeclared(MandatoryStatement.class);
+ }
+
+ @Nonnull
+ @Override
+ public Collection<? extends CaseStatement> getCases() {
+ return allDeclared(CaseStatement.class);
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Nonnull
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class ConfigStatementImpl extends AbstractDeclaredStatement<Boolean> implements ConfigStatement {
+
+ protected ConfigStatementImpl(
+ StmtContext<Boolean, ConfigStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<Boolean,ConfigStatement,EffectiveStatement<Boolean,ConfigStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.CONFIG);
+ }
+
+ @Override public Boolean parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return Boolean.valueOf(value);
+ }
+
+ @Override public ConfigStatement createDeclared(StmtContext<Boolean, ConfigStatement, ?> ctx) {
+ return new ConfigStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<Boolean, ConfigStatement> createEffective(StmtContext<Boolean, ConfigStatement, EffectiveStatement<Boolean, ConfigStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public Boolean getValue() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContactStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class ContactStatementImpl extends AbstractDeclaredStatement<String> implements ContactStatement{
+
+ protected ContactStatementImpl(StmtContext<String, ContactStatement,?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,ContactStatement,EffectiveStatement<String,ContactStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.CONTACT);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override
+ public ContactStatement createDeclared(StmtContext<String, ContactStatement, ?> ctx) {
+ return new ContactStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, ContactStatement> createEffective(StmtContext<String, ContactStatement, EffectiveStatement<String, ContactStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public String getText() {
+ return rawArgument();
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ContainerEffectiveStatementImpl;
+
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class ContainerStatementImpl extends AbstractDeclaredStatement<QName> implements ContainerStatement {
+ //private QName qname;
protected ContainerStatementImpl(StmtContext<QName, ContainerStatement,?> context) {
super(context);
+ //this.qname =
}
public static class Definition extends AbstractStatementSupport<QName,ContainerStatement,EffectiveStatement<QName,ContainerStatement>> {
@Override
public EffectiveStatement<QName,ContainerStatement> createEffective(StmtContext<QName,ContainerStatement,EffectiveStatement<QName,ContainerStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new ContainerEffectiveStatementImpl(ctx);
}
}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.RangeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+
+public class Decimal64SpecificationImpl extends AbstractDeclaredStatement<String> implements TypeStatement.Decimal64Specification{
+
+ protected Decimal64SpecificationImpl(StmtContext<String, TypeStatement.Decimal64Specification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,TypeStatement.Decimal64Specification,EffectiveStatement<String,TypeStatement.Decimal64Specification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.FRACTION_DIGITS);
+ }
+
+ @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return value;
+ }
+
+ @Override public TypeStatement.Decimal64Specification createDeclared(
+ StmtContext<String, TypeStatement.Decimal64Specification, ?> ctx) {
+ return new Decimal64SpecificationImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<String, TypeStatement.Decimal64Specification> createEffective(
+ StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public FractionDigitsStatement getFractionDigits() {
+ return firstDeclared(FractionDigitsStatement.class);
+ }
+
+ @Override
+ public RangeStatement getRange() {
+ return firstDeclared(RangeStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+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.DefaultStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class DefaultStatementImpl extends AbstractDeclaredStatement<String> implements
+ DefaultStatement {
+
+ protected DefaultStatementImpl(
+ StmtContext<String, DefaultStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,DefaultStatement,EffectiveStatement<String,DefaultStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.DEFAULT);
+ }
+
+ @Override public String parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override public DefaultStatement createDeclared(
+ StmtContext<String, DefaultStatement, ?> ctx) {
+ return new DefaultStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<String, DefaultStatement> createEffective(
+ StmtContext<String, DefaultStatement, EffectiveStatement<String, DefaultStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public String getValue() {
+ return rawArgument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nonnull;
+
+public class DescriptionStatementImpl extends AbstractDeclaredStatement<String> implements DescriptionStatement {
+
+ protected DescriptionStatementImpl(
+ StmtContext<String, DescriptionStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,DescriptionStatement,EffectiveStatement<String,DescriptionStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.DESCRIPTION);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override
+ public DescriptionStatement createDeclared(StmtContext<String, DescriptionStatement, ?> ctx) {
+ return new DescriptionStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, DescriptionStatement> createEffective(StmtContext<String, DescriptionStatement, EffectiveStatement<String, DescriptionStatement>> ctx) {
+ return new DescriptionEffectiveStatementImpl(ctx);
+ }
+ }
+
+ @Nonnull @Override
+ public String getText() {
+ return rawArgument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class DeviateStatementImpl extends AbstractDeclaredStatement<String> implements DeviateStatement {
+
+ protected DeviateStatementImpl(
+ StmtContext<String, DeviateStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,DeviateStatement,EffectiveStatement<String,DeviateStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.DEVIATE);
+ }
+
+ @Override public String parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override public DeviateStatement createDeclared(
+ StmtContext<String, DeviateStatement, ?> ctx) {
+ return new DeviateStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<String, DeviateStatement> createEffective(
+ StmtContext<String, DeviateStatement, EffectiveStatement<String, DeviateStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public String getValue() {
+ return rawArgument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements DeviationStatement {
+
+ protected DeviationStatementImpl(
+ StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier,DeviationStatement,EffectiveStatement<SchemaNodeIdentifier,DeviationStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.DEVIATION);
+ }
+
+ @Override public SchemaNodeIdentifier parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+ }
+
+ @Override public DeviationStatement createDeclared(
+ StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+ return new DeviationStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<SchemaNodeIdentifier, DeviationStatement> createEffective(
+ StmtContext<SchemaNodeIdentifier, DeviationStatement, EffectiveStatement<SchemaNodeIdentifier, DeviationStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public SchemaNodeIdentifier getTargetNode() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
+
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class EnumSpecificationImpl extends AbstractDeclaredStatement<String>
+ implements TypeStatement.EnumSpecification {
+
+ protected EnumSpecificationImpl(
+ StmtContext<String, TypeStatement.EnumSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.EnumSpecification, EffectiveStatement<String, TypeStatement.EnumSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ENUM);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.EnumSpecification createDeclared(
+ StmtContext<String, TypeStatement.EnumSpecification, ?> ctx) {
+ return new EnumSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.EnumSpecification> createEffective(
+ StmtContext<String, TypeStatement.EnumSpecification, EffectiveStatement<String, TypeStatement.EnumSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends EnumStatement> getEnums() {
+ return allDeclared(EnumStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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.EnumStatement;
+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;
+
+public class EnumStatementImpl extends AbstractDeclaredStatement<String>
+ implements EnumStatement {
+
+ protected EnumStatementImpl(
+ StmtContext<String, EnumStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, EnumStatement, EffectiveStatement<String, EnumStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ENUM);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public EnumStatement createDeclared(
+ StmtContext<String, EnumStatement, ?> ctx) {
+ return new EnumStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, EnumStatement> createEffective(
+ StmtContext<String, EnumStatement, EffectiveStatement<String, EnumStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public ValueStatement getValue() {
+ return firstDeclared(ValueStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+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;
+
+public class ErrorAppTagStatementImpl extends AbstractDeclaredStatement<String>
+ implements ErrorAppTagStatement {
+
+ protected ErrorAppTagStatementImpl(
+ StmtContext<String, ErrorAppTagStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, ErrorAppTagStatement, EffectiveStatement<String, ErrorAppTagStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ERROR_APP_TAG);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public ErrorAppTagStatement createDeclared(
+ StmtContext<String, ErrorAppTagStatement, ?> ctx) {
+ return new ErrorAppTagStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, ErrorAppTagStatement> createEffective(
+ StmtContext<String, ErrorAppTagStatement, EffectiveStatement<String, ErrorAppTagStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+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.ErrorMessageStatement;
+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;
+
+public class ErrorMessageStatementImpl extends
+ AbstractDeclaredStatement<String> implements ErrorMessageStatement {
+
+ protected ErrorMessageStatementImpl(
+ StmtContext<String, ErrorMessageStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, ErrorMessageStatement, EffectiveStatement<String, ErrorMessageStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ERROR_MESSAGE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public ErrorMessageStatement createDeclared(
+ StmtContext<String, ErrorMessageStatement, ?> ctx) {
+ return new ErrorMessageStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, ErrorMessageStatement> createEffective(
+ StmtContext<String, ErrorMessageStatement, EffectiveStatement<String, ErrorMessageStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.ArgumentStatement;
+
+import org.opendaylight.yangtools.yang.common.QName;
+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.ExtensionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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;
+
+public class ExtensionStatementImpl extends AbstractDeclaredStatement<QName> implements ExtensionStatement {
+
+ protected ExtensionStatementImpl(StmtContext<QName, ExtensionStatement,?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<QName,ExtensionStatement,EffectiveStatement<QName,ExtensionStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.EXTENSION);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?,?,?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx,value);
+ }
+
+ @Override
+ public ExtensionStatement createDeclared(StmtContext<QName, ExtensionStatement,?> ctx) {
+ return new ExtensionStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName,ExtensionStatement> createEffective(StmtContext<QName,ExtensionStatement,EffectiveStatement<QName,ExtensionStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public ArgumentStatement getArgument() {
+ return firstDeclared(ArgumentStatement.class);
+ }
+
+}
--- /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 java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+
+import org.opendaylight.yangtools.yang.common.QName;
+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.FeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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;
+
+public class FeatureStatementImpl extends AbstractDeclaredStatement<QName>
+ implements FeatureStatement {
+
+ protected FeatureStatementImpl(
+ StmtContext<QName, FeatureStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, FeatureStatement, EffectiveStatement<QName, FeatureStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.FEATURE);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public FeatureStatement createDeclared(
+ StmtContext<QName, FeatureStatement, ?> ctx) {
+ return new FeatureStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, FeatureStatement> createEffective(
+ StmtContext<QName, FeatureStatement, EffectiveStatement<QName, FeatureStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsStatement;
+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;
+
+public class FractionDigitsStatementImpl extends
+ AbstractDeclaredStatement<String> implements FractionDigitsStatement {
+
+ protected FractionDigitsStatementImpl(
+ StmtContext<String, FractionDigitsStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, FractionDigitsStatement, EffectiveStatement<String, FractionDigitsStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.FRACTION_DIGITS);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public FractionDigitsStatement createDeclared(
+ StmtContext<String, FractionDigitsStatement, ?> ctx) {
+ return new FractionDigitsStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, FractionDigitsStatement> createEffective(
+ StmtContext<String, FractionDigitsStatement, EffectiveStatement<String, FractionDigitsStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.GroupingEffectiveStatementImpl;
+
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.common.QName;
+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.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+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;
+
+public class GroupingStatementImpl extends AbstractDeclaredStatement<QName>
+ implements GroupingStatement {
+
+ protected GroupingStatementImpl(
+ StmtContext<QName, GroupingStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.GROUPING);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public GroupingStatement createDeclared(
+ StmtContext<QName, GroupingStatement, ?> ctx) {
+ return new GroupingStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, GroupingStatement> createEffective(
+ StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
+ return new GroupingEffectiveStatementImpl(ctx);
+ }
+
+ @Override
+ public void onFullDefinitionDeclared(
+ Mutable<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> stmt)
+ throws InferenceException, SourceException {
+ stmt.getParentContext().addContext(GroupingNamespace.class, stmt.getStatementArgument(),stmt);
+ //
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+
+}
--- /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 java.util.Collection;
+import java.util.HashSet;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+
+public class GroupingUtils {
+
+ /**
+ * @param sourceGrpStmtCtx
+ * @param targetCtx
+ * @throws SourceException
+ */
+ public static void copyFromSourceToTarget(
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+ StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
+
+ QNameModule newQNameModule = getNewQNameModule(targetCtx,
+ sourceGrpStmtCtx);
+ copyDeclaredStmts(sourceGrpStmtCtx, targetCtx, newQNameModule);
+ copyEffectiveStmts(sourceGrpStmtCtx, targetCtx, newQNameModule);
+
+ }
+
+ public static void copyDeclaredStmts(
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+ StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+ throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceGrpStmtCtx
+ .declaredSubstatements();
+ for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
+ if (needToCopyByUses(originalStmtCtx)) {
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx
+ .createCopy(newQNameModule, targetCtx);
+ targetCtx.addEffectiveSubstatement(copy);
+ } else if (isReusedByUses(originalStmtCtx)) {
+ targetCtx.addEffectiveSubstatement(originalStmtCtx);
+ }
+ }
+ }
+
+ public static void copyEffectiveStmts(
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
+ StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+ throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceGrpStmtCtx
+ .effectiveSubstatements();
+ for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
+ if (needToCopyByUses(originalStmtCtx)) {
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx
+ .createCopy(newQNameModule, targetCtx);
+ targetCtx.addEffectiveSubstatement(copy);
+ } else if (isReusedByUses(originalStmtCtx)) {
+ targetCtx.addEffectiveSubstatement(originalStmtCtx);
+ }
+ }
+ }
+
+ public static QNameModule getNewQNameModule(
+ StatementContextBase<?, ?, ?> targetCtx,
+ StmtContext<?, ?, ?> stmtContext) {
+ if (needToCreateNewQName(stmtContext.getPublicDefinition())) {
+ Object targetStmtArgument = targetCtx.getStatementArgument();
+ Object sourceStmtArgument = stmtContext.getStatementArgument();
+ if (targetStmtArgument instanceof QName
+ && sourceStmtArgument instanceof QName) {
+ QName targetQName = (QName) targetStmtArgument;
+ QNameModule targetQNameModule = targetQName.getModule();
+
+ QName sourceQName = (QName) sourceStmtArgument;
+ QNameModule sourceQNameModule = sourceQName.getModule();
+
+ if (targetQNameModule.equals(sourceQNameModule))
+ return null;
+ else
+ return targetQNameModule;
+ } else
+ return null;
+ } else
+ return null;
+ }
+
+ public static boolean needToCreateNewQName(
+ StatementDefinition publicDefinition) {
+ return true;
+ }
+
+ public static boolean needToCopyByUses(StmtContext<?, ?, ?> stmtContext) {
+
+ HashSet<StatementDefinition> noCopyDefSet = new HashSet<StatementDefinition>();
+ noCopyDefSet.add(Rfc6020Mapping.USES);
+
+ StatementDefinition def = stmtContext.getPublicDefinition();
+ if (noCopyDefSet.contains(def))
+ return false;
+ else
+ return true;
+ }
+
+ public static boolean isReusedByUses(StmtContext<?, ?, ?> stmtContext) {
+
+ HashSet<StatementDefinition> reusedDefSet = new HashSet<StatementDefinition>();
+ reusedDefSet.add(Rfc6020Mapping.TYPEDEF);
+
+ StatementDefinition def = stmtContext.getPublicDefinition();
+ if (reusedDefSet.contains(def))
+ return true;
+ else
+ return false;
+ }
+
+ public static void resolveUsesNode(
+ Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
+ StatementContextBase<?, ?, ?> targetNodeStmtCtx)
+ throws SourceException {
+
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = usesNode
+ .declaredSubstatements();
+ for (StatementContextBase<?, ?, ?> subStmtCtx : declaredSubstatements) {
+ if (StmtContextUtils.producesDeclared(subStmtCtx,
+ WhenStatement.class)) {
+ StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(
+ null, targetNodeStmtCtx);
+ targetNodeStmtCtx.addEffectiveSubstatement(copy);
+ }
+ if (StmtContextUtils.producesDeclared(subStmtCtx,
+ RefineStatement.class)) {
+ // :TODO resolve and perform refine statement
+ }
+ if (StmtContextUtils.producesDeclared(subStmtCtx,
+ AugmentStatement.class)) {
+ // :TODO find target node and perform augmentation
+ }
+ // :TODO resolve other uses substatements
+ }
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class IdentityRefSpecificationImpl extends
+ AbstractDeclaredStatement<String> implements
+ TypeStatement.IdentityRefSpecification {
+
+ protected IdentityRefSpecificationImpl(
+ StmtContext<String, TypeStatement.IdentityRefSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.BASE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.IdentityRefSpecification createDeclared(
+ StmtContext<String, TypeStatement.IdentityRefSpecification, ?> ctx) {
+ return new IdentityRefSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.IdentityRefSpecification> createEffective(
+ StmtContext<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
+import org.opendaylight.yangtools.yang.common.QName;
+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.IdentityStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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;
+
+public class IdentityStatementImpl extends AbstractDeclaredStatement<QName>
+ implements IdentityStatement {
+
+ protected IdentityStatementImpl(
+ StmtContext<QName, IdentityStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.IDENTITY);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public IdentityStatement createDeclared(
+ StmtContext<QName, IdentityStatement, ?> ctx) {
+ return new IdentityStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, IdentityStatement> createEffective(
+ StmtContext<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public BaseStatement getBase() {
+ return firstDeclared(BaseStatement.class);
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.common.QName;
+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.IfFeatureStatement;
+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;
+
+public class IfFeatureStatementImpl extends AbstractDeclaredStatement<QName>
+ implements IfFeatureStatement {
+
+ protected IfFeatureStatementImpl(
+ StmtContext<QName, IfFeatureStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, IfFeatureStatement, EffectiveStatement<QName, IfFeatureStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.IF_FEATURE);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public IfFeatureStatement createDeclared(
+ StmtContext<QName, IfFeatureStatement, ?> ctx) {
+ return new IfFeatureStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, IfFeatureStatement> createEffective(
+ StmtContext<QName, IfFeatureStatement, EffectiveStatement<QName, IfFeatureStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-
import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
-
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import com.google.common.base.Optional;
import java.net.URI;
import java.text.ParseException;
}
@Override
- public void onLinkageDeclared(final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
+ public void onLinkageDeclared(
+ final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
throws InferenceException, SourceException {
final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt);
ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final Prerequisite<StmtContext<?, ?, ?>> imported;
final Prerequisite<Mutable<?, ?, ?>> linkageTarget;
imported = importAction.requiresCtx(stmt, ModuleNamespace.class, impIdentifier, SOURCE_LINKAGE);
- linkageTarget = importAction.mutatesCtx(stmt.getRoot(),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() {
});
}
- private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt) throws SourceException {
+ private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt)
+ throws SourceException {
+
String moduleName = stmt.getStatementArgument();
String revisionArg = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
final Optional<Date> revision;
try {
revision = Optional.of(SimpleDateFormatUtil.getRevisionFormat().parse(revisionArg));
} catch (ParseException e) {
- throw new SourceException(
- String.format("Revision value %s is not in required format yyyy-MM-dd", revisionArg),
- stmt.getStatementSourceReference(), e);
+ throw new SourceException(String.format("Revision value %s is not in required format yyyy-MM-dd",
+ revisionArg), stmt.getStatementSourceReference(), e);
}
} else {
- revision = Optional.absent();
+ revision = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP);
}
return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(), revision);
}
--- /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 static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
+import java.net.URI;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Date;
+
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+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.IncludeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+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.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
+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.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import com.google.common.base.Optional;
+
+public class IncludeStatementImpl extends AbstractDeclaredStatement<String> implements IncludeStatement {
+
+ protected IncludeStatementImpl(StmtContext<String, IncludeStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends
+ AbstractStatementSupport<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.INCLUDE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public IncludeStatement createDeclared(StmtContext<String, IncludeStatement, ?> ctx) {
+ return new IncludeStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, IncludeStatement> createEffective(
+ StmtContext<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void onLinkageDeclared(
+ final Mutable<String, IncludeStatement, EffectiveStatement<String, IncludeStatement>> stmt)
+ throws InferenceException, SourceException {
+ final ModuleIdentifier includeSubmoduleIdentifier = getIncludeSubmoduleIdentifier(stmt);
+
+ ModelActionBuilder includeAction = stmt.newInferenceAction(SOURCE_LINKAGE);
+ final Prerequisite<StmtContext<?, ?, ?>> requiresCtxPrerequisite = includeAction.requiresCtx(stmt,
+ SubmoduleNamespace.class, includeSubmoduleIdentifier, SOURCE_LINKAGE);
+ final Prerequisite<Mutable<?, ?, ?>> mutatesCtxPrerequisite = includeAction.mutatesCtx(stmt.getRoot(),
+ SOURCE_LINKAGE);
+
+ includeAction.apply(new InferenceAction() {
+
+ @Override
+ public void apply() throws InferenceException {
+ StmtContext<?, ?, ?> includedSubmoduleStmt = requiresCtxPrerequisite.get();
+
+ mutatesCtxPrerequisite.get().addToNs(IncludedModuleContext.class, includeSubmoduleIdentifier,
+ includedSubmoduleStmt);
+ }
+
+ @Override
+ public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
+ System.out.println("");
+ if (failed.contains(requiresCtxPrerequisite)) {
+ throw new InferenceException("Included submodule was not found.", stmt
+ .getStatementSourceReference());
+ }
+ }
+ });
+ }
+
+ private static ModuleIdentifier getIncludeSubmoduleIdentifier(Mutable<String, IncludeStatement, ?> stmt) {
+
+ String subModuleName = stmt.getStatementArgument();
+ String revisionArg = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
+ final Optional<Date> revision;
+ if (revisionArg != null) {
+ try {
+ revision = Optional.of(SimpleDateFormatUtil.getRevisionFormat().parse(revisionArg));
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e);
+ }
+ } else {
+ revision = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP);
+ }
+
+ return new ModuleIdentifierImpl(subModuleName, Optional.<URI> absent(), revision);
+ }
+ }
+
+ @Override
+ public String getModule() {
+ return argument();
+ }
+
+ @Override
+ public PrefixStatement getPrefix() {
+ return firstDeclared(PrefixStatement.class);
+ }
+
+ @Override
+ public RevisionDateStatement getRevisionDate() {
+ return firstDeclared(RevisionDateStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
+
+public interface IncludedModuleContext extends ImportedNamespaceContext<ModuleIdentifier> {
+
+}
--- /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 org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class InputStatementImpl extends AbstractDeclaredStatement<Void>
+ implements InputStatement {
+
+ protected InputStatementImpl(
+ StmtContext<Void, InputStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Void, InputStatement, EffectiveStatement<Void, InputStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.INPUT);
+ }
+
+ @Override
+ public Void parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return null;
+ }
+
+ @Override
+ public InputStatement createDeclared(
+ StmtContext<Void, InputStatement, ?> ctx) {
+ return new InputStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Void, InputStatement> createEffective(
+ StmtContext<Void, InputStatement, EffectiveStatement<Void, InputStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+}
+
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class InstanceIdentifierSpecificationImpl extends
+ AbstractDeclaredStatement<String> implements
+ TypeStatement.InstanceIdentifierSpecification {
+
+ protected InstanceIdentifierSpecificationImpl(
+ StmtContext<String, TypeStatement.InstanceIdentifierSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.InstanceIdentifierSpecification, EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REQUIRE_INSTANCE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.InstanceIdentifierSpecification createDeclared(
+ StmtContext<String, TypeStatement.InstanceIdentifierSpecification, ?> ctx) {
+ return new InstanceIdentifierSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification> createEffective(
+ StmtContext<String, TypeStatement.InstanceIdentifierSpecification, EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public RequireInstanceStatement getRequireInstance() {
+ return firstDeclared(RequireInstanceStatement.class);
+ }
+
+}
--- /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 java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+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.KeyStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+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 com.google.common.base.Splitter;
+
+public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier>> implements
+ KeyStatement {
+
+ protected KeyStatementImpl(StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement, EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> {
+
+ public static final char SEPARATOR = ' ';
+
+ public Definition() {
+ super(Rfc6020Mapping.KEY);
+ }
+
+ @Override
+ public Collection<SchemaNodeIdentifier> parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+
+ Splitter keySplitter = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults();
+ List<String> keyTokens = keySplitter.splitToList(value);
+
+ // to detect if key contains duplicates
+ if ((new HashSet<>(keyTokens)).size() < keyTokens.size()) {
+ throw new IllegalArgumentException();
+ }
+
+ Set<SchemaNodeIdentifier> keyNodes = new HashSet<>();
+
+ for (String keyToken : keyTokens) {
+
+ SchemaNodeIdentifier keyNode = SchemaNodeIdentifier
+ .create(true, Utils.qNameFromArgument(ctx, keyToken));
+ keyNodes.add(keyNode);
+ }
+
+ return keyNodes;
+ }
+
+ @Override
+ public KeyStatement createDeclared(StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> ctx) {
+ return new KeyStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement> createEffective(
+ StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnitsStatement;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.MaxElementsStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByStatement;
+import org.opendaylight.yangtools.yang.common.QName;
+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.LeafListStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+public class LeafListStatementImpl extends AbstractDeclaredStatement<QName>
+ implements LeafListStatement {
+
+ protected LeafListStatementImpl(
+ StmtContext<QName, LeafListStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.LEAF_LIST);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public LeafListStatement createDeclared(
+ StmtContext<QName, LeafListStatement, ?> ctx) {
+ return new LeafListStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, LeafListStatement> createEffective(
+ StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Nullable
+ @Override
+ public ConfigStatement getConfig() {
+ return firstDeclared(ConfigStatement.class);
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Nonnull
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public MinElementsStatement getMinElements() {
+ return firstDeclared(MinElementsStatement.class);
+ }
+
+ @Override
+ public MaxElementsStatement getMaxElements() {
+ return firstDeclared(MaxElementsStatement.class);
+ }
+
+ @Override
+ public OrderedByStatement getOrderedBy() {
+ return firstDeclared(OrderedByStatement.class);
+ }
+
+ @Override
+ public Collection<? extends MustStatement> getMusts() {
+ return allDeclared(MustStatement.class);
+ }
+
+ @Override
+ public TypeStatement getType() {
+ return firstDeclared(TypeStatement.class);
+ }
+
+ @Override
+ public UnitsStatement getUnits() {
+ return firstDeclared(UnitsStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DefaultStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.LeafStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnitsStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+public class LeafStatementImpl extends AbstractDeclaredStatement<QName> implements LeafStatement {
+
+ protected LeafStatementImpl(StmtContext<QName, LeafStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<QName,LeafStatement,EffectiveStatement<QName,LeafStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.LEAF);
+ }
+
+ @Override public QName parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return Utils.qNameFromArgument(ctx,value);
+ }
+
+ @Override public LeafStatement createDeclared(
+ StmtContext<QName, LeafStatement, ?> ctx) {
+ return new LeafStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<QName, LeafStatement> createEffective(
+ StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nullable @Override
+ public Collection<? extends MustStatement> getMusts() {
+ return allDeclared(MustStatement.class);
+ }
+
+ @Nullable @Override
+ public DefaultStatement getDefault() {
+ return firstDeclared(DefaultStatement.class);
+ }
+
+ @Nullable @Override
+ public ConfigStatement getConfig() {
+ return firstDeclared(ConfigStatement.class);
+ }
+
+ @Nullable @Override
+ public MandatoryStatement getMandatory() {
+ return firstDeclared(MandatoryStatement.class);
+ }
+
+ @Nonnull @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Nonnull @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Nullable @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Nonnull @Override
+ public TypeStatement getType() {
+ return firstDeclared(TypeStatement.class);
+ }
+
+ @Nullable @Override
+ public UnitsStatement getUnits() {
+ return firstDeclared(UnitsStatement.class);
+ }
+
+ @Nullable @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
+ implements TypeStatement.LeafrefSpecification {
+
+ protected LeafrefSpecificationImpl(
+ StmtContext<String, TypeStatement.LeafrefSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.PATH);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.LeafrefSpecification createDeclared(
+ StmtContext<String, TypeStatement.LeafrefSpecification, ?> ctx) {
+ return new LeafrefSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.LeafrefSpecification> createEffective(
+ StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public PathStatement getPath() {
+ return firstDeclared(PathStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+
+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.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class LengthStatementImpl extends AbstractDeclaredStatement<String>
+ implements LengthStatement {
+
+ protected LengthStatementImpl(
+ StmtContext<String, LengthStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, LengthStatement, EffectiveStatement<String, LengthStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.LENGTH);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public LengthStatement createDeclared(
+ StmtContext<String, LengthStatement, ?> ctx) {
+ return new LengthStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, LengthStatement> createEffective(
+ StmtContext<String, LengthStatement, EffectiveStatement<String, LengthStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public ErrorAppTagStatement getErrorAppTagStatement() {
+ return firstDeclared(ErrorAppTagStatement.class);
+ }
+
+ @Override
+ public ErrorMessageStatement getErrorMessageStatement() {
+ return firstDeclared(ErrorMessageStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MaxElementsStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrderedByStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UniqueStatement;
+
+import org.opendaylight.yangtools.yang.common.QName;
+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.ListStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ConfigStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collection;
+
+public class ListStatementImpl extends AbstractDeclaredStatement<QName>
+ implements ListStatement {
+
+ protected ListStatementImpl(StmtContext<QName, ListStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, ListStatement, EffectiveStatement<QName, ListStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.LIST);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public ListStatement createDeclared(
+ StmtContext<QName, ListStatement, ?> ctx) {
+ return new ListStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, ListStatement> createEffective(
+ StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Nullable
+ @Override
+ public ConfigStatement getConfig() {
+ return firstDeclared(ConfigStatement.class);
+ }
+
+ @Override
+ public WhenStatement getWhenStatement() {
+ return firstDeclared(WhenStatement.class);
+ }
+
+ @Nonnull
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public MinElementsStatement getMinElements() {
+ return firstDeclared(MinElementsStatement.class);
+ }
+
+ @Override
+ public MaxElementsStatement getMaxElements() {
+ return firstDeclared(MaxElementsStatement.class);
+ }
+
+ @Override
+ public OrderedByStatement getOrderedBy() {
+ return firstDeclared(OrderedByStatement.class);
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+
+ @Override
+ public Collection<? extends MustStatement> getMusts() {
+ return allDeclared(MustStatement.class);
+ }
+
+ @Override
+ public KeyStatement getKey() {
+ return firstDeclared(KeyStatement.class);
+ }
+
+ @Override
+ public Collection<? extends UniqueStatement> getUnique() {
+ return allDeclared(UniqueStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class MandatoryStatementImpl extends AbstractDeclaredStatement<Boolean> implements
+ MandatoryStatement {
+
+ protected MandatoryStatementImpl(
+ StmtContext<Boolean, MandatoryStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<Boolean,MandatoryStatement,EffectiveStatement<Boolean,MandatoryStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.MANDATORY);
+ }
+
+ @Override public Boolean parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return Boolean.valueOf(value);
+ }
+
+ @Override public MandatoryStatement createDeclared(
+ StmtContext<Boolean, MandatoryStatement, ?> ctx) {
+ return new MandatoryStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<Boolean, MandatoryStatement> createEffective(
+ StmtContext<Boolean, MandatoryStatement, EffectiveStatement<Boolean, MandatoryStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public Boolean getValue() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MaxElementsStatement;
+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;
+
+public class MaxElementsStatementImpl extends AbstractDeclaredStatement<String>
+ implements MaxElementsStatement {
+
+ protected MaxElementsStatementImpl(
+ StmtContext<String, MaxElementsStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, MaxElementsStatement, EffectiveStatement<String, MaxElementsStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.MAX_ELEMENTS);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public MaxElementsStatement createDeclared(
+ StmtContext<String, MaxElementsStatement, ?> ctx) {
+ return new MaxElementsStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, MaxElementsStatement> createEffective(
+ StmtContext<String, MaxElementsStatement, EffectiveStatement<String, MaxElementsStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MinElementsStatement;
+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;
+
+public class MinElementsStatementImpl extends AbstractDeclaredStatement<String>
+ implements MinElementsStatement {
+
+ protected MinElementsStatementImpl(
+ StmtContext<String, MinElementsStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, MinElementsStatement, EffectiveStatement<String, MinElementsStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.MIN_ELEMENTS);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public MinElementsStatement createDeclared(
+ StmtContext<String, MinElementsStatement, ?> ctx) {
+ return new MinElementsStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, MinElementsStatement> createEffective(
+ StmtContext<String, MinElementsStatement, EffectiveStatement<String, MinElementsStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ModuleEffectiveStatementImpl;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
import com.google.common.base.Optional;
import java.net.URI;
import java.util.Date;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-public class ModuleStatementSupport extends AbstractStatementSupport<String, ModuleStatement, EffectiveStatement<String,ModuleStatement>> {
+public class ModuleStatementSupport
+ extends
+ AbstractStatementSupport<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> {
public ModuleStatementSupport() {
super(Rfc6020Mapping.MODULE);
}
@Override
- public String parseArgumentValue(StmtContext<?,?,?> ctx, String value) {
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
return value;
}
@Override
- public ModuleStatement createDeclared(StmtContext<String, ModuleStatement,?> ctx) {
+ public ModuleStatement createDeclared(
+ StmtContext<String, ModuleStatement, ?> ctx) {
return new ModuleStatementImpl(ctx);
}
@Override
- public EffectiveStatement<String,ModuleStatement> createEffective(StmtContext<String, ModuleStatement,EffectiveStatement<String,ModuleStatement>> ctx) {
- throw new UnsupportedOperationException();
+ public EffectiveStatement<String, ModuleStatement> createEffective(
+ StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+ return new ModuleEffectiveStatementImpl(ctx);
}
@Override
- public void onLinkageDeclared(Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt)
+ public void onLinkageDeclared(
+ Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt)
throws InferenceException, SourceException {
- URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(),NamespaceStatement.class);
- QNameModule qnameNamespace = QNameModule.create(moduleNs, null);
- ModuleIdentifierImpl moduleIdentifier = new ModuleIdentifierImpl(stmt.getStatementArgument(), Optional.<URI>absent(), Optional.<Date>absent());
+ Optional<URI> moduleNs = Optional.fromNullable(firstAttributeOf(
+ stmt.declaredSubstatements(), NamespaceStatement.class));
+ if (!moduleNs.isPresent()) {
+ throw new IllegalArgumentException("Namespace of the module ["
+ + stmt.getStatementArgument() + "] is missing.");
+ }
+
+ Optional<Date> revisionDate = Optional.fromNullable(firstAttributeOf(
+ stmt.declaredSubstatements(), RevisionStatement.class));
+
+ QNameModule qNameModule = QNameModule.create(moduleNs.get(),
+ revisionDate.orNull());
+ ModuleIdentifier moduleIdentifier = new ModuleIdentifierImpl(
+ stmt.getStatementArgument(), Optional.<URI> absent(),
+ revisionDate);
+
+ stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
+ stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
+
+ String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(),
+ PrefixStatement.class);
+ if (modulePrefix == null) {
+ throw new IllegalArgumentException("Prefix of the module ["
+ + stmt.getStatementArgument() + "] is missing.");
+ }
+
+ stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
+ stmt.addToNs(ModuleNameToModuleQName.class, stmt.getStatementArgument(), qNameModule);
+ stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, stmt.getStatementArgument());
+ stmt.addToNs(ModuleIdentifierToModuleQName.class, moduleIdentifier, qNameModule);
+
+ stmt.addToNs(ImpPrefixToModuleIdentifier.class, modulePrefix, moduleIdentifier);
- stmt.addContext(ModuleNamespace.class,moduleIdentifier ,stmt);
- stmt.addContext(NamespaceToModule.class, qnameNamespace, stmt);
}
+
+
+// @Override
+// public void onFullDefinitionDeclared(
+// Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt)
+// throws InferenceException, SourceException {
+//
+// Optional<Date> revisionDate = Optional.fromNullable(firstAttributeOf(
+// stmt.declaredSubstatements(), RevisionStatement.class));
+//
+// ModuleIdentifier moduleIdentifier = new ModuleIdentifierImpl(
+// stmt.getStatementArgument(), Optional.<URI> absent(),
+// revisionDate);
+//
+// String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(),
+// PrefixStatement.class);
+//
+// stmt.addToNs(ImpPrefixToModuleIdentifier.class, modulePrefix, moduleIdentifier);
+// }
+
}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public class MustStatementImpl extends AbstractDeclaredStatement<RevisionAwareXPath> implements
+ MustStatement {
+
+ protected MustStatementImpl(
+ StmtContext<RevisionAwareXPath, MustStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<RevisionAwareXPath,MustStatement,EffectiveStatement<RevisionAwareXPath,MustStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.MUST);
+ }
+
+ @Override public RevisionAwareXPath parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return new RevisionAwareXPathImpl(value, false);
+ }
+
+ @Override public MustStatement createDeclared(
+ StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
+ return new MustStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<RevisionAwareXPath, MustStatement> createEffective(
+ StmtContext<RevisionAwareXPath, MustStatement, EffectiveStatement<RevisionAwareXPath, MustStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public RevisionAwareXPath getCondition() {
+ return argument();
+ }
+
+ @Nullable @Override
+ public ErrorAppTagStatement getErrorAppTagStatement() {
+ return firstDeclared(ErrorAppTagStatement.class);
+ }
+
+ @Nullable @Override
+ public ErrorMessageStatement getErrorMessageStatement() {
+ return firstDeclared(ErrorMessageStatement.class);
+ }
+
+ @Nullable @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.NamespaceEffectiveStatementImpl;
+
import java.net.URI;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
@Override
public EffectiveStatement<URI,NamespaceStatement> createEffective(StmtContext<URI, NamespaceStatement,EffectiveStatement<URI,NamespaceStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new NamespaceEffectiveStatementImpl(ctx);
}
}
--- /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.Nullable;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.common.QName;
+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.NotificationStatement;
+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;
+
+public class NotificationStatementImpl extends AbstractDeclaredStatement<QName>
+ implements NotificationStatement {
+
+ protected NotificationStatementImpl(
+ StmtContext<QName, NotificationStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.NOTIFICATION);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public NotificationStatement createDeclared(
+ StmtContext<QName, NotificationStatement, ?> ctx) {
+ return new NotificationStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, NotificationStatement> createEffective(
+ StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RangeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+
+public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String> implements TypeStatement.NumericalRestrictions{
+
+ protected NumericalRestrictionsImpl(StmtContext<String, TypeStatement.NumericalRestrictions, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,TypeStatement.NumericalRestrictions,EffectiveStatement<String,TypeStatement.NumericalRestrictions>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.RANGE);
+ }
+
+ @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return value;
+ }
+
+ @Override public TypeStatement.NumericalRestrictions createDeclared(
+ StmtContext<String, TypeStatement.NumericalRestrictions, ?> ctx) {
+ return new NumericalRestrictionsImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<String, TypeStatement.NumericalRestrictions> createEffective(
+ StmtContext<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public RangeStatement getRange() {
+ return firstDeclared(RangeStatement.class);
+ }
+
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+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.OrderedByStatement;
+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;
+
+public class OrderedByStatementImpl extends AbstractDeclaredStatement<String>
+ implements OrderedByStatement {
+
+ protected OrderedByStatementImpl(
+ StmtContext<String, OrderedByStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, OrderedByStatement, EffectiveStatement<String, OrderedByStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ORDERED_BY);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public OrderedByStatement createDeclared(
+ StmtContext<String, OrderedByStatement, ?> ctx) {
+ return new OrderedByStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, OrderedByStatement> createEffective(
+ StmtContext<String, OrderedByStatement, EffectiveStatement<String, OrderedByStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OrganizationStatement;
+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;
+
+public class OrganizationStatementImpl extends AbstractDeclaredStatement<String>
+ implements OrganizationStatement {
+
+ protected OrganizationStatementImpl(
+ StmtContext<String, OrganizationStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, OrganizationStatement, EffectiveStatement<String, OrganizationStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.ORGANIZATION);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public OrganizationStatement createDeclared(
+ StmtContext<String, OrganizationStatement, ?> ctx) {
+ return new OrganizationStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, OrganizationStatement> createEffective(
+ StmtContext<String, OrganizationStatement, EffectiveStatement<String, OrganizationStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getText() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class OutputStatementImpl extends AbstractDeclaredStatement<Void>
+ implements OutputStatement {
+
+ protected OutputStatementImpl(
+ StmtContext<Void, OutputStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Void, OutputStatement, EffectiveStatement<Void, OutputStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.OUTPUT);
+ }
+
+ @Override
+ public Void parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return null;
+ }
+
+ @Override
+ public OutputStatement createDeclared(
+ StmtContext<Void, OutputStatement, ?> ctx) {
+ return new OutputStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Void, OutputStatement> createEffective(
+ StmtContext<Void, OutputStatement, EffectiveStatement<Void, OutputStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Override
+ public Collection<? extends DataDefinitionStatement> getDataDefinitions() {
+ return allDeclared(DataDefinitionStatement.class);
+ }
+}
+
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+
+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.PatternStatement;
+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;
+
+public class PatternStatementImpl extends AbstractDeclaredStatement<String>
+ implements PatternStatement {
+
+ protected PatternStatementImpl(
+ StmtContext<String, PatternStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, PatternStatement, EffectiveStatement<String, PatternStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.PATTERN);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public PatternStatement createDeclared(
+ StmtContext<String, PatternStatement, ?> ctx) {
+ return new PatternStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, PatternStatement> createEffective(
+ StmtContext<String, PatternStatement, EffectiveStatement<String, PatternStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public ErrorAppTagStatement getErrorAppTagStatement() {
+ return firstDeclared(ErrorAppTagStatement.class);
+ }
+
+ @Override
+ public ErrorMessageStatement getErrorMessageStatement() {
+ return firstDeclared(ErrorMessageStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
+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;
+
+public class PositionStatementImpl extends AbstractDeclaredStatement<String>
+ implements PositionStatement {
+
+ protected PositionStatementImpl(
+ StmtContext<String, PositionStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, PositionStatement, EffectiveStatement<String, PositionStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.POSITION);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public PositionStatement createDeclared(
+ StmtContext<String, PositionStatement, ?> ctx) {
+ return new PositionStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, PositionStatement> createEffective(
+ StmtContext<String, PositionStatement, EffectiveStatement<String, PositionStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PrefixEffectiveStatementImpl;
+
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.PrefixStatement;
@Override
public EffectiveStatement<String,PrefixStatement> createEffective(StmtContext<String, PrefixStatement,EffectiveStatement<String,PrefixStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new PrefixEffectiveStatementImpl(ctx);
}
}
--- /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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PresenceEffectiveStatementImpl;
+
+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.PresenceStatement;
+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;
+
+public class PresenceStatementImpl extends AbstractDeclaredStatement<String>
+ implements PresenceStatement {
+
+ protected PresenceStatementImpl(
+ StmtContext<String, PresenceStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, PresenceStatement, EffectiveStatement<String, PresenceStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.PRESENCE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public PresenceStatement createDeclared(
+ StmtContext<String, PresenceStatement, ?> ctx) {
+ return new PresenceStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, PresenceStatement> createEffective(
+ StmtContext<String, PresenceStatement, EffectiveStatement<String, PresenceStatement>> ctx) {
+ return new PresenceEffectiveStatementImpl(ctx);
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+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.RangeStatement;
+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;
+
+public class RangeStatementImpl extends AbstractDeclaredStatement<String>
+ implements RangeStatement {
+
+ protected RangeStatementImpl(
+ StmtContext<String, RangeStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, RangeStatement, EffectiveStatement<String, RangeStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.RANGE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public RangeStatement createDeclared(
+ StmtContext<String, RangeStatement, ?> ctx) {
+ return new RangeStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, RangeStatement> createEffective(
+ StmtContext<String, RangeStatement, EffectiveStatement<String, RangeStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public ErrorAppTagStatement getErrorAppTagStatement() {
+ return firstDeclared(ErrorAppTagStatement.class);
+ }
+
+ @Override
+ public ErrorMessageStatement getErrorMessageStatement() {
+ return firstDeclared(ErrorMessageStatement.class);
+ }
+
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public String getRange() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
+
+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.ReferenceStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nonnull;
+
+public class ReferenceStatementImpl extends AbstractDeclaredStatement<String> implements ReferenceStatement {
+
+ protected ReferenceStatementImpl(
+ StmtContext<String, ReferenceStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,ReferenceStatement,EffectiveStatement<String,ReferenceStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REFERENCE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override
+ public ReferenceStatement createDeclared(StmtContext<String, ReferenceStatement, ?> ctx) {
+ return new ReferenceStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, ReferenceStatement> createEffective(StmtContext<String, ReferenceStatement, EffectiveStatement<String, ReferenceStatement>> ctx) {
+ return new ReferenceEffectiveStatementImpl(ctx);
+ }
+ }
+
+ @Nonnull @Override
+ public String getText() {
+ return rawArgument();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * <p/>
+ * 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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nullable;
+
+public class RefineStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements RefineStatement {
+
+ protected RefineStatementImpl(
+ StmtContext<SchemaNodeIdentifier, RefineStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends
+ AbstractStatementSupport<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REFINE);
+ }
+
+ @Override
+ public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+ }
+
+ @Override
+ public RefineStatement createDeclared(StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
+ return new RefineStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<SchemaNodeIdentifier, RefineStatement> createEffective(StmtContext<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getTargetNode() {
+ return rawArgument();
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RequireInstanceStatement;
+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;
+
+public class RequireInstanceStatementImpl extends
+ AbstractDeclaredStatement<Boolean> implements RequireInstanceStatement {
+
+ protected RequireInstanceStatementImpl(
+ StmtContext<Boolean, RequireInstanceStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Boolean, RequireInstanceStatement, EffectiveStatement<Boolean, RequireInstanceStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REQUIRE_INSTANCE);
+ }
+
+ @Override
+ public Boolean parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Boolean.valueOf(value);
+ }
+
+ @Override
+ public RequireInstanceStatement createDeclared(
+ StmtContext<Boolean, RequireInstanceStatement, ?> ctx) {
+ return new RequireInstanceStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Boolean, RequireInstanceStatement> createEffective(
+ StmtContext<Boolean, RequireInstanceStatement, EffectiveStatement<Boolean, RequireInstanceStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public Boolean getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
+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;
+
+public class RevisionDateStatementImpl extends
+ AbstractDeclaredStatement<String> implements RevisionDateStatement {
+
+ protected RevisionDateStatementImpl(
+ StmtContext<String, RevisionDateStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, RevisionDateStatement, EffectiveStatement<String, RevisionDateStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REVISION_DATE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public RevisionDateStatement createDeclared(
+ StmtContext<String, RevisionDateStatement, ?> ctx) {
+ return new RevisionDateStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, RevisionDateStatement> createEffective(
+ StmtContext<String, RevisionDateStatement, EffectiveStatement<String, RevisionDateStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getDate() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+
+import java.text.ParseException;
+import java.util.Date;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nullable;
+
+public class RevisionStatementImpl extends AbstractDeclaredStatement<Date>
+ implements RevisionStatement {
+
+ protected RevisionStatementImpl(
+ StmtContext<Date, RevisionStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.REVISION);
+ }
+
+ @Override
+ public Date parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ Date revision;
+ try {
+ revision = SimpleDateFormatUtil.getRevisionFormat()
+ .parse(value);
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ return revision;
+ }
+
+ @Override
+ public RevisionStatement createDeclared(
+ StmtContext<Date, RevisionStatement, ?> ctx) {
+ return new RevisionStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Date, RevisionStatement> createEffective(
+ StmtContext<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public Date getDate() {
+ return argument();
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
--- /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.Nullable;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class RpcStatementImpl extends AbstractDeclaredStatement<QName>
+ implements RpcStatement {
+
+ protected RpcStatementImpl(StmtContext<QName, RpcStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.RPC);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public RpcStatement createDeclared(
+ StmtContext<QName, RpcStatement, ?> ctx) {
+ return new RpcStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, RpcStatement> createEffective(
+ StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends TypedefStatement> getTypedefs() {
+ return allDeclared(TypedefStatement.class);
+ }
+
+ @Override
+ public Collection<? extends GroupingStatement> getGroupings() {
+ return allDeclared(GroupingStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public InputStatement getInput() {
+ return firstDeclared(InputStatement.class);
+ }
+
+ @Override
+ public OutputStatement getOutput() {
+ return firstDeclared(OutputStatement.class);
+ }
+
+ @Override
+ public Collection<? extends IfFeatureStatement> getIfFeatures() {
+ return allDeclared(IfFeatureStatement.class);
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+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;
+
+public class StatusStatementImpl extends AbstractDeclaredStatement<String>
+ implements StatusStatement {
+
+ protected StatusStatementImpl(
+ StmtContext<String, StatusStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, StatusStatement, EffectiveStatement<String, StatusStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.STATUS);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public StatusStatement createDeclared(
+ StmtContext<String, StatusStatement, ?> ctx) {
+ return new StatusStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, StatusStatement> createEffective(
+ StmtContext<String, StatusStatement, EffectiveStatement<String, StatusStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.LengthStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PatternStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class StringRestrictionsImpl extends AbstractDeclaredStatement<String>
+ implements TypeStatement.StringRestrictions {
+
+ protected StringRestrictionsImpl(
+ StmtContext<String, TypeStatement.StringRestrictions, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.StringRestrictions, EffectiveStatement<String, TypeStatement.StringRestrictions>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.TYPE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.StringRestrictions createDeclared(
+ StmtContext<String, TypeStatement.StringRestrictions, ?> ctx) {
+ return new StringRestrictionsImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.StringRestrictions> createEffective(
+ StmtContext<String, TypeStatement.StringRestrictions, EffectiveStatement<String, TypeStatement.StringRestrictions>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public LengthStatement getLength() {
+ return firstDeclared(LengthStatement.class);
+ }
+
+ @Override
+ public Collection<? extends PatternStatement> getPatterns() {
+ return allDeclared(PatternStatement.class);
+ }
+
+}
--- /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 static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.findFirstDeclaredSubstatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.util.Date;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+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.RevisionStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class SubmoduleStatementImpl extends
+ AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
+
+ protected SubmoduleStatementImpl(
+ StmtContext<String, SubmoduleStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.SUBMODULE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public SubmoduleStatement createDeclared(
+ StmtContext<String, SubmoduleStatement, ?> ctx) {
+ return new SubmoduleStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, SubmoduleStatement> createEffective(
+ StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void onLinkageDeclared(
+ Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt)
+ throws InferenceException, SourceException {
+
+ Optional<Date> revisionDate = Optional
+ .fromNullable(firstAttributeOf(
+ stmt.declaredSubstatements(),
+ RevisionStatement.class));
+
+ ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl(
+ stmt.getStatementArgument(), Optional.<URI> absent(),
+ revisionDate);
+
+ stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
+
+ String belongsToModuleName = firstAttributeOf(
+ stmt.declaredSubstatements(), BelongsToStatement.class);
+ StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(
+ stmt, 0, BelongsToStatement.class, PrefixStatement.class);
+
+ if(prefixSubStmtCtx == null) {
+ throw new IllegalArgumentException("Prefix of belongsTo statement is missing in submodule ["
+ + stmt.getStatementArgument() + "].");
+ }
+
+ String prefix = (String) prefixSubStmtCtx.getStatementArgument();
+
+ stmt.addToNs(BelongsToPrefixToModuleName.class, prefix,
+ belongsToModuleName);
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ return rawArgument();
+ }
+
+ @Override
+ public YangVersionStatement getYangVersion() {
+ return firstDeclared(YangVersionStatement.class);
+ }
+
+ @Override
+ public BelongsToStatement getBelongsTo() {
+ return firstDeclared(BelongsToStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+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 javax.annotation.Nonnull;
+
+public class TypeStatementImpl extends AbstractDeclaredStatement<String> implements TypeStatement {
+
+ protected TypeStatementImpl(StmtContext<String, TypeStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,TypeStatement,EffectiveStatement<String,TypeStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.TYPE);
+ }
+
+ @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
+ String value) throws SourceException {
+ return value;
+ }
+
+ @Override public TypeStatement createDeclared(
+ StmtContext<String, TypeStatement, ?> ctx) {
+ return new TypeStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<String, TypeStatement> createEffective(
+ StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public String getName() {
+ return argument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnitsStatement;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import javax.annotation.Nullable;
+
+public class TypedefStatementImpl extends AbstractDeclaredStatement<QName>
+ implements TypedefStatement {
+
+ protected TypedefStatementImpl(
+ StmtContext<QName, TypedefStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<QName, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.TYPEDEF);
+ }
+
+ @Override
+ public QName parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return Utils.qNameFromArgument(ctx, value);
+ }
+
+ @Override
+ public TypedefStatement createDeclared(
+ StmtContext<QName, TypedefStatement, ?> ctx) {
+ return new TypedefStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<QName, TypedefStatement> createEffective(
+ StmtContext<QName, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nullable
+ @Override
+ public StatusStatement getStatus() {
+ return firstDeclared(StatusStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable
+ @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+
+ @Override
+ public TypeStatement getType() {
+ return firstDeclared(TypeStatement.class);
+ }
+
+ @Override
+ public UnitsStatement getUnits() {
+ return firstDeclared(UnitsStatement.class);
+ }
+
+ @Override
+ public QName getName() {
+ return argument();
+ }
+
+}
--- /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 java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+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.TypeStatement;
+
+public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
+ implements TypeStatement.UnionSpecification {
+
+ protected UnionSpecificationImpl(
+ StmtContext<String, TypeStatement.UnionSpecification, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.TYPE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+ throws SourceException {
+ return value;
+ }
+
+ @Override
+ public TypeStatement.UnionSpecification createDeclared(
+ StmtContext<String, TypeStatement.UnionSpecification, ?> ctx) {
+ return new UnionSpecificationImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, TypeStatement.UnionSpecification> createEffective(
+ StmtContext<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+ @Override
+ public Collection<? extends TypeStatement> getTypes() {
+ return allDeclared(TypeStatement.class);
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UnitsStatement;
+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;
+
+public class UnitsStatementImpl extends AbstractDeclaredStatement<String>
+ implements UnitsStatement {
+
+ protected UnitsStatementImpl(StmtContext<String, UnitsStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, UnitsStatement, EffectiveStatement<String, UnitsStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.UNITS);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public UnitsStatement createDeclared(
+ StmtContext<String, UnitsStatement, ?> ctx) {
+ return new UnitsStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, UnitsStatement> createEffective(
+ StmtContext<String, UnitsStatement, EffectiveStatement<String, UnitsStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getName() {
+ return argument();
+ }
+
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.FULL_DECLARATION;
+
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UsesEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
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.meta.ModelProcessingPhase;
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.source.StatementSourceReference;
-public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implements UsesStatement {
+public class UsesStatementImpl extends AbstractDeclaredStatement<QName>
+ implements UsesStatement {
protected UsesStatementImpl(StmtContext<QName, UsesStatement, ?> context) {
super(context);
}
- public static class Definition extends
+ public static class Definition
+ extends
AbstractStatementSupport<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> {
public Definition() {
return Utils.qNameFromArgument(ctx, value);
}
- public void onStatementDeclared(Mutable<QName, UsesStatement, ?> usesNode) throws InferenceException {
- ModelActionBuilder modifier = usesNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
+ @Override
+ public void onFullDefinitionDeclared(final StmtContext.Mutable<QName,UsesStatement,EffectiveStatement<QName,UsesStatement>> usesNode) throws InferenceException ,SourceException {
+
+ ModelActionBuilder usesAction = usesNode.newInferenceAction(FULL_DECLARATION);
final QName groupingName = usesNode.getStatementArgument();
- final StatementSourceReference usesSource = usesNode.getStatementSourceReference();
- final Prerequisite<?> targetPre = modifier.mutatesEffectiveCtx(usesNode.getParentContext());
- final Prerequisite<EffectiveStatement<QName, GroupingStatement>> sourcePre = modifier.requiresEffective(
- usesNode, GroupingNamespace.class, groupingName);
- modifier.apply(new InferenceAction() {
+ final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode, GroupingNamespace.class, groupingName, FULL_DECLARATION);
+ final Prerequisite< ?extends StmtContext.Mutable<?,?,?>> targetNodePre = usesAction.mutatesCtx(usesNode.getParentContext(), FULL_DECLARATION);
+
+ usesAction.apply(new InferenceAction() {
@Override
public void apply() throws InferenceException {
- Mutable<?, ?, ?> targetCtx = (Mutable<?, ?, ?>) targetPre.get();
- EffectiveStatement<QName, GroupingStatement> source = sourcePre.get();
-
- throw new UnsupportedOperationException("Copy of not not yet implemented.");
+ StatementContextBase<?, ?, ?> targetNodeStmtCtx = (StatementContextBase<?, ?, ?>) targetNodePre.get();
+ StatementContextBase<?, ?, ?> sourceGrpStmtCtx = (StatementContextBase<?, ?, ?>) sourceGroupingPre.get();
+
+ try {
+ GroupingUtils.copyFromSourceToTarget(sourceGrpStmtCtx,targetNodeStmtCtx);
+ GroupingUtils.resolveUsesNode(usesNode, targetNodeStmtCtx);
+ } catch (SourceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
@Override
public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
- if(failed.contains(sourcePre)) {
- throw new InferenceException("Grouping " + groupingName + "was not found.", usesSource);
+ if(failed.contains(sourceGroupingPre)) {
+ throw new InferenceException("Grouping " + groupingName + " was not resoled.", usesNode.getStatementSourceReference());
}
- throw new InferenceException("Unknown error occured.", usesSource);
+ throw new InferenceException("Unknown error occured.", usesNode.getStatementSourceReference());
}
});
}
@Override
- public UsesStatement createDeclared(StmtContext<QName, UsesStatement, ?> ctx) {
+ public UsesStatement createDeclared(
+ StmtContext<QName, UsesStatement, ?> ctx) {
return new UsesStatementImpl(ctx);
}
@Override
public EffectiveStatement<QName, UsesStatement> createEffective(
StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
- throw new UnsupportedOperationException("Not implemented yet.");
+ return new UsesEffectiveStatementImpl(ctx);
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+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.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+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;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Splitter;
public class Utils {
+ private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
+ private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
+
+ private static final char SEPARATOR_QNAME = '/';
+
+ private static final String REGEX_PATH_ABS = "/[^/].+";
+ private static final String REGEX_PATH_REL1 = "\\.\\.?\\s*/(.+)";
+ private static final String REGEX_PATH_REL2 = "//.*";
+
+ public static final StatementSourceReference CONTEXT_REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.CONTEXT;
+ }
+ };
+
+ public static void validateXPath(String path) {
+
+ final XPath xPath = XPathFactory.newInstance().newXPath();
+
+ try {
+ xPath.compile(path);
+ } catch (XPathExpressionException e) {
+ throw new IllegalArgumentException("An argument is not valid XPath string");
+ }
+ }
+
+ public static boolean isXPathAbsolute(String path) {
+
+ validateXPath(path);
+
+ return path.matches(REGEX_PATH_ABS);
+ }
+
+ public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
+
+ validateXPath(path);
- public static QName qNameFromArgument(StmtContext<?,?,?> ctx, String value) {
- // TODO: Implement real parsing
- String prefix = "";
- ctx.getFromNamespace(PrefixToModule.class, prefix);
+ Splitter keySplitter = Splitter.on(SEPARATOR_QNAME).omitEmptyStrings().trimResults();
+ List<String> nodeNames = keySplitter.splitToList(path);
+ List<QName> qNames = new ArrayList<>();
- return QName.create(value);
+ for (String nodeName : nodeNames) {
+ try {
+ final QName qName = Utils.qNameFromArgument(ctx, nodeName);
+ qNames.add(qName);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ return qNames;
+ }
+
+ public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx, String path) {
+
+ if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) {
+ throw new IllegalArgumentException(
+ "An argument for augment can be only absolute path; or descendant if used in uses");
+ }
+
+ return parseXPath(ctx, path);
+ }
+
+ public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
+ StringBuilder sb = new StringBuilder();
+ List<TerminalNode> strings = context.STRING();
+ if (strings.size() == 0) {
+ strings = Arrays.asList(context.IDENTIFIER());
+ }
+ for (TerminalNode stringNode : strings) {
+ final String str = stringNode.getText();
+ char firstChar = str.charAt(0);
+ final CharMatcher quoteMatcher;
+ if (SINGLE_QUOTE_MATCHER.matches(firstChar)) {
+ quoteMatcher = SINGLE_QUOTE_MATCHER;
+ } else if (DOUBLE_QUOTE_MATCHER.matches(firstChar)) {
+ quoteMatcher = DOUBLE_QUOTE_MATCHER;
+ } else {
+ sb.append(str);
+ continue;
+ }
+ sb.append(quoteMatcher.removeFrom(str.substring(1, str.length() - 1)));
+ }
+ return sb.toString();
}
+ public static QName qNameFromArgument(StmtContext<?, ?, ?> ctx, String value) {
+
+ String prefix = null;
+ QNameModule qNameModule = null;
+ try {
+ qNameModule = QNameModule.create(new URI(""), new Date(0));
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ String localName = null;
+ String[] namesParts = value.split(":");
+ switch (namesParts.length) {
+ case 1:
+ localName = namesParts[0];
+
+ if (StmtContextUtils.producesDeclared(ctx.getRoot(), ModuleStatement.class)) {
+ prefix = firstAttributeOf(ctx.getRoot().declaredSubstatements(), PrefixStatement.class);
+ qNameModule = ctx.getFromNamespace(PrefixToModule.class, prefix);
+
+ } else if (StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
+ String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(),
+ BelongsToStatement.class);
+ qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
+ }
+ break;
+ case 2:
+ prefix = namesParts[0];
+ localName = namesParts[1];
+
+ 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);
+ }
+
+ break;
+ default:
+ break;
+ }
+
+ return QName.create(qNameModule, localName);
+ }
}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
+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;
+
+public class ValueStatementImpl extends AbstractDeclaredStatement<String>
+ implements ValueStatement {
+
+ protected ValueStatementImpl(StmtContext<String, ValueStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<String, ValueStatement, EffectiveStatement<String, ValueStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.VALUE);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return value;
+ }
+
+ @Override
+ public ValueStatement createDeclared(
+ StmtContext<String, ValueStatement, ?> ctx) {
+ return new ValueStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, ValueStatement> createEffective(
+ StmtContext<String, ValueStatement, EffectiveStatement<String, ValueStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public String getValue() {
+ return argument();
+ }
+
+}
--- /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 org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public class WhenStatementImpl extends AbstractDeclaredStatement<RevisionAwareXPath> implements
+ WhenStatement {
+
+ protected WhenStatementImpl(
+ StmtContext<RevisionAwareXPath, WhenStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<RevisionAwareXPath,WhenStatement,EffectiveStatement<RevisionAwareXPath,WhenStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.WHEN);
+ }
+
+ @Override public RevisionAwareXPath parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return new RevisionAwareXPathImpl(value, false);
+ }
+
+ @Override public WhenStatement createDeclared(
+ StmtContext<RevisionAwareXPath, WhenStatement, ?> ctx) {
+ return new WhenStatementImpl(ctx);
+ }
+
+ @Override public EffectiveStatement<RevisionAwareXPath, WhenStatement> createEffective(
+ StmtContext<RevisionAwareXPath, WhenStatement, EffectiveStatement<RevisionAwareXPath, WhenStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public RevisionAwareXPath getCondition() {
+ return argument();
+ }
+
+ @Nullable @Override
+ public DescriptionStatement getDescription() {
+ return firstDeclared(DescriptionStatement.class);
+ }
+
+ @Nullable @Override
+ public ReferenceStatement getReference() {
+ return firstDeclared(ReferenceStatement.class);
+ }
+}
import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.global;
import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
+import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle.builder()
.addSupport(new ModuleStatementSupport())
+ .addSupport(new SubmoduleStatementImpl.Definition())
.addSupport(new NamespaceStatementImpl.Definition())
.addSupport(new ImportStatementDefinition())
+ .addSupport(new IncludeStatementImpl.Definition())
.addSupport(new PrefixStatementImpl.Definition())
+ .addSupport(new YangVersionStatementImpl.Definition())
+ .addSupport(new DescriptionStatementImpl.Definition())
+ .addSupport(new RevisionStatementImpl.Definition())
+ .addSupport(new RevisionDateStatementImpl.Definition())
+ .addSupport(new ReferenceStatementImpl.Definition())
+ .addSupport(new ContactStatementImpl.Definition())
+ .addSupport(new OrganizationStatementImpl.Definition())
+ .addSupport(new BelongsToStatementImpl.Definition())
.addSupport(global(ModuleNamespace.class))
+ .addSupport(global(SubmoduleNamespace.class))
.addSupport(global(NamespaceToModule.class))
+ .addSupport(global(ModuleNameToModuleQName.class))
+ .addSupport(global(ModuleQNameToModuleName.class))
+ .addSupport(global(PrefixToModule.class))
+ .addSupport(global(ModuleIdentifierToModuleQName.class))
.addSupport(sourceLocal(ImportedModuleContext.class))
- .build();
+ .addSupport(sourceLocal(IncludedModuleContext.class))
+ .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
+ .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
+ //.addSupport(global(ImpPrefixToModuleIdentifier.class))
+ .build();
- private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.derivedFrom(LINKAGE_BUNDLE).build();
+ private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.
+ derivedFrom(LINKAGE_BUNDLE)
+ .addSupport(new YinElementStatementImpl.Definition())
+ .addSupport(new ArgumentStatementImpl.Definition())
+ .addSupport(new ExtensionStatementImpl.Definition())
+ //TODO: implement extension support in SourceSpecificContext
+ // in order to prepare statements for full declaration phase,
+ // when those ones are read.
+ .build();
- private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.derivedFrom(STMT_DEF_BUNDLE).build();
+ private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.
+ derivedFrom(STMT_DEF_BUNDLE)
+ .addSupport(new ContainerStatementImpl.Definition())
+ .addSupport(new LeafStatementImpl.Definition())
+ .addSupport(new TypeStatementImpl.Definition())
+ .addSupport(new ConfigStatementImpl.Definition())
+ .addSupport(new DeviationStatementImpl.Definition())
+ .addSupport(new DeviateStatementImpl.Definition())
+ .addSupport(new ChoiceStatementImpl.Definition())
+ .addSupport(new CaseStatementImpl.Definition())
+ .addSupport(new DefaultStatementImpl.Definition())
+ .addSupport(new MustStatementImpl.Definition())
+ .addSupport(new MandatoryStatementImpl.Definition())
+ .addSupport(new TypedefStatementImpl.Definition())
+ .addSupport(new AnyxmlStatementImpl.Definition())
+ .addSupport(new IfFeatureStatementImpl.Definition())
+ .addSupport(new UsesStatementImpl.Definition())
+ .addSupport(new GroupingStatementImpl.Definition())
+ .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
+ .addSupport(new StatusStatementImpl.Definition())
+ .addSupport(new ErrorMessageStatementImpl.Definition())
+ .addSupport(new ErrorAppTagStatementImpl.Definition())
+ .addSupport(new LeafListStatementImpl.Definition())
+ .addSupport(new ListStatementImpl.Definition())
+ .addSupport(new PresenceStatementImpl.Definition())
+ .addSupport(new KeyStatementImpl.Definition())
+ .addSupport(new MaxElementsStatementImpl.Definition())
+ .addSupport(new MinElementsStatementImpl.Definition())
+ .addSupport(new OrderedByStatementImpl.Definition())
+ .addSupport(new WhenStatementImpl.Definition())
+ .addSupport(new AugmentStatementImpl.Definition())
+ .addSupport(new RefineStatementImpl.Definition())
+ .addSupport(new IdentityStatementImpl.Definition())
+ .addSupport(new BaseStatementImpl.Definition())
+ .addSupport(new FractionDigitsStatementImpl.Definition())
+ .addSupport(new EnumStatementImpl.Definition())
+ .addSupport(new FeatureStatementImpl.Definition())
+ .addSupport(new RpcStatementImpl.Definition())
+ .addSupport(new InputStatementImpl.Definition())
+ .addSupport(new OutputStatementImpl.Definition())
+ .addSupport(new LengthStatementImpl.Definition())
+ .addSupport(new NotificationStatementImpl.Definition())
+ .addSupport(new PatternStatementImpl.Definition())
+ .addSupport(new PositionStatementImpl.Definition())
+ .addSupport(new RangeStatementImpl.Definition())
+ .addSupport(new ValueStatementImpl.Definition())
+ .addSupport(new UnitsStatementImpl.Definition())
+ .addSupport(new RequireInstanceStatementImpl.Definition())
+ //TODO: add mapping to Rfc6020Mapping class and uncomment following. Please test it.
+// .addSupport(new EnumSpecificationImpl.Definition())
+// .addSupport(new Decimal64SpecificationImpl.Definition())
+// .addSupport(new IdentityRefSpecificationImpl.Definition())
+// .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
+// .addSupport(new LeafrefSpecificationImpl.Definition())
+// .addSupport(new NumericalRestrictionsImpl.Definition())
+// .addSupport(new StringRestrictionsImpl.Definition())
+// .addSupport(new UnionSpecificationImpl.Definition())
+// .addSupport(new BitStatementImpl.Definition())
+ .build();
public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
.<ModelProcessingPhase, StatementSupportBundle> builder()
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTreeWalker;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementLexer;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *
+ * This class represents implementation of StatementStreamSource
+ * in order to emit YANG statements using supplied StatementWriter
+ *
+ */
+
+public class YangStatementSourceImpl implements StatementStreamSource {
+
+ private YangStatementParserListenerImpl yangStatementModelParser;
+ private YangStatementParser.StatementContext statementContext;
+ private ParseTreeWalker walker;
+
+ public YangStatementSourceImpl(String fileName) {
+ try {
+ statementContext = parseYangSource(loadFile(fileName));
+ walker = new ParseTreeWalker();
+ yangStatementModelParser = new YangStatementParserListenerImpl(REF);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ private FileInputStream loadFile(String fileName) throws Exception {
+ return new FileInputStream(new File(getClass().getResource(fileName).toURI()));
+ }
+
+ 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);
+ final YangStatementParser.StatementContext result = parser.statement();
+ return result;
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import javax.annotation.Nonnull;
+
+public class YangVersionStatementImpl extends AbstractDeclaredStatement<String> implements YangVersionStatement {
+
+ protected YangVersionStatementImpl(StmtContext<String, YangVersionStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition extends AbstractStatementSupport<String,YangVersionStatement,EffectiveStatement<String,YangVersionStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.YANG_VERSION);
+ }
+
+ @Override
+ public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return value;
+ }
+
+ @Override
+ public YangVersionStatement createDeclared(StmtContext<String, YangVersionStatement, ?> ctx) {
+ return new YangVersionStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<String, YangVersionStatement> createEffective(StmtContext<String, YangVersionStatement, EffectiveStatement<String, YangVersionStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Nonnull @Override
+ public String getValue() {
+ return rawArgument();
+ }
+}
--- /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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.YinElementStatement;
+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;
+
+public class YinElementStatementImpl extends AbstractDeclaredStatement<Boolean>
+ implements YinElementStatement {
+
+ protected YinElementStatementImpl(
+ StmtContext<Boolean, YinElementStatement, ?> context) {
+ super(context);
+ }
+
+ public static class Definition
+ extends
+ AbstractStatementSupport<Boolean, YinElementStatement, EffectiveStatement<Boolean, YinElementStatement>> {
+
+ public Definition() {
+ super(Rfc6020Mapping.YIN_ELEMENT);
+ }
+
+ @Override
+ public Boolean parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
+ return Boolean.valueOf(value);
+ }
+
+ @Override
+ public YinElementStatement createDeclared(
+ StmtContext<Boolean, YinElementStatement, ?> ctx) {
+ return new YinElementStatementImpl(ctx);
+ }
+
+ @Override
+ public EffectiveStatement<Boolean, YinElementStatement> createEffective(
+ StmtContext<Boolean, YinElementStatement, EffectiveStatement<Boolean, YinElementStatement>> ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ @Override
+ public Boolean getValue() {
+ return argument();
+ }
+
+}
--- /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.parser.stmt.rfc6020.effective;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+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.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+
+public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
+ extends AbstractEffectiveDocumentedNode<A, D> implements
+ DataNodeContainer {
+
+ private final Map<QName, DataSchemaNode> childNodes;
+ private final Set<GroupingDefinition> groupings;
+ private final Set<UsesNode> uses;
+ private final Set<TypeDefinition<?>> typeDefinitions;
+ private final Set<DataSchemaNode> publicChildNodes;
+
+ protected AbstractEffectiveDocumentedDataNodeContainer(
+ final StmtContext<A, D, ?> ctx) {
+ super(ctx);
+
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ childNodes = new HashMap<QName, DataSchemaNode>();
+ groupings = new HashSet<GroupingDefinition>();
+ uses = new HashSet<UsesNode>();
+ typeDefinitions = new HashSet<TypeDefinition<?>>();
+ publicChildNodes = new HashSet<DataSchemaNode>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof DataSchemaNode) {
+ DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
+
+ childNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
+ publicChildNodes.add(dataSchemaNode);
+ }
+ if (effectiveStatement instanceof UsesNode) {
+ UsesNode usesNode = (UsesNode) effectiveStatement;
+ uses.add(usesNode);
+ }
+ if (effectiveStatement instanceof TypeDefinition) {
+ TypeDefinition<?> typeDef = (TypeDefinition<?>) effectiveStatement;
+ typeDefinitions.add(typeDef);
+ }
+ if (effectiveStatement instanceof GroupingDefinition) {
+ GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
+ groupings.add(grp);
+ }
+ }
+ }
+
+ @Override
+ public final Set<TypeDefinition<?>> getTypeDefinitions() {
+ return typeDefinitions;
+ }
+
+ @Override
+ public final Set<DataSchemaNode> getChildNodes() {
+ return publicChildNodes;
+ }
+
+ @Override
+ public final Set<GroupingDefinition> getGroupings() {
+ return groupings;
+ }
+
+ @Override
+ public final DataSchemaNode getDataChildByName(final QName name) {
+ // Child nodes are keyed by their container name, so we can do a direct
+ // lookup
+ return childNodes.get(name);
+ }
+
+ @Override
+ public final DataSchemaNode getDataChildByName(final String name) {
+ for (DataSchemaNode node : childNodes.values()) {
+ if (node.getQName().getLocalName().equals(name)) {
+ return node;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Set<UsesNode> getUses() {
+ return uses;
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+public abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
+ extends EffectiveStatementBase<A, D> implements DocumentedNode {
+
+ private final String description;
+ private final String reference;
+ private final Status status;
+
+ AbstractEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx) {
+ super(ctx);
+
+ DescriptionEffectiveStatementImpl descStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
+ if (descStmt != null) {
+ description = descStmt.argument();
+ } else
+ description = "";
+
+ ReferenceEffectiveStatementImpl refStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
+ if (refStmt != null) {
+ reference = refStmt.argument();
+ } else
+ reference = "";
+
+ // :TODO
+ status = null;
+ }
+
+ @Override
+ public final String getDescription() {
+ return description;
+ }
+
+ @Override
+ public final String getReference() {
+ return reference;
+ }
+
+ @Override
+ public final Status getStatus() {
+ return status;
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.collect.SetMultimap;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+
+
+public abstract class AbstractEffectiveSchemaContext implements SchemaContext {
+
+ protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = new Supplier<TreeSet<Module>>() {
+ @Override
+ public TreeSet<Module> get() {
+ return new TreeSet<>(REVISION_COMPARATOR);
+ }
+ };
+
+ protected static final Comparator<Module> REVISION_COMPARATOR = new Comparator<Module>() {
+ @Override
+ public int compare(final Module o1, final Module o2) {
+ if (o2.getRevision() == null) {
+ return -1;
+ }
+
+ return o2.getRevision().compareTo(o1.getRevision());
+ }
+ };
+
+ /**
+ * @return yang sources where key is ModuleIdentifier
+ */
+ protected abstract Map<ModuleIdentifier, String> getIdentifiersToSources();
+
+ /**
+ * @return Map of modules where key is namespace
+ */
+ protected abstract SetMultimap<URI, Module> getNamespaceToModules();
+
+ /**
+ * @return Map of modules where key is name of module
+ */
+ protected abstract SetMultimap<String, Module> getNameToModules();
+
+ @Override
+ public Set<DataSchemaNode> getDataDefinitions() {
+ final Set<DataSchemaNode> dataDefs = new HashSet<>();
+ for (Module m : getModules()) {
+ dataDefs.addAll(m.getChildNodes());
+ }
+ return dataDefs;
+ }
+
+ @Override
+ public Set<NotificationDefinition> getNotifications() {
+ final Set<NotificationDefinition> notifications = new HashSet<>();
+ for (Module m : getModules()) {
+ notifications.addAll(m.getNotifications());
+ }
+ return notifications;
+ }
+
+ @Override
+ public Set<RpcDefinition> getOperations() {
+ final Set<RpcDefinition> rpcs = new HashSet<>();
+ for (Module m : getModules()) {
+ rpcs.addAll(m.getRpcs());
+ }
+ return rpcs;
+ }
+
+ @Override
+ public Set<ExtensionDefinition> getExtensions() {
+ final Set<ExtensionDefinition> extensions = new HashSet<>();
+ for (Module m : getModules()) {
+ extensions.addAll(m.getExtensionSchemaNodes());
+ }
+ return extensions;
+ }
+
+ @Override
+ public Module findModuleByName(final String name, final Date revision) {
+ for (final Module module : getNameToModules().get(name)) {
+ if (revision == null || revision.equals(module.getRevision())) {
+ return module;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Set<Module> findModuleByNamespace(final URI namespace) {
+ final Set<Module> ret = getNamespaceToModules().get(namespace);
+ return ret == null ? Collections.<Module>emptySet() : ret;
+ }
+
+ @Override
+ public Module findModuleByNamespaceAndRevision(final URI namespace, final Date revision) {
+ if (namespace == null) {
+ return null;
+ }
+ for (Module module : findModuleByNamespace(namespace)) {
+ if (revision == null || revision.equals(module.getRevision())) {
+ return module;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override
+ public boolean isConfiguration() {
+ return false;
+ }
+
+ @Override
+ public ConstraintDefinition getConstraints() {
+ return null;
+ }
+
+ @Override
+ public QName getQName() {
+ return SchemaContext.NAME;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return SchemaPath.ROOT;
+ }
+
+ @Override
+ public String getDescription() {
+ return null;
+ }
+
+ @Override
+ public String getReference() {
+ return null;
+ }
+
+ @Override
+ public Status getStatus() {
+ return Status.CURRENT;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ final List<UnknownSchemaNode> result = new ArrayList<>();
+ for (Module module : getModules()) {
+ result.addAll(module.getUnknownSchemaNodes());
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ @Override
+ public Set<TypeDefinition<?>> getTypeDefinitions() {
+ final Set<TypeDefinition<?>> result = new LinkedHashSet<>();
+ for (Module module : getModules()) {
+ result.addAll(module.getTypeDefinitions());
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @Override
+ public Set<DataSchemaNode> getChildNodes() {
+ final Set<DataSchemaNode> result = new LinkedHashSet<>();
+ for (Module module : getModules()) {
+ result.addAll(module.getChildNodes());
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
+ final Set<GroupingDefinition> result = new LinkedHashSet<>();
+ for (Module module : getModules()) {
+ result.addAll(module.getGroupings());
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ @Override
+ public DataSchemaNode getDataChildByName(final QName name) {
+ for (Module module : getModules()) {
+ final DataSchemaNode result = module.getDataChildByName(name);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public DataSchemaNode getDataChildByName(final String name) {
+ for (Module module : getModules()) {
+ final DataSchemaNode result = module.getDataChildByName(name);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Set<UsesNode> getUses() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public boolean isPresenceContainer() {
+ return false;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAvailableAugmentations() {
+ return Collections.emptySet();
+ }
+
+ //FIXME: should work for submodules too
+ @Override
+ public Set<ModuleIdentifier> getAllModuleIdentifiers() {
+ return getIdentifiersToSources().keySet();
+ }
+
+ @Override
+ public Optional<String> getModuleSource(final ModuleIdentifier moduleIdentifier) {
+ String maybeSource = getIdentifiersToSources().get(moduleIdentifier);
+ return Optional.fromNullable(maybeSource);
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import java.util.HashSet;
+
+import java.util.LinkedList;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import com.google.common.base.Optional;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+public class ContainerEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
+ implements ContainerSchemaNode, DerivableSchemaNode {
+ private final QName qname;
+ private final SchemaPath path;
+
+ boolean augmenting;
+ boolean addedByUses;
+ boolean configuration;
+ ContainerSchemaNode original;
+ ConstraintDefinition constraints;
+
+ boolean presence;
+
+ private Set<AugmentationSchema> augmentations;
+ private List<UnknownSchemaNode> unknownNodes;
+
+ public ContainerEffectiveStatementImpl(
+ StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
+ super(ctx);
+ qname = ctx.getStatementArgument();
+
+ initSubstatementCollections();
+ initPresence();
+
+ // :TODO init other fields
+ path = null;
+
+ }
+
+ private void initPresence() {
+ presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
+ : true;
+ }
+
+ private void initSubstatementCollections() {
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ unknownNodes = new LinkedList<UnknownSchemaNode>();
+ augmentations = new HashSet<AugmentationSchema>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ unknownNodes.add(unknownNode);
+ }
+ if (effectiveStatement instanceof AugmentationSchema) {
+ AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
+ augmentations.add(augmentationSchema);
+ }
+ }
+
+ // :TODO other substatement collections ...
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return augmenting;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public Optional<ContainerSchemaNode> getOriginal() {
+ return Optional.fromNullable(original);
+ }
+
+ @Override
+ public boolean isConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public ConstraintDefinition getConstraints() {
+ return constraints;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAvailableAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public boolean isPresenceContainer() {
+ return presence;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @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;
+ }
+ ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) 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() {
+ return "container " + qname.getLocalName();
+ }
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
+
+public class DescriptionEffectiveStatementImpl extends EffectiveStatementBase<String, DescriptionStatement> {
+
+ public DescriptionEffectiveStatementImpl(
+ StmtContext<String, DescriptionStatement, ?> ctx) {
+ super(ctx);
+ }
+
+}
--- /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.parser.stmt.rfc6020.effective;
+
+import java.util.HashSet;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+
+public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
+
+ private final Map<ModuleIdentifier, String> identifiersToSources;
+ private final SetMultimap<URI, Module> namespaceToModules;
+ private final SetMultimap<String, Module> nameToModules;
+ private final Set<Module> modules;
+
+
+ private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
+ private final ImmutableList<EffectiveStatement<?,?>> rootEffectiveStatements;
+
+ public EffectiveSchemaContext(List<DeclaredStatement<?>> rootDeclaredStatements, List<EffectiveStatement<?,?>> rootEffectiveStatements) {
+ this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
+ this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);
+
+ HashSet<Module> modules = new HashSet<Module>();
+ for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
+ if(rootEffectiveStatement instanceof Module) {
+ Module module = (Module) rootEffectiveStatement;
+ modules.add(module);
+ }
+ }
+ this.modules = ImmutableSet.copyOf(modules);
+
+ final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
+ new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
+ final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(
+ new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);
+
+ for (Module m : modules) {
+ nameMap.put(m.getName(), m);
+ nsMap.put(m.getNamespace(), m);
+ }
+
+ namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
+ nameToModules = ImmutableSetMultimap.copyOf(nameMap);
+
+ //:TODO
+ //this.identifiersToSources = ImmutableMap.copyOf(identifiersToSources);
+ this.identifiersToSources = null;
+
+ }
+
+ public ImmutableList<DeclaredStatement<?>> getRootDeclaredStatements() {
+ return rootDeclaredStatements;
+ }
+
+ public ImmutableList<EffectiveStatement<?,?>> getRootEffectiveStatements() {
+ return rootEffectiveStatements;
+ }
+
+ @Override
+ protected Map<ModuleIdentifier, String> getIdentifiersToSources(){
+
+ return identifiersToSources;
+ }
+
+ @Override
+ public Set<Module> getModules(){
+
+ return modules;
+ }
+
+ @Override
+ protected SetMultimap<URI, Module> getNamespaceToModules() {
+
+ return namespaceToModules;
+ }
+
+ @Override
+ protected SetMultimap<String, Module> getNameToModules() {
+
+ return nameToModules;
+ }
+
+ @Override
+ public String toString() {
+
+ return String.format("SchemaContextImpl{modules=%s}", modules);
+ }
+}
--- /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.effective;
+
+import java.util.Collections;
+
+import java.util.NoSuchElementException;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import com.google.common.collect.Collections2;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+import java.util.LinkedList;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import com.google.common.collect.FluentIterable;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import java.util.Collection;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+
+abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
+ implements EffectiveStatement<A, D> {
+
+ private final StmtContext<A, D, ?> stmtCtx;
+ private final ImmutableList<? extends EffectiveStatement<?, ?>> substatements;
+ private final StatementSource statementSource;
+ private final StatementDefinition statementDefinition;
+ private D declaredInstance;
+
+ private final A argument;
+
+ public EffectiveStatementBase(StmtContext<A, D, ?> ctx) {
+
+ this.stmtCtx = ctx;
+ this.statementDefinition = ctx.getPublicDefinition();
+ this.argument = ctx.getStatementArgument();
+ this.statementSource = ctx.getStatementSource();
+
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = ctx
+ .declaredSubstatements();
+ Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx
+ .effectiveSubstatements();
+
+ Collection<StatementContextBase<?, ?, ?>> substatements = new LinkedList<StatementContextBase<?, ?, ?>>();
+ substatements.addAll(declaredSubstatements);
+ substatements.addAll(effectiveSubstatements);
+
+ this.substatements = FluentIterable.from(substatements)
+ .transform(StmtContextUtils.buildEffective()).toList();
+ }
+
+ @Override
+ public StatementDefinition statementDefinition() {
+ return statementDefinition;
+ }
+
+ @Override
+ public A argument() {
+ return argument;
+ }
+
+ @Override
+ public StatementSource getStatementSource() {
+ return statementSource;
+ }
+
+ @Override
+ public D getDeclared() {
+ if (declaredInstance == null) {
+ declaredInstance = stmtCtx.buildDeclared();
+ }
+
+ return declaredInstance;
+ }
+
+ // public <K, V, N extends IdentifierNamespace<? super K, ? extends V>> V
+ // get(
+ @Override
+ public <K, V, N extends IdentifierNamespace<K, V>> V get(
+ Class<N> namespace, K identifier) {
+ return stmtCtx.getFromNamespace(namespace, identifier);
+ }
+
+ @Override
+ public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(
+ Class<N> namespace) {
+ return (Map<K, V>) stmtCtx.getAllFromNamespace(namespace);
+ }
+
+ @Override
+ public Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return substatements;
+ }
+
+ public StmtContext<A, D, ?> getStatementContext() {
+ return stmtCtx;
+ }
+
+ protected final <S extends EffectiveStatement<?, ?>> S firstEffective(
+ Class<S> type) {
+ S result = null;
+ try {
+ result = type.cast(Iterables.find(substatements,
+ Predicates.instanceOf(type)));
+ } catch (NoSuchElementException e) {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected final <S extends EffectiveStatement<?, ?>> Collection<? extends S> allEffective(
+ Class<S> type) {
+ Collection<? extends S> result = null;
+
+ try {
+ result = Collection.class.cast(Collections2.filter(substatements,
+ Predicates.instanceOf(type)));
+ } catch (NoSuchElementException e) {
+ result = Collections.EMPTY_LIST;
+ }
+ return result;
+ }
+
+ protected final <S extends SchemaNode> S firstSchemaNode(Class<S> type) {
+ S result = null;
+ try {
+ result = type.cast(Iterables.find(substatements,
+ Predicates.instanceOf(type)));
+ } catch (NoSuchElementException e) {
+ result = null;
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected final <S extends SchemaNode> Collection<? extends S> allSchemaNodes(
+ Class<S> type) {
+ Collection<? extends S> result = null;
+
+ try {
+ result = Collection.class.cast(Collections2.filter(substatements,
+ Predicates.instanceOf(type)));
+ } catch (NoSuchElementException e) {
+ result = Collections.EMPTY_LIST;
+ }
+ return result;
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
+import java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+
+public class GroupingEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement>
+ implements GroupingDefinition {
+ private final QName qname;
+ private final SchemaPath path;
+
+ private boolean addedByUses;
+ private List<UnknownSchemaNode> unknownNodes;
+
+ public GroupingEffectiveStatementImpl(
+ StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
+ super(ctx);
+
+ qname = ctx.getStatementArgument();
+ // :TODO init other fields
+ path = null;
+
+ initSubstatementCollections();
+ }
+
+ private void initSubstatementCollections() {
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ unknownNodes = new LinkedList<UnknownSchemaNode>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ unknownNodes.add(unknownNode);
+ }
+ }
+
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @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;
+ }
+ final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) 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(
+ GroupingEffectiveStatementImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("qname=").append(qname);
+ sb.append("]");
+ return sb.toString();
+ }
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import java.net.URI;
+import java.util.Date;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+
+public class ModuleEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
+ implements Module, Immutable {
+
+ private QNameModule qnameModule;
+ private String name;
+ private String sourcePath;
+ private String prefix;
+ private String yangVersion;
+ private String organization;
+ private String contact;
+ private Set<ModuleImport> imports;
+ private Set<Module> submodules;
+ private Set<FeatureDefinition> features;
+ private Set<NotificationDefinition> notifications;
+ private Set<AugmentationSchema> augmentations;
+ private Set<RpcDefinition> rpcs;
+ private Set<Deviation> deviations;
+ private List<ExtensionDefinition> extensionNodes;
+ private Set<IdentitySchemaNode> identities;
+ private List<UnknownSchemaNode> unknownNodes;
+ private String source;
+
+ public ModuleEffectiveStatementImpl(
+ StmtContext<String, ModuleStatement, ?> ctx) {
+ super(ctx);
+
+ name = argument();
+ qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
+
+ initSubstatementCollections();
+
+ // :TODO init other fields
+ }
+
+ private void initSubstatementCollections() {
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ unknownNodes = new LinkedList<UnknownSchemaNode>();
+ augmentations = new HashSet<AugmentationSchema>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ unknownNodes.add(unknownNode);
+ }
+ if (effectiveStatement instanceof AugmentationSchema) {
+ AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
+ augmentations.add(augmentationSchema);
+ }
+ }
+
+ // :TODO other substatement collections ...
+ }
+
+ @Override
+ public String getModuleSourcePath() {
+ return sourcePath;
+ }
+
+ @Override
+ public URI getNamespace() {
+ return qnameModule.getNamespace();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Date getRevision() {
+ return qnameModule.getRevision();
+ }
+
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Override
+ public String getYangVersion() {
+ return yangVersion;
+ }
+
+ @Override
+ public String getOrganization() {
+ return organization;
+ }
+
+ @Override
+ public String getContact() {
+ return contact;
+ }
+
+ @Override
+ public Set<ModuleImport> getImports() {
+ return imports;
+ }
+
+ @Override
+ public Set<Module> getSubmodules() {
+ return submodules;
+ }
+
+ @Override
+ public Set<FeatureDefinition> getFeatures() {
+ return features;
+ }
+
+ @Override
+ public Set<NotificationDefinition> getNotifications() {
+ return notifications;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public Set<RpcDefinition> getRpcs() {
+ return rpcs;
+ }
+
+ @Override
+ public Set<Deviation> getDeviations() {
+ return deviations;
+ }
+
+ @Override
+ public List<ExtensionDefinition> getExtensionSchemaNodes() {
+ return extensionNodes;
+ }
+
+ @Override
+ public Set<IdentitySchemaNode> getIdentities() {
+ return identities;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @Override
+ public String getSource() {
+ return source;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result
+ + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+ result = prime * result + qnameModule.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;
+ }
+ ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (!qnameModule.equals(other.qnameModule)) {
+ return false;
+ }
+ if (yangVersion == null) {
+ if (other.yangVersion != null) {
+ return false;
+ }
+ } else if (!yangVersion.equals(other.yangVersion)) {
+ return false;
+ }
+ return true;
+ }
+
+ // private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final
+ // Set<T> original) {
+ // TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+ // sorted.addAll(original);
+ // return Collections.unmodifiableSet(sorted);
+ // }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("name=").append(name);
+ sb.append(", namespace=").append(getNamespace());
+ sb.append(", revision=").append(getRevision());
+ sb.append(", prefix=").append(prefix);
+ sb.append(", yangVersion=").append(yangVersion);
+ sb.append("]");
+ return sb.toString();
+ }
+
+ @Override
+ public QNameModule getQNameModule() {
+ return qnameModule;
+ }
+
+}
--- /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.effective;
+
+import java.net.URI;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class NamespaceEffectiveStatementImpl extends EffectiveStatementBase<URI, NamespaceStatement> {
+
+ public NamespaceEffectiveStatementImpl(
+ StmtContext<URI, NamespaceStatement, ?> ctx) {
+ super(ctx);
+ }
+
+}
--- /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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class PrefixEffectiveStatementImpl extends EffectiveStatementBase<String, PrefixStatement> {
+
+ public PrefixEffectiveStatementImpl(
+ StmtContext<String, PrefixStatement, ?> ctx) {
+ super(ctx);
+ }
+
+}
--- /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.effective;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.PresenceStatement;
+
+public class PresenceEffectiveStatementImpl extends EffectiveStatementBase<String, PresenceStatement> {
+
+ public PresenceEffectiveStatementImpl(
+ StmtContext<String, PresenceStatement, ?> ctx) {
+ super(ctx);
+ }
+
+}
--- /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.effective;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+
+public class ReferenceEffectiveStatementImpl extends EffectiveStatementBase<String, ReferenceStatement> {
+
+ public ReferenceEffectiveStatementImpl(
+ StmtContext<String, ReferenceStatement, ?> ctx) {
+ super(ctx);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013-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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+
+public class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, UsesStatement>implements UsesNode {
+ private SchemaPath groupingPath;
+ ImmutableSet<AugmentationSchema> augmentations;
+ private boolean addedByUses;
+ ImmutableMap<SchemaPath, SchemaNode> refines;
+ ImmutableList<UnknownSchemaNode> unknownNodes;
+
+ public UsesEffectiveStatementImpl(StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
+ super(ctx);
+
+ this.groupingPath = null;
+ }
+
+ @Override
+ public SchemaPath getGroupingPath() {
+ return groupingPath;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ @Override
+ public Map<SchemaPath, SchemaNode> getRefines() {
+ return refines;
+ }
+
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());
+ result = prime * result + ((augmentations == null) ? 0 : augmentations.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;
+ }
+ final UsesEffectiveStatementImpl other = (UsesEffectiveStatementImpl) obj;
+ if (groupingPath == null) {
+ if (other.groupingPath != null) {
+ return false;
+ }
+ } else if (!groupingPath.equals(other.groupingPath)) {
+ return false;
+ }
+ if (augmentations == null) {
+ if (other.augmentations != null) {
+ return false;
+ }
+ } else if (!augmentations.equals(other.augmentations)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(UsesEffectiveStatementImpl.class.getSimpleName());
+ sb.append("[groupingPath=");
+ sb.append(groupingPath);
+ sb.append("]");
+ return sb.toString();
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.effective.build.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import java.net.URI;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class EffectiveBuildTest {
+
+ private static final YangFileStatementSource SIMPLE_MODULE = new YangFileStatementSource("/stmt-test/effective-build/simple-module.yang");
+ private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(URI.create("simple.yang"), null);
+
+ @Test
+ public void effectiveBuildTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, SIMPLE_MODULE);
+ EffectiveSchemaContext result = reactor.buildEffective();
+
+ assertNotNull(result);
+
+ Module simpleModule = result.findModuleByName("simple-module",null);
+ assertNotNull(simpleModule);
+
+ QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
+ QName q2 = QName.create(SIMPLE_MODULE_QNAME, "sub-container");
+ QName q3 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container");
+ QName q4 = QName.create(SIMPLE_MODULE_QNAME, "root-container2");
+ QName q5 = QName.create(SIMPLE_MODULE_QNAME, "sub-container2");
+ QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
+ QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");
+
+ ContainerSchemaNode rootCon = (ContainerSchemaNode)simpleModule.getDataChildByName(q1);
+ assertNotNull(rootCon);
+
+ ContainerSchemaNode subCon = (ContainerSchemaNode)rootCon.getDataChildByName(q2);
+ assertNotNull(subCon);
+
+ ContainerSchemaNode subSubCon = (ContainerSchemaNode)subCon.getDataChildByName(q3);
+ assertNotNull(subSubCon);
+
+ ContainerSchemaNode rootCon2 = (ContainerSchemaNode)simpleModule.getDataChildByName(q4);
+ assertNotNull(rootCon2);
+
+ ContainerSchemaNode subCon2 = (ContainerSchemaNode)rootCon2.getDataChildByName(q5);
+ assertNotNull(subCon2);
+
+ ContainerSchemaNode subSubCon2 = (ContainerSchemaNode)subCon2.getDataChildByName(q6);
+ assertNotNull(subSubCon2);
+
+ GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
+ assertNotNull(grp);
+ assertEquals(q7,grp.getQName());
+
+ ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
+ assertNotNull(grpSubCon2);
+
+ ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode)grpSubCon2.getDataChildByName(q6);
+ assertNotNull(grpSubSubCon2);
+
+ }
+
+ private void log(Throwable e, String indent) {
+ System.out.println(indent + e.getMessage());
+
+ Throwable[] suppressed = e.getSuppressed();
+ for (Throwable throwable : suppressed) {
+ log(throwable, indent + " ");
+ }
+
+ }
+
+ private void addSources(BuildAction reactor,
+ YangFileStatementSource... sources) {
+ for (YangFileStatementSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.effective.build.test;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTreeWalker;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementLexer;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class YangFileStatementSource implements StatementStreamSource {
+
+ private YangStatementParserListenerImpl yangStatementModelParser;
+ private YangStatementParser.StatementContext statementContext;
+ private ParseTreeWalker walker;
+
+ public YangFileStatementSource(String fileName) {
+ try {
+ statementContext = parseYangSource(loadFile(fileName));
+ walker = new ParseTreeWalker();
+ yangStatementModelParser = new YangStatementParserListenerImpl(REF);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ private FileInputStream loadFile(String fileName) throws Exception {
+ return new FileInputStream(new File(getClass().getResource(fileName).toURI()));
+ }
+
+ private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException {
+ final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
+ final CommonTokenStream tokens = new CommonTokenStream(lexer);
+ final YangStatementParser parser = new YangStatementParser(tokens);
+ //TODO: no error listener yet
+ //parser.removeErrorListeners();
+ //final YangErrorListener errorListener = new YangErrorListener();
+ //parser.addErrorListener(errorListener);
+ final YangStatementParser.StatementContext result = parser.statement();
+ //errorListener.validate();
+ return result;
+ }
+}
\ 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
+ */
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.IMPORT;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.*;
+
+import java.util.Arrays;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+class ImportBasicTestStatementSource implements StatementStreamSource {
+
+ private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
+
+ private final String name;
+ private final List<String> imports;
+ private StatementWriter writer;
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+
+ public ImportBasicTestStatementSource(String name, String... imports) {
+ this.name = name;
+ this.imports = Arrays.asList(imports);
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ body();
+ end();
+
+ }
+
+
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ this.writer = writer;
+ header().end();
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
+ PrefixToModule prefixes) throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ end();
+
+ }
+
+ protected void extensions() throws SourceException {
+
+ }
+
+ protected void body() throws SourceException {
+// stmt(YangVersion).arg("1");end();
+// stmt(Description).arg("Here goes description of this module");end();
+// stmt(Contact).arg("Here goes our address...");end();
+//
+// stmt(Revision).arg("2015-03-12");
+// stmt(Description).arg("This revision brings this and that...");end();
+// stmt(Reference).arg("Learn more here...");end();
+// end();
+
+ stmt(CONTAINER).arg(name+":my-container-with-prefix");
+// stmt(Leaf).arg("MyContainerLeaf");
+// stmt(Type).arg("string");end();
+// stmt(Config).arg("TRUE");end();
+// end();
+// stmt(Choice).arg("choose-your-destiny");
+// stmt(Default).arg("destiny-one");end();
+// stmt(Case).arg("destiny-one");
+// stmt(Leaf).arg("destiny-one-leaf");end();
+// end();
+// stmt(Case).arg("destiny-two");
+// stmt(Mandatory).arg("true");
+// stmt(Container).arg("InnerContainer");
+// stmt(Leaf).arg("leaf-of-deep");end();
+// end();
+// end();
+// end();
+// stmt(Container).arg("MyContainerInContainer");
+// stmt(Must).arg("xpath expression");
+// stmt(Leaf).arg("MyContainerInContainerLeaf");
+// stmt(Type).arg("string");end();
+// end();
+// stmt(Deviation).arg("/tst:test/tst:element");
+// stmt(Deviate).arg("add");end();
+// end();
+// end();
+ end();
+ stmt(CONTAINER).arg("my-container-without-prefix").end();
+
+ int i = 0;
+ for(String imp : imports) {
+ i++;
+ stmt(CONTAINER).arg(imp+":my-container-with-imported-prefix"+i).end();
+ }
+
+ }
+
+ ImportBasicTestStatementSource header() throws SourceException {
+ stmt(MODULE).arg(name); {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ stmt(REVISION).arg("2000-01-01").end();
+ for(String imp : imports) {
+ stmt(IMPORT).arg(imp);
+ stmt(PREFIX).arg(imp).end();
+ stmt(REVISION_DATE).arg("2000-01-01").end();
+ end();
+ }
+ }
+ return this;
+ }
+
+ private String getNamespace() {
+ return NS_PREFIX + name;
+ }
+
+ protected ImportBasicTestStatementSource arg(String arg) throws SourceException {
+ writer.argumentValue(arg, REF);
+ return this;
+ }
+
+ protected ImportBasicTestStatementSource stmt(Rfc6020Mapping stmt) throws SourceException {
+ writer.startStatement(stmt.getStatementName(), REF);
+ return this;
+ }
+
+ protected ImportBasicTestStatementSource end() throws SourceException {
+ writer.endStatement(REF);
+ return this;
+ }
+
+
+}
--- /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.stmt.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+
+public class ImportResolutionBasicTest {
+
+ private static final ImportBasicTestStatementSource ROOT_WITHOUT_IMPORT = new ImportBasicTestStatementSource("nature");
+ private static final ImportBasicTestStatementSource IMPORT_ROOT = new ImportBasicTestStatementSource("mammal","nature");
+ private static final ImportBasicTestStatementSource IMPORT_DERIVED = new ImportBasicTestStatementSource("human", "mammal");
+ private static final ImportBasicTestStatementSource IMPORT_SELF = new ImportBasicTestStatementSource("egocentric", "egocentric");
+ private static final ImportBasicTestStatementSource CICLE_YIN = new ImportBasicTestStatementSource("cycle-yin", "cycle-yang");
+ private static final ImportBasicTestStatementSource CICLE_YANG = new ImportBasicTestStatementSource("cycle-yang", "cycle-yin");
+
+
+ @Test
+ public void inImportOrderTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,ROOT_WITHOUT_IMPORT,IMPORT_ROOT,IMPORT_DERIVED);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void inInverseOfImportOrderTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,IMPORT_DERIVED,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void missingImportedSourceTest() throws SourceException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,IMPORT_DERIVED,ROOT_WITHOUT_IMPORT);
+ try {
+ reactor.build();
+ fail("reactor.process should fail doe to misssing imported source");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ }
+
+ }
+
+ @Test
+ public void circularImportsTest() throws SourceException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,CICLE_YIN,CICLE_YANG);
+ try {
+ reactor.build();
+ fail("reactor.process should fail doe to circular import");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ }
+ }
+
+ @Test
+ public void selfImportTest() throws SourceException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,IMPORT_SELF,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
+ try {
+ reactor.build();
+ fail("reactor.process should fail doe to self import");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ }
+ }
+
+
+ private void addSources(BuildAction reactor, ImportBasicTestStatementSource... sources) {
+ for(ImportBasicTestStatementSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.stmt.test.TestStatementSource.ModuleEntry;
public class ImportResolutionTest {
- private static final TestStatementSource ROOT_WITHOUT_IMPORT = new TestStatementSource("nature");
- private static final TestStatementSource IMPORT_ROOT = new TestStatementSource("mammal","nature");
- private static final TestStatementSource IMPORT_DERIVED = new TestStatementSource("human", "mammal");
- private static final TestStatementSource IMPORT_SELF = new TestStatementSource("egocentric", "egocentric");
- private static final TestStatementSource CICLE_YIN = new TestStatementSource("cycle-yin", "cycle-yang");
- private static final TestStatementSource CICLE_YANG = new TestStatementSource("cycle-yang", "cycle-yin");
+ private static final ModuleEntry modNature = new ModuleEntry("nature", "2000-01-01");
+ private static final ModuleEntry modMammal = new ModuleEntry("mammal", "2000-01-01");
+ private static final ModuleEntry modHuman = new ModuleEntry("human", "2000-01-01");
+ private static final ModuleEntry modEgocentric = new ModuleEntry("egocentric", "2000-01-01");
+ private static final ModuleEntry modCycleYin = new ModuleEntry("cycle-yin", "2000-01-01");
+ private static final ModuleEntry modCycleYang = new ModuleEntry("cycle-yang", "2000-01-01");
+ private static final TestStatementSource ROOT_WITHOUT_IMPORT = new TestStatementSource(modNature);
+ private static final TestStatementSource IMPORT_ROOT = new TestStatementSource(modMammal, modNature);
+ private static final TestStatementSource IMPORT_DERIVED = new TestStatementSource(modHuman, modMammal);
+ private static final TestStatementSource IMPORT_SELF = new TestStatementSource(modEgocentric, modEgocentric);
+ private static final TestStatementSource CICLE_YIN = new TestStatementSource(modCycleYin, modCycleYang);
+ private static final TestStatementSource CICLE_YANG = new TestStatementSource(modCycleYang, modCycleYin);
@Test
public void inImportOrderTest() throws SourceException, ReactorException {
BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor,ROOT_WITHOUT_IMPORT,IMPORT_ROOT,IMPORT_DERIVED);
+ addSources(reactor, ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED);
EffectiveModelContext result = reactor.build();
assertNotNull(result);
}
@Test
public void inInverseOfImportOrderTest() throws SourceException, ReactorException {
BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor,IMPORT_DERIVED,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
+ addSources(reactor, IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
EffectiveModelContext result = reactor.build();
assertNotNull(result);
}
@Test
public void missingImportedSourceTest() throws SourceException {
BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor,IMPORT_DERIVED,ROOT_WITHOUT_IMPORT);
+ addSources(reactor, IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
try {
reactor.build();
- fail("reactor.process should fail doe to misssing imported source");
+ fail("reactor.process should fail due to misssing imported source");
} catch (ReactorException e) {
assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
}
-
}
@Test
public void circularImportsTest() throws SourceException {
BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor,CICLE_YIN,CICLE_YANG);
+ addSources(reactor, CICLE_YIN, CICLE_YANG);
try {
reactor.build();
- fail("reactor.process should fail doe to circular import");
+ fail("reactor.process should fail due to circular import");
} catch (ReactorException e) {
assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
}
}
@Test
public void selfImportTest() throws SourceException {
BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor,IMPORT_SELF,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
+ addSources(reactor, IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
try {
reactor.build();
- fail("reactor.process should fail doe to self import");
+ fail("reactor.process should fail due to self import");
} catch (ReactorException e) {
assertTrue(e instanceof SomeModifiersUnresolvedException);
- assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
}
}
-
private void addSources(BuildAction reactor, TestStatementSource... sources) {
- for(TestStatementSource source : sources) {
+ for (TestStatementSource source : sources) {
reactor.addSource(source);
}
}
--- /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 static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.stmt.test.TestStatementSource.ModuleEntry;
+
+public class ImportRevisionsTest {
+
+ private static final ModuleEntry modImported = new ModuleEntry("nature", "2006-05-05");
+ private static final ModuleEntry modImportedRevDiff = new ModuleEntry("nature", "2011-12-12");
+ private static final ModuleEntry modImportedRevMiss = new ModuleEntry("nature", null);
+ private static final ModuleEntry modImported1970 = new ModuleEntry("nature", "1970-01-01");
+
+ private static final ModuleEntry modImporter = new ModuleEntry("mammal", "2006-05-05");
+
+ private static final TestStatementSource IMPORTED = new TestStatementSource(modImported);
+ private static final TestStatementSource IMPORTED_NO_REV = new TestStatementSource(modImportedRevMiss);
+
+ private static final TestStatementSource IMPORT = new TestStatementSource(modImporter, modImported);
+ private static final TestStatementSource IMPORT_REV_DFLT = new TestStatementSource(modImporter, modImported1970);
+ private static final TestStatementSource IMPORT_REV_DIFF = new TestStatementSource(modImporter, modImportedRevDiff);
+ private static final TestStatementSource IMPORT_NO_REV = new TestStatementSource(modImporter, modImportedRevMiss);
+
+ @Test
+ public void revsEqualTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED, IMPORT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revsDiffTest() throws SourceException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED, IMPORT_REV_DIFF);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to unequal revisions in imported modules");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
+ }
+ }
+
+ @Test
+ public void revInModuleOnly() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED, IMPORT_NO_REV);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revImportOnly() throws SourceException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED_NO_REV, IMPORT);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to missing revision in imported module");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
+ }
+ }
+
+ @Test
+ public void revDefault1970InImport() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED_NO_REV, IMPORT_REV_DFLT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revNowhere() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED_NO_REV, IMPORT_NO_REV);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ private void log(Throwable e, String indent) {
+ System.out.println(indent + e.getMessage());
+
+ Throwable[] suppressed = e.getSuppressed();
+ for (Throwable throwable : suppressed) {
+ log(throwable, indent + " ");
+ }
+ }
+
+ private void addSources(BuildAction reactor, TestStatementSource... sources) {
+ for (TestStatementSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+}
--- /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 static org.junit.Assert.fail;
+
+import java.util.logging.Logger;
+
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class IncludeResolutionTest {
+
+ private static final Logger log = Logger.getLogger(IncludeResolutionTest.class.getName());
+
+ private static final IncludeTestStatementSource ROOT = new IncludeTestStatementSource(false,"root-module",null, "submodule-1");
+ private static final IncludeTestStatementSource SUBMODULE1 = new IncludeTestStatementSource(true,"submodule-1","root-module", "submodule-2");
+ private static final IncludeTestStatementSource SUBMODULE2 = new IncludeTestStatementSource(true,"submodule-2", "root-module");
+ private static final IncludeTestStatementSource ERROR_MODULE = new IncludeTestStatementSource(false,"error-module", null, "foo");
+ private static final IncludeTestStatementSource ERROR_SUBMODULE = new IncludeTestStatementSource(true,"error-submodule", "root-module", "foo");
+
+ private static final IncludeTestStatementSource MISSING_PARENT_MODULE = new IncludeTestStatementSource(true,"missing-parent", "foo");
+ @Test
+ public void includeTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,ROOT,SUBMODULE1,SUBMODULE2);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void missingIncludedSourceTest() throws SourceException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,ERROR_MODULE);
+ try {
+ reactor.build();
+ fail("reactor.process should fail doe to misssing included source");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ log.info(e.getMessage());
+ }
+
+ }
+
+ @Test
+ public void missingIncludedSourceTest2() throws SourceException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,ERROR_SUBMODULE);
+ try {
+ reactor.build();
+ fail("reactor.process should fail doe to misssing included source");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
+ log.info(e.getMessage());
+ }
+
+ }
+
+ //@Test
+ public void missingIncludedSourceTest3() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor,MISSING_PARENT_MODULE);
+ try {
+ EffectiveModelContext build = reactor.build();
+ //fail("reactor.process should fail doe to misssing belongsTo source");
+ } catch (ReactorException e) {
+ //assertTrue(e instanceof SomeModifiersUnresolvedException);
+ //assertEquals(ModelProcessingPhase.SourceLinkage,e.getPhase());
+ throw(e);
+ }
+
+ }
+
+ private void addSources(BuildAction reactor, IncludeTestStatementSource... sources) {
+ for(IncludeTestStatementSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+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.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class IncludeRevisionsTest {
+
+ private static final YangStatementSourceImpl EQUAL_ROOT = new YangStatementSourceImpl("/revisions/equal-root.yang");
+ private static final YangStatementSourceImpl EQUAL_REV = new YangStatementSourceImpl("/revisions/equal-rev.yang");
+ private static final YangStatementSourceImpl UNEQUAL_ROOT = new YangStatementSourceImpl("/revisions/unequal-root.yang");
+ private static final YangStatementSourceImpl UNEQUAL_REV = new YangStatementSourceImpl("/revisions/unequal-rev.yang");
+ private static final YangStatementSourceImpl SUBMOD_ONLY_ROOT = new YangStatementSourceImpl("/revisions/submod-only-root.yang");
+ private static final YangStatementSourceImpl SUBMOD_ONLY_REV = new YangStatementSourceImpl("/revisions/submod-only-rev.yang");
+ private static final YangStatementSourceImpl MOD_ONLY_ROOT = new YangStatementSourceImpl("/revisions/mod-only-root.yang");
+ private static final YangStatementSourceImpl MOD_ONLY_REV = new YangStatementSourceImpl("/revisions/mod-only-rev.yang");
+ private static final YangStatementSourceImpl MOD_ONLY_1970_ROOT = new YangStatementSourceImpl("/revisions/mod-1970-root.yang");
+ private static final YangStatementSourceImpl MOD_ONLY_1970_REV = new YangStatementSourceImpl("/revisions/mod-1970-rev.yang");
+ private static final YangStatementSourceImpl NOWHERE_ROOT = new YangStatementSourceImpl("/revisions/nowhere-root.yang");
+ private static final YangStatementSourceImpl NOWHERE_REV = new YangStatementSourceImpl("/revisions/nowhere-rev.yang");
+
+
+ @Test
+ public void revsEqualTest() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, EQUAL_REV, EQUAL_ROOT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revsUnequalTest() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to unequal revisions in include and submodule");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
+ }
+ }
+
+ @Test
+ public void revIncludeOnly() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revInModuleOnly() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to missing revision in included submodule");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
+ }
+ }
+
+
+ @Test
+ public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void revNowhereTest() throws SourceException, ReactorException {
+
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+ for (StatementStreamSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.*;
+import java.util.Arrays;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+
+
+
+class IncludeTestStatementSource implements StatementStreamSource {
+
+ private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
+
+ private final String name;
+ private final List<String> includes;
+ private StatementWriter writer;
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ private boolean isSubmodule;
+
+ private String belongsTo;
+
+
+ public IncludeTestStatementSource(boolean isSubmodule, String name, String belongsTo, String... includes) {
+ this.name = name;
+ this.includes = Arrays.asList(includes);
+ this.isSubmodule=isSubmodule;
+ this.belongsTo = belongsTo;
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ body();
+ end();
+
+ }
+
+
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ this.writer = writer;
+ header().end();
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
+ PrefixToModule prefixes) throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ end();
+
+ }
+
+ protected void extensions() throws SourceException {
+
+ }
+
+ protected void body() throws SourceException {
+
+ String prefix = isSubmodule ? belongsTo : name;
+
+ stmt(CONTAINER).arg(prefix+":my-container-with-prefix");
+
+ end();
+ stmt(CONTAINER).arg("my-container-without-prefix").end();
+
+ }
+
+ IncludeTestStatementSource header() throws SourceException {
+
+ if(isSubmodule) writeSubmoduleHeader();
+ else writeModuleHeader();
+
+ return this;
+ }
+
+ /**
+ *
+ */
+ private void writeSubmoduleHeader() throws SourceException {
+ stmt(SUBMODULE).arg(name); {
+
+
+ stmt(REVISION).arg("2000-01-01").end();
+ if(belongsTo != null) {
+ stmt(BELONGS_TO).arg(belongsTo);
+ stmt(PREFIX).arg(belongsTo).end();
+ end();
+ }
+
+ for(String inc : includes) {
+ stmt(INCLUDE).arg(inc);
+ stmt(REVISION_DATE).arg("2000-01-01").end();
+ end();
+ }
+ }
+
+ }
+
+ /**
+ *
+ */
+ private void writeModuleHeader() throws SourceException{
+ stmt(MODULE).arg(name); {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ stmt(REVISION).arg("2000-01-01").end();
+ for(String inc : includes) {
+ stmt(INCLUDE).arg(inc);
+ stmt(REVISION_DATE).arg("2000-01-01").end();
+ end();
+ }
+ }
+
+ }
+
+ private String getNamespace() {
+ return NS_PREFIX + name;
+ }
+
+ protected IncludeTestStatementSource arg(String arg) throws SourceException {
+ writer.argumentValue(arg, REF);
+ return this;
+ }
+
+ protected IncludeTestStatementSource stmt(Rfc6020Mapping stmt) throws SourceException {
+ writer.startStatement(stmt.getStatementName(), REF);
+ return this;
+ }
+
+ protected IncludeTestStatementSource end() throws SourceException {
+ writer.endStatement(REF);
+ return this;
+ }
+
+
+}
*/
package org.opendaylight.yangtools.yang.stmt.test;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.CONTAINER;
import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.IMPORT;
import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.PREFIX;
-
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.REVISION;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.REVISION_DATE;
import java.util.Arrays;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
class TestStatementSource implements StatementStreamSource {
+ public static class ModuleEntry {
+
+ private final String name;
+ private final String revision;
+
+ public ModuleEntry(String name, String revision) {
+
+ this.name = name;
+ this.revision = revision;
+ }
+
+ public String getName() {
+
+ return name;
+ }
+
+ public String getRevision() {
+
+ return revision;
+ }
+ }
+
private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
private final String name;
- private final List<String> imports;
+ private final String revision;
+ private final List<ModuleEntry> imports;
+ private String container;
private StatementWriter writer;
private StatementSourceReference REF = new StatementSourceReference() {
}
};
+ public TestStatementSource(ModuleEntry module, ModuleEntry... imports) {
- public TestStatementSource(String name, String... imports) {
- this.name = name;
+ this.name = module.getName();
+ this.revision = module.getRevision();
this.imports = Arrays.asList(imports);
}
+ public void setContainer(String container) {
+
+ this.container = container;
+ }
+
@Override
public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
throws SourceException {
end();
}
- protected void extensions() {
- // TODO Auto-generated method stub
+ protected void extensions() throws SourceException {
}
- protected void body() {
+ protected void body() throws SourceException {
+ if (container != null)
+ stmt(CONTAINER).arg(container).end();
}
TestStatementSource header() throws SourceException {
- stmt(MODULE).arg(name); {
+
+ stmt(MODULE).arg(name);
+ {
stmt(NAMESPACE).arg(getNamespace()).end();
stmt(PREFIX).arg(name).end();
- for(String imp : imports) {
+
+ if (revision != null) {
+ stmt(REVISION).arg(revision).end();
+ }
+
+ for (ModuleEntry impEntry : imports) {
+
+ String imp = impEntry.getName();
+ String rev = impEntry.getRevision();
+
stmt(IMPORT).arg(imp);
+ {
stmt(PREFIX).arg(imp).end();
+
+ if (rev != null) {
+ stmt(REVISION_DATE).arg(rev).end();
+ }
+ }
end();
}
}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTreeWalker;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementLexer;
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class TestYangFileStatementSource implements StatementStreamSource {
+
+ private YangStatementParserListenerImpl yangStatementModelParser;
+ private YangStatementParser.StatementContext statementContext;
+ private ParseTreeWalker walker;
+
+ public TestYangFileStatementSource(String fileName) {
+ try {
+ statementContext = parseYangSource(loadFile(fileName));
+ walker = new ParseTreeWalker();
+ yangStatementModelParser = new YangStatementParserListenerImpl(REF);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes) throws SourceException {
+ yangStatementModelParser.setAttributes(writer, stmtDef, prefixes);
+ walker.walk(yangStatementModelParser, statementContext);
+ }
+
+ private FileInputStream loadFile(String fileName) throws Exception {
+ return new FileInputStream(new File(getClass().getResource(fileName).toURI()));
+ }
+
+ private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException {
+ final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
+ final CommonTokenStream tokens = new CommonTokenStream(lexer);
+ final YangStatementParser parser = new YangStatementParser(tokens);
+ //TODO: no error listener yet
+ //parser.removeErrorListeners();
+ //final YangErrorListener errorListener = new YangErrorListener();
+ //parser.addErrorListener(errorListener);
+ final YangStatementParser.StatementContext result = parser.statement();
+ //errorListener.validate();
+ return result;
+ }
+}
\ No newline at end of file
--- /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 static org.junit.Assert.fail;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class UsesResolutionTest {
+
+ //private static final Logger log = Logger.getLogger(IncludeResolutionTest.class.getName());
+
+ public static enum TYPE {
+ CYCLIC,
+ MISSING,
+ NON_CYCLIC,
+ ROOT,
+ IMPORT,
+ INCORRECT_ROOT,
+ DEFAULT
+ }
+
+ private static final UsesTestStatementSource GRP_TST = new UsesTestStatementSource(
+ "my-module", "grouping-1", "grouping-2");
+
+ private static final UsesTestStatementSource CYCLIC = new UsesTestStatementSource("my-module",TYPE.CYCLIC);
+
+ private static final UsesTestStatementSource MISSING = new UsesTestStatementSource("my-module",TYPE.MISSING);
+
+ private static final UsesTestStatementSource NON_CYCLIC = new UsesTestStatementSource("my-module",TYPE.NON_CYCLIC);
+
+ private static final UsesTestStatementSource ROOT = new UsesTestStatementSource("root-module",TYPE.ROOT);
+ private static final UsesTestStatementSource IMPORT = new UsesTestStatementSource("import-module",TYPE.IMPORT);
+ private static final UsesTestStatementSource INCORRECT_ROOT = new UsesTestStatementSource("import-module",TYPE.INCORRECT_ROOT);
+
+ @Test
+ public void usesImportTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, ROOT,IMPORT);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void usesTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, GRP_TST);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void usesAlmostCyclicTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, NON_CYCLIC);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void usesCyclicTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, CYCLIC);
+ try {
+ EffectiveModelContext result = reactor.build();
+ fail("reactor.process should fail doe to cyclic uses-grouping statements");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.FULL_DECLARATION, e.getPhase());
+ log(e,"");
+ }
+ }
+
+ @Test
+ public void usesMissingTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, MISSING);
+ try {
+ EffectiveModelContext result = reactor.build();
+ fail("reactor.process should fail doe to misssing grouping");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.FULL_DECLARATION, e.getPhase());
+ log(e,"");
+ }
+ }
+
+ @Test
+ public void usesBadImportTest() throws SourceException, ReactorException {
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INCORRECT_ROOT, IMPORT);
+ try {
+ EffectiveModelContext result = reactor.build();
+ fail("reactor.process should fail doe to misssing grouping");
+ } catch (ReactorException e) {
+ assertTrue(e instanceof SomeModifiersUnresolvedException);
+ assertEquals(ModelProcessingPhase.FULL_DECLARATION, e.getPhase());
+ log(e,"");
+ }
+ }
+
+ private void log(Throwable e, String indent) {
+ System.out.println(indent + e.getMessage());
+
+ Throwable[] suppressed = e.getSuppressed();
+ for (Throwable throwable : suppressed) {
+ log(throwable, indent + " ");
+ }
+
+ }
+
+ private void addSources(BuildAction reactor,
+ UsesTestStatementSource... sources) {
+ for (UsesTestStatementSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.*;
+
+import java.util.Arrays;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+class UsesTestStatementSource implements StatementStreamSource {
+
+ private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
+
+ private final String name;
+ private StatementWriter writer;
+ private List<String> groupingChain;
+ private UsesResolutionTest.TYPE type;
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ public UsesTestStatementSource(String name, String... groupingChain) {
+ this.name = name;
+ this.groupingChain = Arrays.asList(groupingChain);
+ this.type = UsesResolutionTest.TYPE.DEFAULT;
+ }
+
+ /**
+ * @param name2
+ * @param cyclic
+ */
+ public UsesTestStatementSource(String name, UsesResolutionTest.TYPE type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer,
+ QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ body();
+ end();
+
+ }
+
+ @Override
+ public void writeLinkage(StatementWriter writer,
+ QNameToStatementDefinition stmtDef) throws SourceException {
+ this.writer = writer;
+ header().end();
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer,
+ QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ end();
+
+ }
+
+ protected void extensions() throws SourceException {
+
+ }
+
+ protected void body() throws SourceException {
+
+ switch (type) {
+ case CYCLIC:
+ writeCyclic();
+ break;
+ case NON_CYCLIC:
+ writeNonCyclic();
+ break;
+ case MISSING:
+ writeMissing();
+ break;
+ case ROOT:
+ writeRoot();
+ break;
+ case INCORRECT_ROOT:
+ writeIncorrectRoot();
+ break;
+ case IMPORT:
+ writeImport();
+ break;
+
+ default:
+ writeDefault();
+
+ }
+
+ }
+
+
+ private void writeIncorrectRoot() throws SourceException {
+ stmt(CONTAINER).arg("root-container-with-uses");
+ {
+ stmt(USES).arg("imp-grp").end();
+ stmt(USES).arg("local-grp").end();
+ }
+ end();
+
+ stmt(GROUPING).arg("local-grp");
+ {
+ writeGroupingBody("local-grp");
+ }
+ end();
+ }
+
+ private void writeRoot() throws SourceException {
+ stmt(CONTAINER).arg("root-container-with-uses");
+ {
+ stmt(USES).arg("imp:imp-grp").end();
+ stmt(USES).arg("local-grp").end();
+ }
+ end();
+
+ stmt(GROUPING).arg("local-grp");
+ {
+ writeGroupingBody("local-grp");
+ }
+ end();
+ }
+
+ private void writeImport() throws SourceException {
+ stmt(GROUPING).arg("imp-grp");
+ {
+ writeGroupingBody("imp-grp");
+ }
+ end();
+ }
+
+ private void writeNonCyclic() throws SourceException {
+ stmt(CONTAINER).arg("container-with-uses");
+ stmt(USES).arg("grp1").end();
+ end();
+
+ stmt(GROUPING).arg("grp1");
+ stmt(USES).arg("grp2").end();
+ end();
+
+ stmt(GROUPING).arg("grp2");
+ stmt(USES).arg("grp3").end();
+ end();
+
+ stmt(GROUPING).arg("grp3");
+ writeGroupingBody("grp3");
+ end();
+ }
+
+ private void writeMissing() throws SourceException {
+ stmt(CONTAINER).arg("container-with-uses");
+ stmt(USES).arg("grp1").end();
+ stmt(USES).arg("missing-grp").end();
+ end();
+
+ stmt(GROUPING).arg("grp1");
+ writeGroupingBody("grp1");
+ end();
+ }
+
+ private void writeCyclic() throws SourceException {
+ stmt(CONTAINER).arg("container-with-uses");
+ stmt(USES).arg("grp1").end();
+ end();
+
+ stmt(GROUPING).arg("grp1");
+ stmt(USES).arg("grp2").end();
+ end();
+
+ stmt(GROUPING).arg("grp2");
+ stmt(USES).arg("grp3").end();
+ end();
+
+ stmt(GROUPING).arg("grp3");
+ stmt(USES).arg("grp1").end();
+ end();
+ }
+
+ private void writeDefault() throws SourceException {
+ stmt(CONTAINER).arg("container-with-uses");
+ for (String grpName : groupingChain) {
+ stmt(USES).arg(grpName).end();
+ }
+ end();
+
+ for (String grpName : groupingChain) {
+ stmt(GROUPING).arg(grpName);
+ writeGroupingBody(grpName);
+ stmt(USES).arg("inner-" + grpName).end();
+ end();
+ }
+
+ for (String grpName : groupingChain) {
+ stmt(GROUPING).arg("inner-" + grpName);
+ writeGroupingBody("inner-" + grpName);
+ end();
+ }
+ }
+
+ private void writeGroupingBody(String groupingName) throws SourceException {
+ stmt(CONTAINER).arg(groupingName + "-container");
+ stmt(CONTAINER).arg(groupingName + "-container-2");
+ stmt(CONTAINER).arg(groupingName + "-container-3");
+ end();
+ end();
+ end();
+
+ stmt(CONTAINER).arg(groupingName + "-container-b");
+ stmt(CONTAINER).arg(groupingName + "-container-2-b");
+ stmt(CONTAINER).arg(groupingName + "-container-3-b");
+ end();
+ end();
+ end();
+ }
+
+ UsesTestStatementSource header() throws SourceException {
+ switch (type) {
+ case ROOT:
+ writeRootHeader();
+ break;
+ default:
+ writeModuleHeader();
+
+ }
+ return this;
+ }
+
+ private void writeRootHeader() throws SourceException {
+ stmt(MODULE).arg(name);
+ {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ stmt(REVISION).arg("2000-01-01").end();
+
+ stmt(IMPORT).arg("import-module");
+ stmt(PREFIX).arg("imp").end();
+ stmt(REVISION_DATE).arg("2000-01-01").end();
+ end();
+ }
+ }
+
+ /**
+ *
+ */
+ private void writeModuleHeader() throws SourceException {
+
+ stmt(MODULE).arg(name);
+ {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ stmt(REVISION).arg("2000-01-01").end();
+ // for(String inc : includes) {
+ // stmt(Include).arg(inc);
+ // stmt(RevisionDate).arg("2000-01-01").end();
+ // end();
+ // }
+ }
+
+ }
+
+ private String getNamespace() {
+ return NS_PREFIX + name;
+ }
+
+ protected UsesTestStatementSource arg(String arg) throws SourceException {
+ writer.argumentValue(arg, REF);
+ return this;
+ }
+
+ protected UsesTestStatementSource stmt(Rfc6020Mapping stmt)
+ throws SourceException {
+ writer.startStatement(stmt.getStatementName(), REF);
+ return this;
+ }
+
+ protected UsesTestStatementSource end() throws SourceException {
+ writer.endStatement(REF);
+ return this;
+ }
+
+}
--- /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.stmt.test;
+
+import org.junit.Test;
+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.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+import static org.junit.Assert.assertNotNull;
+
+public class YangFileStmtTest {
+ private static final YangStatementSourceImpl YANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/test.yang");
+ private static final YangStatementSourceImpl IMPORTEDYANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/importedtest.yang");
+ private static final YangStatementSourceImpl SIMPLENODES = new YangStatementSourceImpl("/semantic-statement-parser/simple-nodes-semantic.yang");
+ private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl("/semantic-statement-parser/foo.yang");
+ private static final YangStatementSourceImpl FILE1 = new YangStatementSourceImpl("/model/bar.yang");
+ private static final YangStatementSourceImpl FILE2 = new YangStatementSourceImpl("/model/baz.yang");
+ private static final YangStatementSourceImpl FILE3 = new YangStatementSourceImpl("/model/foo.yang");
+ private static final YangStatementSourceImpl FILE4 = new YangStatementSourceImpl("/model/subfoo.yang");
+ private static final YangStatementSourceImpl EXTFILE = new YangStatementSourceImpl("/semantic-statement-parser/ext-typedef.yang");
+ private static final YangStatementSourceImpl EXTUSE = new YangStatementSourceImpl("/semantic-statement-parser/ext-use.yang");
+
+ @Test
+ public void readAndParseYangFileTest() throws SourceException, ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, YANGFILE, SIMPLENODES, IMPORTEDYANGFILE, FOO);
+ addSources(reactor, FILE1, FILE2, FILE3, FILE4);
+ addSources(reactor, EXTFILE, EXTUSE);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+ for (StatementStreamSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+}
\ 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
+ */
+
+package org.opendaylight.yangtools.yang.stmt.test.augment;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+
+public class AugmentTest {
+
+ private static final TestAugmentSource IMPORTED = new TestAugmentSource("imp", "/a");
+ private static final TestAugmentSource VALID_ABS = new TestAugmentSource("root", "/aug1/aug11/aug111");
+ private static final TestAugmentSource VALID_ABS_PREFIXED = new TestAugmentSource("root",
+ "/imp:aug1/imp:aug11/imp:aug111", "imp");
+ private static final TestAugmentSource VALID_REL = new TestAugmentSource("root", "aug1/aug11");
+ private static final TestAugmentSource VALID_REL_PREFIXED = new TestAugmentSource("root",
+ "imp:aug1/imp:aug11/imp:aug111", "imp");
+ private static final TestAugmentSource INVALID_REL_WHITE_SPACE = new TestAugmentSource("root", ".. /aug1/aug11");
+ private static final TestAugmentSource INVALID_REL1 = new TestAugmentSource("root", "./aug1/aug11");
+ private static final TestAugmentSource INVALID_REL2 = new TestAugmentSource("root", "../aug1/aug11");
+ private static final TestAugmentSource INVALID_ABS = new TestAugmentSource("root", "//aug1/aug11/aug111");
+ private static final TestAugmentSource INVALID_ABS_PREFIXED_NO_IMP = new TestAugmentSource("root",
+ "imp:aug1/imp:aug11/imp:aug111");
+ private static final TestAugmentSource INVALID_EMPTY = new TestAugmentSource("root", "");
+ private static final TestAugmentSource INVALID_XPATH = new TestAugmentSource("root", "/aug1/-");
+
+ @Test
+ public void validAugAbsTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, VALID_ABS);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void validAugAbsPrefixedTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED, VALID_ABS_PREFIXED);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void validAugRelTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, VALID_REL);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void validAugRelPrefixedTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, IMPORTED, VALID_REL_PREFIXED);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void validAugRelWhiteSpaceTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_REL_WHITE_SPACE);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to invalid relative path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugRel1Test() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_REL1);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to invalid relative path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugRel2Test() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_REL2);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to invalid relative path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugAbs() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_ABS);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to invalid absolute path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugAbsPrefixedNoImp() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_ABS_PREFIXED_NO_IMP);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to missing import from augment path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugEmptyTest() throws SourceException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_EMPTY);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to empty path");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void invalidAugXPathTest() throws SourceException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, INVALID_XPATH);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to invalid XPath");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ private void addSources(BuildAction reactor, TestAugmentSource... sources) {
+ for (TestAugmentSource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test.augment;
+
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.AUGMENT;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.IMPORT;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.PREFIX;
+
+import java.util.Arrays;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+public class TestAugmentSource implements StatementStreamSource {
+
+ private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
+
+ private final String name;
+ private final String augment;
+ private final java.util.List<String> imports;
+ private StatementWriter writer;
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ public TestAugmentSource(String name, String augment, String... imports) {
+ this.name = name;
+ this.augment = augment;
+ this.imports = Arrays.asList(imports);
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ body();
+ end();
+ }
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ this.writer = writer;
+ header().end();
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
+ PrefixToModule prefixes) throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ end();
+ }
+
+ protected void extensions() throws SourceException {
+
+ }
+
+ protected void body() throws SourceException {
+
+ stmt(AUGMENT).arg(augment);
+ end();
+ }
+
+ TestAugmentSource header() throws SourceException {
+
+ stmt(MODULE).arg(name);
+ {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ }
+
+ for (String impEntry : imports) {
+
+ stmt(IMPORT).arg(impEntry);
+ {
+ stmt(PREFIX).arg(impEntry).end();
+ }
+ end();
+ }
+
+ return this;
+ }
+
+ private String getNamespace() {
+ return NS_PREFIX + name;
+ }
+
+ protected TestAugmentSource arg(String arg) throws SourceException {
+ writer.argumentValue(arg, REF);
+ return this;
+ }
+
+ protected TestAugmentSource stmt(Rfc6020Mapping stmt) throws SourceException {
+ writer.startStatement(stmt.getStatementName(), REF);
+ return this;
+ }
+
+ protected TestAugmentSource end() throws SourceException {
+ writer.endStatement(REF);
+ return this;
+ }
+}
--- /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.stmt.test.key;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+
+import static org.junit.Assert.*;
+
+public class KeyTest {
+
+ private static final TestKeySource KEY_SIMPLE = new TestKeySource("root", "key");
+ private static final TestKeySource KEY_COMP = new TestKeySource("root", "key1 key2 key3");
+ private static final TestKeySource KEY_COMP_DUPLICATE = new TestKeySource("root", "key1 key1 key2");
+
+ @Test
+ public void keySimpleTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, KEY_SIMPLE);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void keyCompositeTest() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, KEY_COMP);
+
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
+ @Test
+ public void keyCompositeInvalid() throws SourceException, ReactorException {
+
+ BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, KEY_COMP_DUPLICATE);
+
+ try {
+ reactor.build();
+ fail("reactor.process should fail due to duplicate name in key");
+ } catch (Exception e) {
+ assertEquals(IllegalArgumentException.class, e.getClass());
+ }
+ }
+
+ private void addSources(BuildAction reactor, TestKeySource... sources) {
+ for (TestKeySource source : sources) {
+ reactor.addSource(source);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.test.key;
+
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.KEY;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.MODULE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.NAMESPACE;
+import static org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping.PREFIX;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+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.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+
+public class TestKeySource implements StatementStreamSource {
+
+ private static final String NS_PREFIX = "urn:org:opendaylight:yangtools:test:";
+
+ private final String name;
+ private final String key;
+ private StatementWriter writer;
+ private StatementSourceReference REF = new StatementSourceReference() {
+
+ @Override
+ public StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+ };
+
+ public TestKeySource(String name, String key) {
+ this.name = name;
+ this.key = key;
+ }
+
+ @Override
+ public void writeFull(StatementWriter writer, QNameToStatementDefinition stmtDef, PrefixToModule prefixes)
+ throws SourceException {
+
+ this.writer = writer;
+
+ header();
+ extensions();
+ body();
+ end();
+ }
+
+ @Override
+ public void writeLinkage(StatementWriter writer, QNameToStatementDefinition stmtDef) throws SourceException {
+ this.writer = writer;
+ header().end();
+ }
+
+ @Override
+ public void writeLinkageAndStatementDefinitions(StatementWriter writer, QNameToStatementDefinition stmtDef,
+ PrefixToModule prefixes) throws SourceException {
+ this.writer = writer;
+ header();
+ extensions();
+ end();
+ }
+
+ protected void extensions() throws SourceException {
+
+ }
+
+ protected void body() throws SourceException {
+
+ stmt(Rfc6020Mapping.LIST).arg("lst");
+ {
+ stmt(KEY).arg(key).end();
+ }
+ end();
+ }
+
+ TestKeySource header() throws SourceException {
+
+ stmt(MODULE).arg(name);
+ {
+ stmt(NAMESPACE).arg(getNamespace()).end();
+ stmt(PREFIX).arg(name).end();
+ }
+
+ return this;
+ }
+
+ private String getNamespace() {
+ return NS_PREFIX + name;
+ }
+
+ protected TestKeySource arg(String arg) throws SourceException {
+ writer.argumentValue(arg, REF);
+ return this;
+ }
+
+ protected TestKeySource stmt(Rfc6020Mapping stmt) throws SourceException {
+ writer.startStatement(stmt.getStatementName(), REF);
+ return this;
+ }
+
+ protected TestKeySource end() throws SourceException {
+ writer.endStatement(REF);
+ return this;
+ }
+}
revision-date 2013-02-27;
}
- include subfoo;
+ include subfoo {
+ revision-date "2013-02-27";
+ }
organization "opendaylight";
contact "http://www.opendaylight.org/";
--- /dev/null
+submodule equal-rev {
+ belongs-to "equal-root" {
+ prefix equal-root;
+ }
+
+ revision "2001-05-19";
+}
\ No newline at end of file
--- /dev/null
+module equal-root {
+ namespace equal-root;
+ prefix equal-root;
+
+ include equal-rev {
+ revision-date "2001-05-19";
+ }
+}
\ No newline at end of file
--- /dev/null
+submodule mod-1970-rev {
+ belongs-to "mod-1970-root" {
+ prefix mod-1970-root;
+ }
+}
\ No newline at end of file
--- /dev/null
+module mod-1970-root {
+ namespace mod-1970-root;
+ prefix mod-1970-root;
+
+ include mod-1970-rev {
+ revision-date "1970-01-01";
+ }
+}
\ No newline at end of file
--- /dev/null
+submodule mod-only-rev {
+ belongs-to "mod-only-root" {
+ prefix mod-only-root;
+ }
+}
\ No newline at end of file
--- /dev/null
+module mod-only-root {
+ namespace mod-only-root;
+ prefix mod-only-root;
+
+ include mod-only-rev {
+ revision-date "2001-05-19";
+ }
+}
\ No newline at end of file
--- /dev/null
+submodule nowhere-rev {
+ belongs-to "nowhere-root" {
+ prefix nowhere-root;
+ }
+}
\ No newline at end of file
--- /dev/null
+module nowhere-root {
+ namespace nowhere-root;
+ prefix nowhere-root;
+
+ include nowhere-rev;
+}
\ No newline at end of file
--- /dev/null
+submodule submod-only-rev {
+ belongs-to "submod-only-root" {
+ prefix submod-only-root;
+ }
+
+ revision "2001-05-19";
+}
\ No newline at end of file
--- /dev/null
+module submod-only-root {
+ namespace submod-only-root;
+ prefix submod-only-root;
+
+ include submod-only-rev;
+}
\ No newline at end of file
--- /dev/null
+submodule unequal-rev {
+ belongs-to "unequal-root" {
+ prefix unequal-root;
+ }
+
+ revision "2001-05-20";
+}
\ No newline at end of file
--- /dev/null
+module unequal-root {
+ namespace unequal-root;
+ prefix unequal-root;
+
+ include unequal-rev {
+ revision-date "2001-05-19";
+ }
+}
\ No newline at end of file
--- /dev/null
+module ext-typedef {
+ yang-version 1;
+ namespace "urn:simple.extension.typedefs";
+ prefix "ext";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ description "Model for testing and resolving of extension typedefs.";
+
+ revision "2015-03-30" {
+ reference "Initial revision.";
+ }
+
+ extension simple-ext-w-arg {
+ argument "ext-arg";
+ description "Extension with single argument definition.";
+ }
+
+ leaf myleaf {
+ type union {
+ type string;
+ type int32;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module ext-use {
+ yang-version 1;
+ namespace "urn:simple.extension.use";
+ prefix "ext-use";
+
+ import ext-typedef {
+ prefix "ext";
+ }
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ description "Model for testing of used extensions across model.";
+
+ revision "2015-03-30" {
+ reference "Initial revision.";
+ }
+
+ leaf value {
+ ext:simple-ext-w-arg "key:value";
+ type uint32;
+ description "value";
+ }
+
+ grouping inner-ext {
+ ext:simple-ext-w-arg "value:test";
+
+ leaf inner-value {
+ ext:simple-ext-w-arg "key:inner-value";
+ type uint32;
+ description "value";
+ }
+ }
+
+ container cont-ext {
+ ext:simple-ext-w-arg "value:test";
+
+ leaf inner-value {
+ ext:simple-ext-w-arg "value:test";
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module foo {
+ yang-version 1;
+ namespace "urn:opendaylight.foo";
+ prefix "foo";
+
+ revision "2015-07-08" {
+ }
+
+ container x {
+ leaf x15 {
+ type string;
+ }
+
+ list x10 {}
+
+ container x5 {}
+
+ leaf-list x1 {
+ type string;
+ }
+
+ uses a;
+
+ container x2 {}
+
+ uses b;
+
+ container x3 {}
+ }
+
+
+ grouping a {
+ anyxml a5;
+ anyxml a1;
+ }
+
+ grouping b {
+ anyxml b5;
+ anyxml b1;
+ }
+
+ augment /x {
+ leaf ax15 {
+ type string;
+ }
+ container ax5 {}
+ }
+
+}
--- /dev/null
+module importedtest {
+ yang-version 1;
+ namespace "urn:imptst:yang";
+ prefix "imptst";
+
+ description "This is a to be imported test module";
+
+ revision 2015-03-20;
+
+ container myimportedcontainer {
+ leaf myimportedleaf {
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module simple-nodes {
+ yang-version 1;
+ namespace "urn:opendaylight:"+
+ "simple-nodes";
+ prefix "sn";
+
+ organization "opendaylight";
+
+ import test {
+ prefix tst;
+ }
+
+ description
+ "test file containing yang data nodes";
+
+ revision "2013-07-30" {
+ description
+ "Initial revision.";
+ reference "will be defined";
+ }
+
+
+ typedef mytype {
+ type string;
+ }
+
+ // NOTE: simple comment
+
+
+
+ anyxml data {
+ config false;
+ description "anyxml desc";
+ if-feature has-name;
+ mandatory true;
+ must "ifType != 'ethernet' or " +
+ "(ifType = 'ethernet' and ifMTU = 1500)" {
+ error-message "An ethernet MTU must be 1500";
+ }
+ must "ifType != 'atm' or " +
+ "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
+ error-app-tag "anyxml data error-app-tag";
+ error-message "An atm MTU must be 64 .. 17966";
+ description "an error occured in data";
+ reference "data must ref";
+ }
+ reference "data ref";
+ status obsolete;
+ when "class != 'wheel'";
+ }
+
+}
--- /dev/null
+module test {
+ yang-version 1;
+ namespace "urn:tst:yang";
+ prefix "tst";
+
+ import importedtest {
+ prefix "imptst";
+ }
+
+ description "This is a test module";
+
+ revision 2015-03-04;
+
+ container mycontainer {
+ leaf myleaf {
+ type string;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module simple-module {
+
+ namespace "simple.yang";
+ prefix sim;
+
+ container root-container {
+ container sim:sub-container {
+ container sub-sub-container {
+ }
+ }
+ }
+
+// container sim:root-container2 {
+// container sub-container2 {
+// container "sim:sub-sub-container2" {
+// }
+// }
+// }
+
+ container sim:root-container2 {
+ uses grp;
+ }
+
+ grouping grp{
+ container sub-container2 {
+ container "sim:sub-sub-container2" {
+ }
+ }
+ }
+}