mirror of
https://github.com/lightbend/config.git
synced 2025-03-23 07:40:25 +08:00
change ConfigParseable.url to ConfigParseable.origin
This commit is contained in:
parent
cb5017af8b
commit
680a295add
@ -3,7 +3,6 @@
|
||||
*/
|
||||
package com.typesafe.config;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* An opaque handle to something that can be parsed, obtained from
|
||||
@ -21,7 +20,7 @@ public interface ConfigParseable {
|
||||
* Parse whatever it is. The options should come from
|
||||
* {@link ConfigParseable#options options()} but you could tweak them if you
|
||||
* like.
|
||||
*
|
||||
*
|
||||
* @param options
|
||||
* parse options, should be based on the ones from
|
||||
* {@link ConfigParseable#options options()}
|
||||
@ -29,10 +28,10 @@ public interface ConfigParseable {
|
||||
ConfigObject parse(ConfigParseOptions options);
|
||||
|
||||
/**
|
||||
* Possibly return a URL representing the resource; this may return null if
|
||||
* the resource has no meaningful URL representation.
|
||||
* Returns a {@link ConfigOrigin} describing the origin of the parseable
|
||||
* item.
|
||||
*/
|
||||
URL url();
|
||||
ConfigOrigin origin();
|
||||
|
||||
/**
|
||||
* Get the initial options, which can be modified then passed to parse().
|
||||
|
@ -40,6 +40,7 @@ import com.typesafe.config.ConfigValue;
|
||||
public abstract class Parseable implements ConfigParseable {
|
||||
private ConfigIncludeContext includeContext;
|
||||
private ConfigParseOptions initialOptions;
|
||||
private ConfigOrigin initialOrigin;
|
||||
|
||||
protected Parseable() {
|
||||
|
||||
@ -69,6 +70,11 @@ public abstract class Parseable implements ConfigParseable {
|
||||
return Parseable.this.relativeTo(filename);
|
||||
}
|
||||
};
|
||||
|
||||
if (initialOptions.getOriginDescription() != null)
|
||||
initialOrigin = SimpleConfigOrigin.newSimple(initialOptions.getOriginDescription());
|
||||
else
|
||||
initialOrigin = createOrigin();
|
||||
}
|
||||
|
||||
// the general idea is that any work should be in here, not in the
|
||||
@ -118,7 +124,7 @@ public abstract class Parseable implements ConfigParseable {
|
||||
if (options.getOriginDescription() != null)
|
||||
origin = SimpleConfigOrigin.newSimple(options.getOriginDescription());
|
||||
else
|
||||
origin = origin();
|
||||
origin = initialOrigin;
|
||||
return parseValue(origin, options);
|
||||
}
|
||||
|
||||
@ -165,13 +171,13 @@ public abstract class Parseable implements ConfigParseable {
|
||||
return parseValue(options());
|
||||
}
|
||||
|
||||
abstract ConfigOrigin origin();
|
||||
|
||||
@Override
|
||||
public URL url() {
|
||||
return null;
|
||||
public final ConfigOrigin origin() {
|
||||
return initialOrigin;
|
||||
}
|
||||
|
||||
protected abstract ConfigOrigin createOrigin();
|
||||
|
||||
@Override
|
||||
public ConfigParseOptions options() {
|
||||
return initialOptions;
|
||||
@ -255,7 +261,7 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newSimple("Reader");
|
||||
}
|
||||
}
|
||||
@ -282,7 +288,7 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newSimple("String");
|
||||
}
|
||||
}
|
||||
@ -320,15 +326,10 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newURL(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL url() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + input.toExternalForm()
|
||||
@ -372,19 +373,10 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newFile(input.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL url() {
|
||||
try {
|
||||
return input.toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + input.getPath() + ")";
|
||||
@ -483,17 +475,10 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newResource(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL url() {
|
||||
// because we may represent multiple resources, there's nothing
|
||||
// good to return here.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + resource + ","
|
||||
@ -562,15 +547,10 @@ public abstract class Parseable implements ConfigParseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
ConfigOrigin origin() {
|
||||
protected ConfigOrigin createOrigin() {
|
||||
return SimpleConfigOrigin.newSimple("properties");
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL url() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "(" + props.size() + " props)";
|
||||
|
Loading…
Reference in New Issue
Block a user