module org.opendaylight.yangtools.yang.model.api {
exports org.opendaylight.yangtools.yang.model.api;
exports org.opendaylight.yangtools.yang.model.api.meta;
+ exports org.opendaylight.yangtools.yang.model.api.source;
exports org.opendaylight.yangtools.yang.model.api.stmt;
exports org.opendaylight.yangtools.yang.model.api.stmt.compat;
exports org.opendaylight.yangtools.yang.model.api.type;
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.api.source;
import static java.util.Objects.requireNonNull;
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.api.source;
-import com.google.common.annotations.Beta;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Identifiable;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
/**
* <p>
* Typical examples of a schema source representation include:
* <ul>
- * <li>a {@link java.lang.String} - textual representation of source code
- * <li>a {@link java.io.InputStream} - input stream containing source code
- * <li>a {@link com.google.common.io.ByteSource} - source for input streams
- * containing source code
- * <li>Parsed abstract syntax tree (AST), which is the result of a syntactic parser
+ * <li>a {@link java.lang.String} - textual representation of source code</li>
+ * <li>a {@link java.io.InputStream} - input stream containing source code</li>
+ * <li>a {@link com.google.common.io.ByteSource} - source for input streams containing source code</li>
+ * <li>Parsed abstract syntax tree (AST), which is the result of a syntactic parser</li>
* </ul>
*
* <p>
* Implementations of this interface expected to comply with the {@link Immutable} contract.
*/
-@Beta
-public sealed interface SchemaSourceRepresentation extends Identifiable<SourceIdentifier>, Immutable
- permits YangSchemaSourceRepresentation, YinSchemaSourceRepresentation {
- @Override
- SourceIdentifier getIdentifier();
+public sealed interface SourceRepresentation extends Immutable
+ permits YangSourceRepresentation, YinSourceRepresentation {
+ /**
+ * The {@link SourceIdentifier} of this source.
+ *
+ * @return {@link SourceIdentifier} of this source
+ */
+ @NonNull SourceIdentifier sourceId();
/**
* Return the concrete representation type.
*
* @return The type of representation.
*/
- @NonNull Class<? extends SchemaSourceRepresentation> getType();
+ @NonNull Class<? extends SourceRepresentation> getType();
/**
* Return the symbolic name, if available. This name has no semantic meaning beyond being useful for debugging
*
* @return Symbolic name, if available
*/
- Optional<String> getSymbolicName();
+ @Nullable String symbolicName();
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.api.source;
/**
- * A YIN {@link SchemaSourceRepresentation}.
+ * A YANG {@link SourceRepresentation}.
*/
-public non-sealed interface YinSchemaSourceRepresentation extends SchemaSourceRepresentation {
+public non-sealed interface YangSourceRepresentation extends SourceRepresentation {
@Override
- Class<? extends YinSchemaSourceRepresentation> getType();
+ Class<? extends YangSourceRepresentation> getType();
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.api.source;
/**
- * A YANG {@link SchemaSourceRepresentation}.
+ * A YIN {@link SourceRepresentation}.
*/
-public non-sealed interface YangSchemaSourceRepresentation extends SchemaSourceRepresentation {
+public non-sealed interface YinSourceRepresentation extends SourceRepresentation {
@Override
- Class<? extends YangSchemaSourceRepresentation> getType();
+ Class<? extends YinSourceRepresentation> getType();
}
--- /dev/null
+/*
+ * Copyright (c) 2024 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
+ */
+/**
+ * Base interfaces for identifying and source of YANG and YIN models. Two main entry points are
+ * <ol>
+ * <li>{@link SourceIdentifier}, i.e. how a model source is known</li>
+ * <li>{@link SourceRepresentation}, i.e. its format</li>
+ * </ol>
+ */
+package org.opendaylight.yangtools.yang.model.api.source;
\ No newline at end of file
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
}
@Override
- public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
+ public void schemaSourceEncountered(final SourceRepresentation source) {
// NOOP
}
})) {
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ActionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.AnydataEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YinElementEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.YinElementStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.impl.decl.EmptyRequireInstanceStatement;
import org.opendaylight.yangtools.yang.model.ri.stmt.impl.decl.EmptyStatusStatement;
import org.opendaylight.yangtools.yang.model.ri.stmt.impl.decl.EmptyYangVersionStatement;
public static ImportEffectiveStatement createImport(final ImportStatement declared,
final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
final SourceIdentifier importedSource) {
- return new ImportEffectiveStatementImpl(declared, substatements, importedSource);
+ return new ImportEffectiveStatementImpl(declared, substatements, importedSource.revision());
}
public static IncludeEffectiveStatement createInclude(final IncludeStatement declared,
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.spi.meta.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
import org.opendaylight.yangtools.yang.model.spi.meta.EffectiveStatementMixins.DocumentedNodeMixin;
private final @Nullable Revision revision;
public ImportEffectiveStatementImpl(final ImportStatement declared,
- final ImmutableList<? extends EffectiveStatement<?, ?>> substatements,
- final @NonNull SourceIdentifier importedSource) {
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final @NonNull Revision revision) {
super(declared, substatements);
- revision = importedSource.revision();
+ this.revision = revision;
}
@Override
module org.opendaylight.yangtools.yang.model.spi {
exports org.opendaylight.yangtools.yang.model.spi;
exports org.opendaylight.yangtools.yang.model.spi.meta;
+ exports org.opendaylight.yangtools.yang.model.spi.source;
requires transitive com.google.common;
requires transitive org.opendaylight.yangtools.concepts;
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import com.google.common.io.CharSource;
import java.io.IOException;
import java.io.Reader;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<CharSource> {
+final class DelegatedYangTextSource extends YangTextSource implements Delegator<CharSource> {
private final @NonNull CharSource delegate;
- DelegatedYangTextSchemaSource(final SourceIdentifier identifier, final CharSource delegate) {
- super(identifier);
+ DelegatedYangTextSource(final SourceIdentifier sourceId, final CharSource delegate) {
+ super(sourceId);
this.delegate = requireNonNull(delegate);
}
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of("[" + delegate.toString() + "]");
+ public String symbolicName() {
+ return "[" + delegate.toString() + "]";
}
@Override
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import com.google.common.io.ByteSource;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-final class DelegatedYinTextSchemaSource extends YinTextSchemaSource implements Delegator<ByteSource> {
+final class DelegatedYinTextSource extends YinTextSource implements Delegator<ByteSource> {
private final @NonNull ByteSource delegate;
- DelegatedYinTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
- super(identifier);
+ DelegatedYinTextSource(final SourceIdentifier sourceId, final ByteSource delegate) {
+ super(sourceId);
this.delegate = requireNonNull(delegate);
}
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of("[" + delegate.toString() + "]");
+ public String symbolicName() {
+ return "[" + delegate.toString() + "]";
}
@Override
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A resource-backed {@link YinTextSchemaSource}.
+ * A resource-backed {@link YangTextSource}.
*/
-final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator<URL> {
+final class ResourceYangTextSource extends YangTextSource implements Delegator<URL> {
private final @NonNull URL url;
private final @NonNull Charset charset;
- ResourceYangTextSchemaSource(final SourceIdentifier identifier, final URL url, final Charset charset) {
- super(identifier);
+ ResourceYangTextSource(final SourceIdentifier sourceId, final URL url, final Charset charset) {
+ super(sourceId);
this.url = requireNonNull(url);
this.charset = requireNonNull(charset);
}
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of(url.toString());
+ public String symbolicName() {
+ return url.toString();
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A resource-backed {@link YangTextSchemaSource}.
+ * A resource-backed {@link YinTextSource}.
*/
-final class ResourceYinTextSchemaSource extends YinTextSchemaSource implements Delegator<URL> {
+final class ResourceYinTextSource extends YinTextSource implements Delegator<URL> {
private final @NonNull URL url;
- ResourceYinTextSchemaSource(final SourceIdentifier identifier, final URL url) {
- super(identifier);
+ ResourceYinTextSource(final SourceIdentifier sourceId, final URL url) {
+ super(sourceId);
this.url = requireNonNull(url);
}
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of(url.toString());
+ public String symbolicName() {
+ return url.toString();
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import java.io.Reader;
import java.io.StringReader;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A {@link YangTextSchemaSource} with content readily available.
+ * A {@link YangTextSource} with content readily available.
*/
-public class StringYangTextSchemaSource extends YangTextSchemaSource {
+public class StringYangTextSource extends YangTextSource {
private final @Nullable String symbolicName;
private final @NonNull String content;
- public StringYangTextSchemaSource(final SourceIdentifier identifier, final String content) {
- this(identifier, content, null);
+ public StringYangTextSource(final SourceIdentifier sourceId, final String content) {
+ this(sourceId, content, null);
}
- public StringYangTextSchemaSource(final SourceIdentifier identifier, final String content,
+ public StringYangTextSource(final SourceIdentifier sourceId, final String content,
final @Nullable String symbolicName) {
- super(identifier);
+ super(sourceId);
this.content = requireNonNull(content);
this.symbolicName = symbolicName;
}
@Override
- public final Optional<String> getSymbolicName() {
- return Optional.ofNullable(symbolicName);
+ public final String symbolicName() {
+ return symbolicName;
}
@Override
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A {@link YangTextSchemaSource} backed by a file.
- *
- * @author Robert Varga
+ * A {@link YangTextSource} backed by a file.
*/
-final class YangTextFileSchemaSource extends YangTextSchemaSource implements Delegator<Path> {
+final class YangTextFileSource extends YangTextSource implements Delegator<Path> {
private final @NonNull Path path;
private final @NonNull Charset charset;
- YangTextFileSchemaSource(final SourceIdentifier identifier, final Path path, final Charset charset) {
- super(identifier);
+ YangTextFileSource(final SourceIdentifier sourceId, final Path path, final Charset charset) {
+ super(sourceId);
this.path = requireNonNull(path);
this.charset = requireNonNull(charset);
}
}
@Override
- public Optional<String> getSymbolicName() {
+ public String symbolicName() {
// FIXME: NEXT: this is forcing internal normalization. I think this boils down to providing Path back, which
// is essentially getDelegate() anyway. Perhaps expose it as PathAware?
- return Optional.of(path.toString());
+ return path.toString();
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.opendaylight.yangtools.yang.common.YangConstants.RFC6020_YANG_FILE_EXTENSION;
import static org.opendaylight.yangtools.yang.common.YangNames.parseFilename;
-import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
/**
* YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as an {@link InputStream}.
*/
-@Beta
-public abstract class YangTextSchemaSource extends CharSource implements YangSchemaSourceRepresentation {
- private final @NonNull SourceIdentifier identifier;
+public abstract class YangTextSource extends CharSource implements YangSourceRepresentation {
+ private final @NonNull SourceIdentifier sourceId;
- protected YangTextSchemaSource(final SourceIdentifier identifier) {
- this.identifier = requireNonNull(identifier);
+ protected YangTextSource(final SourceIdentifier sourceId) {
+ this.sourceId = requireNonNull(sourceId);
}
public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
* @param charset Expected character set
* @return A new YangTextSchemaSource
*/
- public static @NonNull YangTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
+ public static @NonNull YangTextSource delegateForByteSource(final SourceIdentifier identifier,
final ByteSource delegate, final Charset charset) {
return delegateForCharSource(identifier, delegate.asCharSource(charset));
}
* @return A new YangTextSchemaSource
* @throws IllegalArgumentException if the file name has invalid format
*/
- public static @NonNull YangTextSchemaSource delegateForByteSource(final String fileName,
+ public static @NonNull YangTextSource delegateForByteSource(final String fileName,
final ByteSource delegate, final Charset charset) {
return delegateForCharSource(fileName, delegate.asCharSource(charset));
}
* @param delegate Backing CharSource instance
* @return A new YangTextSchemaSource
*/
- public static @NonNull YangTextSchemaSource delegateForCharSource(final SourceIdentifier identifier,
+ public static @NonNull YangTextSource delegateForCharSource(final SourceIdentifier identifier,
final CharSource delegate) {
- return new DelegatedYangTextSchemaSource(identifier, delegate);
+ return new DelegatedYangTextSource(identifier, delegate);
}
/**
* @return A new YangTextSchemaSource
* @throws IllegalArgumentException if the file name has invalid format
*/
- public static @NonNull YangTextSchemaSource delegateForCharSource(final String fileName,
+ public static @NonNull YangTextSource delegateForCharSource(final String fileName,
final CharSource delegate) {
- return new DelegatedYangTextSchemaSource(identifierFromFilename(fileName), delegate);
+ return new DelegatedYangTextSource(identifierFromFilename(fileName), delegate);
}
/**
* @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
* @throws NullPointerException if file is {@code null}
*/
- public static @NonNull YangTextSchemaSource forPath(final Path path) {
+ public static @NonNull YangTextSource forPath(final Path path) {
return forPath(path, identifierFromFilename(path.toFile().getName()));
}
* @throws NullPointerException if any argument is {@code null}
* @throws IllegalArgumentException if the supplied path is not a regular file
*/
- public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier) {
+ public static @NonNull YangTextSource forPath(final Path path, final SourceIdentifier identifier) {
return forPath(path, identifier, StandardCharsets.UTF_8);
}
* @throws NullPointerException if any argument is {@code null}
* @throws IllegalArgumentException if the supplied path is not a regular file
*/
- public static @NonNull YangTextSchemaSource forPath(final Path path, final SourceIdentifier identifier,
+ public static @NonNull YangTextSource forPath(final Path path, final SourceIdentifier identifier,
final Charset charset) {
checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
- return new YangTextFileSchemaSource(identifier, path, charset);
+ return new YangTextFileSource(identifier, path, charset);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a resource available in the ClassLoader where this
+ * Create a new {@link YangTextSource} backed by a resource available in the ClassLoader where this
* class resides.
*
* @param resourceName Resource name
* @return A new instance.
* @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
*/
- public static @NonNull YangTextSchemaSource forResource(final String resourceName) {
- return forResource(YangTextSchemaSource.class, resourceName);
+ public static @NonNull YangTextSource forResource(final String resourceName) {
+ return forResource(YangTextSource.class, resourceName);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a resource by a resource available on the ClassLoader
+ * Create a new {@link YangTextSource} backed by a resource by a resource available on the ClassLoader
* which loaded the specified class.
*
* @param clazz Class reference
* @return A new instance.
* @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
*/
- public static @NonNull YangTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+ public static @NonNull YangTextSource forResource(final Class<?> clazz, final String resourceName) {
return forResource(clazz, resourceName, StandardCharsets.UTF_8);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a resource by a resource available on the ClassLoader
+ * Create a new {@link YangTextSource} backed by a resource by a resource available on the ClassLoader
* which loaded the specified class.
*
* @param clazz Class reference
* @return A new instance.
* @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
*/
- public static @NonNull YangTextSchemaSource forResource(final Class<?> clazz, final String resourceName,
+ public static @NonNull YangTextSource forResource(final Class<?> clazz, final String resourceName,
final Charset charset) {
final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
final SourceIdentifier identifier = identifierFromFilename(fileName);
final URL url = Resources.getResource(clazz, resourceName);
- return new ResourceYangTextSchemaSource(identifier, url, charset);
+ return new ResourceYangTextSource(identifier, url, charset);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a URL.
+ * Create a new {@link YangTextSource} backed by a URL.
*
* @param url Backing URL
* @param identifier Source identifier
* @return A new instance.
* @throws NullPointerException if any argument is {@code null}
*/
- public static @NonNull YangTextSchemaSource forURL(final URL url, final SourceIdentifier identifier) {
+ public static @NonNull YangTextSource forURL(final URL url, final SourceIdentifier identifier) {
return forURL(url, identifier, StandardCharsets.UTF_8);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a URL.
+ * Create a new {@link YangTextSource} backed by a URL.
*
* @param url Backing URL
* @param identifier Source identifier
* @return A new instance.
* @throws NullPointerException if any argument is {@code null}
*/
- public static @NonNull YangTextSchemaSource forURL(final URL url, final SourceIdentifier identifier,
+ public static @NonNull YangTextSource forURL(final URL url, final SourceIdentifier identifier,
final Charset charset) {
- return new ResourceYangTextSchemaSource(identifier, url, charset);
+ return new ResourceYangTextSource(identifier, url, charset);
}
-
@Override
- public final SourceIdentifier getIdentifier() {
- return identifier;
+ public final Class<YangTextSource> getType() {
+ return YangTextSource.class;
}
@Override
- public final Class<YangTextSchemaSource> getType() {
- return YangTextSchemaSource.class;
+ public final SourceIdentifier sourceId() {
+ return sourceId;
}
@Override
* @return ToStringHelper supplied as input argument.
*/
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("identifier", identifier);
+ return toStringHelper.add("identifier", sourceId);
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
-import java.util.Optional;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.NodeList;
/**
- * Utility {@link YinXmlSchemaSource} exposing a W3C {@link DOMSource} representation of YIN model.
+ * Utility {@link YinXmlSource} exposing a W3C {@link DOMSource} representation of YIN model.
*/
-public abstract class YinDomSchemaSource implements YinXmlSchemaSource {
- private static final Logger LOG = LoggerFactory.getLogger(YinDomSchemaSource.class);
+public abstract sealed class YinDomSource implements YinXmlSource {
+ private static final Logger LOG = LoggerFactory.getLogger(YinDomSource.class);
private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
private static final QName REVISION_STMT = REVISION.getStatementName();
private static final String MODULE_ARG = MODULE.getArgumentDefinition().orElseThrow()
private static final String REVISION_ARG = REVISION.getArgumentDefinition().orElseThrow()
.argumentName().getLocalName();
- YinDomSchemaSource() {
- // Prevent outside instantiation
- }
-
/**
- * Create a new {@link YinDomSchemaSource} using an identifier and a source.
+ * Create a new {@link YinDomSource} using an identifier and a source.
*
* @param identifier Schema source identifier
* @param source W3C DOM source
* @param symbolicName Source symbolic name
- * @return A new {@link YinDomSchemaSource} instance.
+ * @return A new {@link YinDomSource} instance.
*/
- public static @NonNull YinDomSchemaSource create(final @NonNull SourceIdentifier identifier,
+ public static @NonNull YinDomSource create(final @NonNull SourceIdentifier identifier,
final @NonNull DOMSource source, final @Nullable String symbolicName) {
final Node root = source.getNode().getFirstChild();
final Attr dateAttr = revisionStmt.getAttributeNode(REVISION_ARG);
checkArgument(dateAttr != null, "No revision statement argument found in %s", revisionStmt);
- final SourceIdentifier parsedId = new SourceIdentifier(nameAttr.getValue(), dateAttr.getValue());
+ final var parsedId = new SourceIdentifier(nameAttr.getValue(), dateAttr.getValue());
final SourceIdentifier id;
if (!parsedId.equals(identifier)) {
LOG.debug("Changed identifier from {} to {}", identifier, parsedId);
}
/**
- * Create a {@link YinDomSchemaSource} from a {@link YinXmlSchemaSource}. If the argument is already a
+ * Create a {@link YinDomSource} from a {@link YinXmlSource}. If the argument is already a
* YinDomSchemaSource, this method returns the same instance. The source will be translated on first access,
* at which point an {@link IllegalStateException} may be raised.
*
* @param xmlSchemaSource Backing schema source
- * @return A {@link YinDomSchemaSource} instance
+ * @return A {@link YinDomSource} instance
*/
- public static @NonNull YinDomSchemaSource lazyTransform(final YinXmlSchemaSource xmlSchemaSource) {
- final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
+ public static @NonNull YinDomSource lazyTransform(final YinXmlSource xmlSchemaSource) {
+ final var cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast : new Transforming(xmlSchemaSource);
}
/**
- * Create a {@link YinDomSchemaSource} from a {@link YinXmlSchemaSource}. If the argument is already a
+ * Create a {@link YinDomSource} from a {@link YinXmlSource}. If the argument is already a
* YinDomSchemaSource, this method returns the same instance. The source will be translated immediately.
*
* @param xmlSchemaSource Backing schema source
- * @return A {@link YinDomSchemaSource} instance
+ * @return A {@link YinDomSource} instance
* @throws TransformerException when the provided source fails to transform
*/
- public static @NonNull YinDomSchemaSource transform(final YinXmlSchemaSource xmlSchemaSource)
+ public static @NonNull YinDomSource transform(final YinXmlSource xmlSchemaSource)
throws TransformerException {
- final YinDomSchemaSource cast = castSchemaSource(xmlSchemaSource);
+ final var cast = castSchemaSource(xmlSchemaSource);
return cast != null ? cast :
- create(xmlSchemaSource.getIdentifier(), transformSource(xmlSchemaSource.getSource()),
- xmlSchemaSource.getSymbolicName().orElse(null));
+ create(xmlSchemaSource.sourceId(), transformSource(xmlSchemaSource.getSource()),
+ xmlSchemaSource.symbolicName());
}
@Override
- public abstract DOMSource getSource();
+ public final Class<YinDomSource> getType() {
+ return YinDomSource.class;
+ }
@Override
- public final Class<YinDomSchemaSource> getType() {
- return YinDomSchemaSource.class;
- }
+ public abstract DOMSource getSource();
@Override
public final String toString() {
- return addToStringAttributes(MoreObjects.toStringHelper(this).add("identifier", getIdentifier())).toString();
+ return addToStringAttributes(MoreObjects.toStringHelper(this).add("sourceId", sourceId())).toString();
}
/**
return new DOMSource(result.getNode(), result.getSystemId());
}
- private static @Nullable YinDomSchemaSource castSchemaSource(final YinXmlSchemaSource xmlSchemaSource) {
- if (xmlSchemaSource instanceof YinDomSchemaSource yinDom) {
+ private static @Nullable YinDomSource castSchemaSource(final YinXmlSource xmlSchemaSource) {
+ if (xmlSchemaSource instanceof YinDomSource yinDom) {
return yinDom;
}
- final Source source = xmlSchemaSource.getSource();
+ final var source = xmlSchemaSource.getSource();
if (source instanceof DOMSource dom) {
- return create(xmlSchemaSource.getIdentifier(), dom, xmlSchemaSource.getSymbolicName().orElse(null));
+ return create(xmlSchemaSource.sourceId(), dom, xmlSchemaSource.symbolicName());
}
return null;
}
- private static final class Simple extends YinDomSchemaSource {
- private final @NonNull SourceIdentifier identifier;
+ private static final class Simple extends YinDomSource {
+ private final @NonNull SourceIdentifier sourceId;
private final @NonNull DOMSource source;
private final String symbolicName;
- Simple(final @NonNull SourceIdentifier identifier, final @NonNull DOMSource source,
+ Simple(final @NonNull SourceIdentifier sourceId, final @NonNull DOMSource source,
final @Nullable String symbolicName) {
- this.identifier = requireNonNull(identifier);
+ this.sourceId = requireNonNull(sourceId);
this.source = requireNonNull(source);
this.symbolicName = symbolicName;
}
@Override
- public DOMSource getSource() {
- return source;
+ public SourceIdentifier sourceId() {
+ return sourceId;
}
@Override
- public SourceIdentifier getIdentifier() {
- return identifier;
+ public DOMSource getSource() {
+ return source;
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.ofNullable(symbolicName);
+ public String symbolicName() {
+ return symbolicName;
}
@Override
}
}
- private static final class Transforming extends YinDomSchemaSource {
- private final YinXmlSchemaSource xmlSchemaSource;
+ private static final class Transforming extends YinDomSource {
+ private final YinXmlSource xmlSchemaSource;
+
private volatile DOMSource source;
- Transforming(final YinXmlSchemaSource xmlSchemaSource) {
+ Transforming(final YinXmlSource xmlSchemaSource) {
this.xmlSchemaSource = requireNonNull(xmlSchemaSource);
}
+ @Override
+ public SourceIdentifier sourceId() {
+ return xmlSchemaSource.sourceId();
+ }
+
+ @Override
+ public String symbolicName() {
+ return xmlSchemaSource.symbolicName();
+ }
+
@Override
public DOMSource getSource() {
DOMSource ret = source;
return ret;
}
- @Override
- public SourceIdentifier getIdentifier() {
- return xmlSchemaSource.getIdentifier();
- }
-
- @Override
- public Optional<String> getSymbolicName() {
- return xmlSchemaSource.getSymbolicName();
- }
-
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper.add("xmlSchemaSource", xmlSchemaSource);
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static java.util.Objects.requireNonNull;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A {@link YinTextSchemaSource} backed by a file.
- *
- * @author Robert Varga
+ * A {@link YinTextSource} backed by a file.
*/
-final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator<Path> {
+final class YinTextFileSource extends YinTextSource implements Delegator<Path> {
private final @NonNull Path path;
- YinTextFileSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull Path path) {
- super(identifier);
+ YinTextFileSource(final @NonNull SourceIdentifier sourceId, final @NonNull Path path) {
+ super(sourceId);
this.path = requireNonNull(path);
}
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of(path.toString());
+ public String symbolicName() {
+ return path.toString();
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.common.YangNames;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YinSourceRepresentation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* YIN text schema source representation. Exposes an RFC6020 or RFC7950 XML representation as an {@link InputStream}.
*/
-@Beta
-public abstract class YinTextSchemaSource extends ByteSource implements YinSchemaSourceRepresentation {
- private static final Logger LOG = LoggerFactory.getLogger(YinTextSchemaSource.class);
+public abstract class YinTextSource extends ByteSource implements YinSourceRepresentation {
+ private static final Logger LOG = LoggerFactory.getLogger(YinTextSource.class);
private static final String XML_EXTENSION = ".xml";
- private final @NonNull SourceIdentifier identifier;
+ private final @NonNull SourceIdentifier sourceId;
- protected YinTextSchemaSource(final SourceIdentifier identifier) {
- this.identifier = requireNonNull(identifier);
+ protected YinTextSource(final SourceIdentifier sourceId) {
+ this.sourceId = requireNonNull(sourceId);
}
public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
}
@Override
- public final SourceIdentifier getIdentifier() {
- return identifier;
+ public final SourceIdentifier sourceId() {
+ return sourceId;
}
@Override
- public final Class<YinTextSchemaSource> getType() {
- return YinTextSchemaSource.class;
+ public final Class<YinTextSource> getType() {
+ return YinTextSource.class;
}
@Override
* @return ToStringHelper supplied as input argument.
*/
protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
- return toStringHelper.add("identifier", identifier);
+ return toStringHelper.add("identifier", sourceId);
}
/**
* @param delegate Backing ByteSource instance
* @return A new YinTextSchemaSource
*/
- public static @NonNull YinTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
+ public static @NonNull YinTextSource delegateForByteSource(final SourceIdentifier identifier,
final ByteSource delegate) {
- return new DelegatedYinTextSchemaSource(identifier, delegate);
+ return new DelegatedYinTextSource(identifier, delegate);
}
- public static @NonNull YinTextSchemaSource forPath(final Path path) {
+ public static @NonNull YinTextSource forPath(final Path path) {
checkArgument(Files.isRegularFile(path), "Supplied path %s is not a regular file", path);
- return new YinTextFileSchemaSource(identifierFromFilename(path.toFile().getName()), path);
+ return new YinTextFileSource(identifierFromFilename(path.toFile().getName()), path);
}
- public static @NonNull YinTextSchemaSource forResource(final Class<?> clazz, final String resourceName) {
+ public static @NonNull YinTextSource forResource(final Class<?> clazz, final String resourceName) {
final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
- return new ResourceYinTextSchemaSource(identifierFromFilename(fileName),
+ return new ResourceYinTextSource(identifierFromFilename(fileName),
Resources.getResource(clazz, resourceName));
}
}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.model.spi.source;
-import com.google.common.annotations.Beta;
import javax.xml.transform.Source;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.source.YinSourceRepresentation;
/**
* YIN text schema source representation. Exposes an RFC6020 or RFC7950 XML representation as an XML {@link Source}.
*/
-@Beta
-public interface YinXmlSchemaSource extends YinSchemaSourceRepresentation {
+public interface YinXmlSource extends YinSourceRepresentation {
@Override
- Class<? extends YinXmlSchemaSource> getType();
+ Class<? extends YinXmlSource> getType();
/**
* Return an XML {@link Source} of the YIN document.
--- /dev/null
+/*
+ * Copyright (c) 2024 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
+ */
+/**
+ * Various utilities dealing with sources of YANG and YIN models.
+ */
+package org.opendaylight.yangtools.yang.model.spi.source;
\ No newline at end of file
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.Submodule;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* The Schema Context Util contains support methods for searching through Schema Context modules for specified schema
import java.util.Set;
import org.junit.jupiter.api.Test;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.spi.SimpleSchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
.build();
final var foo = reactor.newBuild()
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ .addSource(YangStatementStreamSource.create(YangTextSource.forResource(
ContextReferenceTest.class, "/yang-ext.yang")))
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ .addSource(YangStatementStreamSource.create(YangTextSource.forResource(
ContextReferenceTest.class, "/ctxref.yang")))
.buildEffective()
.getModuleStatements()
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
new MountStatementSupport(YangParserConfiguration.DEFAULT))
.build();
final var foo = reactor.newBuild()
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- MountTest.class, "/yang-ext.yang")))
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- MountTest.class, "/mount.yang")))
+ .addSource(YangStatementStreamSource.create(YangTextSource.forResource(MountTest.class, "/yang-ext.yang")))
+ .addSource(YangStatementStreamSource.create(YangTextSource.forResource(MountTest.class, "/mount.yang")))
.buildEffective()
.getModuleStatements()
.get(FOO);
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
.build();
final var context = reactor.newBuild()
.addLibSources(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(NetconfTest.class, "/ietf-inet-types@2013-07-15.yang")))
+ YangTextSource.forResource(NetconfTest.class, "/ietf-inet-types@2013-07-15.yang")))
.addSource(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(NetconfTest.class, "/ietf-netconf@2011-06-01.yang")))
+ YangTextSource.forResource(NetconfTest.class, "/ietf-netconf@2011-06-01.yang")))
.buildEffective();
final var module = context.findModule(NetconfConstants.RFC6241_MODULE).orElseThrow();
import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyWriteSchemaNode;
import org.opendaylight.yangtools.rfc6536.model.api.NACMConstants;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
final var context = reactor.newBuild()
.addSources(
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(NACMTest.class, "/ietf-netconf-acm@2012-02-22.yang")),
+ YangTextSource.forResource(NACMTest.class, "/ietf-netconf-acm@2012-02-22.yang")),
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(NACMTest.class, "/ietf-yang-types@2013-07-15.yang")))
+ YangTextSource.forResource(NACMTest.class, "/ietf-yang-types@2013-07-15.yang")))
.buildEffective();
final var module = context.findModule(NACMConstants.RFC6536_MODULE).orElseThrow();
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
.build();
final var schema = reactor.newBuild()
.addSources(
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
IetfYangSmiv2ExtensionPluginTest.class, "/foo.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
IetfYangSmiv2ExtensionPluginTest.class, "/ietf-yang-smiv2.yang")))
.buildEffective();
import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
import org.opendaylight.yangtools.yang.common.AnnotationName;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
final var context = reactor.newBuild()
.addSources(
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(AnnotationTest.class, "/ietf-yang-metadata@2016-08-05.yang")),
+ YangTextSource.forResource(AnnotationTest.class, "/ietf-yang-metadata@2016-08-05.yang")),
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(AnnotationTest.class, "/example-last-modified.yang")))
+ YangTextSource.forResource(AnnotationTest.class, "/example-last-modified.yang")))
.buildEffective();
final var annotations = AnnotationSchemaNode.findAll(context);
import java.io.IOException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
static StatementStreamSource sourceForResource(final String resourceName) {
try {
return YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(AbstractYangDataTest.class, resourceName));
+ YangTextSource.forResource(AbstractYangDataTest.class, resourceName));
} catch (IOException | YangSyntaxErrorException e) {
throw new IllegalArgumentException("Failed to create source", e);
}
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
final var context = reactor.newBuild()
.addLibSources(
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(MountPointTest.class, "/ietf-inet-types@2013-07-15.yang")),
+ YangTextSource.forResource(MountPointTest.class, "/ietf-inet-types@2013-07-15.yang")),
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(MountPointTest.class, "/ietf-yang-schema-mount@2019-01-14.yang")),
+ YangTextSource.forResource(MountPointTest.class, "/ietf-yang-schema-mount@2019-01-14.yang")),
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(MountPointTest.class, "/ietf-yang-types@2013-07-15.yang")))
+ YangTextSource.forResource(MountPointTest.class, "/ietf-yang-types@2013-07-15.yang")))
.addSources(
+ YangStatementStreamSource.create(YangTextSource.forResource(MountPointTest.class, "/example-grp.yang")),
YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(MountPointTest.class, "/example-grp.yang")),
- YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(MountPointTest.class, "/example-uses.yang")))
+ YangTextSource.forResource(MountPointTest.class, "/example-uses.yang")))
.buildEffective();
assertEquals(5, context.getModules().size());
import org.opendaylight.yangtools.rfc8639.model.api.SubscribedNotificationsConstants;
import org.opendaylight.yangtools.rfc8639.model.api.SubscriptionStateNotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
final var context = reactor.newBuild()
.addLibSources(
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-inet-types@2013-07-15.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-interfaces@2018-02-20.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-ip@2018-02-22.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-netconf-acm@2018-02-14.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-network-instance@2019-01-21.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-restconf@2017-01-26.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-yang-schema-mount@2019-01-14.yang")),
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-yang-types@2013-07-15.yang")))
.addSources(
- YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ YangStatementStreamSource.create(YangTextSource.forResource(
SubscribedNotificationsTest.class, "/ietf-subscribed-notifications@2019-09-09.yang")))
.buildEffective();
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.rfc8819.model.api.ModuleTagEffectiveStatement;
import org.opendaylight.yangtools.rfc8819.model.api.Tag;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
private static YangStatementStreamSource moduleFromResources(final String resourceName) {
try {
- return YangStatementStreamSource.create(
- YangTextSchemaSource.forResource(ModuleTagTest.class, resourceName));
+ return YangStatementStreamSource.create(YangTextSource.forResource(ModuleTagTest.class, resourceName));
} catch (final YangSyntaxErrorException | IOException e) {
throw new IllegalStateException("Failed to find resource " + resourceName, e);
}
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-api</artifactId>
+ </dependency>
</dependencies>
</project>
exports org.opendaylight.yangtools.yang.ir;
requires transitive com.google.common;
+ requires transitive org.opendaylight.yangtools.yang.model.api;
requires org.opendaylight.yangtools.concepts;
// Annotations
requires static transitive org.eclipse.jdt.annotation;
-}
\ No newline at end of file
+}
* 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.repo.api;
+package org.opendaylight.yangtools.yang.ir;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.annotations.Beta;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
-import org.opendaylight.yangtools.yang.ir.IRKeyword;
import org.opendaylight.yangtools.yang.ir.IRKeyword.Unqualified;
-import org.opendaylight.yangtools.yang.ir.IRStatement;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
-@Beta
-public final class YangIRSchemaSource extends AbstractSimpleIdentifiable<SourceIdentifier>
- implements YangSchemaSourceRepresentation {
+public final class YangIRSchemaSource implements YangSourceRepresentation {
+ private final @NonNull SourceIdentifier sourceId;
private final @NonNull IRStatement rootStatement;
private final @Nullable String symbolicName;
- public YangIRSchemaSource(final @NonNull SourceIdentifier identifier, final @NonNull IRStatement rootStatement,
+ public YangIRSchemaSource(final @NonNull SourceIdentifier sourceId, final @NonNull IRStatement rootStatement,
final @Nullable String symbolicName) {
- super(identifier);
+ this.sourceId = requireNonNull(sourceId);
this.rootStatement = requireNonNull(rootStatement);
this.symbolicName = symbolicName;
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.ofNullable(symbolicName);
+ public SourceIdentifier sourceId() {
+ return sourceId;
+ }
+
+ @Override
+ public String symbolicName() {
+ return symbolicName;
}
@Override
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* A single <a href="https://www.rfc-editor.org/rfc/rfc8525">RFC8525</a> {@code module} or {@code import-only-module}
* @param submodules Submodules of this module
* @param features The set of supported features in this module
* @param deviationModuleNames Names of modules containing {@code deviate} statements targetting this module
- * @param source A {@link SchemaSourceRepresentation} of the module
+ * @param source A {@link SourceRepresentation} of the module
*/
public record YangLibModule(@NonNull SourceIdentifier identifier, @NonNull XMLNamespace namespace,
@NonNull ImmutableMap<Unqualified, YangLibSubmodule> submodules, @NonNull ImmutableSet<Unqualified> features,
- @NonNull ImmutableSet<Unqualified> deviationModuleNames, @NonNull SchemaSourceRepresentation source) {
+ @NonNull ImmutableSet<Unqualified> deviationModuleNames, @NonNull SourceRepresentation source) {
public YangLibModule {
requireNonNull(identifier);
requireNonNull(namespace);
import com.google.common.collect.ImmutableMap;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* A single <a href="https://www.rfc-editor.org/rfc/rfc8525">RFC8525</a> {@code module-set}.
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* A service capable of transforming a {@link YangLibModuleSet} to an {@link EffectiveModelContext}.
@Beta
public interface YangLibResolver {
/**
- * Return enumeration of concrete types of {@link SchemaSourceRepresentation} this resolver supports. Users can use
- * this information prepare the source they have to a representation which will be accepted by this resolver.
+ * Return enumeration of concrete types of {@link SourceRepresentation} this resolver supports. Users can use this
+ * information prepare the source they have to a representation which will be accepted by this resolver.
*
* @return Enumeration of supported schema source representations.
*/
- @NonNull Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations();
+ @NonNull Collection<Class<? extends SourceRepresentation>> supportedSourceRepresentations();
/**
* Build the effective view of a combined view of effective statements.
* @throws IOException if a module source cannot be read
* @throws YangSyntaxErrorException when a syntactic error is encountered
* @throws NullPointerException if {@code moduleSet} is {@code null}
- * @throws IllegalArgumentException if {@code moduleSet} references an unsupported
- * {@link SchemaSourceRepresentation}
+ * @throws IllegalArgumentException if {@code moduleSet} references an unsupported {@link SourceRepresentation}
*/
@NonNull EffectiveModelContext resolveModuleSet(YangLibModuleSet moduleSet) throws IOException, YangParserException;
}
import static java.util.Objects.requireNonNull;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* A single <a href="https://www.rfc-editor.org/rfc/rfc8525">RFC8525</a> {@code submodule} list entry.
*
* @param identifier {@link SourceIdentifier} of this submodule, e.g. the combination of {@code name} and
* {@code revision}
- * @param source A {@link SchemaSourceRepresentation} of the submodule
+ * @param source A {@link SourceRepresentation} of the submodule
*/
-public record YangLibSubmodule(@NonNull SourceIdentifier identifier, @NonNull SchemaSourceRepresentation source) {
+public record YangLibSubmodule(@NonNull SourceIdentifier identifier, @NonNull SourceRepresentation source) {
public YangLibSubmodule {
requireNonNull(identifier);
requireNonNull(source);
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.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-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
@Beta
public interface YangParser {
/**
- * Return enumeration of concrete types of {@link SchemaSourceRepresentation} parsers created from this factory
+ * Return enumeration of concrete types of {@link SourceRepresentation} 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();
+ @NonNull Collection<Class<? extends SourceRepresentation>> supportedSourceRepresentations();
/**
* 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
*/
- @NonNull YangParser addSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
+ @NonNull YangParser addSource(SourceRepresentation 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 @NonNull YangParser addSources(final SchemaSourceRepresentation... sources) throws IOException,
- YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
+ default @NonNull YangParser addSources(final SourceRepresentation... sources)
+ throws IOException, YangSyntaxErrorException {
+ for (var source : sources) {
addSource(source);
}
return this;
}
- default @NonNull YangParser addSources(final Collection<? extends SchemaSourceRepresentation> sources)
+ default @NonNull YangParser addSources(final Collection<? extends SourceRepresentation> sources)
throws IOException, YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
+ for (var source : sources) {
addSource(source);
}
return this;
}
- YangParser addLibSource(SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException;
+ YangParser addLibSource(SourceRepresentation source) throws IOException, YangSyntaxErrorException;
/**
* Add library sources. Only library sources required by main sources are present in resulting SchemaContext.
* @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) {
+ default @NonNull YangParser addLibSources(final SourceRepresentation... sources)
+ throws IOException, YangSyntaxErrorException {
+ for (var source : sources) {
addLibSource(source);
}
return this;
}
- default @NonNull YangParser addLibSources(final Collection<SchemaSourceRepresentation> sources) throws IOException,
- YangSyntaxErrorException {
- for (SchemaSourceRepresentation source : sources) {
+ default @NonNull YangParser addLibSources(final Collection<SourceRepresentation> sources)
+ throws IOException, YangSyntaxErrorException {
+ for (var source : sources) {
addLibSource(source);
}
return this;
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;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
@Beta
public class YangSyntaxErrorException extends YangParserException {
+ @java.io.Serial
private static final long serialVersionUID = 2L;
- private final SourceIdentifier source;
+ private final SourceIdentifier sourceId;
private final int line;
private final int charPositionInLine;
- public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
+ public YangSyntaxErrorException(final @Nullable SourceIdentifier sourceId, final int line,
final int charPositionInLine, final String message) {
- this(source, line, charPositionInLine, message, null);
+ this(sourceId, line, charPositionInLine, message, null);
}
- public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
+ public YangSyntaxErrorException(final @Nullable SourceIdentifier sourceId, final int line,
final int charPositionInLine, final String message, final @Nullable Throwable cause) {
super(message, cause);
- this.source = source;
+ this.sourceId = sourceId;
this.line = line;
this.charPositionInLine = charPositionInLine;
}
public final Optional<SourceIdentifier> getSource() {
- return Optional.ofNullable(source);
+ return Optional.ofNullable(sourceId);
}
public final int getLine() {
public @NonNull String getFormattedMessage() {
final StringBuilder sb = new StringBuilder(getMessage());
- if (source != null) {
- sb.append(" in source ").append(source);
+ if (sourceId != null) {
+ sb.append(" in source ").append(sourceId);
}
if (line != 0) {
sb.append(" on line ").append(line);
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.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.parser.api.YangLibModuleSet;
import org.opendaylight.yangtools.yang.parser.api.YangLibResolver;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
}
@Override
- public Collection<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations() {
+ public Collection<Class<? extends SourceRepresentation>> supportedSourceRepresentations() {
return DefaultYangParser.REPRESENTATIONS;
}
import javax.xml.transform.TransformerException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinXmlSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinDomSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinXmlSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.xml.sax.SAXException;
final class DefaultYangParser implements YangParser {
- static final @NonNull ImmutableSet<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS = ImmutableSet.of(
+ static final @NonNull ImmutableSet<Class<? extends SourceRepresentation>> REPRESENTATIONS = ImmutableSet.of(
// In order of preference
YangIRSchemaSource.class,
- YangTextSchemaSource.class,
- YinDomSchemaSource.class,
- YinXmlSchemaSource.class,
- YinTextSchemaSource.class);
+ YangTextSource.class,
+ YinDomSource.class,
+ YinXmlSource.class,
+ YinTextSource.class);
private final BuildAction buildAction;
}
@Override
- public ImmutableSet<Class<? extends SchemaSourceRepresentation>> supportedSourceRepresentations() {
+ public ImmutableSet<Class<? extends SourceRepresentation>> supportedSourceRepresentations() {
return REPRESENTATIONS;
}
@Override
- public YangParser addSource(final SchemaSourceRepresentation source) throws IOException, YangSyntaxErrorException {
+ public YangParser addSource(final SourceRepresentation source) throws IOException, YangSyntaxErrorException {
buildAction.addSource(sourceToStatementStream(source));
return this;
}
@Override
- public YangParser addLibSource(final SchemaSourceRepresentation source)
- throws IOException, YangSyntaxErrorException {
+ public YangParser addLibSource(final SourceRepresentation source) throws IOException, YangSyntaxErrorException {
buildAction.addLibSource(sourceToStatementStream(source));
return this;
}
return new YangParserException("Failed to assemble sources", reported);
}
- static StatementStreamSource sourceToStatementStream(final SchemaSourceRepresentation source)
+ static StatementStreamSource sourceToStatementStream(final SourceRepresentation source)
throws IOException, YangSyntaxErrorException {
requireNonNull(source);
if (source instanceof YangIRSchemaSource irSource) {
return YangStatementStreamSource.create(irSource);
- } else if (source instanceof YangTextSchemaSource yangSource) {
+ } else if (source instanceof YangTextSource yangSource) {
return YangStatementStreamSource.create(yangSource);
- } else if (source instanceof YinDomSchemaSource yinDom) {
+ } else if (source instanceof YinDomSource yinDom) {
return YinStatementStreamSource.create(yinDom);
- } else if (source instanceof YinTextSchemaSource yinText) {
+ } else if (source instanceof YinTextSource yinText) {
try {
return YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(yinText));
} catch (SAXException e) {
- throw new YangSyntaxErrorException(source.getIdentifier(), 0, 0, "Failed to parse XML text", e);
+ throw new YangSyntaxErrorException(source.sourceId(), 0, 0, "Failed to parse XML text", e);
}
- } else if (source instanceof YinXmlSchemaSource yinXml) {
+ } else if (source instanceof YinXmlSource yinXml) {
try {
return YinStatementStreamSource.create(yinXml);
} catch (TransformerException e) {
- throw new YangSyntaxErrorException(source.getIdentifier(), 0, 0,
+ throw new YangSyntaxErrorException(source.sourceId(), 0, 0,
"Failed to assemble in-memory representation", e);
}
} else {
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
this.parserFactory = parserFactory;
this.config = config;
getIdentifier = switch (config.getStatementParserMode()) {
- case DEFAULT_MODE -> YangIRSchemaSource::getIdentifier;
+ case DEFAULT_MODE -> YangIRSchemaSource::sourceId;
};
}
config.getSupportedFeatures().ifPresent(parser::setSupportedFeatures);
config.getModulesDeviatedByModules().ifPresent(parser::setModulesWithSupportedDeviations);
- for (final Entry<SourceIdentifier, YangIRSchemaSource> entry : srcs.entrySet()) {
+ for (var entry : srcs.entrySet()) {
try {
parser.addSource(entry.getValue());
} catch (YangSyntaxErrorException | IOException e) {
- throw new SchemaResolutionException("Failed to add source " + entry.getKey(), e);
+ final var sourceId = entry.getKey();
+ throw new SchemaResolutionException("Failed to add source " + sourceId, sourceId, e);
}
}
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
import org.slf4j.Logger;
}
}
- this.resolvedSources = ImmutableList.copyOf(resolved);
- this.unresolvedSources = ImmutableList.copyOf(pending);
- this.unsatisfiedImports = ImmutableMultimap.copyOf(imports);
+ resolvedSources = ImmutableList.copyOf(resolved);
+ unresolvedSources = ImmutableList.copyOf(pending);
+ unsatisfiedImports = ImmutableMultimap.copyOf(imports);
}
protected abstract boolean isKnown(Collection<SourceIdentifier> haystack, ModuleImport mi);
import java.util.Map;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
import java.util.function.Function;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kohsuke.MetaInfServices;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.AbstractSchemaRepository;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
import java.util.Map;
import java.util.Set;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Iterator<SourceIdentifier> srcIt = sourceIdentifiers.iterator();
final Map<SourceIdentifier, YangIRSchemaSource> filtered = new LinkedHashMap<>();
for (YangIRSchemaSource irSchemaSource : input) {
- final SourceIdentifier realSId = irSchemaSource.getIdentifier();
+ final SourceIdentifier realSId = irSchemaSource.sourceId();
if (srcIt.hasNext()) {
final SourceIdentifier expectedSId = srcIt.next();
if (!expectedSId.equals(realSId)) {
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.GuavaSchemaSourceCache;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class YangTextSchemaContextResolver implements AutoCloseable, SchemaSourceProvider<YangTextSchemaSource> {
+public final class YangTextSchemaContextResolver implements AutoCloseable, SchemaSourceProvider<YangTextSource> {
private static final Logger LOG = LoggerFactory.getLogger(YangTextSchemaContextResolver.class);
private static final Duration SOURCE_LIFETIME = Duration.ofSeconds(60);
private final Collection<SourceIdentifier> requiredSources = new ConcurrentLinkedDeque<>();
- private final Multimap<SourceIdentifier, YangTextSchemaSource> texts = ArrayListMultimap.create();
+ private final Multimap<SourceIdentifier, YangTextSource> texts = ArrayListMultimap.create();
@GuardedBy("this")
private final Map<QNameModule, List<ImmutableSet<String>>> registeredFeatures = new HashMap<>();
private final AtomicReference<Optional<EffectiveModelContext>> currentSchemaContext =
}
/**
- * Register a {@link YangTextSchemaSource}.
+ * Register a {@link YangTextSource}.
*
* @param source YANG text source
* @return a {@link Registration}
* @throws SchemaSourceException When parsing encounters general error
* @throws NullPointerException if {@code source} is {@code null}
*/
- public @NonNull Registration registerSource(final @NonNull YangTextSchemaSource source)
+ public @NonNull Registration registerSource(final @NonNull YangTextSource source)
throws SchemaSourceException, IOException, YangSyntaxErrorException {
final var ast = TextToIRTransformer.transformText(source);
LOG.trace("Resolved source {} to source {}", source, ast);
// AST carries an accurate identifier, check if it matches the one supplied by the source. If it
// does not, check how much it differs and emit a warning.
- final var providedId = source.getIdentifier();
- final var parsedId = ast.getIdentifier();
- final YangTextSchemaSource text;
+ final var providedId = source.sourceId();
+ final var parsedId = ast.sourceId();
+ final YangTextSource text;
if (!parsedId.equals(providedId)) {
if (!parsedId.name().equals(providedId.name())) {
LOG.info("Provided module name {} does not match actual text {}, corrected",
}
}
- text = YangTextSchemaSource.delegateForCharSource(parsedId, source);
+ text = YangTextSource.delegateForCharSource(parsedId, source);
} else {
text = source;
}
LOG.debug("Populated {} with text", parsedId);
final var reg = registry.registerSchemaSource(this,
- PotentialSchemaSource.create(parsedId, YangTextSchemaSource.class, Costs.IMMEDIATE.getValue()));
+ PotentialSchemaSource.create(parsedId, YangTextSource.class, Costs.IMMEDIATE.getValue()));
requiredSources.add(parsedId);
cache.schemaSourceEncountered(ast);
LOG.debug("Added source {} to schema context requirements", parsedId);
throws SchemaSourceException, IOException, YangSyntaxErrorException {
final String path = url.getPath();
final String fileName = path.substring(path.lastIndexOf('/') + 1);
- return registerSource(YangTextSchemaSource.forURL(url, guessSourceIdentifier(fileName)));
+ return registerSource(YangTextSource.forURL(url, guessSourceIdentifier(fileName)));
}
/**
private static SourceIdentifier guessSourceIdentifier(final @NonNull String fileName) {
try {
- return YangTextSchemaSource.identifierFromFilename(fileName);
+ return YangTextSource.identifierFromFilename(fileName);
} catch (IllegalArgumentException e) {
LOG.warn("Invalid file name format in '{}'", fileName, e);
return new SourceIdentifier(fileName);
}
@Override
- public synchronized @NonNull FluentFuture<YangTextSchemaSource> getSource(
- final SourceIdentifier sourceIdentifier) {
+ public synchronized @NonNull FluentFuture<YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
final var ret = texts.get(sourceIdentifier);
LOG.debug("Lookup {} result {}", sourceIdentifier, ret);
}
@Beta
- public synchronized Collection<YangTextSchemaSource> getSourceTexts(final SourceIdentifier sourceIdentifier) {
+ public synchronized Collection<YangTextSource> getSourceTexts(final SourceIdentifier sourceIdentifier) {
return ImmutableSet.copyOf(texts.get(sourceIdentifier));
}
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationInText;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
public class YT1193Test {
void testDeclarationReference() throws Exception {
final var declaredRoots = new DefaultYangParserFactory()
.createParser(YangParserConfiguration.builder().retainDeclarationReferences(true).build())
- .addSource(YangTextSchemaSource.forResource(getClass(), "/yt1193/foo.yang"))
- .addSource(YangTextSchemaSource.forResource(getClass(), "/yt1193/bar.yang"))
- .addSource(YangTextSchemaSource.forResource(getClass(), "/yt1193/baz.yang"))
+ .addSource(YangTextSource.forResource(getClass(), "/yt1193/foo.yang"))
+ .addSource(YangTextSource.forResource(getClass(), "/yt1193/bar.yang"))
+ .addSource(YangTextSource.forResource(getClass(), "/yt1193/baz.yang"))
.buildDeclaredModel();
assertEquals(3, declaredRoots.size());
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
private static SettableSchemaProvider<YangIRSchemaSource> assertYangTextResource(final String resourceName) {
final YangIRSchemaSource yangSource;
try {
- yangSource = TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName));
+ yangSource = TextToIRTransformer.transformText(YangTextSource.forResource(resourceName));
} catch (YangSyntaxErrorException | IOException e) {
throw new AssertionError("Failed to parse " + resourceName, e);
}
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo.ModuleDependencyInfo;
private static void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final String yangFileName)
throws Exception {
- final var info = ModuleDependencyInfo.forYangText(YangTextSchemaSource.forResource(DependencyResolverTest.class,
+ final var info = ModuleDependencyInfo.forYangText(YangTextSource.forResource(DependencyResolverTest.class,
yangFileName));
map.put(new SourceIdentifier(info.getName(), info.getFormattedRevision()), info);
}
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class MultipleRevImportBug6875Test {
private static SettableSchemaProvider<YangIRSchemaSource> getSourceProvider(final String resourceName)
throws Exception {
return SettableSchemaProvider.createImmediate(
- TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
+ TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)),
YangIRSchemaSource.class);
}
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class OpenconfigVerSharedSchemaRepositoryTest {
static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
return SettableSchemaProvider.createImmediate(
- TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
- YangIRSchemaSource.class);
+ TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
}
}
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
-class SettableSchemaProvider<T extends SchemaSourceRepresentation> implements SchemaSourceProvider<T> {
+class SettableSchemaProvider<T extends SourceRepresentation> implements SchemaSourceProvider<T> {
private final SettableFuture<T> future = SettableFuture.create();
private final T schemaSourceRepresentation;
SettableSchemaProvider(final T schemaSourceRepresentation, final SourceIdentifier sourceIdentifier,
final Class<T> representation, final int cost) {
this.schemaSourceRepresentation = schemaSourceRepresentation;
- this.potentialSchemaSource = PotentialSchemaSource.create(sourceIdentifier, representation, cost);
+ potentialSchemaSource = PotentialSchemaSource.create(sourceIdentifier, representation, cost);
}
- public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createRemote(
+ public static <T extends SourceRepresentation> SettableSchemaProvider<T> createRemote(
final T schemaSourceRepresentation, final Class<T> representation) {
- return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(),
+ return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.sourceId(),
representation, PotentialSchemaSource.Costs.REMOTE_IO.getValue());
}
- public static <T extends SchemaSourceRepresentation> SettableSchemaProvider<T> createImmediate(
+ public static <T extends SourceRepresentation> SettableSchemaProvider<T> createImmediate(
final T schemaSourceRepresentation, final Class<T> representation) {
- return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(),
+ return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.sourceId(),
representation, PotentialSchemaSource.Costs.IMMEDIATE.getValue());
}
}
public SourceIdentifier getId() {
- return schemaSourceRepresentation.getIdentifier();
+ return schemaSourceRepresentation.sourceId();
}
public void setResult() {
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class SharedEffectiveModelContextFactoryTest {
@BeforeEach
public void setUp() {
- final var source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
- final var source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+ final var source1 = YangTextSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final var source2 = YangTextSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
s1 = new SourceIdentifier("ietf-inet-types", "2010-09-24");
s2 = new SourceIdentifier("iana-timezones", "2012-07-09");
repository.registerSchemaSourceListener(transformer);
repository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(source1),
- PotentialSchemaSource.create(s1, YangTextSchemaSource.class, 1));
+ PotentialSchemaSource.create(s1, YangTextSource.class, 1));
repository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(source2),
- PotentialSchemaSource.create(s2, YangTextSchemaSource.class, 1));
+ PotentialSchemaSource.create(s2, YangTextSource.class, 1));
}
@Test
@Test
public void testSourceRegisteredWithDifferentSI() throws Exception {
- final var source1 = YangTextSchemaSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
- final var source2 = YangTextSchemaSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
- s1 = source1.getIdentifier();
- s2 = source2.getIdentifier();
+ final var source1 = YangTextSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final var source2 = YangTextSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+ s1 = source1.sourceId();
+ s2 = source2.sourceId();
final var provider = SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource(
"/no-revision/imported@2012-12-12.yang");
final SourceIdentifier s3 = new SourceIdentifier("network-topology", "2013-10-21");
repository.registerSchemaSource(new TransientFailureProvider(
- YangTextSchemaSource.forResource("/ietf/network-topology@2013-10-21.yang")),
- PotentialSchemaSource.create(s3, YangTextSchemaSource.class, 1));
+ YangTextSource.forResource("/ietf/network-topology@2013-10-21.yang")),
+ PotentialSchemaSource.create(s3, YangTextSource.class, 1));
final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
* Schema source provider that fails on first attempt of getSource() and succeeds on every subsequent call
* to simulate transient failures of source retrieval.
*/
- private static final class TransientFailureProvider implements SchemaSourceProvider<YangTextSchemaSource> {
- private final YangTextSchemaSource schemaSource;
+ private static final class TransientFailureProvider implements SchemaSourceProvider<YangTextSource> {
+ private final YangTextSource schemaSource;
private boolean shouldFail = true;
- private TransientFailureProvider(final YangTextSchemaSource schemaSource) {
+ private TransientFailureProvider(final YangTextSource schemaSource) {
this.schemaSource = requireNonNull(schemaSource);
}
@Override
- public ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
if (shouldFail) {
shouldFail = false;
return immediateFailedFluentFuture(new Exception("Transient test failure."));
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class SharedSchemaRepositoryTest {
final var id2 = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported@2012-12-12.yang");
var source = sharedSchemaRepository.getSchemaSource(idNoRevision, YangIRSchemaSource.class);
- assertEquals(idNoRevision, source.get().getIdentifier());
+ assertEquals(idNoRevision, source.get().sourceId());
source = sharedSchemaRepository.getSchemaSource(id2, YangIRSchemaSource.class);
- assertEquals(id2, source.get().getIdentifier());
+ assertEquals(id2, source.get().sourceId());
}
private static SourceIdentifier loadAndRegisterSource(final SharedSchemaRepository sharedSchemaRepository,
static SettableSchemaProvider<YangIRSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName)
throws Exception {
return SettableSchemaProvider.createRemote(
- TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
- YangIRSchemaSource.class);
+ TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
}
static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
return SettableSchemaProvider.createImmediate(
- TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
- YangIRSchemaSource.class);
+ TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
}
}
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
public class SharedSchemaRepositoryWithFeaturesTest {
private static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
final String resourceName) throws Exception {
return SettableSchemaProvider.createImmediate(
- TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName)),
- YangIRSchemaSource.class);
+ TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
}
private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
public class YT1428Test extends AbstractSchemaRepositoryTest {
@Test
- public void testDeviateSourceReported() {
+ void testDeviateSourceReported() {
final var ex = assertExecutionException(null, "/yt1428/orig.yang", "/yt1428/deviate.yang");
assertEquals(new SourceIdentifier("deviate"),
assertInstanceOf(SchemaResolutionException.class, ex.getCause()).getFailedSource());
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
public class YangTextSchemaContextResolverTest {
@Test
final var fooModuleId = new SourceIdentifier("foo", "2016-09-26");
final var foo = yangTextSchemaContextResolver.getSource(fooModuleId);
assertTrue(foo.isDone());
- assertEquals(fooModuleId, foo.get().getIdentifier());
+ assertEquals(fooModuleId, foo.get().sourceId());
final var barModuleId = new SourceIdentifier("bar", "2016-09-26");
final var bar = yangTextSchemaContextResolver.getSource(barModuleId);
assertTrue(bar.isDone());
- assertEquals(barModuleId, bar.get().getIdentifier());
+ assertEquals(barModuleId, bar.get().sourceId());
final var bazModuleId = new SourceIdentifier("baz", "2016-09-26");
final var baz = yangTextSchemaContextResolver.getSource(bazModuleId);
assertTrue(baz.isDone());
- assertEquals(bazModuleId, baz.get().getIdentifier());
+ assertEquals(bazModuleId, baz.get().sourceId());
final var foobarModuleId = new SourceIdentifier("foobar", "2016-09-26");
final var foobar = yangTextSchemaContextResolver.getSource(foobarModuleId);
import org.opendaylight.yangtools.yang.common.YangVersion;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
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.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ConfigEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
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.StatementSourceReference;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
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.StatementSourceReference;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.ir.IRStatement;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceTransformer;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.antlr.IRSupport;
@Beta
-public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSchemaSource, YangIRSchemaSource> {
+public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSource, YangIRSchemaSource> {
private TextToIRTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
- super(provider, YangTextSchemaSource.class, consumer, YangIRSchemaSource.class,
+ super(provider, YangTextSource.class, consumer, YangIRSchemaSource.class,
input -> Futures.immediateFuture(transformText(input)));
}
return new TextToIRTransformer(provider, consumer);
}
- public static @NonNull YangIRSchemaSource transformText(final YangTextSchemaSource text)
+ public static @NonNull YangIRSchemaSource transformText(final YangTextSource text)
throws YangSyntaxErrorException, IOException {
final IRStatement rootStatement = IRSupport.createStatement(YangStatementStreamSource.parseYangSource(text));
- final String name = YangModelDependencyInfo.safeStringArgument(text.getIdentifier(), rootStatement, "name");
- final String latestRevision = YangModelDependencyInfo.getLatestRevision(rootStatement, text.getIdentifier());
+ final String name = YangModelDependencyInfo.safeStringArgument(text.sourceId(), rootStatement, "name");
+ final String latestRevision = YangModelDependencyInfo.getLatestRevision(rootStatement, text.sourceId());
final SourceIdentifier sourceId = new SourceIdentifier(name, latestRevision);
- return new YangIRSchemaSource(sourceId, rootStatement, text.getSymbolicName().orElse(null));
+ return new YangIRSchemaSource(sourceId, rootStatement, text.symbolicName());
}
}
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(YangErrorListener.class);
private final List<YangSyntaxErrorException> exceptions = new ArrayList<>();
- private final SourceIdentifier source;
+ private final SourceIdentifier sourceId;
- YangErrorListener(final SourceIdentifier source) {
- this.source = requireNonNull(source);
+ YangErrorListener(final SourceIdentifier sourceId) {
+ this.sourceId = requireNonNull(sourceId);
}
@Override
@SuppressWarnings("checkstyle:parameterName")
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
final int charPositionInLine, final String msg, final RecognitionException e) {
- LOG.debug("Syntax error in {} at {}:{}: {}", source, line, charPositionInLine, msg, e);
- exceptions.add(new YangSyntaxErrorException(source, line, charPositionInLine, msg, e));
+ LOG.debug("Syntax error in {} at {}:{}: {}", sourceId, line, charPositionInLine, msg, e);
+ exceptions.add(new YangSyntaxErrorException(sourceId, line, charPositionInLine, msg, e));
}
void validate() throws YangSyntaxErrorException {
throw exceptions.get(0);
}
- final StringBuilder sb = new StringBuilder();
+ final var sb = new StringBuilder();
boolean first = true;
- for (YangSyntaxErrorException e : exceptions) {
+ for (var ex : exceptions) {
if (first) {
first = false;
} else {
sb.append('\n');
}
- sb.append(e.getFormattedMessage());
+ sb.append(ex.getFormattedMessage());
}
- throw new YangSyntaxErrorException(source, 0, 0, sb.toString());
+ throw new YangSyntaxErrorException(sourceId, 0, 0, sb.toString());
}
}
import org.opendaylight.yangtools.yang.ir.IRKeyword;
import org.opendaylight.yangtools.yang.ir.IRKeyword.Unqualified;
import org.opendaylight.yangtools.yang.ir.IRStatement;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.source.ExplicitStatement;
* @throws IllegalArgumentException If the root statement is not a valid YANG module/submodule
*/
public static @NonNull YangModelDependencyInfo forIR(final YangIRSchemaSource source) {
- return forIR(source.getRootStatement(), source.getIdentifier());
+ return forIR(source.getRootStatement(), source.sourceId());
}
/**
* Extracts {@link YangModelDependencyInfo} from an intermediate representation root statement of a YANG model.
*
- * @param source Source identifier
+ * @param sourceId Source identifier
* @param rootStatement root statement
* @return {@link YangModelDependencyInfo}
* @throws IllegalArgumentException If the root statement is not a valid YANG module/submodule
*/
static @NonNull YangModelDependencyInfo forIR(final IRStatement rootStatement,
- final SourceIdentifier source) {
+ final SourceIdentifier sourceId) {
final IRKeyword keyword = rootStatement.keyword();
checkArgument(keyword instanceof Unqualified, "Invalid root statement %s", keyword);
final String arg = keyword.identifier();
if (MODULE.equals(arg)) {
- return parseModuleContext(rootStatement, source);
+ return parseModuleContext(rootStatement, sourceId);
}
if (SUBMODULE.equals(arg)) {
- return parseSubmoduleContext(rootStatement, source);
+ return parseSubmoduleContext(rootStatement, sourceId);
}
throw new IllegalArgumentException("Root of parsed AST must be either module or submodule");
}
/**
- * Extracts {@link YangModelDependencyInfo} from a {@link YangTextSchemaSource}. This parsing does not
- * validate full YANG module, only parses header up to the revisions and imports.
+ * Extracts {@link YangModelDependencyInfo} from a {@link YangTextSource}. This parsing does not validate full YANG
+ * module, only parses header up to the revisions and imports.
*
- * @param yangText {@link YangTextSchemaSource}
+ * @param yangText {@link YangTextSource}
* @return {@link YangModelDependencyInfo}
* @throws YangSyntaxErrorException If the resource does not pass syntactic analysis
* @throws IOException When the resource cannot be read
*/
- public static YangModelDependencyInfo forYangText(final YangTextSchemaSource yangText)
+ public static YangModelDependencyInfo forYangText(final YangTextSource yangText)
throws IOException, YangSyntaxErrorException {
- final YangStatementStreamSource source = YangStatementStreamSource.create(yangText);
+ final var source = YangStatementStreamSource.create(yangText);
return forIR(source.rootStatement(), source.getIdentifier());
}
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.ir.IRKeyword;
import org.opendaylight.yangtools.yang.ir.IRStatement;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementLexer;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser;
import org.opendaylight.yangtools.yang.parser.antlr.YangStatementParser.FileContext;
private final IRStatement rootStatement;
private final String sourceName;
- private YangStatementStreamSource(final SourceIdentifier identifier, final IRStatement rootStatement,
+ private YangStatementStreamSource(final SourceIdentifier sourceId, final IRStatement rootStatement,
final String sourceName) {
- super(identifier);
+ super(sourceId);
this.rootStatement = requireNonNull(rootStatement);
this.sourceName = sourceName;
}
/**
- * Create a {@link YangStatementStreamSource} for a {@link YangTextSchemaSource}.
+ * Create a {@link YangStatementStreamSource} for a {@link YangTextSource}.
*
* @param source YangTextSchemaSource, must not be null
* @return A new {@link YangStatementStreamSource}
* @throws IOException When we fail to read the source
* @throws YangSyntaxErrorException If the source fails basic parsing
*/
- public static YangStatementStreamSource create(final YangTextSchemaSource source) throws IOException,
- YangSyntaxErrorException {
- return new YangStatementStreamSource(source.getIdentifier(),
- IRSupport.createStatement(parseYangSource(source)), source.getSymbolicName().orElse(null));
+ public static YangStatementStreamSource create(final YangTextSource source)
+ throws IOException, YangSyntaxErrorException {
+ return new YangStatementStreamSource(source.sourceId(),
+ IRSupport.createStatement(parseYangSource(source)), source.symbolicName());
}
/**
* @throws NullPointerException if {@code source} is null
*/
public static YangStatementStreamSource create(final YangIRSchemaSource source) {
- return create(source.getIdentifier(), source.getRootStatement(), source.getSymbolicName().orElse(null));
+ return create(source.sourceId(), source.getRootStatement(), source.symbolicName());
}
public static YangStatementStreamSource create(final SourceIdentifier identifier, final IRStatement rootStatement,
return rootStatement;
}
- static StatementContext parseYangSource(final YangTextSchemaSource source)
+ static StatementContext parseYangSource(final YangTextSource source)
throws IOException, YangSyntaxErrorException {
try (var reader = source.openStream()) {
- return parseYangSource(source.getIdentifier(), reader);
+ return parseYangSource(source.sourceId(), reader);
}
}
- private static StatementContext parseYangSource(final SourceIdentifier source, final Reader stream)
+ private static StatementContext parseYangSource(final SourceIdentifier sourceId, final Reader stream)
throws IOException, YangSyntaxErrorException {
final YangStatementLexer lexer = new CompactYangStatementLexer(CharStreams.fromReader(stream));
final YangStatementParser parser = new YangStatementParser(new CommonTokenStream(lexer));
lexer.removeErrorListeners();
parser.removeErrorListeners();
- final YangErrorListener errorListener = new YangErrorListener(source);
+ final YangErrorListener errorListener = new YangErrorListener(sourceId);
lexer.addErrorListener(errorListener);
parser.addErrorListener(errorListener);
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSourceReference;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinXmlSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.YinDomSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinXmlSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixResolver;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
import org.w3c.dom.NodeList;
/**
- * A {@link StatementStreamSource} based on a {@link YinXmlSchemaSource}. Internal implementation works on top
- * of {@link YinDomSchemaSource} and its DOM document.
+ * A {@link StatementStreamSource} based on a {@link YinXmlSource}. Internal implementation works on top
+ * of {@link YinDomSource} and its DOM document.
*
* @author Robert Varga
*/
});
private final Node root;
- private YinStatementStreamSource(final SourceIdentifier identifier, final Node root) {
- super(identifier);
+ private YinStatementStreamSource(final SourceIdentifier sourceId, final Node root) {
+ super(sourceId);
this.root = requireNonNull(root);
}
- public static StatementStreamSource create(final YinXmlSchemaSource source) throws TransformerException {
- return create(YinDomSchemaSource.transform(source));
+ public static StatementStreamSource create(final YinXmlSource source) throws TransformerException {
+ return create(YinDomSource.transform(source));
}
- public static StatementStreamSource create(final YinDomSchemaSource source) {
- return new YinStatementStreamSource(source.getIdentifier(), source.getSource().getNode());
+ public static StatementStreamSource create(final YinDomSource source) {
+ return new YinStatementStreamSource(source.sourceId(), source.getSource().getNode());
}
private static StatementDefinition getValidDefinition(final Node node, final StatementWriter writer,
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceTransformer;
+import org.opendaylight.yangtools.yang.model.spi.source.YinDomSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
- * A {@link SchemaSourceTransformer} which handles translation of models from
- * {@link YinTextSchemaSource} representation into {@link YinDomSchemaSource}.
- *
- * @author Robert Varga
+ * A {@link SchemaSourceTransformer} which handles translation of models from {@link YinTextSource} representation into
+ * {@link YinDomSource}.
*/
@Beta
-public final class YinTextToDomTransformer extends SchemaSourceTransformer<YinTextSchemaSource, YinDomSchemaSource> {
+public final class YinTextToDomTransformer extends SchemaSourceTransformer<YinTextSource, YinDomSource> {
private YinTextToDomTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
- super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class,
+ super(provider, YinTextSource.class, consumer, YinDomSource.class,
input -> Futures.immediateFuture(transformSource(input)));
}
return new YinTextToDomTransformer(provider, consumer);
}
- public static YinDomSchemaSource transformSource(final YinTextSchemaSource source) throws SAXException,
- IOException {
+ public static YinDomSource transformSource(final YinTextSource source) throws SAXException, IOException {
final Document doc = UntrustedXML.newDocumentBuilder().newDocument();
final SAXParser parser = UntrustedXML.newSAXParser();
final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null);
parser.parse(source.openStream(), handler);
- return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc),
- source.getSymbolicName().orElse(null));
+ return YinDomSource.create(source.sourceId(), new DOMSource(doc), source.symbolicName());
}
}
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
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.RevisionDateStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.rfc7950.namespace.ModuleQNameToPrefix;
import org.opendaylight.yangtools.yang.parser.spi.ParserNamespaces;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.IncludeEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
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.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatementDecorators;
import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
import org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException;
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.ir.IOSupport;
import org.opendaylight.yangtools.yang.ir.IRStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
import org.opendaylight.yangtools.yang.stmt.TestUtils;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
public static YangStatementStreamSource sourceForResource(final String resourceName) {
try {
- return YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
+ return YangStatementStreamSource.create(YangTextSource.forPath(Path.of(
StmtTestUtils.class.getResource(resourceName).toURI())));
} catch (IOException | YangSyntaxErrorException | URISyntaxException e) {
throw new IllegalArgumentException("Failed to create source", e);
final Collection<YangStatementStreamSource> sources = new ArrayList<>(files.length);
for (File file : files) {
- sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
+ sources.add(YangStatementStreamSource.create(YangTextSource.forPath(file.toPath())));
}
return parseYangSources(config, supportedFeatures, sources);
final File[] files = new File(resourceDir.toURI()).listFiles(YIN_FILE_FILTER);
final StatementStreamSource[] sources = new StatementStreamSource[files.length];
for (int i = 0; i < files.length; i++) {
- final SourceIdentifier identifier = YinTextSchemaSource.identifierFromFilename(files[i].getName());
+ final SourceIdentifier identifier = YinTextSource.identifierFromFilename(files[i].getName());
sources[i] = YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSchemaSource.delegateForByteSource(identifier, Files.asByteSource(files[i]))));
+ YinTextSource.delegateForByteSource(identifier, Files.asByteSource(files[i]))));
}
return parseYinSources(config, sources);
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
.listFiles(StmtTestUtils.YANG_FILE_FILTER);
final var sources = new ArrayList<StatementStreamSource>(files.length);
for (var file : files) {
- sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
+ sources.add(YangStatementStreamSource.create(YangTextSource.forPath(file.toPath())));
}
return sources;
}
return reactor.buildEffective();
}
- public static YangTextSchemaSource assertSchemaSource(final String resourcePath) {
+ public static YangTextSource assertSchemaSource(final String resourcePath) {
try {
- return YangTextSchemaSource.forPath(Path.of(TestUtils.class.getResource(resourcePath).toURI()));
+ return YangTextSource.forPath(Path.of(TestUtils.class.getResource(resourcePath).toURI()));
} catch (URISyntaxException e) {
throw new AssertionError(e);
}
for (File file : new File(resourceDirectory).listFiles()) {
reactor.addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSchemaSource.forPath(file.toPath()))));
+ YinTextSource.forPath(file.toPath()))));
}
return reactor.buildEffective();
}
- public static Module loadYinModule(final YinTextSchemaSource source) throws ReactorException, SAXException,
- IOException {
+ public static Module loadYinModule(final YinTextSource source) throws ReactorException, SAXException, IOException {
return RFC7950Reactors.defaultReactor().newBuild()
- .addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source)))
- .buildEffective()
- .getModules().iterator().next();
+ .addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source)))
+ .buildEffective()
+ .getModules().iterator().next();
}
public static ModuleImport findImport(final Collection<? extends ModuleImport> imports, final String prefix) {
import java.io.IOException;
import org.junit.jupiter.api.Test;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YinTextSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YinTextToDomTransformer;
private static StatementStreamSource createSource(final String name) {
try {
return YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(
- YinTextSchemaSource.forResource(YinFileStmtTest.class, "/semantic-statement-parser/yin/" + name)));
+ YinTextSource.forResource(YinFileStmtTest.class, "/semantic-statement-parser/yin/" + name)));
} catch (SAXException | IOException e) {
throw new IllegalArgumentException(e);
}
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* Namespace key matching criterion.
*
* @param <K> Key type
- *
- * @author Robert Varga
*/
@Beta
public abstract class NamespaceKeyCriterion<K> {
import static java.util.Objects.requireNonNull;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
public class ReactorException extends Exception {
private static final long serialVersionUID = 1L;
final Throwable cause) {
super(message, cause);
this.phase = requireNonNull(phase);
- this.sourceIdentifier = sourceId;
+ sourceIdentifier = sourceId;
}
public ReactorException(final ModelProcessingPhase phase, final String message, final SourceIdentifier sourceId) {
super(message);
this.phase = requireNonNull(phase);
- this.sourceIdentifier = sourceId;
+ sourceIdentifier = sourceId;
}
public final ModelProcessingPhase getPhase() {
*/
package org.opendaylight.yangtools.yang.parser.spi.meta;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
public class SomeModifiersUnresolvedException extends ReactorException {
-
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- public SomeModifiersUnresolvedException(ModelProcessingPhase phase, SourceIdentifier sourceId, Throwable cause) {
+ public SomeModifiersUnresolvedException(final ModelProcessingPhase phase, final SourceIdentifier sourceId,
+ final Throwable cause) {
super(phase, "Some of " + phase + " modifiers for statements were not resolved.", sourceId, cause);
}
-
}
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.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* An inference context associated with an instance of a statement.
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* Statement stream source, which is used for inference of effective model.
import static java.util.Objects.requireNonNull;
import java.io.StringReader;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.UnresolvedQName;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
/**
- * A {@link YangTextSchemaSource} backed by a string literal.
+ * A {@link YangTextSource} backed by a string literal.
*/
-final class LiteralYangTextSchemaSource extends YangTextSchemaSource {
+final class LiteralYangTextSource extends YangTextSource {
private final @NonNull String sourceString;
- private LiteralYangTextSchemaSource(final SourceIdentifier identifier, final String sourceString,
+ private LiteralYangTextSource(final SourceIdentifier identifier, final String sourceString,
final String symbolicName) {
super(identifier);
this.sourceString = requireNonNull(sourceString);
}
/**
- * Create a new {@link YangTextSchemaSource} backed by a String input.
+ * Create a new {@link YangTextSource} backed by a String input.
*
* @param sourceString YANG file as a String
* @return A new instance.
* @throws IllegalArgumentException if {@code sourceString} does not a valid YANG body, given a rather restrictive
* view of what is valid.
*/
- static @NonNull LiteralYangTextSchemaSource ofLiteral(final String sourceString) {
+ static @NonNull LiteralYangTextSource ofLiteral(final String sourceString) {
// First line of a YANG file looks as follows:
// `module module-name {`
// therefore in order to extract the name of the module from a plain string, we are interested in the second
final String arg = firstLine[1].strip();
final var localName = UnresolvedQName.tryLocalName(arg);
checkArgument(localName != null);
- return new LiteralYangTextSchemaSource(new SourceIdentifier(localName), sourceString, arg);
+ return new LiteralYangTextSource(new SourceIdentifier(localName), sourceString, arg);
}
@Override
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.of(getIdentifier().name().getLocalName());
+ public String symbolicName() {
+ return sourceId().name().getLocalName();
}
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
*/
public static EffectiveModelContext parseYangResource(final String resource, final YangParserConfiguration config,
final Set<QName> supportedFeatures) {
- final YangTextSchemaSource source = YangTextSchemaSource.forResource(YangParserTestUtils.class, resource);
- return parseYangSources(config, supportedFeatures, source);
+ return parseYangSources(config, supportedFeatures,
+ YangTextSource.forResource(YangParserTestUtils.class, resource));
}
/**
public static EffectiveModelContext parseYangFiles(final Set<QName> supportedFeatures,
final YangParserConfiguration config, final Collection<File> files) {
return parseSources(config, supportedFeatures,
- files.stream().map(file -> YangTextSchemaSource.forPath(file.toPath())).collect(Collectors.toList()));
+ files.stream().map(file -> YangTextSource.forPath(file.toPath())).collect(Collectors.toList()));
}
/**
}
public static EffectiveModelContext parseYangResources(final Class<?> clazz, final Collection<String> resources) {
- final List<YangTextSchemaSource> sources = new ArrayList<>(resources.size());
+ final var sources = new ArrayList<YangTextSource>(resources.size());
for (final String r : resources) {
- sources.add(YangTextSchemaSource.forResource(clazz, r));
+ sources.add(YangTextSource.forResource(clazz, r));
}
return parseSources(YangParserConfiguration.DEFAULT, null, sources);
}
}
public static EffectiveModelContext parseYangSources(final YangParserConfiguration config,
- final Set<QName> supportedFeatures, final YangTextSchemaSource... sources) {
+ final Set<QName> supportedFeatures, final YangTextSource... sources) {
return parseSources(config, supportedFeatures, Arrays.asList(sources));
}
public static EffectiveModelContext parseSources(final YangParserConfiguration config,
- final Set<QName> supportedFeatures, final Collection<? extends SchemaSourceRepresentation> sources) {
+ final Set<QName> supportedFeatures, final Collection<? extends SourceRepresentation> sources) {
final YangParser parser = PARSER_FACTORY.createParser(config);
if (supportedFeatures != null) {
parser.setSupportedFeatures(FeatureSet.of(supportedFeatures));
*/
public static EffectiveModelContext parseYang(final String... sources) {
return parseSources(YangParserConfiguration.DEFAULT, null,
- Arrays.stream(sources).map(LiteralYangTextSchemaSource::ofLiteral).toList());
+ Arrays.stream(sources).map(LiteralYangTextSource::ofLiteral).toList());
}
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Wrong inferent on listFiles")
requires transitive com.google.common;
requires transitive org.opendaylight.yangtools.yang.model.api;
- requires transitive org.opendaylight.yangtools.yang.repo.api;
+ requires transitive org.opendaylight.yangtools.yang.model.spi;
requires transitive org.opendaylight.yangtools.concepts;
// Annotations
import java.util.Optional;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
/**
* An SPI-level interface to find the schema source for a particular YANG module, as packaged in the final artifact.
* @throws NullPointerException if any argument is {@code null}
* @throws IllegalArgumentException if the requested representation is not supported by this resolver
*/
- Optional<String> findModuleResourcePath(ModuleLike module,
- Class<? extends SchemaSourceRepresentation> representation);
+ Optional<String> findModuleResourcePath(ModuleLike module, Class<? extends SourceRepresentation> representation);
default Optional<String> findModuleYangTextResourcePath(final ModuleLike module) {
- return findModuleResourcePath(module, YangTextSchemaSource.class);
+ return findModuleResourcePath(module, YangTextSource.class);
}
}
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
final class ContextHolder implements Immutable, ModuleResourceResolver {
private final @NonNull EffectiveModelContext context;
@Override
public Optional<String> findModuleResourcePath(final ModuleLike module,
- final Class<? extends SchemaSourceRepresentation> representation) {
- checkArgument(YangTextSchemaSource.class.equals(requireNonNull(representation)),
+ final Class<? extends SourceRepresentation> representation) {
+ checkArgument(YangTextSource.class.equals(requireNonNull(representation)),
"Unsupported representation %s", representation);
final SourceIdentifier id = Util.moduleToIdentifier(module);
return sources.contains(id)
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.Submodule;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.slf4j.Logger;
final class ProcessorModuleReactor {
private static final Logger LOG = LoggerFactory.getLogger(ProcessorModuleReactor.class);
- private final Map<SourceIdentifier, YangTextSchemaSource> modelsInProject;
+ private final Map<SourceIdentifier, YangTextSource> modelsInProject;
private final Collection<ScannedDependency> dependencies;
private YangParser parser;
- ProcessorModuleReactor(final YangParser parser, final Collection<YangTextSchemaSource> modelsInProject,
+ ProcessorModuleReactor(final YangParser parser, final Collection<YangTextSource> modelsInProject,
final Collection<ScannedDependency> dependencies) {
this.parser = requireNonNull(parser);
- this.modelsInProject = Maps.uniqueIndex(modelsInProject, YangTextSchemaSource::getIdentifier);
+ this.modelsInProject = Maps.uniqueIndex(modelsInProject, YangTextSource::sourceId);
this.dependencies = ImmutableList.copyOf(dependencies);
}
ContextHolder toContext() throws IOException, YangParserException {
checkState(parser != null, "Context has already been assembled");
- for (YangTextSchemaSource source : toUniqueSources(dependencies)) {
+ for (var source : toUniqueSources(dependencies)) {
// This source is coming from a dependency:
// - its identifier should be accurate, as it should have been processed into a file with accurate name
// - it is not required to be parsed, hence we add it just as a library source
return new ContextHolder(schemaContext, modules, modelsInProject.keySet());
}
- Collection<YangTextSchemaSource> getModelsInProject() {
+ Collection<YangTextSource> getModelsInProject() {
return modelsInProject.values();
}
- private static Collection<YangTextSchemaSource> toUniqueSources(final Collection<ScannedDependency> dependencies)
+ private static Collection<YangTextSource> toUniqueSources(final Collection<ScannedDependency> dependencies)
throws IOException {
- final Map<String, YangTextSchemaSource> byContent = new HashMap<>();
+ final Map<String, YangTextSource> byContent = new HashMap<>();
for (ScannedDependency dependency : dependencies) {
- for (YangTextSchemaSource s : dependency.sources()) {
+ for (YangTextSource s : dependency.sources()) {
try (Reader reader = s.openStream()) {
final String contents = CharStreams.toString(reader);
byContent.putIfAbsent(contents, s);
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- ImmutableList<YangTextSchemaSource> sources() {
- return ImmutableList.of(YangTextSchemaSource.forPath(file().toPath()));
+ ImmutableList<YangTextSource> sources() {
+ return ImmutableList.of(YangTextSource.forPath(file().toPath()));
}
}
}
@Override
- ImmutableList<YangTextSchemaSource> sources() throws IOException {
- final var builder = ImmutableList.<YangTextSchemaSource>builderWithExpectedSize(entryNames.size());
+ ImmutableList<YangTextSource> sources() throws IOException {
+ final var builder = ImmutableList.<YangTextSource>builderWithExpectedSize(entryNames.size());
try (ZipFile zip = new ZipFile(file())) {
for (String entryName : entryNames) {
final ZipEntry entry = requireNonNull(zip.getEntry(entryName));
- builder.add(YangTextSchemaSource.delegateForByteSource(
+ builder.add(YangTextSource.delegateForByteSource(
entryName.substring(entryName.lastIndexOf('/') + 1),
// FIXME: can we reasonable make this a CharSource?
ByteSource.wrap(ByteStreams.toByteArray(zip.getInputStream(entry))),
return file;
}
- abstract ImmutableList<YangTextSchemaSource> sources() throws IOException;
+ abstract ImmutableList<YangTextSource> sources() throws IOException;
@VisibleForTesting
static List<File> getClassPath(final MavenProject project) {
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
import org.opendaylight.yangtools.yang.model.api.ModuleLike;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
final class Util {
private Util() {
import java.util.Collection;
import java.util.List;
import org.apache.maven.project.MavenProject;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
@FunctionalInterface
@VisibleForTesting
interface YangProvider {
- List<FileState> addYangsToMetaInf(MavenProject project,
- Collection<YangTextSchemaSource> modelsInProject) throws IOException;
+ List<FileState> addYangsToMetaInf(MavenProject project, Collection<YangTextSource> modelsInProject)
+ throws IOException;
}
import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorException;
import org.opendaylight.yangtools.plugin.generator.api.FileGeneratorFactory;
import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.model.repo.api.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.ir.YangIRSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
final var stateListBuilder = ImmutableList.<FileState>builderWithExpectedSize(modelsInProject.size());
for (var source : modelsInProject) {
- final File file = new File(withMetaInf, source.getIdentifier().toYangFilename());
+ final File file = new File(withMetaInf, source.sourceId().toYangFilename());
stateListBuilder.add(FileState.ofWrittenFile(file,
out -> source.asByteSource(StandardCharsets.UTF_8).copyTo(out)));
- LOG.debug("Created file {} for {}", file, source.getIdentifier());
+ LOG.debug("Created file {} for {}", file, source.sourceId());
}
ProjectFileAccess.addResourceDir(project, generatedYangDir);
final Stopwatch watch = Stopwatch.createStarted();
- final List<Entry<YangTextSchemaSource, YangIRSchemaSource>> parsed = yangFilesInProject.parallelStream()
+ final List<Entry<YangTextSource, YangIRSchemaSource>> parsed = yangFilesInProject.parallelStream()
.map(file -> {
- final YangTextSchemaSource textSource = YangTextSchemaSource.forPath(file.toPath());
+ final var textSource = YangTextSource.forPath(file.toPath());
try {
return Map.entry(textSource, TextToIRTransformer.transformText(textSource));
} catch (YangSyntaxErrorException | IOException e) {
LOG.info("{} Project model files found: {} in {}", LOG_PREFIX, yangFilesInProject.size(), watch);
final var outputFiles = ImmutableList.<FileState>builder();
- Collection<YangTextSchemaSource> modelsInProject = null;
+ Collection<YangTextSource> modelsInProject = null;
for (var parserConfig : codeGenerators.stream().map(GeneratorTask::parserConfig).collect(Collectors.toSet())) {
final var moduleReactor = createReactor(yangFilesInProject, parserConfig, dependencies, parsed);
final var yangSw = Stopwatch.createStarted();
@SuppressWarnings("checkstyle:illegalCatch")
private @NonNull ProcessorModuleReactor createReactor(final List<File> yangFilesInProject,
final YangParserConfiguration parserConfig, final Collection<ScannedDependency> dependencies,
- final List<Entry<YangTextSchemaSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
+ final List<Entry<YangTextSource, YangIRSchemaSource>> parsed) throws MojoExecutionException {
try {
- final var sourcesInProject = new ArrayList<YangTextSchemaSource>(yangFilesInProject.size());
+ final var sourcesInProject = new ArrayList<YangTextSource>(yangFilesInProject.size());
final var parser = parserFactory.createParser(parserConfig);
for (var entry : parsed) {
final var textSource = entry.getKey();
final var astSource = entry.getValue();
parser.addSource(astSource);
- if (!astSource.getIdentifier().equals(textSource.getIdentifier())) {
+ if (!astSource.sourceId().equals(textSource.sourceId())) {
// AST indicates a different source identifier, make sure we use that
- sourcesInProject.add(YangTextSchemaSource.delegateForCharSource(astSource.getIdentifier(),
+ sourcesInProject.add(YangTextSource.delegateForCharSource(astSource.sourceId(),
textSource));
} else {
sourcesInProject.add(textSource);
import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
@ExtendWith(MockitoExtension.class)
class FilenameResolutionTest extends AbstractCodeGeneratorTest {
final var module = Iterables.getOnlyElement(context.getModules());
assertEquals(Optional.of("/META-INF/yang/foo@2020-10-13.yang"),
- resolver.findModuleResourcePath(module, YangTextSchemaSource.class));
+ resolver.findModuleResourcePath(module, YangTextSource.class));
final var submodule = Iterables.getOnlyElement(module.getSubmodules());
assertEquals(Optional.of("/META-INF/yang/foo-submodule@2020-10-12.yang"),
- resolver.findModuleResourcePath(submodule, YangTextSchemaSource.class));
+ resolver.findModuleResourcePath(submodule, YangTextSource.class));
return ImmutableTable.of();
}).when(mock).generateFiles(any(), any(), any());
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.api.YangParser;
import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
import org.opendaylight.yangtools.yang.parser.api.YangParserException;
}
for (File file : testFiles) {
- parser.addSource(YangTextSchemaSource.forPath(file.toPath()));
+ parser.addSource(YangTextSource.forPath(file.toPath()));
}
for (File file : libFiles) {
- parser.addLibSource(YangTextSchemaSource.forPath(file.toPath()));
+ parser.addLibSource(YangTextSource.forPath(file.toPath()));
}
return parser.buildEffectiveModel();
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-ir</artifactId>
+ <artifactId>yang-model-api</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-api</artifactId>
+ <artifactId>yang-model-spi</artifactId>
</dependency>
</dependencies>
</project>
requires transitive com.google.common;
requires transitive org.opendaylight.yangtools.concepts;
requires transitive org.opendaylight.yangtools.yang.common;
- requires transitive org.opendaylight.yangtools.yang.ir;
requires transitive org.opendaylight.yangtools.yang.model.api;
+ requires transitive org.opendaylight.yangtools.yang.model.spi;
requires org.opendaylight.yangtools.util;
requires org.slf4j;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* An asynchronous factory for building {@link EffectiveModelContext} instances based on a specification of what
default @NonNull ListenableFuture<EffectiveModelContext> createEffectiveModelContext(
final SourceIdentifier... requiredSources) {
- return createEffectiveModelContext(Arrays.asList(requiredSources));
+ return createEffectiveModelContext(List.of(requiredSources));
}
}
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* Exception thrown when a the specified schema source is not available.
import com.google.common.util.concurrent.ListenableFuture;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* Interface exposed by repository implementations. A schema repository is a logically centralized place for model
return createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.getDefault());
}
- <T extends SchemaSourceRepresentation> @NonNull ListenableFuture<T> getSchemaSource(@NonNull SourceIdentifier id,
+ <T extends SourceRepresentation> @NonNull ListenableFuture<T> getSchemaSource(@NonNull SourceIdentifier id,
@NonNull Class<T> represetation);
}
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* Exception thrown when a Schema Source fails to resolve.
* @return YANG schema source identifier
*/
public final SourceIdentifier getFailedSource() {
- return this.failedSource;
+ return failedSource;
}
/**
import com.google.common.util.concurrent.ListenableFuture;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* A filter of schema sources. This is used to restrict which sources representation instances are allowed
* A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
*/
@NonNull SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
- private final ImmutableList<Class<? extends SchemaSourceRepresentation>> representations =
- ImmutableList.of(SchemaSourceRepresentation.class);
+ private final ImmutableList<Class<? extends SourceRepresentation>> representations =
+ ImmutableList.of(SourceRepresentation.class);
@Override
- public ImmutableList<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
+ public ImmutableList<Class<? extends SourceRepresentation>> supportedRepresentations() {
return representations;
}
@Override
- public FluentFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) {
+ public FluentFuture<Boolean> apply(final SourceRepresentation schemaSource) {
return FluentFutures.immediateTrueFluentFuture();
}
};
*
* @return Set of supported representations.
*/
- Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations();
+ Iterable<Class<? extends SourceRepresentation>> supportedRepresentations();
/**
* Check if a particular schema source is acceptable to the filter. The process
* @return Promise of a filtering decision. The result should be {@link Boolean#TRUE}
* if the source is acceptable.
*/
- ListenableFuture<Boolean> apply(SchemaSourceRepresentation schemaSource);
+ ListenableFuture<Boolean> apply(SourceRepresentation schemaSource);
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.AbstractSchemaSourceCache;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Cache implementation that stores schemas in form of files under provided folder.
*/
-public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentation>
- extends AbstractSchemaSourceCache<T> {
-
+public final class FilesystemSchemaSourceCache<T extends SourceRepresentation> extends AbstractSchemaSourceCache<T> {
private static final Logger LOG = LoggerFactory.getLogger(FilesystemSchemaSourceCache.class);
// Init storage adapters
- private static final Map<Class<? extends SchemaSourceRepresentation>,
- StorageAdapter<? extends SchemaSourceRepresentation>> STORAGE_ADAPTERS = Collections.singletonMap(
- YangTextSchemaSource.class, new YangTextSchemaStorageAdapter());
+ private static final Map<Class<? extends SourceRepresentation>, StorageAdapter<? extends SourceRepresentation>>
+ STORAGE_ADAPTERS = Collections.singletonMap(YangTextSource.class, new YangTextStorageAdapter());
private static final Pattern CACHED_FILE_PATTERN =
Pattern.compile("(?<moduleName>[^@]+)" + "(@(?<revision>" + Revision.STRING_FORMAT_PATTERN + "))?");
private final Class<T> representation;
private final File storageDirectory;
- public FilesystemSchemaSourceCache(
- final SchemaSourceRegistry consumer, final Class<T> representation, final File storageDirectory) {
+ public FilesystemSchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation,
+ final File storageDirectory) {
super(consumer, representation, Costs.LOCAL_IO);
this.representation = representation;
this.storageDirectory = requireNonNull(storageDirectory);
init();
}
- private static void checkSupportedRepresentation(final Class<? extends SchemaSourceRepresentation> representation) {
- for (final Class<? extends SchemaSourceRepresentation> supportedRepresentation : STORAGE_ADAPTERS.keySet()) {
+ private static void checkSupportedRepresentation(final Class<? extends SourceRepresentation> representation) {
+ for (final var supportedRepresentation : STORAGE_ADAPTERS.keySet()) {
if (supportedRepresentation.isAssignableFrom(representation)) {
return;
}
}
throw new IllegalArgumentException(String.format(
- "This cache does not support representation: %s, supported representations are: %s",
- representation, STORAGE_ADAPTERS.keySet()));
+ "This cache does not support representation: %s, supported representations are: %s",
+ representation, STORAGE_ADAPTERS.keySet()));
}
/**
final File file = sourceIdToFile(sourceIdentifier, storageDirectory);
if (file.exists() && file.canRead()) {
LOG.trace("Source {} found in cache as {}", sourceIdentifier, file);
- final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier,
- file);
+ final var restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file);
return immediateFluentFuture(representation.cast(restored));
}
@Override
protected synchronized void offer(final T source) {
- LOG.trace("Source {} offered to cache", source.getIdentifier());
+ LOG.trace("Source {} offered to cache", source.sourceId());
final File file = sourceIdToFile(source);
if (file.exists()) {
- LOG.debug("Source {} already in cache as {}", source.getIdentifier(), file);
+ LOG.debug("Source {} already in cache as {}", source.sourceId(), file);
return;
}
storeSource(file, source);
- register(source.getIdentifier());
- LOG.trace("Source {} stored in cache as {}", source.getIdentifier(), file);
+ register(source.sourceId());
+ LOG.trace("Source {} stored in cache as {}", source.sourceId(), file);
}
private File sourceIdToFile(final T source) {
- return sourceIdToFile(source.getIdentifier(), storageDirectory);
+ return sourceIdToFile(source.sourceId(), storageDirectory);
}
static File sourceIdToFile(final SourceIdentifier identifier, final File storageDirectory) {
STORAGE_ADAPTERS.get(representation).store(file, schemaRepresentation);
}
- private abstract static class StorageAdapter<T extends SchemaSourceRepresentation> {
-
+ private abstract static class StorageAdapter<T extends SourceRepresentation> {
private final Class<T> supportedType;
protected StorageAdapter(final Class<T> supportedType) {
this.supportedType = supportedType;
}
- void store(final File file, final SchemaSourceRepresentation schemaSourceRepresentation) {
+ void store(final File file, final SourceRepresentation schemaSourceRepresentation) {
checkArgument(supportedType.isAssignableFrom(schemaSourceRepresentation.getClass()),
"Cannot store schema source %s, this adapter only supports %s", schemaSourceRepresentation,
supportedType);
abstract T restoreAsType(SourceIdentifier sourceIdentifier, File cachedSource);
}
- private static final class YangTextSchemaStorageAdapter extends StorageAdapter<YangTextSchemaSource> {
-
- protected YangTextSchemaStorageAdapter() {
- super(YangTextSchemaSource.class);
+ private static final class YangTextStorageAdapter extends StorageAdapter<YangTextSource> {
+ protected YangTextStorageAdapter() {
+ super(YangTextSource.class);
}
@Override
- protected void storeAsType(final File file, final YangTextSchemaSource cast) {
+ protected void storeAsType(final File file, final YangTextSource cast) {
try (var castStream = cast.asByteSource(StandardCharsets.UTF_8).openStream()) {
Files.copy(castStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (final IOException e) {
- throw new IllegalStateException("Cannot store schema source " + cast.getIdentifier() + " to " + file,
- e);
+ throw new IllegalStateException("Cannot store schema source " + cast.sourceId() + " to " + file, e);
}
}
@Override
- YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
- return YangTextSchemaSource.forPath(cachedSource.toPath(), sourceIdentifier);
+ YangTextSource restoreAsType(final SourceIdentifier sourceIdentifier, final File cachedSource) {
+ return YangTextSource.forPath(cachedSource.toPath(), sourceIdentifier);
}
}
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
List<PotentialSchemaSource<?>> registeredSources = new ArrayList<>();
@Override
- public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
+ public void schemaSourceEncountered(final SourceRepresentation source) {
}
@Override
final File test4 = new File(tempDir, "module@2010-12-12.yang");
Files.asCharSink(test4, StandardCharsets.UTF_8).write("content-module-2010");
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
- sharedSchemaRepository, YangTextSchemaSource.class, tempDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(
+ sharedSchemaRepository, YangTextSource.class, tempDir);
sharedSchemaRepository.registerSchemaSourceListener(cache);
assertEquals(4, listener.registeredSources.size());
final File storageDir = Files.createTempDir();
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
- sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(
+ sharedSchemaRepository, YangTextSource.class, storageDir);
sharedSchemaRepository.registerSchemaSourceListener(cache);
final SourceIdentifier runningId = new SourceIdentifier("running", "2012-12-12");
- sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> immediateFluentFuture(
- new YangTextSchemaSource(runningId) {
+ sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> FluentFutures.immediateFluentFuture(
+ new YangTextSource(runningId) {
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper;
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.empty();
+ public String symbolicName() {
+ return null;
}
- }), PotentialSchemaSource.create(runningId, YangTextSchemaSource.class,
+ }), PotentialSchemaSource.create(runningId, YangTextSource.class,
PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
final TextToIRTransformer transformer = TextToIRTransformer.create(sharedSchemaRepository,
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
public void testCacheAndRestore() throws Exception {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache
- = new FilesystemSchemaSourceCache<>(registry, YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", "2012-12-12", content);
cache.offer(source);
final String content2 = "content2";
- final YangTextSchemaSource source2 = new TestingYangSource("test2", null, content);
+ final YangTextSource source2 = new TestingYangSource("test2", null, content);
cache.offer(source2);
final List<File> storedFiles = getFilesFromCache();
any(PotentialSchemaSource.class));
// Create new cache from stored sources
- new FilesystemSchemaSourceCache<>(registry, YangTextSchemaSource.class, storageDir);
+ new FilesystemSchemaSourceCache<>(registry, YangTextSource.class, storageDir);
verify(registry, times(4)).registerSchemaSource(any(SchemaSourceProvider.class),
any(PotentialSchemaSource.class));
@Test
public void testCacheDuplicate() throws Exception {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache
- = new FilesystemSchemaSourceCache<>(registry, YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", null, content);
+ final YangTextSource source = new TestingYangSource("test", null, content);
// Double offer
cache.offer(source);
cache.offer(source);
@Test
public void testCacheMultipleRevisions() throws Exception {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache
- = new FilesystemSchemaSourceCache<>(registry, YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", null, content);
- final YangTextSchemaSource source2 = new TestingYangSource("test", "2012-12-12", content);
- final YangTextSchemaSource source3 = new TestingYangSource("test", "2013-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", null, content);
+ final YangTextSource source2 = new TestingYangSource("test", "2012-12-12", content);
+ final YangTextSource source3 = new TestingYangSource("test", "2013-12-12", content);
// Double offer
cache.offer(source);
cache.offer(source2);
public void sourceIdToFileEmptyRevWithEmptyDir() {
final SourceIdentifier sourceIdentifier = new SourceIdentifier("test");
final File sourceIdToFile = FilesystemSchemaSourceCache.sourceIdToFile(sourceIdentifier, storageDir);
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(registry,
- YangTextSchemaSource.class, sourceIdToFile);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, sourceIdToFile);
assertNotNull(cache);
final List<File> storedFiles = Arrays.asList(sourceIdToFile.listFiles());
assertEquals(0, storedFiles.size());
@Test
public void sourceIdToFileEmptyRevWithOneItemInDir() {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(registry,
- YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", "2013-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
cache.offer(source);
final SourceIdentifier sourceIdentifier = new SourceIdentifier("test");
@Test
public void sourceIdToFileEmptyRevWithMoreItemsInDir() {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(registry,
- YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
- final YangTextSchemaSource source2 = new TestingYangSource("test", "2013-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", "2012-12-12", content);
+ final YangTextSource source2 = new TestingYangSource("test", "2013-12-12", content);
cache.offer(source);
cache.offer(source2);
@Test
public void test() throws Exception {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(registry,
- YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", "2013-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
cache.offer(source);
final SourceIdentifier sourceIdentifier = new SourceIdentifier("test", "2013-12-12");
- final ListenableFuture<? extends YangTextSchemaSource> checked = cache.getSource(sourceIdentifier);
+ final ListenableFuture<? extends YangTextSource> checked = cache.getSource(sourceIdentifier);
assertNotNull(checked);
assertTrue(checked.isDone());
- final YangTextSchemaSource checkedGet = checked.get();
- assertEquals(sourceIdentifier, checkedGet.getIdentifier());
+ final YangTextSource checkedGet = checked.get();
+ assertEquals(sourceIdentifier, checkedGet.sourceId());
}
@Test
public void test1() throws Exception {
- final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(registry,
- YangTextSchemaSource.class, storageDir);
+ final FilesystemSchemaSourceCache<YangTextSource> cache = new FilesystemSchemaSourceCache<>(registry,
+ YangTextSource.class, storageDir);
final String content = "content1";
- final YangTextSchemaSource source = new TestingYangSource("test", "2013-12-12", content);
+ final YangTextSource source = new TestingYangSource("test", "2013-12-12", content);
cache.offer(source);
final SourceIdentifier sourceIdentifier = new SourceIdentifier("test1", "2012-12-12");
- final ListenableFuture<? extends YangTextSchemaSource> checked = cache.getSource(sourceIdentifier);
+ final ListenableFuture<? extends YangTextSource> checked = cache.getSource(sourceIdentifier);
assertNotNull(checked);
assertThrows(ExecutionException.class, () -> checked.get());
}
return Arrays.asList(storageDir.listFiles());
}
- private static class TestingYangSource extends YangTextSchemaSource {
+ private static class TestingYangSource extends YangTextSource {
private final String content;
TestingYangSource(final String name, final String revision, final String content) {
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.empty();
+ public String symbolicName() {
+ return null;
}
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* a specific representation of a source.
*/
@GuardedBy("this")
- private final Map<SourceIdentifier, ListMultimap<Class<? extends SchemaSourceRepresentation>,
+ private final Map<SourceIdentifier, ListMultimap<Class<? extends SourceRepresentation>,
SchemaSourceRegistration>> sources = new HashMap<>();
/*
@GuardedBy("this")
private final List<SchemaListenerRegistration> listeners = new ArrayList<>();
- private static <T extends SchemaSourceRepresentation> ListenableFuture<T> fetchSource(final SourceIdentifier id,
- final Iterator<SchemaSourceRegistration> it) {
+ private static <T extends SourceRepresentation> ListenableFuture<T> fetchSource(
+ final SourceIdentifier sourceId, final Iterator<SchemaSourceRegistration> it) {
final var reg = it.next();
@SuppressWarnings("unchecked")
final var provider = (SchemaSourceProvider<T>) reg.provider();
- return Futures.catchingAsync(provider.getSource(id), Throwable.class, input -> {
+ return Futures.catchingAsync(provider.getSource(sourceId), Throwable.class, input -> {
LOG.debug("Failed to acquire source from {}", reg, input);
if (it.hasNext()) {
- return fetchSource(id, it);
+ return fetchSource(sourceId, it);
}
- throw new MissingSchemaSourceException("All available providers exhausted", id, input);
+ throw new MissingSchemaSourceException("All available providers exhausted", sourceId, input);
}, MoreExecutors.directExecutor());
}
@Override
- public <T extends SchemaSourceRepresentation> ListenableFuture<T> getSchemaSource(final SourceIdentifier id,
+ public <T extends SourceRepresentation> ListenableFuture<T> getSchemaSource(final SourceIdentifier id,
final Class<T> representation) {
final ArrayList<SchemaSourceRegistration> sortedSchemaSourceRegistrations;
final var regs = sortedSchemaSourceRegistrations.iterator();
if (!regs.hasNext()) {
return immediateFailedFluentFuture(new MissingSchemaSourceException(
- "No providers for source " + id + " representation " + representation + " available", id));
+ "No providers for source " + id + " representation " + representation + " available", id));
}
final ListenableFuture<T> fetchSourceFuture = fetchSource(id, regs);
}
@Override
- public <T extends SchemaSourceRepresentation> Registration registerSchemaSource(
+ public <T extends SourceRepresentation> Registration registerSchemaSource(
final SchemaSourceProvider<? super T> provider, final PotentialSchemaSource<T> source) {
final var ret = new SchemaSourceRegistration(source.cachedReference(), provider);
addSource(ret);
import static java.util.Objects.requireNonNull;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
/**
* Abstract base class for cache-type SchemaSourceListeners. It needs to be registered with a
* {@link SchemaSourceRegistry}, where it gets notifications from. It performs filtering and
- * {@link #offer(SchemaSourceRepresentation)}s conforming sources to the subclass.
+ * {@link #offer(SourceRepresentation)}s conforming sources to the subclass.
*
* @param <T> Cached schema source type.
*/
-public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresentation>
+public abstract class AbstractSchemaSourceCache<T extends SourceRepresentation>
implements SchemaSourceListener, SchemaSourceProvider<T> {
private final SchemaSourceRegistry consumer;
private final Class<T> representation;
* have cached a schema source representation, or when they have determined they have a schema source is available
* -- like when a persistent cache reads its cache index.
*
- * @param sourceIdentifier Source identifier
+ * @param sourceId Source identifier
* @return schema source registration, which the subclass needs to {@link Registration#close()} once it expunges the
* source from the cache.
*/
- protected final Registration register(final SourceIdentifier sourceIdentifier) {
- return consumer.registerSchemaSource(this, PotentialSchemaSource.create(sourceIdentifier, representation,
+ protected final Registration register(final SourceIdentifier sourceId) {
+ return consumer.registerSchemaSource(this, PotentialSchemaSource.create(sourceId, representation,
cost.getValue()));
}
@Override
- public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
+ public void schemaSourceEncountered(final SourceRepresentation source) {
if (representation.isAssignableFrom(source.getType())) {
offer(representation.cast(source));
}
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
/**
* A simple {@link AbstractSchemaSourceCache} based on {@link Cache Guava Cache}.
*
- * @param <T> {@link SchemaSourceRepresentation} type stored in this cache
+ * @param <T> {@link SourceRepresentation} type stored in this cache
* @deprecated This class has a rather complicated and ugly design. Use {@link SoftSchemaSourceCache} instead.
*/
@Beta
@Deprecated(since = "7.0.13", forRemoval = true)
-public final class GuavaSchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T>
+public final class GuavaSchemaSourceCache<T extends SourceRepresentation> extends AbstractSchemaSourceCache<T>
implements AutoCloseable {
// FIXME: 7.0.0: use a java.util.Cleaner?
private final List<FinalizablePhantomReference<T>> regs = Collections.synchronizedList(new ArrayList<>());
cache = cacheBuilder.build();
}
- public static <R extends SchemaSourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
+ public static <R extends SourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
final SchemaSourceRegistry consumer, final Class<R> representation) {
return new GuavaSchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues());
}
- public static <R extends SchemaSourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
+ public static <R extends SourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
final SchemaSourceRegistry consumer, final Class<R> representation, final long lifetime,
final TimeUnit units) {
return new GuavaSchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues()
.expireAfterAccess(lifetime, units));
}
- public static <R extends SchemaSourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
+ public static <R extends SourceRepresentation> @NonNull GuavaSchemaSourceCache<R> createSoftCache(
final SchemaSourceRegistry consumer, final Class<R> representation, final Duration duration) {
return new GuavaSchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues()
.expireAfterAccess(duration));
}
@Override
- public FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) {
- final T present = cache.getIfPresent(sourceIdentifier);
+ public FluentFuture<? extends T> getSource(final SourceIdentifier sourceId) {
+ final T present = cache.getIfPresent(sourceId);
return present != null ? FluentFutures.immediateFluentFuture(present)
- : FluentFutures.immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found",
- sourceIdentifier));
+ : FluentFutures.immediateFailedFluentFuture(
+ new MissingSchemaSourceException("Source not found", sourceId));
}
@Override
protected void offer(final T source) {
- final var srcId = source.getIdentifier();
+ final var srcId = source.sourceId();
if (cache.getIfPresent(srcId) != null) {
// We already have this source, do not track it
return;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import java.util.Objects;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
- * A potential schema source. Instances of this class track the various
- * representations of a schema source and the cost attached to obtaining
- * the source from them.
+ * A potential schema source. Instances of this class track the various representations of a schema source and the cost
+ * attached to obtaining the source from them.
*/
@Beta
-public final class PotentialSchemaSource<T extends SchemaSourceRepresentation> {
+public final class PotentialSchemaSource<T extends SourceRepresentation> {
/**
* Each registered source has a cost associated with it. Since a particular
* representation can be acquired by various means, here are general constants
this.cost = cost;
}
- public static <T extends SchemaSourceRepresentation> PotentialSchemaSource<T> create(
- final SourceIdentifier sourceIdentifier, final Class<? extends T> representation, final int cost) {
- return new PotentialSchemaSource<>(sourceIdentifier, representation, cost);
+ public static <T extends SourceRepresentation> PotentialSchemaSource<T> create(
+ final SourceIdentifier sourceId, final Class<? extends T> representation, final int cost) {
+ return new PotentialSchemaSource<>(sourceId, representation, cost);
}
- public static <T extends SchemaSourceRepresentation> PotentialSchemaSource<T> create(
- final SourceIdentifier sourceIdentifier, final Class<? extends T> representation, final Costs cost) {
- return new PotentialSchemaSource<>(sourceIdentifier, representation, cost.getValue());
+ public static <T extends SourceRepresentation> PotentialSchemaSource<T> create(
+ final SourceIdentifier sourceId, final Class<? extends T> representation, final Costs cost) {
+ return new PotentialSchemaSource<>(sourceId, representation, cost.getValue());
}
/**
import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
- * Listener on {@link SchemaSourceRepresentation} lifecycle.
+ * Listener on {@link SourceRepresentation} lifecycle.
*/
@Beta
@NonNullByDefault
*
* @param source Schema source
*/
- void schemaSourceEncountered(SchemaSourceRepresentation source);
+ void schemaSourceEncountered(SourceRepresentation source);
/**
* Invoked when a new schema source is registered by a provider. This call
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
/**
* Schema source provider implementations take care of resolving a {@link SourceIdentifier}
* @param <T> Schema source representation type provided by this implementation
*/
@Beta
-public interface SchemaSourceProvider<T extends SchemaSourceRepresentation> {
+public interface SchemaSourceProvider<T extends SourceRepresentation> {
/**
* Returns a representation a for supplied YANG source identifier. The resolution
* criteria are as follows:
*
* <ul>
- * <li> If the source identifier specifies a revision, this method returns either
- * a representation of that particular revision or throw {@link MissingSchemaSourceException}.
- * <li> If the source identifier does not specify a revision, this method returns
- * the newest available revision, or throws {@link MissingSchemaSourceException}.
+ * <li>If the source identifier specifies a revision, this method returns either a representation of that
+ * particular revision or throw {@link MissingSchemaSourceException}</li>
+ * <li>If the source identifier does not specify a revision, this method returns the newest available revision,
+ * or throws {@link MissingSchemaSourceException}</li>
* </ul>
*
* <p>
- * In either case the returned representation is required to report a non-null
- * revision in the {@link SourceIdentifier} returned from
- * {@link SchemaSourceRepresentation#getIdentifier()}.
+ * In either case the returned representation is required to report a non-null revision in the
+ * {@link SourceIdentifier} returned from {@link SourceRepresentation#sourceId()}.
*
* <p>
- * Implementations are not required to provide constant behavior in time, notably
- * this different invocation of this method may produce different results.
+ * Implementations are not required to provide constant behavior in time, notably this different invocation of this
+ * method may produce different results.
*
- * @param sourceIdentifier source identifier
+ * @param sourceId source identifier
* @return future source representation, if supplied YANG module is available
* @throws NullPointerException if {@code sourceIdentifier} is null
*/
- @NonNull ListenableFuture<? extends T> getSource(@NonNull SourceIdentifier sourceIdentifier);
+ @NonNull ListenableFuture<? extends T> getSource(@NonNull SourceIdentifier sourceId);
}
import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
/**
* Registry of all potentially available schema sources. Processes capable of dynamic schema discovery, such as OSGi
* @param source Schema source details
* @return A registration handle. Invoking {@link Registration#close()} will cancel the registration.
*/
- <T extends SchemaSourceRepresentation> Registration registerSchemaSource(SchemaSourceProvider<? super T> provider,
+ <T extends SourceRepresentation> Registration registerSchemaSource(SchemaSourceProvider<? super T> provider,
PotentialSchemaSource<T> source);
/**
import com.google.common.util.concurrent.MoreExecutors;
import java.util.HashMap;
import java.util.Map;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-public class SchemaSourceTransformer<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
+public class SchemaSourceTransformer<S extends SourceRepresentation, D extends SourceRepresentation>
implements SchemaSourceListener, SchemaSourceProvider<D> {
@FunctionalInterface
- public interface Transformation<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
+ public interface Transformation<S extends SourceRepresentation, D extends SourceRepresentation>
extends AsyncFunction<S, D> {
@Override
ListenableFuture<D> apply(S input) throws Exception;
}
@Override
- public final void schemaSourceEncountered(final SchemaSourceRepresentation source) {
+ public final void schemaSourceEncountered(final SourceRepresentation source) {
// Not interesting
}
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
/**
* A simple {@link AbstractSchemaSourceCache} maintaining soft references.
*
- * @param <T> {@link SchemaSourceRepresentation} type stored in this cache
+ * @param <T> {@link SourceRepresentation} type stored in this cache
*/
@Beta
-public final class SoftSchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T>
+public final class SoftSchemaSourceCache<T extends SourceRepresentation> extends AbstractSchemaSourceCache<T>
implements AutoCloseable {
private static final Cleaner CLEANER = Cleaner.create();
return;
}
- final var id = source.getIdentifier();
+ final var sourceId = source.sourceId();
final var ref = new SoftReference<>(source);
while (true) {
- final var prev = references.putIfAbsent(id, ref);
+ final var prev = references.putIfAbsent(sourceId, ref);
if (prev == null) {
// We have performed a fresh insert and need to add a cleanup
break;
}
// Existing reference is dead, remove it and retry
- references.remove(id, prev);
+ references.remove(sourceId, prev);
}
// We have populated a cache entry, register the source and a cleanup action
- final var reg = register(id);
+ final var reg = register(sourceId);
cleanables.put(reg, CLEANER.register(source, () -> {
cleanables.remove(reg);
reg.close();
- references.remove(id, ref);
+ references.remove(sourceId, ref);
}));
// Ensure 'source' is still reachable here. This is needed to ensure the cleanable action does not fire before
import com.google.common.base.MoreObjects.ToStringHelper;
import java.io.StringReader;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
@Deprecated
@ExtendWith(MockitoExtension.class)
class GuavaSchemaSourceCacheTest {
- private static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
+ private static final Class<YangSourceRepresentation> REPRESENTATION = YangSourceRepresentation.class;
private static final long LIFETIME = 1000L;
private static final TimeUnit UNITS = TimeUnit.MILLISECONDS;
assertNotNull(checkedSource);
final var yangSchemaSourceRepresentation = checkedSource.get();
assertNotNull(yangSchemaSourceRepresentation);
- assertEquals(sourceIdentifier, yangSchemaSourceRepresentation.getIdentifier());
+ assertEquals(sourceIdentifier, yangSchemaSourceRepresentation.sourceId());
}
}
}
}
- private static class TestingYangSource extends YangTextSchemaSource {
+ private static class TestingYangSource extends YangTextSource {
private final String content;
TestingYangSource(final String name, final String revision, final String content) {
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.empty();
+ public String symbolicName() {
+ return null;
}
@Override
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
@ExtendWith(MockitoExtension.class)
class PotentialSchemaSourceTest {
- private interface TestSchemaSourceRepresentation extends YangSchemaSourceRepresentation {
+ private interface TestSourceRepresentation extends YangSourceRepresentation {
@Override
- default Class<TestSchemaSourceRepresentation> getType() {
- return TestSchemaSourceRepresentation.class;
+ default Class<TestSourceRepresentation> getType() {
+ return TestSourceRepresentation.class;
}
}
public final SourceIdentifier sourceIdentifier = new SourceIdentifier("foo");
@SuppressWarnings("exports")
- public PotentialSchemaSource<TestSchemaSourceRepresentation> source;
+ public PotentialSchemaSource<TestSourceRepresentation> source;
@SuppressWarnings("exports")
- public PotentialSchemaSource<TestSchemaSourceRepresentation> same;
+ public PotentialSchemaSource<TestSourceRepresentation> same;
@BeforeEach
void before() {
- source = PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class,
+ source = PotentialSchemaSource.create(sourceIdentifier, TestSourceRepresentation.class,
PotentialSchemaSource.Costs.LOCAL_IO.getValue());
same = PotentialSchemaSource.create(source.getSourceIdentifier(), source.getRepresentation(),
source.getCost());
@Test
void testNegativeCost() {
assertThrows(IllegalArgumentException.class,
- () -> PotentialSchemaSource.create(sourceIdentifier, TestSchemaSourceRepresentation.class, -1));
+ () -> PotentialSchemaSource.create(sourceIdentifier, TestSourceRepresentation.class, -1));
}
@Test
void testMethods() {
assertEquals(PotentialSchemaSource.Costs.LOCAL_IO.getValue(), source.getCost());
assertSame(sourceIdentifier, source.getSourceIdentifier());
- assertSame(TestSchemaSourceRepresentation.class, source.getRepresentation());
+ assertSame(TestSourceRepresentation.class, source.getRepresentation());
assertEquals(same.hashCode(), source.hashCode());
assertNotEquals(null, source);
assertEquals(source, source);
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YinXmlSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
+import org.opendaylight.yangtools.yang.model.spi.source.YinXmlSource;
@ExtendWith(MockitoExtension.class)
class SchemaSourceTransformerTest {
- public static final Class<YangSchemaSourceRepresentation> SRC_CLASS = YangSchemaSourceRepresentation.class;
- public static final Class<YinXmlSchemaSource> DST_CLASS = YinXmlSchemaSource.class;
+ public static final Class<YangSourceRepresentation> SRC_CLASS = YangSourceRepresentation.class;
+ public static final Class<YinXmlSource> DST_CLASS = YinXmlSource.class;
@Mock
public SchemaRepository provider;
public SchemaSourceRegistry consumer;
@Mock
- public AsyncFunction<YangSchemaSourceRepresentation, YinXmlSchemaSource> function;
+ public AsyncFunction<YangSourceRepresentation, YinXmlSource> function;
- public SchemaSourceTransformer<YangSchemaSourceRepresentation, YinXmlSchemaSource> schema;
+ public SchemaSourceTransformer<YangSourceRepresentation, YinXmlSource> schema;
@Test
void schemaSourceTransformerTest() {
assertNotNull(source2);
}
- private static class Foo<T extends SchemaSourceRepresentation> {
+ private static class Foo<T extends SourceRepresentation> {
final PotentialSchemaSource<T> src;
Foo(final SourceIdentifier sourceIdentifier, final Class<T> representation, final Costs cost) {
}
}
- private static class Registrator extends AbstractSchemaSourceCache<YangSchemaSourceRepresentation> {
- Registrator(final SchemaSourceRegistry consumer, final Class<YangSchemaSourceRepresentation> srcClass,
+ private static class Registrator extends AbstractSchemaSourceCache<YangSourceRepresentation> {
+ Registrator(final SchemaSourceRegistry consumer, final Class<YangSourceRepresentation> srcClass,
final Costs cost) {
super(consumer, srcClass, cost);
}
@Override
- protected void offer(final YangSchemaSourceRepresentation source) {
+ protected void offer(final YangSourceRepresentation source) {
}
@Override
- public ListenableFuture<? extends YangSchemaSourceRepresentation> getSource(
- final SourceIdentifier sourceIdentifier) {
+ public ListenableFuture<? extends YangSourceRepresentation> getSource(final SourceIdentifier sourceId) {
return SettableFuture.create();
}
}
import com.google.common.base.MoreObjects.ToStringHelper;
import java.io.StringReader;
-import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangSchemaSourceRepresentation;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
@ExtendWith(MockitoExtension.class)
class SoftSchemaSourceCacheTest {
- private static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
+ private static final Class<YangSourceRepresentation> REPRESENTATION = YangSourceRepresentation.class;
@Mock
private SchemaSourceRegistry registry;
assertNotNull(checkedSource);
final var yangSchemaSourceRepresentation = checkedSource.get();
assertNotNull(yangSchemaSourceRepresentation);
- assertEquals(sourceIdentifier, yangSchemaSourceRepresentation.getIdentifier());
+ assertEquals(sourceIdentifier, yangSchemaSourceRepresentation.sourceId());
}
}
}
}
- private static class TestingYangSource extends YangTextSchemaSource {
+ private static class TestingYangSource extends YangTextSource {
private final String content;
TestingYangSource(final String name, final String revision, final String content) {
}
@Override
- public Optional<String> getSymbolicName() {
- return Optional.empty();
+ public String symbolicName() {
+ return null;
}
@Override