mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 23:01:05 +08:00
parent
79fc367685
commit
41b6193261
@ -4,28 +4,34 @@ import com.typesafe.config.impl.ConfigBeanImpl;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for automatically creating a Java class from a {@link Config}.
|
* Factory for automatically creating a Java class from a {@link Config}.
|
||||||
|
* See {@link #create(Config,Class)}.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* @since 1.3.0
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* Config configSource = ConfigFactory.load().getConfig("foo");
|
|
||||||
* FooConfig config = ConfigBeanFactory.create(configSource, FooConfig.class);
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* The Java class should follow JavaBean conventions. Field types
|
|
||||||
* can be any of the types you can normally get from a {@link
|
|
||||||
* Config}, including <code>java.time.Duration</code> or {@link
|
|
||||||
* ConfigMemorySize}. Fields may also be another JavaBean-style
|
|
||||||
* class.
|
|
||||||
*
|
|
||||||
* Fields are mapped to config by converting the config key to
|
|
||||||
* camel case. So the key <code>foo-bar</code> becomes JavaBean
|
|
||||||
* setter <code>setFooBar</code>.
|
|
||||||
*/
|
*/
|
||||||
public class ConfigBeanFactory {
|
public class ConfigBeanFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of a class, initializing its fields from a {@link Config}.
|
* Creates an instance of a class, initializing its fields from a {@link Config}.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* Config configSource = ConfigFactory.load().getConfig("foo");
|
||||||
|
* FooConfig config = ConfigBeanFactory.create(configSource, FooConfig.class);
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* The Java class should follow JavaBean conventions. Field types
|
||||||
|
* can be any of the types you can normally get from a {@link
|
||||||
|
* Config}, including <code>java.time.Duration</code> or {@link
|
||||||
|
* ConfigMemorySize}. Fields may also be another JavaBean-style
|
||||||
|
* class.
|
||||||
|
*
|
||||||
|
* Fields are mapped to config by converting the config key to
|
||||||
|
* camel case. So the key <code>foo-bar</code> becomes JavaBean
|
||||||
|
* setter <code>setFooBar</code>.
|
||||||
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param config source of config information
|
* @param config source of config information
|
||||||
* @param clazz class to be instantiated
|
* @param clazz class to be instantiated
|
||||||
* @param <T> the type of the class to be instantiated
|
* @param <T> the type of the class to be instantiated
|
||||||
|
@ -394,6 +394,7 @@ public abstract class ConfigException extends RuntimeException implements Serial
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Some problem with a JavaBean we are trying to initialize.
|
* Some problem with a JavaBean we are trying to initialize.
|
||||||
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
public static class BadBean extends BugOrBroken {
|
public static class BadBean extends BugOrBroken {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
@ -639,7 +639,7 @@ public final class ConfigFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link parseProperties(Properties, ConfigParseOptions)} but uses default
|
* Like {@link #parseProperties(Properties, ConfigParseOptions)} but uses default
|
||||||
* parse options.
|
* parse options.
|
||||||
* @param properties
|
* @param properties
|
||||||
* a Java Properties object
|
* a Java Properties object
|
||||||
|
@ -129,7 +129,7 @@ public interface ConfigObject extends ConfigValue, Map<String, ConfigValue> {
|
|||||||
* @return the new instance with the new map entry
|
* @return the new instance with the new map entry
|
||||||
*/
|
*/
|
||||||
ConfigObject withValue(String key, ConfigValue value);
|
ConfigObject withValue(String key, ConfigValue value);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ConfigObject withOrigin(ConfigOrigin origin);
|
ConfigObject withOrigin(ConfigOrigin origin);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,8 @@ public interface ConfigOrigin {
|
|||||||
* Note that when the given comments are equal to the comments on this object,
|
* Note that when the given comments are equal to the comments on this object,
|
||||||
* a new instance may not be created and {@code this} is returned directly.
|
* a new instance may not be created and {@code this} is returned directly.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param comments the comments used on the returned origin
|
* @param comments the comments used on the returned origin
|
||||||
* @return the ConfigOrigin with the given comments
|
* @return the ConfigOrigin with the given comments
|
||||||
*/
|
*/
|
||||||
@ -107,6 +109,8 @@ public interface ConfigOrigin {
|
|||||||
* object, a new instance may not be created and {@code this} is returned
|
* object, a new instance may not be created and {@code this} is returned
|
||||||
* directly.
|
* directly.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param lineNumber the new line number
|
* @param lineNumber the new line number
|
||||||
* @return the created ConfigOrigin
|
* @return the created ConfigOrigin
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,7 @@ import com.typesafe.config.impl.ConfigImpl;
|
|||||||
* But you can also set the origin of an existing {@code ConfigValue}, using
|
* But you can also set the origin of an existing {@code ConfigValue}, using
|
||||||
* {@link ConfigValue#withOrigin(ConfigOrigin)}.
|
* {@link ConfigValue#withOrigin(ConfigOrigin)}.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
public final class ConfigOriginFactory {
|
public final class ConfigOriginFactory {
|
||||||
private ConfigOriginFactory() {
|
private ConfigOriginFactory() {
|
||||||
@ -21,6 +22,8 @@ public final class ConfigOriginFactory {
|
|||||||
* provided. This is the origin used in {@link ConfigValueFactory
|
* provided. This is the origin used in {@link ConfigValueFactory
|
||||||
* #fromAnyRef(Object)}.
|
* #fromAnyRef(Object)}.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @return the default origin
|
* @return the default origin
|
||||||
*/
|
*/
|
||||||
public static ConfigOrigin newSimple() {
|
public static ConfigOrigin newSimple() {
|
||||||
@ -30,6 +33,8 @@ public final class ConfigOriginFactory {
|
|||||||
/**
|
/**
|
||||||
* Returns an origin with the given description.
|
* Returns an origin with the given description.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param description brief description of what the origin is
|
* @param description brief description of what the origin is
|
||||||
* @return a new origin
|
* @return a new origin
|
||||||
*/
|
*/
|
||||||
@ -40,6 +45,8 @@ public final class ConfigOriginFactory {
|
|||||||
/**
|
/**
|
||||||
* Creates a file origin with the given filename.
|
* Creates a file origin with the given filename.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param filename the filename of this origin
|
* @param filename the filename of this origin
|
||||||
* @return a new origin
|
* @return a new origin
|
||||||
*/
|
*/
|
||||||
@ -50,6 +57,8 @@ public final class ConfigOriginFactory {
|
|||||||
/**
|
/**
|
||||||
* Creates a url origin with the given URL object.
|
* Creates a url origin with the given URL object.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param url the url of this origin
|
* @param url the url of this origin
|
||||||
* @return a new origin
|
* @return a new origin
|
||||||
*/
|
*/
|
||||||
|
@ -107,12 +107,14 @@ public interface ConfigValue extends ConfigMergeable {
|
|||||||
* @return a {@code Config} instance containing this value at the given key.
|
* @return a {@code Config} instance containing this value at the given key.
|
||||||
*/
|
*/
|
||||||
Config atKey(String key);
|
Config atKey(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@code ConfigValue} based on this one, but with the given
|
* Returns a {@code ConfigValue} based on this one, but with the given
|
||||||
* origin. This is useful when you are parsing a new format of file or setting
|
* origin. This is useful when you are parsing a new format of file or setting
|
||||||
* comments for a single ConfigValue.
|
* comments for a single ConfigValue.
|
||||||
*
|
*
|
||||||
|
* @since 1.3.0
|
||||||
|
*
|
||||||
* @param origin the origin set on the returned value
|
* @param origin the origin set on the returned value
|
||||||
* @return the new ConfigValue with the given origin
|
* @return the new ConfigValue with the given origin
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user