Skip to content

Commit

Permalink
refs: eclipse#70 bring spec up2date with API
Browse files Browse the repository at this point in the history
  • Loading branch information
struberg committed Mar 13, 2019
1 parent fab25d3 commit edfad41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
17 changes: 8 additions & 9 deletions spec/src/main/asciidoc/configaccessor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ This can also be handled via `ConfigAccessor` as shown in the following example:
.Simple example of ConfigAccessor
[source,java]
-----------------------------------------------------------------
String userName = config.access("user.name").getValue();
String userName = config.access("user.name", String.class).build().getValue();
-----------------------------------------------------------------

Additional to this the `ConfigAccessor` also allows for far more complex control over the access to configured values.

The call to `config.access(..)` returns a `ConfigAccessor`.
The call to `config.access(..)` returns a `ConfigAccessor.Builder`.
This is basically a builder which has methods to refine the resolution, including the following:

* `as(Class<N> clazz)` -- defines the return type of the property
* `asList()` -- Declare the ConfigAccessor to return a List of the given Type.
* `evaluateVariables(boolean evaluateVariables)`
* `evaluateVariables(boolean evaluateVariables)` -- Allows variable parts in configured values.
* `useConverter(Converter<T> converter)` -- Defines a specific {@link Converter} to be used instead of applying the default Converter resolving logic.
* `addLookupSuffix(String postfixName)` -- sets a parameter for the resolution of a 'postfix' for the resolution
* `addLookupSuffix(ConfigAccessor)` -- you can also use a `ConfigAccessor` to determine the 'postfix' for the resolution
Expand All @@ -55,11 +53,12 @@ This is basically a builder which has methods to refine the resolution, includin
Config config = ConfigProvider.getConfig();
ConfigAccessor<Integer> dbPortCfg
= config.access("db.port")
.as(Integer.class)
.addLookupSuffix(config.access("project.projectStage").cacheFor(12, TimeUnit.HOURS))
= config.access("db.port", Integer.class)
.addLookupSuffix(config.access("project.projectStage")
.cacheFor(Duration.ofHours(12L))
.addLookupSuffix("database.vendor")
.withDefault(3306);
.withDefault(3306)
.build();
...
Integer port = dbPortCfg.getValue();
-----------------------------------------------------------------
4 changes: 2 additions & 2 deletions spec/src/main/asciidoc/javaconfig-spec.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
//

= Configuration API for Java, v1.0
:authors: Mark Struberg, Emily Jiang, John D. Ament
:authors: Mark Struberg, Emily Jiang, John D. Ament, et al
:email: [email protected], [email protected], [email protected]
:revnumber: 1.0-Draft
:revdate: 2018-07-05
:revdate: 2019-03-13
:revremark: Draft
:version-label!:
:sectanchors:
Expand Down
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/license-alv2.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Status: {revremark}
Release: {revdate}
Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
Copyright (c) 2016-2019 Contributors to the Eclipse Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit edfad41

Please sign in to comment.