Skip to content

Commit

Permalink
@ConfigMapping specification
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Apr 4, 2024
1 parent 5032abb commit 2453402
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/jakarta/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public interface Config {
*
* @param path a configuration path
* @return a new instance of the {@link Config} class with a new <em>configuration path</em>
*
* @see ConfigMapping#path() Configuration#path
*/
Config path(String path);

Expand Down
22 changes: 22 additions & 0 deletions api/src/main/java/jakarta/config/ConfigDefault.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package jakarta.config;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specify the default value of a configuration member.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface ConfigDefault {
/**
* The default value of the member.
*
* @return the default value as a string
*/
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Configuration {
public @interface ConfigMapping {

/**
* The <em>configuration path</em> identifies where the configuration relevant for the annotated configuration class is found
Expand Down
22 changes: 22 additions & 0 deletions api/src/main/java/jakarta/config/ConfigName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package jakarta.config;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Override the configuration member name.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD })
public @interface ConfigName {
/**
* The name of the configuration member name. Must not be empty.
*
* @return the configuration member name
*/
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type name and the member name of the nested type
- A member with a `Collection` or `Array` type requires the configuration name to be in its indexed format
- Each configuration name, plus its index maps the configuration value to the corresponding `Collection` or
`Array` element in the object type
- TODO - Define how to represent the indexed format. A well accepted representation is the presence of square brackets
with the collection / array index inside after the name.
- The index specified in the configuration name is used to order the element in the `Collection` or `Array`. Missing
elements or gaps are removed.
- The index must be part of the configuration path, by appending the index between square brackets to the
`Collection` or `Array` member
- The index specified in the configuration name is used to order the element in the `Collection` or `Array`
- Missing elements or gaps are removed

=== Maps

Expand All @@ -43,7 +43,7 @@ the configuration value as the Map entry value
=== Optionals

- A mapping can wrap any complex type with an `Optional`
- `Optional` mappings do not require the corresponding configuration path and value to be present
- `Optional` mappings do not require the configuration path and value to be present

== Override Conventions

Expand Down Expand Up @@ -106,7 +106,7 @@ class Service {
Config config;
void service() {
Server server = config.getMapping(Server.class);
Server server = config.load(Server.class);
}
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package jakarta.config.tck.common;

import jakarta.config.Configuration;
import jakarta.config.ConfigMapping;

@Configuration(path = "my.configuration")
@ConfigMapping(path = "my.configuration")
public interface AnyConfiguration {
String key();
}
4 changes: 2 additions & 2 deletions tck/src/main/java/jakarta/config/tck/common/My.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package jakarta.config.tck.common;

import jakarta.config.Configuration;
import jakarta.config.ConfigMapping;

@Configuration(path="my")
@ConfigMapping(path="my")
public interface My {
String username();
String password();
Expand Down
4 changes: 2 additions & 2 deletions tck/src/main/java/jakarta/config/tck/common/Other.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package jakarta.config.tck.common;

import jakarta.config.Configuration;
import jakarta.config.ConfigMapping;

@Configuration(path = "other")
@ConfigMapping(path = "other")
public interface Other {
AnyConfiguration configuration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package jakarta.config.tck.common;

import jakarta.config.Configuration;
import jakarta.config.ConfigMapping;

@Configuration
@ConfigMapping
public interface TopLevelConfig {
My my();
Other other();
Expand Down

0 comments on commit 2453402

Please sign in to comment.