001package com.typesafe.config;
002
003import java.net.URL;
004
005import com.typesafe.config.impl.ConfigImpl;
006
007/**
008 * This class contains some static factory methods for building a {@link
009 * ConfigOrigin}. {@code ConfigOrigin}s are automatically created when you
010 * call other API methods to get a {@code ConfigValue} or {@code Config}.
011 * But you can also set the origin of an existing {@code ConfigValue}, using
012 * {@link ConfigValue#withOrigin(ConfigOrigin)}.
013 *
014 * @since 1.3.0
015 */
016public final class ConfigOriginFactory {
017    private ConfigOriginFactory() {
018    }
019
020    /**
021     * Returns the default origin for values when no other information is
022     * provided. This is the origin used in {@link ConfigValueFactory
023     * #fromAnyRef(Object)}.
024     *
025     * @since 1.3.0
026     *
027     * @return the default origin
028     */
029    public static ConfigOrigin newSimple() {
030        return newSimple(null);
031    }
032
033    /**
034     * Returns an origin with the given description.
035     *
036     *  @since 1.3.0
037     *
038     * @param description brief description of what the origin is
039     * @return a new origin
040     */
041    public static ConfigOrigin newSimple(String description) {
042        return ConfigImpl.newSimpleOrigin(description);
043    }
044
045    /**
046     * Creates a file origin with the given filename.
047     *
048     * @since 1.3.0
049     *
050     * @param filename the filename of this origin
051     * @return a new origin
052     */
053    public static ConfigOrigin newFile(String filename) {
054        return ConfigImpl.newFileOrigin(filename);
055    }
056
057    /**
058     * Creates a url origin with the given URL object.
059     *
060     * @since 1.3.0
061     *
062     * @param url the url of this origin
063     * @return a new origin
064     */
065    public static ConfigOrigin newURL(URL url) {
066        return ConfigImpl.newURLOrigin(url);
067    }
068}