-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom validator annotations at the nested element method (#1004
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
implementation/src/main/java/io/smallrye/config/SmallRyeConfigSourceInterceptors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.smallrye.config; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class SmallRyeConfigSourceInterceptors implements ConfigSourceInterceptorContext { | ||
private final List<ConfigSourceInterceptor> interceptors; | ||
|
||
private int current = 0; | ||
|
||
public SmallRyeConfigSourceInterceptors(final List<ConfigSourceInterceptor> interceptors) { | ||
this.interceptors = interceptors; | ||
} | ||
|
||
ConfigValue getValue(final String name) { | ||
ConfigValue configValue = null; | ||
for (int i = 0; i < interceptors.size(); i++) { | ||
ConfigSourceInterceptor interceptor = interceptors.get(i); | ||
configValue = interceptor.getValue(this, name); | ||
} | ||
return configValue; | ||
} | ||
|
||
@Override | ||
public ConfigValue proceed(final String name) { | ||
ConfigSourceInterceptorContext context = new ConfigSourceInterceptorContext() { | ||
int position = 0; | ||
|
||
@Override | ||
public ConfigValue proceed(final String name) { | ||
return interceptors.get(position++).getValue(this, name); | ||
} | ||
|
||
@Override | ||
public Iterator<String> iterateNames() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterator<ConfigValue> iterateValues() { | ||
return null; | ||
} | ||
}; | ||
|
||
return context.proceed(name); | ||
} | ||
|
||
@Override | ||
public Iterator<String> iterateNames() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterator<ConfigValue> iterateValues() { | ||
return null; | ||
} | ||
|
||
public static void main(String[] args) { | ||
SmallRyeConfigSourceInterceptors interceptors = new SmallRyeConfigSourceInterceptors( | ||
List.of(new ConfigSourceInterceptor() { | ||
@Override | ||
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { | ||
return context.proceed(name); | ||
} | ||
}, new ConfigSourceInterceptor() { | ||
@Override | ||
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { | ||
return context.proceed(name); | ||
} | ||
}, new ConfigSourceInterceptor() { | ||
@Override | ||
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) { | ||
throw new RuntimeException(); | ||
} | ||
})); | ||
|
||
interceptors.getValue("foo.bar"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters