@@ -50,81 +50,114 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties {
5050
5151 private static final String OTEL_INSTRUMENTATION_PREFIX = "otel.instrumentation." ;
5252
53+ private final PropertyTranslator translator ;
5354 @ Nullable private final DeclarativeConfigProperties baseNode ;
54- private final Map <String , String > translationMap ;
5555
5656 static DeclarativeConfigPropertiesBridge fromInstrumentationConfig (
57- @ Nullable DeclarativeConfigProperties instrumentationConfig ,
58- Map <String , String > translationMap ) {
57+ @ Nullable DeclarativeConfigProperties instrumentationConfig , PropertyTranslator translator ) {
5958 if (instrumentationConfig == null ) {
6059 instrumentationConfig = DeclarativeConfigProperties .empty ();
6160 }
6261 return new DeclarativeConfigPropertiesBridge (
63- instrumentationConfig .getStructured ("java" , empty ()), translationMap );
62+ instrumentationConfig .getStructured ("java" , empty ()), translator );
6463 }
6564
6665 static DeclarativeConfigPropertiesBridge create (
67- @ Nullable DeclarativeConfigProperties node , Map < String , String > translationMap ) {
68- return new DeclarativeConfigPropertiesBridge (node , translationMap );
66+ @ Nullable DeclarativeConfigProperties node , PropertyTranslator translator ) {
67+ return new DeclarativeConfigPropertiesBridge (node , translator );
6968 }
7069
7170 private DeclarativeConfigPropertiesBridge (
72- @ Nullable DeclarativeConfigProperties baseNode , Map < String , String > translationMap ) {
71+ @ Nullable DeclarativeConfigProperties baseNode , PropertyTranslator translator ) {
7372 this .baseNode = baseNode ;
74- this .translationMap = translationMap ;
73+ this .translator = translator ;
7574 }
7675
7776 @ Nullable
7877 @ Override
7978 public String getString (String propertyName ) {
79+ Object value = translator .get (propertyName );
80+ if (value != null ) {
81+ return value .toString ();
82+ }
8083 return getPropertyValue (propertyName , DeclarativeConfigProperties ::getString );
8184 }
8285
8386 @ Nullable
8487 @ Override
8588 public Boolean getBoolean (String propertyName ) {
89+ Object value = translator .get (propertyName );
90+ if (value != null ) {
91+ return (Boolean ) value ;
92+ }
8693 return getPropertyValue (propertyName , DeclarativeConfigProperties ::getBoolean );
8794 }
8895
8996 @ Nullable
9097 @ Override
9198 public Integer getInt (String propertyName ) {
99+ Object value = translator .get (propertyName );
100+ if (value != null ) {
101+ return (Integer ) value ;
102+ }
92103 return getPropertyValue (propertyName , DeclarativeConfigProperties ::getInt );
93104 }
94105
95106 @ Nullable
96107 @ Override
97108 public Long getLong (String propertyName ) {
109+ Object value = translator .get (propertyName );
110+ if (value != null ) {
111+ return (Long ) value ;
112+ }
98113 return getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
99114 }
100115
101116 @ Nullable
102117 @ Override
103118 public Double getDouble (String propertyName ) {
119+ Object value = translator .get (propertyName );
120+ if (value != null ) {
121+ return (Double ) value ;
122+ }
104123 return getPropertyValue (propertyName , DeclarativeConfigProperties ::getDouble );
105124 }
106125
107126 @ Nullable
108127 @ Override
109128 public Duration getDuration (String propertyName ) {
129+ Object value = translator .get (propertyName );
130+ if (value != null ) {
131+ return (Duration ) value ;
132+ }
110133 Long millis = getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
111134 if (millis == null ) {
112135 return null ;
113136 }
114137 return Duration .ofMillis (millis );
115138 }
116139
140+ @ SuppressWarnings ("unchecked" )
117141 @ Override
118142 public List <String > getList (String propertyName ) {
143+ Object value = translator .get (propertyName );
144+ if (value != null ) {
145+ return (List <String >) value ;
146+ }
119147 List <String > propertyValue =
120148 getPropertyValue (
121149 propertyName ,
122150 (properties , lastPart ) -> properties .getScalarList (lastPart , String .class ));
123151 return propertyValue == null ? Collections .emptyList () : propertyValue ;
124152 }
125153
154+ @ SuppressWarnings ("unchecked" )
126155 @ Override
127156 public Map <String , String > getMap (String propertyName ) {
157+ Object fixed = translator .get (propertyName );
158+ if (fixed != null ) {
159+ return (Map <String , String >) fixed ;
160+ }
128161 DeclarativeConfigProperties propertyValue =
129162 getPropertyValue (propertyName , DeclarativeConfigProperties ::getStructured );
130163 if (propertyValue == null ) {
@@ -151,7 +184,7 @@ private <T> T getPropertyValue(
151184 return null ;
152185 }
153186
154- String [] segments = getSegments (translate (property ));
187+ String [] segments = getSegments (translator . translateProperty (property ));
155188 if (segments .length == 0 ) {
156189 return null ;
157190 }
@@ -168,21 +201,12 @@ private <T> T getPropertyValue(
168201 return extractor .apply (target , lastPart );
169202 }
170203
171- private String translate (String property ) {
172- for (Map .Entry <String , String > entry : translationMap .entrySet ()) {
173- if (property .startsWith (entry .getKey ())) {
174- return entry .getValue () + property .substring (entry .getKey ().length ());
175- }
176- }
177- return property ;
178- }
179-
180204 private static String [] getSegments (String property ) {
181205 if (property .startsWith (OTEL_INSTRUMENTATION_PREFIX )) {
182206 property = property .substring (OTEL_INSTRUMENTATION_PREFIX .length ());
183207 }
184208 // Split the remainder of the property on "."
185- return property .split ("\\ ." );
209+ return property .replace ( '-' , '_' ). split ("\\ ." );
186210 }
187211
188212 static String yamlPath (String property ) {
0 commit comments