Java Code Examples for io.quarkus.runtime.annotations.ConfigItem#name()
The following examples show how to use
io.quarkus.runtime.annotations.ConfigItem#name() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassDefinition.java From quarkus with Apache License 2.0 | 5 votes |
LeafMember(final ClassDefinition classDefinition, final Field field) { this.classDefinition = Assert.checkNotNullParam("classDefinition", classDefinition); this.field = Assert.checkNotNullParam("field", field); final Class<?> declaringClass = field.getDeclaringClass(); final Class<?> configurationClass = classDefinition.configurationClass; if (declaringClass != configurationClass) { throw new IllegalArgumentException( "Member declaring " + declaringClass + " does not match configuration " + configurationClass); } descriptor = FieldDescriptor.of(field); final ConfigItem configItem = field.getAnnotation(ConfigItem.class); String propertyName = ConfigItem.HYPHENATED_ELEMENT_NAME; if (configItem != null) { propertyName = configItem.name(); if (propertyName.isEmpty()) { throw reportError(field, "Invalid empty property name"); } } if (propertyName.equals(ConfigItem.HYPHENATED_ELEMENT_NAME)) { this.propertyName = StringUtil.hyphenate(field.getName()); } else if (propertyName.equals(ConfigItem.ELEMENT_NAME)) { this.propertyName = field.getName(); } else if (propertyName.equals(ConfigItem.PARENT)) { this.propertyName = ""; } else { this.propertyName = propertyName; } }
Example 2
Source File: ConfigInstantiator.java From quarkus with Apache License 2.0 | 4 votes |
private static void handleObject(String prefix, Object o, SmallRyeConfig config) { try { final Class cls = o.getClass(); if (!isClassNameSuffixSupported(o)) { return; } for (Field field : cls.getDeclaredFields()) { if (Modifier.isFinal(field.getModifiers())) { continue; } field.setAccessible(true); ConfigItem configItem = field.getDeclaredAnnotation(ConfigItem.class); final Class<?> fieldClass = field.getType(); if (configItem == null || fieldClass.isAnnotationPresent(ConfigGroup.class)) { Constructor<?> constructor = fieldClass.getConstructor(); constructor.setAccessible(true); Object newInstance = constructor.newInstance(); field.set(o, newInstance); handleObject(prefix + "." + dashify(field.getName()), newInstance, config); } else if (fieldClass == Map.class) { //TODO: FIXME, this cannot handle Map yet field.set(o, new HashMap<>()); } else { String name = configItem.name(); if (name.equals(ConfigItem.HYPHENATED_ELEMENT_NAME)) { name = dashify(field.getName()); } else if (name.equals(ConfigItem.ELEMENT_NAME)) { name = field.getName(); } String fullName = prefix + "." + name; final Type genericType = field.getGenericType(); final Converter<?> conv = getConverterFor(genericType); try { Optional<?> value = config.getOptionalValue(fullName, conv); if (value.isPresent()) { field.set(o, value.get()); } else if (!configItem.defaultValue().equals(ConfigItem.NO_DEFAULT)) { //the runtime config source handles default automatically //however this may not have actually been installed depending on where the failure occured field.set(o, conv.convert(configItem.defaultValue())); } } catch (NoSuchElementException ignored) { } } } } catch (Exception e) { throw new RuntimeException(e); } }