+ this.identifier = requireNonNull(identifier);
+ }
+
+ public static @NonNull SourceIdentifier identifierFromFilename(final String name) {
+ checkArgument(name.endsWith(RFC6020_YANG_FILE_EXTENSION), "Filename %s does not end with '%s'",
+ RFC6020_YANG_FILE_EXTENSION, name);
+
+ final String baseName = name.substring(0, name.length() - RFC6020_YANG_FILE_EXTENSION.length());
+ final Entry<String, String> parsed = parseFilename(baseName);
+ return RevisionSourceIdentifier.create(parsed.getKey(), Revision.ofNullable(parsed.getValue()));
+ }
+
+ /**
+ * Create a new YangTextSchemaSource with a specific source identifier and backed
+ * by ByteSource, which provides the actual InputStreams.
+ *
+ * @param identifier SourceIdentifier of the resulting schema source
+ * @param delegate Backing ByteSource instance
+ * @return A new YangTextSchemaSource
+ */
+ public static @NonNull YangTextSchemaSource delegateForByteSource(final SourceIdentifier identifier,
+ final ByteSource delegate) {
+ return new DelegatedYangTextSchemaSource(identifier, delegate);
+ }
+
+ /**
+ * Create a new YangTextSchemaSource with {@link SourceIdentifier} derived from a supplied filename and backed
+ * by ByteSource, which provides the actual InputStreams.
+ *
+ * @param fileName File name
+ * @param delegate Backing ByteSource instance
+ * @return A new YangTextSchemaSource
+ * @throws IllegalArgumentException if the file name has invalid format
+ */
+ public static @NonNull YangTextSchemaSource delegateForByteSource(final String fileName,
+ final ByteSource delegate) {
+ return new DelegatedYangTextSchemaSource(identifierFromFilename(fileName), delegate);
+ }
+
+ /**
+ * Create a new YangTextSchemaSource backed by a {@link File} with {@link SourceIdentifier} derived from the file
+ * name.
+ *
+ * @param file Backing File
+ * @return A new YangTextSchemaSource
+ * @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 forFile(final File file) {
+ return forFile(file, identifierFromFilename(file.getName()));
+ }
+
+ /**
+ * Create a new YangTextSchemaSource backed by a {@link File} and specified {@link SourceIdentifier}.
+ *
+ * @param file Backing File
+ * @param identifier source identifier
+ * @return A new YangTextSchemaSource
+ * @throws IllegalArgumentException if the file name has invalid format or if the supplied File is not a file
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static @NonNull YangTextSchemaSource forFile(final File file, final SourceIdentifier identifier) {
+ checkArgument(file.isFile(), "Supplied file %s is not a file", file);
+ return new YangTextFileSchemaSource(identifier, file);