--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.model.api;
+
+import com.google.common.annotations.Beta;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
+
+/**
+ * {@link EffectiveStatement}-based result of YANG parser compilation. Unlike a SchemaContext, which it extends,
+ * it gives access to individual {@link ModuleEffectiveStatement}s that comprise it.
+ *
+ * @author Robert Varga
+ */
+@Beta
+// FIXME: 4.0.0: evaluate if we still need to extend SchemaContext here
+public interface EffectiveModelContext extends SchemaContext {
+
+ Map<QNameModule, ModuleEffectiveStatement> getModuleStatements();
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.model.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+
+/**
+ * A static provider of an {@link EffectiveModelContext}.
+ *
+ * @author Robert Varga
+ */
+@Beta
+public interface EffectiveModelContextProvider extends SchemaContextProvider {
+ /**
+ * Return the {@link EffectiveModelContext} attached to this object.
+ *
+ * @return An EffectiveModelContext instance.
+ */
+ @NonNull EffectiveModelContext getEffectiveModelContext();
+
+ @Override
+ default @NonNull SchemaContext getSchemaContext() {
+ return getEffectiveModelContext();
+ }
+}
*/
// FIXME: 3.0.0: ContainerSchemaNode is far too broad. A combination of DataNodeContainer, NotificationNodeContainer
// and possibly DataSchemaNode would reflect SchemaContext traits better.
+// FIXME: 4.0.0: consider deprecating this class in favor of EffectiveModelContext
public interface SchemaContext extends ContainerSchemaNode, Immutable {
/**
* QName of NETCONF top-level data node.
import java.io.IOException;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
/**
*
* @return Enumeration of supported schema source representations.
*/
- Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations();
+ @NonNull Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations();
/**
* Return the set of all YANG statements semantically supported by this parser instance.
*
* @return Set of all YANG statements semantically supported by this parser instance.
*/
- Set<QName> supportedStatements();
+ @NonNull Set<QName> supportedStatements();
/**
* Add main source. All main sources are present in resulting SchemaContext.
* @throws IOException when an IO error occurs
* @throws IllegalArgumentException if the representation is not supported
*/
- YangParser addSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
+ @NonNull YangParser addSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
/**
* Add main sources. All main sources are present in resulting SchemaContext.
* @throws IOException when an IO error occurs
* @throws IllegalArgumentException if the representation is not supported
*/
- default YangParser addSources(final SchemaSourceRepresentation... sources) throws IOException,
+ default @NonNull YangParser addSources(final SchemaSourceRepresentation... sources) throws IOException,
YangSyntaxErrorException {
for (SchemaSourceRepresentation source : sources) {
addSource(source);
return this;
}
- default YangParser addSources(final Collection<? extends SchemaSourceRepresentation> sources) throws IOException,
- YangSyntaxErrorException {
+ default @NonNull YangParser addSources(final Collection<? extends SchemaSourceRepresentation> sources)
+ throws IOException, YangSyntaxErrorException {
for (SchemaSourceRepresentation source : sources) {
addSource(source);
}
* @throws IOException when an IO error occurs
* @throws IllegalArgumentException if the representation is not supported
*/
- default YangParser addLibSources(final SchemaSourceRepresentation... sources) throws IOException,
+ default @NonNull YangParser addLibSources(final SchemaSourceRepresentation... sources) throws IOException,
YangSyntaxErrorException {
for (SchemaSourceRepresentation source : sources) {
addLibSource(source);
return this;
}
- default YangParser addLibSources(final Collection<SchemaSourceRepresentation> sources) throws IOException,
+ default @NonNull YangParser addLibSources(final Collection<SchemaSourceRepresentation> sources) throws IOException,
YangSyntaxErrorException {
for (SchemaSourceRepresentation source : sources) {
addLibSource(source);
* @param supportedFeatures Set of supported features in the final SchemaContext. If the set is empty, no features
* encountered will be supported.
*/
- YangParser setSupportedFeatures(@NonNull Set<QName> supportedFeatures);
+ @NonNull YangParser setSupportedFeatures(@NonNull Set<QName> supportedFeatures);
/**
* Set YANG modules which can be deviated by specified modules during the parsing process. Map key (QNameModule)
* value) in the final SchemaContext. If the map is empty, no deviations encountered
* will be supported.
*/
- YangParser setModulesWithSupportedDeviations(
+ @NonNull YangParser setModulesWithSupportedDeviations(
@NonNull SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules);
/**
* @return Ordered collection of declared statements from requested sources.
* @throws YangSyntaxErrorException When a syntactic error is encountered.
*/
- List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException;
+ @NonNull List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException;
/**
* Build the effective view of a combined view of effective statements. Note that this representation, unlike
* @return Effective module statements indexed by their QNameModule.
* @throws YangSyntaxErrorException When a syntactic error is encountered.
*/
- Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException;
+ @NonNull EffectiveModelContext buildEffectiveModel() throws YangParserException;
/**
* Build effective {@link SchemaContext}.
* @return An effective schema context comprised of configured models.
* @throws YangSyntaxErrorException When a syntactic error is encountered.
*/
- SchemaContext buildSchemaContext() throws YangParserException;
+ default @NonNull SchemaContext buildSchemaContext() throws YangParserException {
+ return buildEffectiveModel();
+ }
}
*/
package org.opendaylight.yangtools.yang.parser.impl;
-import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Objects.requireNonNull;
-import static java.util.function.Function.identity;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.xml.transform.TransformerException;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.parser.api.YangParser;
import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.xml.sax.SAXException;
final class YangParserImpl implements YangParser {
- private static final Collection<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS = ImmutableList.of(
- ASTSchemaSource.class, YangTextSchemaSource.class, YinDomSchemaSource.class, YinXmlSchemaSource.class,
- YinTextSchemaSource.class);
+ private static final @NonNull Collection<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS =
+ ImmutableList.of(ASTSchemaSource.class, YangTextSchemaSource.class,
+ YinDomSchemaSource.class, YinXmlSchemaSource.class, YinTextSchemaSource.class);
private final BuildAction buildAction;
}
@Override
- public Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations() {
+ public @NonNull Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations() {
return REPRESENTATIONS;
}
@Override
- public Set<QName> supportedStatements() {
+ public @NonNull Set<QName> supportedStatements() {
// TODO Auto-generated method stub
return null;
}
@Override
- public YangParser addSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException {
+ public @NonNull YangParser addSource(final SchemaSourceRepresentation source) throws IOException,
+ YangSyntaxErrorException {
buildAction.addSources(sourceToStatementStream(source));
return this;
}
@Override
- public YangParser addLibSource(final SchemaSourceRepresentation source) throws IOException,
+ public @NonNull YangParser addLibSource(final SchemaSourceRepresentation source) throws IOException,
YangSyntaxErrorException {
buildAction.addLibSources(sourceToStatementStream(source));
return this;
}
@Override
- public YangParser setSupportedFeatures(final Set<QName> supportedFeatures) {
+ public @NonNull YangParser setSupportedFeatures(final Set<QName> supportedFeatures) {
buildAction.setSupportedFeatures(supportedFeatures);
return this;
}
@Override
- public YangParser setModulesWithSupportedDeviations(
+ public @NonNull YangParser setModulesWithSupportedDeviations(
final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
buildAction.setModulesWithSupportedDeviations(modulesDeviatedByModules);
return this;
}
@Override
- public List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException {
+ public @NonNull List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException {
try {
return buildAction.build().getRootStatements();
} catch (ReactorException e) {
}
@Override
- public Map<QNameModule, ModuleEffectiveStatement> buildEffectiveModel() throws YangParserException {
- final List<EffectiveStatement<?, ?>> effectiveStatements;
- try {
- effectiveStatements = buildAction.buildEffective().getRootEffectiveStatements();
- } catch (ReactorException e) {
- throw decodeReactorException(e);
- }
-
- return effectiveStatements.stream()
- .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast)
- .collect(toImmutableMap(ModuleEffectiveStatement::localQNameModule, identity()));
- }
-
- @Override
- public SchemaContext buildSchemaContext() throws YangParserException {
+ public @NonNull EffectiveModelContext buildEffectiveModel() throws YangParserException {
try {
return buildAction.buildEffective();
} catch (ReactorException e) {
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.function.Function;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
@VisibleForTesting
-public final class EffectiveSchemaContext extends SimpleSchemaContext {
+public final class EffectiveSchemaContext extends SimpleSchemaContext implements EffectiveModelContext {
private final ImmutableList<DeclaredStatement<?>> rootDeclaredStatements;
- private final ImmutableList<EffectiveStatement<?, ?>> rootEffectiveStatements;
+ private final ImmutableMap<QNameModule, ModuleEffectiveStatement> rootEffectiveStatements;
private EffectiveSchemaContext(final Set<Module> modules, final List<DeclaredStatement<?>> rootDeclaredStatements,
final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
super(modules);
this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
- this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);
+ this.rootEffectiveStatements = rootEffectiveStatements.stream()
+ .filter(ModuleEffectiveStatement.class::isInstance).map(ModuleEffectiveStatement.class::cast)
+ .collect(ImmutableMap.toImmutableMap(ModuleEffectiveStatement::localQNameModule, Function.identity()));
}
static EffectiveSchemaContext create(final List<DeclaredStatement<?>> rootDeclaredStatements,
}
@Beta
- public List<EffectiveStatement<?, ?>> getRootEffectiveStatements() {
+ public ImmutableMap<QNameModule, ModuleEffectiveStatement> getModuleStatements() {
return rootEffectiveStatements;
}
}
Module fooModule = schemaContext.findModule("foo", Revision.of("2016-09-21")).get();
assertEquals(3, schemaContext.getModules().size());
assertEquals(3, schemaContext.getRootDeclaredStatements().size());
- assertEquals(3, schemaContext.getRootEffectiveStatements().size());
+ assertEquals(3, schemaContext.getModuleStatements().size());
final Set<Module> modules = schemaContext.getModules();
final SchemaContext copiedSchemaContext = SimpleSchemaContext.forModules(modules);