@Override protected Object getDefaultValue(final Field field) { final ConfigProperty configProperty = field.getAnnotation(ConfigProperty.class); if (configProperty != null && this.configPropertyName.equals(configProperty.name())) { return configProperty.defaultValue(); } return super.getDefaultValue(field); }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Integer> produceIntegerListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Integer> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Integer.parseInt(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Integer property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Long> produceLongListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Long> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Long.parseLong(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
defaultValue = null; String name = property.name();
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Map<String,String> produceStringStringMapConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] pairs = StringUtils.split(propertyValue, "|"); Map<String,String> map = new LinkedHashMap<>(); if (pairs != null) { for (String pair : pairs) { String[] keyValue = StringUtils.split(pair, ";"); if (keyValue != null && (keyValue.length == 1 || keyValue.length == 2)) { map.put(keyValue[0], keyValue.length == 1 ? "" : keyValue[1]); } else { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Map<String,String> property '" + configProperty.name() + "' pair: " + pair + " of " + propertyValue + " happening in bean " + injectionPoint.getBean()); } } } return map; }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Double> produceDoubleListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Double> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Double.parseDouble(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Double property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
/** * Verifies the name of the {@link ConfigProperty}. If the field type matches and the {@link ConfigProperty}'s name * matches, the method returns <code>true</code>. If the {@link ConfigProperty} has a default value set, the value * will be used in case the injection value is <code>null</code>. */ @Override protected boolean isMatching(final Field field) { if (!this.isAutoConvertible(field, super.getValue()) && !super.isMatching(field)) { return false; } final ConfigProperty configProperty = field.getAnnotation(ConfigProperty.class); if (configProperty != null && this.configPropertyName.equals(configProperty.name())) { return true; } return false; }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public List<Float> produceFloatListConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] values = StringUtils.split(propertyValue, ","); ArrayList<Float> list = new ArrayList<>(); if (values != null) { for (String value : values) { try { list.add(Float.parseFloat(value)); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Float property '" + configProperty.name() + "' value: " + value + " of " + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe); } } } return list; }
private <T> T getPropertyWithException(InjectionPoint ip, Type ipCls) { try { return getUntypedPropertyValue(ip, ipCls); } catch (RuntimeException rte) { ConfigProperty configProperty = getAnnotation(ip, ConfigProperty.class); throw new RuntimeException("Error while converting property '" + configProperty.name() + "' happening in bean " + ip.getBean(), rte); } } }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Long produceLongConfiguration(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } try { return Long.parseLong(configuredValue); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Long property '" + configProperty.name() + "' value: " + configuredValue + " happening in bean " + injectionPoint.getBean() , nfe); } }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Integer produceIntegerConfiguration(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } try { return Integer.parseInt(configuredValue); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Integer property '" + configProperty.name() + "' value: " + configuredValue + " happening in bean " + injectionPoint.getBean() , nfe); } }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Float produceFloatConfiguration(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } try { return Float.parseFloat(configuredValue); } catch (NumberFormatException nfe) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Float property '" + configProperty.name() + "' value: " + configuredValue + " happening in bean " + injectionPoint.getBean() , nfe); } } }
@Produces @Dependent @ConfigProperty(name = "ignored") // we actually don't need the name public Map<String,AuditType> produceStringAuditTypeMapConfiguration(InjectionPoint injectionPoint) { String propertyValue = getStringPropertyValue(injectionPoint); String[] pairs = StringUtils.split(propertyValue, "|"); Map<String,AuditType> map = new LinkedHashMap<>(); if (pairs != null) { for (String pair : pairs) { String[] keyValue = StringUtils.split(pair, ";"); if (keyValue != null && keyValue.length == 2) { map.put(keyValue[0], AuditType.valueOf(keyValue[1])); } else { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); throw new RuntimeException("Error while converting Map<String,AuditType> property '" + configProperty.name() + "' pair: " + pair + " of " + propertyValue + " happening in bean " + injectionPoint.getBean()); } } } return map; } }
/** * <p>Inspects the given InjectionPoint and search for a {@link ConfigProperty} * annotation or an Annotation with a {@link ConfigProperty} meta-Annotation. * The name and defaultValue information will be used to resolve the * configured value.</p> * * @param injectionPoint current injection point * @return the configured value for the given InjectionPoint */ protected String getStringPropertyValue(InjectionPoint injectionPoint) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } String configuredValue; String defaultValue = configProperty.defaultValue(); configuredValue = getPropertyValue(configProperty.name(), defaultValue); return configuredValue; }
protected <T> T getUntypedPropertyValue(InjectionPoint injectionPoint, Type ipCls) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } return readEntry(configProperty.name(), configProperty.defaultValue(), ipCls, configProperty.converter(), configProperty.parameterizedBy(), configProperty.projectStageAware(), configProperty.evaluateVariables()); }
protected <T> T getUntypedPropertyValue(InjectionPoint injectionPoint, Type ipCls) { ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class); if (configProperty == null) { throw new IllegalStateException("producer method called without @ConfigProperty being present!"); } return readEntry(configProperty.name(), configProperty.defaultValue(), ipCls, configProperty.converter(), configProperty.parameterizedBy(), configProperty.projectStageAware(), configProperty.evaluateVariables()); }
prefix + annotation.name(), list || set ? ConfigProperty.NULL : defaultValue, returnType, converter, annotation.parameterizedBy(), annotation.projectStageAware(), annotation.evaluateVariables());