*
* 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.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 javax.annotation.Nonnull;
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}.
*/
@Beta
-public abstract class YangTextSchemaSource extends ByteSource implements SchemaSourceRepresentation {
+public abstract class YangTextSchemaSource extends ByteSource implements YangSchemaSourceRepresentation {
private final SourceIdentifier identifier;
protected YangTextSchemaSource(final SourceIdentifier identifier) {
}
public static SourceIdentifier identifierFromFilename(final String name) {
- checkArgument(name.endsWith(".yang"), "Filename %s does not have a .yang extension", name);
- // FIXME: add revision-awareness
- return SourceIdentifier.create(name.substring(0, name.length() - 5), Optional.<String>absent());
+ 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<String, String> parsed = YangNames.parseFilename(baseName);
+ return RevisionSourceIdentifier.create(parsed.getKey(), Optional.fromNullable(parsed.getValue()));
}
/**
/**
* {@inheritDoc}
*/
+ @Nonnull
@Override
public Class<? extends YangTextSchemaSource> getType() {
return YangTextSchemaSource.class;
}
@Override
- public final ByteSource getDelegate() {
+ public ByteSource getDelegate() {
return delegate;
}