Class RelaxedPropertySource

java.lang.Object
org.apache.juneau.commons.settings.RelaxedPropertySource
All Implemented Interfaces:
PropertySource

public class RelaxedPropertySource extends Object implements PropertySource
A PropertySource decorator that adds relaxed binding over a delegate source.

When a property lookup misses against the delegate, this source retries with a small set of canonical name variants derived from the requested name, so a single logical key can be supplied in any of the common environment conventions and still resolve. This is the mechanism that lets a Kubernetes-style environment variable such as MY_SECTION_MY_KEY satisfy a lookup for MySection/myKey, or MY_PROP satisfy my.prop / myProp.

Candidate order

The requested name is always tried verbatim first, so exact-match behavior is preserved unchanged (an already-canonical key resolves with no transformation, and a source that defines the literal name wins). Only on a miss are the relaxed variants tried, in this order:

  1. verbatim (the requested name, unchanged);
  2. upper underscore — every run of non-alphanumeric characters (and every lower→upper camel-case boundary) becomes a single _, then the whole thing is upper-cased. This is the dominant env-var form: my.prop/my-prop/myProp/MySection/myKey → MY_PROP / MY_SECTION_MY_KEY;
  3. lower dotted — the same separator collapse but joined with . and lower-cased (MY_PROP → my.prop), so a dotted-property lookup can be satisfied by an env-style key and vice-versa.

Because the boundary between "section" and "key" in a flat relaxed name (e.g. the underscores in MY_SECTION_MY_KEY) is inherently ambiguous, this decorator deliberately works in the lookup-key → candidate-name direction only (the well-defined direction): the caller asks for a known logical key and the decorator generates the environment-convention spellings to probe. It never tries to reverse a flat env name back into a section/key pair.

Usage

// Wrap the system-env source so env vars bind relaxedly. settings = Settings.create().addSource(new RelaxedPropertySource(Settings.SYSTEM_ENV_SOURCE)).build();

Since:
10.0.0