-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathConfigBuilder.java
More file actions
118 lines (110 loc) · 4.25 KB
/
ConfigBuilder.java
File metadata and controls
118 lines (110 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
*******************************************************************************
* Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* 2016-07-20 - Romain Manni-Bucau
* Initial ConfigBuilder PR 0945b23cbf9dadb75fb9
* 2016-07-17 - Mark Struberg
* Merged and JavaDoc c8525998a43fe798f367
* 2016-11-14 - Emily Jiang / IBM
* API improvements + JavaDoc f53258b8eca1253fee52
*
*******************************************************************************/
package jakarta.config.spi;
import jakarta.config.Config;
/**
* Builder for manually creating an instance of a {@code Config}.
*
* @see ConfigProviderResolver#getBuilder()
*
* @author <a href="mailto:rmannibucau@apache.org">Romain Manni-Bucau</a>
* @author <a href="mailto:struberg@apache.org">Mark Struberg</a>
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*/
public interface ConfigBuilder {
/**
* Add the default config sources appearing on the builder's classpath
* including:
* <ol>
* <li>System properties</li>
* <li>Environment properties</li>
* <li>/META-INF/javaconfig.properties</li>
* </ol>
*
* @return the ConfigBuilder with the default config sources
*/
ConfigBuilder addDefaultSources();
/**
* Add the config sources appearing to be loaded via service loader pattern
*
* @return the ConfigBuilder with the autodiscovered config sources
*/
ConfigBuilder addDiscoveredSources();
/**
* Add the converters to be loaded via service loader pattern
*
* @return the ConfigBuilder with the auto-discovered converters
*/
ConfigBuilder addDiscoveredConverters();
/**
* Return the ConfigBuilder for a given classloader
*
* @param loader the specified classloader
* @return the ConfigureBuilder for the given classloader
*/
ConfigBuilder forClassLoader(ClassLoader loader);
/**
* Add the specified {@link ConfigSource}.
*
* Attention: If you register the same {@code ConfigSource} instance within multiple {@link Config} then non-portable behaviour results.
*
* @param sources the config sources
* @return the ConfigBuilder with the configured sources
*/
ConfigBuilder withSources(ConfigSource... sources);
/**
* Add the specified {@link Converter}.
* This method uses reflection to determine what type the converter is for.
* When using lambda expressions for custom converters you should use
* {@link #withConverter(Class, int, Converter)} and pass the target type explicitly
* as lambda expressions do not offer enough type information to the reflection API.
*
* @param converters the converters
* @return the ConfigBuilder with the added converters
*/
ConfigBuilder withConverters(Converter<?>... converters);
/**
* Add the specified {@link Converter} for the given type.
* This method does not rely on reflection to determine what type the converter is for
* therefore also lambda expressions can be used.
*
* @param type the Class of type to convert
* @param priority the priority of the converter (custom converters have a default priority of 100).
* @param converter the converter (can not be {@code null})
* @param <T> the type to convert
* @return the ConfigBuilder with the added converters
*/
<T> ConfigBuilder withConverter(Class<T> type, int priority, Converter<T> converter);
/**
* Build the {@link Config} object.
*
* @return the Config object
*/
Config build();
}