* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
module org.opendaylight.yangtools.yang.parser.api {
- exports org.opendaylight.yangtools.yang.model.parser.api;
exports org.opendaylight.yangtools.yang.parser.api;
requires transitive com.google.common;
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.parser.api;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.SetMultimap;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-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.repo.api.SchemaSourceRepresentation;
-
-/**
- * Configurable single-use YANG parser. Each instance can be configured to use a different set of models after
- * which it is built. Models once added cannot be removed. Implementations are expected to be NOT thread-safe.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.parser.api.YangParser} instead.
- */
-@Beta
-@Deprecated(since = "7.0.0", forRemoval = true)
-public interface YangParser {
- /**
- * Return enumeration of concrete types of {@link SchemaSourceRepresentation} parsers created from this factory
- * support. Users can use this information prepare the source they have to a representation which will be accepted
- * by this parser.
- *
- * @return Enumeration of supported schema source representations.
- */
- @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.
- */
- @NonNull Set<QName> supportedStatements();
-
- /**
- * Add main source. All main sources are present in resulting SchemaContext.
- *
- * @param source which should be added into main sources
- * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
- * @throws IOException when an IO error occurs
- * @throws IllegalArgumentException if the representation is not supported
- */
- @NonNull YangParser addSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
-
- /**
- * Add main sources. All main sources are present in resulting SchemaContext.
- *
- * @param sources which should be added into main sources
- * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
- * @throws IOException when an IO error occurs
- * @throws IllegalArgumentException if the representation is not supported
- */
- default @NonNull YangParser addSources(final SchemaSourceRepresentation... sources) throws IOException,
- YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
- addSource(source);
- }
- return this;
- }
-
- default @NonNull YangParser addSources(final Collection<? extends SchemaSourceRepresentation> sources)
- throws IOException, YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
- addSource(source);
- }
- return this;
- }
-
- YangParser addLibSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
-
- /**
- * Add library sources. Only library sources required by main sources are present in resulting SchemaContext.
- * Any other library sources are ignored and this also applies to error reporting.
- *
- * <p>
- * Note: Library sources are not supported in semantic version mode currently.
- *
- * @param sources YANG sources which should be added into library sources
- * @throws YangSyntaxErrorException when one of the sources fails syntactic analysis
- * @throws IOException when an IO error occurs
- * @throws IllegalArgumentException if the representation is not supported
- */
- default @NonNull YangParser addLibSources(final SchemaSourceRepresentation... sources) throws IOException,
- YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
- addLibSource(source);
- }
- return this;
- }
-
- default @NonNull YangParser addLibSources(final Collection<SchemaSourceRepresentation> sources) throws IOException,
- YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
- addLibSource(source);
- }
- return this;
- }
-
- /**
- * Set supported features based on which all if-feature statements in the parsed YANG modules will be resolved. If
- * this method is not invoked, all features will be supported.
- *
- * @param supportedFeatures Set of supported features in the final SchemaContext. If the set is empty, no features
- * encountered will be supported.
- */
- @NonNull YangParser setSupportedFeatures(@NonNull Set<QName> supportedFeatures);
-
- /**
- * Set YANG modules which can be deviated by specified modules during the parsing process. Map key (QNameModule)
- * denotes a module which can be deviated by the modules in the Map value.
- *
- * @param modulesDeviatedByModules Map of YANG modules (Map key) which can be deviated by specified modules (Map
- * value) in the final SchemaContext. If the map is empty, no deviations encountered
- * will be supported.
- */
- @NonNull YangParser setModulesWithSupportedDeviations(
- @NonNull SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules);
-
- /**
- * Build the declared view of a combined view of declared statements.
- *
- * @return Ordered collection of declared statements from requested sources.
- * @throws YangSyntaxErrorException When a syntactic error is encountered.
- */
- @NonNull List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException;
-
- /**
- * Build the effective view of a combined view of effective statements. Note that this representation, unlike
- * {@link #buildDeclaredModel()} does not expose submodules as top-level contracts. These are available from their
- * respective parent modules.
- *
- * @return Effective module statements indexed by their QNameModule.
- * @throws YangSyntaxErrorException When a syntactic error is encountered.
- */
- @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.
- * @deprecated Use {@link #buildEffectiveModel()} instead.
- */
- @Deprecated(forRemoval = true)
- default @NonNull SchemaContext buildSchemaContext() throws YangParserException {
- return buildEffectiveModel();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.parser.api;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Base exception reported by {@link YangParser}. This is used as an exception of last resort, semantic reporting
- * of individual errors is performed via subclasses, like {@link YangSyntaxErrorException}.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.parser.api.YangParserException} instead.
- */
-@Beta
-@Deprecated(since = "7.0.0", forRemoval = true)
-public class YangParserException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public YangParserException(final String message) {
- super(requireNonNull(message));
- }
-
- public YangParserException(final String message, final Throwable cause) {
- super(requireNonNull(message), cause);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.parser.api;
-
-import com.google.common.annotations.Beta;
-import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang.parser.api.ImportResolutionMode;
-import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-
-/**
- * Basic entry point into a YANG parser implementation. Implementations of this interface are expected to be
- * thread-safe.
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.parser.api.YangParserFactory} instead.
- */
-@Beta
-@Deprecated(since = "7.0.0", forRemoval = true)
-public interface YangParserFactory {
- /**
- * Return enumeration of {@link StatementParserMode}s supported by this factory.
- *
- * @return Enumeration of supported schema source representations
- */
- Collection<StatementParserMode> supportedParserModes();
-
- /**
- * Create a {@link YangParser} instance operating with default {@link YangParserConfiguration}.
- *
- * @return A new {@link YangParser} instance
- */
- default @NonNull YangParser createParser() {
- return createParser(YangParserConfiguration.DEFAULT);
- }
-
- /**
- * Create a {@link YangParser} instance operating with specified {@link YangParserConfiguration}.
- *
- * @param configuration Requested parser configuration
- * @return A new {@link YangParser} instance
- * @throws NullPointerException if configuration is null
- * @throws IllegalArgumentException if specified configuration is not supported
- */
- @NonNull YangParser createParser(YangParserConfiguration configuration);
-
- /**
- * Create a {@link YangParser} instance operating in specified import resolution mode.
- *
- * @param parserMode Requested parser mode, may not be null.
- * @return A new {@link YangParser} instance
- * @throws NullPointerException if parser mode is null
- * @throws IllegalArgumentException if specified parser mode is not supported
- * @deprecated Use {@link #createParser(YangParserConfiguration)} instead.
- */
- @Deprecated(forRemoval = true)
- default @NonNull YangParser createParser(final StatementParserMode parserMode) {
- final ImportResolutionMode importMode;
- switch (parserMode) {
- case DEFAULT_MODE:
- importMode = ImportResolutionMode.DEFAULT;
- break;
- case SEMVER_MODE:
- importMode = ImportResolutionMode.OPENCONFIG_SEMVER;
- break;
- default:
- throw new IllegalArgumentException("Unsupported mode " + parserMode);
- }
-
- return createParser(YangParserConfiguration.builder().importResolutionMode(importMode).build());
- }
-}
+++ /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.model.parser.api;
-
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-
-@Deprecated(since = "7.0.0", forRemoval = true)
-public class YangSyntaxErrorException extends YangParserException {
- private static final long serialVersionUID = 2L;
-
- private final SourceIdentifier source;
- private final int line;
- private final int charPositionInLine;
-
- public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
- final int charPositionInLine, final String message) {
- this(source, line, charPositionInLine, message, null);
- }
-
- public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
- final int charPositionInLine, final String message, final @Nullable Throwable cause) {
- super(message, cause);
- this.source = source;
- this.line = line;
- this.charPositionInLine = charPositionInLine;
- }
-
- public final Optional<SourceIdentifier> getSource() {
- return Optional.ofNullable(source);
- }
-
- public final int getLine() {
- return line;
- }
-
- public final int getCharPositionInLine() {
- return charPositionInLine;
- }
-
- public @NonNull String getFormattedMessage() {
- final StringBuilder sb = new StringBuilder(getMessage());
- if (source != null) {
- sb.append(" in source ");
- sb.append(source);
- }
- if (line != 0) {
- sb.append(" on line ");
- sb.append(line);
- if (charPositionInLine != 0) {
- sb.append(" character ");
- sb.append(charPositionInLine);
- }
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return this.getClass().getName() + ": " + getFormattedMessage();
- }
-}
+++ /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
- */
-@java.lang.Deprecated(forRemoval = true)
-package org.opendaylight.yangtools.yang.model.parser.api;
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.parser.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.Collections2;
-import java.util.Collection;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.eclipse.jdt.annotation.NonNull;
-import org.kohsuke.MetaInfServices;
-import org.opendaylight.yangtools.yang.model.parser.api.YangParser;
-import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
-import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-/**
- * Reference {@link YangParserFactory} implementation.
- *
- * @deprecated Use {@link DefaultYangParserFactory} instead.
- */
-@Beta
-@MetaInfServices
-@Singleton
-@Component(immediate = true)
-@Deprecated(since = "7.0.0", forRemoval = true)
-public final class YangParserFactoryImpl implements YangParserFactory {
- private final DefaultYangParserFactory delegate;
-
- private YangParserFactoryImpl(final DefaultYangParserFactory delegate) {
- this.delegate = requireNonNull(delegate);
- }
-
- /**
- * Construct a new {@link YangParserFactory} backed by {@link DefaultReactors#defaultReactor()}.
- */
- public YangParserFactoryImpl() {
- this(new DefaultYangParserFactory());
- }
-
- @Inject
- @Activate
- public YangParserFactoryImpl(final @Reference YangXPathParserFactory xpathFactory) {
- this(new DefaultYangParserFactory(xpathFactory));
- }
-
- @Override
- public Collection<StatementParserMode> supportedParserModes() {
- return Collections2.transform(delegate.supportedImportResolutionModes(), mode -> {
- switch (mode) {
- case DEFAULT:
- return StatementParserMode.DEFAULT_MODE;
- case OPENCONFIG_SEMVER:
- return StatementParserMode.SEMVER_MODE;
- default:
- throw new IllegalStateException("Unhandled mode " + mode);
- }
- });
- }
-
- @Override
- public @NonNull YangParser createParser(final YangParserConfiguration configuration) {
- return new YangParserImpl(delegate.createParser(configuration));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.parser.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.SetMultimap;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.List;
-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.meta.DeclaredStatement;
-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.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-
-@Deprecated(since = "7.0.0", forRemoval = true)
-final class YangParserImpl implements YangParser {
- private final org.opendaylight.yangtools.yang.parser.api.YangParser delegate;
-
- YangParserImpl(final org.opendaylight.yangtools.yang.parser.api.YangParser yangParser) {
- this.delegate = requireNonNull(yangParser);
- }
-
- @Override
- public @NonNull Set<QName> supportedStatements() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public @NonNull Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations() {
- return delegate.supportedSourceRepresentations();
- }
-
- @Override
- public @NonNull YangParser addSource(final SchemaSourceRepresentation source) throws IOException,
- YangSyntaxErrorException {
- try {
- delegate.addSource(source);
- } catch (org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException e) {
- throw mapException(e);
- }
- return this;
- }
-
- @Override
- public @NonNull YangParser addLibSource(final SchemaSourceRepresentation source) throws IOException,
- YangSyntaxErrorException {
- try {
- delegate.addLibSource(source);
- } catch (org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException e) {
- throw mapException(e);
- }
- return this;
- }
-
- @Override
- public @NonNull YangParser setSupportedFeatures(final Set<QName> supportedFeatures) {
- delegate.setSupportedFeatures(supportedFeatures);
- return this;
- }
-
- @Override
- public @NonNull YangParser setModulesWithSupportedDeviations(
- final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
- delegate.setModulesWithSupportedDeviations(modulesDeviatedByModules);
- return this;
- }
-
- @Override
- public @NonNull List<DeclaredStatement<?>> buildDeclaredModel() throws YangParserException {
- try {
- return delegate.buildDeclaredModel();
- } catch (org.opendaylight.yangtools.yang.parser.api.YangParserException e) {
- throw mapException(e);
- }
- }
-
- @Override
- public @NonNull EffectiveModelContext buildEffectiveModel() throws YangParserException {
- try {
- return delegate.buildEffectiveModel();
- } catch (org.opendaylight.yangtools.yang.parser.api.YangParserException e) {
- throw mapException(e);
- }
- }
-
- private static YangParserException mapException(
- final org.opendaylight.yangtools.yang.parser.api.YangParserException ex) {
- return new YangParserException(ex.getMessage(), ex);
- }
-
- private static YangSyntaxErrorException mapException(
- final org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException ex) {
- return new YangSyntaxErrorException(ex.getSource().orElse(null), ex.getLine(), ex.getCharPositionInLine(),
- ex.getMessage(), ex);
- }
-}