* 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.spi.source;
-
-import static java.util.Objects.requireNonNull;
+package org.opendaylight.yangtools.yang.model.api.source;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import java.io.InputStream;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.YinSourceRepresentation;
+import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* YIN text schema source representation. Exposes an RFC6020 or RFC7950 XML representation as an {@link InputStream}.
*/
+@NonNullByDefault
public abstract class YinTextSource extends ByteSource implements YinSourceRepresentation {
- private final @NonNull SourceIdentifier sourceId;
-
- protected YinTextSource(final SourceIdentifier sourceId) {
- this.sourceId = requireNonNull(sourceId);
- }
-
- @Override
- public final SourceIdentifier sourceId() {
- return sourceId;
- }
-
@Override
public final Class<YinTextSource> getType() {
return YinTextSource.class;
* @param toStringHelper ToStringHelper onto the attributes can be added
* @return ToStringHelper supplied as input argument.
*/
- protected ToStringHelper addToStringAttributes(final @NonNull ToStringHelper toStringHelper) {
- return toStringHelper.add("identifier", sourceId);
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper.add("sourceId", sourceId());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.spi.source;
+
+import static java.util.Objects.requireNonNull;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
+
+/**
+ * Abstract base class for implementing {@link YinTextSource}s with {@link Delegator}.
+ */
+@NonNullByDefault
+abstract class AbstractYinTextSource<T> extends YinTextSource implements Delegator<T> {
+ private final SourceIdentifier sourceId;
+ private final T delegate;
+
+ AbstractYinTextSource(final SourceIdentifier sourceId, final T delegate) {
+ this.sourceId = requireNonNull(sourceId);
+ this.delegate = requireNonNull(delegate);
+ }
+
+ @Override
+ public final SourceIdentifier sourceId() {
+ return sourceId;
+ }
+
+ @Override
+ public final T getDelegate() {
+ return delegate;
+ }
+
+}
*/
package org.opendaylight.yangtools.yang.model.spi.source;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.ByteSource;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
* A {@link YangTextSource} delegating to a {@link ByteSource}.
*/
@NonNullByDefault
-public class DelegatedYinTextSource extends YinTextSource implements Delegator<ByteSource> {
- private final ByteSource delegate;
-
+public class DelegatedYinTextSource extends AbstractYinTextSource<ByteSource> {
/**
* Default constructor.
*
* @param delegate backing {@link ByteSource} instance
*/
public DelegatedYinTextSource(final SourceIdentifier sourceId, final ByteSource delegate) {
- super(sourceId);
- this.delegate = requireNonNull(delegate);
- }
-
- @Override
- public final ByteSource getDelegate() {
- return delegate;
+ super(sourceId, delegate);
}
@Override
public final InputStream openStream() throws IOException {
- return delegate.openStream();
+ return getDelegate().openStream();
}
@Override
public final @NonNull String symbolicName() {
- return "[" + delegate.toString() + "]";
+ return "[" + getDelegate().toString() + "]";
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("delegate", delegate);
+ return super.addToStringAttributes(toStringHelper).add("delegate", getDelegate());
}
}
*/
package org.opendaylight.yangtools.yang.model.spi.source;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.base.MoreObjects.ToStringHelper;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A {@link YinTextSource} backed by a file.
+ * A {@link AbstractYinTextSource} backed by a file.
*/
@NonNullByDefault
-public class FileYinTextSource extends YinTextSource implements Delegator<Path> {
- private final Path path;
-
+public class FileYinTextSource extends AbstractYinTextSource<Path> {
public FileYinTextSource(final SourceIdentifier sourceId, final Path path) {
- super(sourceId);
+ super(sourceId, path);
if (!Files.isRegularFile(path)) {
throw new IllegalArgumentException("Supplied path " + path + " is not a regular file");
}
- this.path = requireNonNull(path);
}
public FileYinTextSource(final Path path) {
this(SourceIdentifier.ofYinFileName(path.toFile().getName()), path);
}
- @Override
- public final Path getDelegate() {
- return path;
- }
-
@Override
public final InputStream openStream() throws IOException {
- return Files.newInputStream(path);
+ return Files.newInputStream(getDelegate());
}
@Override
public final @NonNull String symbolicName() {
- return path.toString();
+ return getDelegate().toString();
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("path", path);
+ return super.addToStringAttributes(toStringHelper).add("path", getDelegate());
}
}
*/
package org.opendaylight.yangtools.yang.model.spi.source;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.base.MoreObjects.ToStringHelper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.concepts.Delegator;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
/**
- * A {@link YinTextSource}.backed by a {@link URL}.
+ * A {@link AbstractYinTextSource}.backed by a {@link URL}.
*/
@NonNullByDefault
-public class URLYinTextSource extends YinTextSource implements Delegator<URL> {
- private final URL url;
-
+public class URLYinTextSource extends AbstractYinTextSource<URL> {
public URLYinTextSource(final SourceIdentifier sourceId, final URL url) {
- super(sourceId);
- this.url = requireNonNull(url);
+ super(sourceId, url);
}
public URLYinTextSource(final URL url) {
this(SourceIdentifier.ofYinFileName(extractFileName(url.getPath())), url);
}
- @Override
- public final URL getDelegate() {
- return url;
- }
-
@Override
public final InputStream openStream() throws IOException {
- return url.openStream();
+ return getDelegate().openStream();
}
@Override
public final @NonNull String symbolicName() {
- return url.toString();
+ return getDelegate().toString();
}
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("url", url);
+ return super.addToStringAttributes(toStringHelper).add("url", getDelegate());
}
private static String extractFileName(final String path) {
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.source.YinTextSource;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
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 javax.xml.parsers.SAXParser;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
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;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.source.YinTextSource;
import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
import org.opendaylight.yangtools.yang.model.spi.source.FileYinTextSource;
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;