in geronimo-microprofile-reporter/src/main/java/org/apache/geronimo/microprofile/reporter/storage/templating/TemplatingEngine.java [299:353]
private Object getVariable(final Object registry, final String name) {
if (registry == null) {
return registry;
}
// map handling
if (Map.class.isInstance(registry)) {
return Map.class.cast(registry).get(name);
}
final Class<?> registryClass = registry.getClass();
// array handling - foo.1.name syntax
if (registryClass.isArray()) {
return Array.get(registry, Integer.parseInt(name));
}
return accessors.computeIfAbsent(new AccessorKey(registryClass, name), key -> {
// try getter
try {
final Method method = key.type
.getMethod("get" + Character.toUpperCase(key.name.charAt(0)) + key.name.substring(1));
if (!method.isAccessible()) {
method.setAccessible(true);
}
return o -> {
try {
return method.invoke(o);
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (final InvocationTargetException e) {
throw new IllegalStateException(e.getTargetException());
}
};
} catch (final NoSuchMethodException e) {
// no-op
}
// try field
try {
final Field field = key.type.getDeclaredField(key.name);
if (!field.isAccessible()) {
field.setAccessible(true);
}
return o -> {
try {
return field.get(o);
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
}
};
} catch (final Exception e) {
// no-op
}
return o -> null;
}).apply(registry);
}