X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Frepo%2Fapi%2FYangTextSchemaSource.java;h=82651b466a791c5b4da5af0d258b192423f0b5d7;hb=f5d2344a51831445e13facb10db4b9076d8f42d2;hp=be52a90f777131055f9423d98d9893d0568c3371;hpb=9251a7269bd40a0c44df23426b2e73506d04740b;p=yangtools.git diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java index be52a90f77..82651b466a 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java @@ -3,31 +3,46 @@ * * 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/eplv10.html + * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.model.repo.api; -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.io.ByteSource; - import java.io.IOException; import java.io.InputStream; - +import java.util.Map.Entry; import org.opendaylight.yangtools.concepts.Delegator; +import org.opendaylight.yangtools.yang.common.YangConstants; +import org.opendaylight.yangtools.yang.common.YangNames; /** * YANG text schema source representation. Exposes an RFC6020 text representation * as an {@link InputStream}. */ -public abstract class YangTextSchemaSource extends ByteSource implements SchemaSourceRepresentation { +@Beta +public abstract class YangTextSchemaSource extends ByteSource implements YangSchemaSourceRepresentation { private final SourceIdentifier identifier; protected YangTextSchemaSource(final SourceIdentifier identifier) { this.identifier = Preconditions.checkNotNull(identifier); } + public static SourceIdentifier identifierFromFilename(final String name) { + checkArgument(name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION), "Filename %s does not have a .yang extension", + name); + + final String baseName = name.substring(0, name.length() - YangConstants.RFC6020_YANG_FILE_EXTENSION.length()); + final Entry parsed = YangNames.parseFilename(baseName); + return RevisionSourceIdentifier.create(parsed.getKey(), Optional.fromNullable(parsed.getValue())); + } + /** * {@inheritDoc} */ @@ -46,7 +61,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements SchemaS @Override public final String toString() { - return addToStringAttributes(Objects.toStringHelper(this).add("identifier", identifier)).toString(); + return addToStringAttributes(MoreObjects.toStringHelper(this).add("identifier", identifier)).toString(); } /** @@ -81,7 +96,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements SchemaS } @Override - public final ByteSource getDelegate() { + public ByteSource getDelegate() { return delegate; }