@@ -50,81 +50,114 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties {
50
50
51
51
private static final String OTEL_INSTRUMENTATION_PREFIX = "otel.instrumentation." ;
52
52
53
+ private final PropertyTranslator translator ;
53
54
@ Nullable private final DeclarativeConfigProperties baseNode ;
54
- private final Map <String , String > translationMap ;
55
55
56
56
static DeclarativeConfigPropertiesBridge fromInstrumentationConfig (
57
- @ Nullable DeclarativeConfigProperties instrumentationConfig ,
58
- Map <String , String > translationMap ) {
57
+ @ Nullable DeclarativeConfigProperties instrumentationConfig , PropertyTranslator translator ) {
59
58
if (instrumentationConfig == null ) {
60
59
instrumentationConfig = DeclarativeConfigProperties .empty ();
61
60
}
62
61
return new DeclarativeConfigPropertiesBridge (
63
- instrumentationConfig .getStructured ("java" , empty ()), translationMap );
62
+ instrumentationConfig .getStructured ("java" , empty ()), translator );
64
63
}
65
64
66
65
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 );
69
68
}
70
69
71
70
private DeclarativeConfigPropertiesBridge (
72
- @ Nullable DeclarativeConfigProperties baseNode , Map < String , String > translationMap ) {
71
+ @ Nullable DeclarativeConfigProperties baseNode , PropertyTranslator translator ) {
73
72
this .baseNode = baseNode ;
74
- this .translationMap = translationMap ;
73
+ this .translator = translator ;
75
74
}
76
75
77
76
@ Nullable
78
77
@ Override
79
78
public String getString (String propertyName ) {
79
+ Object value = translator .get (propertyName );
80
+ if (value != null ) {
81
+ return value .toString ();
82
+ }
80
83
return getPropertyValue (propertyName , DeclarativeConfigProperties ::getString );
81
84
}
82
85
83
86
@ Nullable
84
87
@ Override
85
88
public Boolean getBoolean (String propertyName ) {
89
+ Object value = translator .get (propertyName );
90
+ if (value != null ) {
91
+ return (Boolean ) value ;
92
+ }
86
93
return getPropertyValue (propertyName , DeclarativeConfigProperties ::getBoolean );
87
94
}
88
95
89
96
@ Nullable
90
97
@ Override
91
98
public Integer getInt (String propertyName ) {
99
+ Object value = translator .get (propertyName );
100
+ if (value != null ) {
101
+ return (Integer ) value ;
102
+ }
92
103
return getPropertyValue (propertyName , DeclarativeConfigProperties ::getInt );
93
104
}
94
105
95
106
@ Nullable
96
107
@ Override
97
108
public Long getLong (String propertyName ) {
109
+ Object value = translator .get (propertyName );
110
+ if (value != null ) {
111
+ return (Long ) value ;
112
+ }
98
113
return getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
99
114
}
100
115
101
116
@ Nullable
102
117
@ Override
103
118
public Double getDouble (String propertyName ) {
119
+ Object value = translator .get (propertyName );
120
+ if (value != null ) {
121
+ return (Double ) value ;
122
+ }
104
123
return getPropertyValue (propertyName , DeclarativeConfigProperties ::getDouble );
105
124
}
106
125
107
126
@ Nullable
108
127
@ Override
109
128
public Duration getDuration (String propertyName ) {
129
+ Object value = translator .get (propertyName );
130
+ if (value != null ) {
131
+ return (Duration ) value ;
132
+ }
110
133
Long millis = getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
111
134
if (millis == null ) {
112
135
return null ;
113
136
}
114
137
return Duration .ofMillis (millis );
115
138
}
116
139
140
+ @ SuppressWarnings ("unchecked" )
117
141
@ Override
118
142
public List <String > getList (String propertyName ) {
143
+ Object value = translator .get (propertyName );
144
+ if (value != null ) {
145
+ return (List <String >) value ;
146
+ }
119
147
List <String > propertyValue =
120
148
getPropertyValue (
121
149
propertyName ,
122
150
(properties , lastPart ) -> properties .getScalarList (lastPart , String .class ));
123
151
return propertyValue == null ? Collections .emptyList () : propertyValue ;
124
152
}
125
153
154
+ @ SuppressWarnings ("unchecked" )
126
155
@ Override
127
156
public Map <String , String > getMap (String propertyName ) {
157
+ Object fixed = translator .get (propertyName );
158
+ if (fixed != null ) {
159
+ return (Map <String , String >) fixed ;
160
+ }
128
161
DeclarativeConfigProperties propertyValue =
129
162
getPropertyValue (propertyName , DeclarativeConfigProperties ::getStructured );
130
163
if (propertyValue == null ) {
@@ -151,7 +184,7 @@ private <T> T getPropertyValue(
151
184
return null ;
152
185
}
153
186
154
- String [] segments = getSegments (translate (property ));
187
+ String [] segments = getSegments (translator . translateProperty (property ));
155
188
if (segments .length == 0 ) {
156
189
return null ;
157
190
}
@@ -168,21 +201,12 @@ private <T> T getPropertyValue(
168
201
return extractor .apply (target , lastPart );
169
202
}
170
203
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
-
180
204
private static String [] getSegments (String property ) {
181
205
if (property .startsWith (OTEL_INSTRUMENTATION_PREFIX )) {
182
206
property = property .substring (OTEL_INSTRUMENTATION_PREFIX .length ());
183
207
}
184
208
// Split the remainder of the property on "."
185
- return property .split ("\\ ." );
209
+ return property .replace ( '-' , '_' ). split ("\\ ." );
186
210
}
187
211
188
212
static String yamlPath (String property ) {
0 commit comments