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}.
|
||||
* See {@link #create(Config,Class)}.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
public class ConfigBeanFactory {
|
||||
|
||||
/**
|
||||
* 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 clazz 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.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static class BadBean extends BugOrBroken {
|
||||
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.
|
||||
* @param properties
|
||||
* a Java Properties object
|
||||
|
@ -90,6 +90,8 @@ public interface ConfigOrigin {
|
||||
* 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.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param comments the comments used on the returned origin
|
||||
* @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
|
||||
* directly.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param lineNumber the new line number
|
||||
* @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
|
||||
* {@link ConfigValue#withOrigin(ConfigOrigin)}.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public final class ConfigOriginFactory {
|
||||
private ConfigOriginFactory() {
|
||||
@ -21,6 +22,8 @@ public final class ConfigOriginFactory {
|
||||
* provided. This is the origin used in {@link ConfigValueFactory
|
||||
* #fromAnyRef(Object)}.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @return the default origin
|
||||
*/
|
||||
public static ConfigOrigin newSimple() {
|
||||
@ -30,6 +33,8 @@ public final class ConfigOriginFactory {
|
||||
/**
|
||||
* Returns an origin with the given description.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param description brief description of what the origin is
|
||||
* @return a new origin
|
||||
*/
|
||||
@ -40,6 +45,8 @@ public final class ConfigOriginFactory {
|
||||
/**
|
||||
* Creates a file origin with the given filename.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param filename the filename of this origin
|
||||
* @return a new origin
|
||||
*/
|
||||
@ -50,6 +57,8 @@ public final class ConfigOriginFactory {
|
||||
/**
|
||||
* Creates a url origin with the given URL object.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param url the url of this origin
|
||||
* @return a new origin
|
||||
*/
|
||||
|
@ -113,6 +113,8 @@ public interface ConfigValue extends ConfigMergeable {
|
||||
* origin. This is useful when you are parsing a new format of file or setting
|
||||
* comments for a single ConfigValue.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param origin the origin set on the returned value
|
||||
* @return the new ConfigValue with the given origin
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user