@Override public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { String name = attribute.getName(); MAttribute a = this.attributes.get(name); if(null == a) { throw new AttributeNotFoundException("Attribute '" + name + "' not found in '" + bean.getClass() + "'"); } //todo : convert the value. try{ a.valued().setValue(bean, attribute.getValue()); }catch(ReflectException e) { throw new ReflectionException(e); }catch(Exception e) { throw new MBeanException(e); } }
v.setValue(bean, array); return true; List<String> list = new ArrayList<>(); Collections2.addAll(list, array); v.setValue(bean, list); return true; Set<String> set = new LinkedHashSet<>(); Collections2.addAll(set, array); v.setValue(bean, set); return true; value = JSON.decode(prop, v.getType(), v.getGenericType()); v.setValue(bean, value); } catch (Exception e) { throw new BeanCreationException("Error configure property '" + bean.getClass().getName() + "#" + v.getName() +
private void configureNested(Object bean, String keyPrefix, ReflectValued member, Configurable.Nested nested) { String nestedPrefix = nested.prefix(); if(Strings.isEmpty(nestedPrefix)) { nestedPrefix = Strings.lowerUnderscore(member.getName()); if(nestedPrefix.endsWith("_config")) { nestedPrefix = Strings.removeEnd(nestedPrefix, "_config"); } } String fullKeyPrefix = keyPrefix(keyPrefix + nestedPrefix); Object nestedBean = member.getValue(bean); BeanType nestedType; if(null == nestedBean) { nestedType = BeanType.of(member.getType()); nestedBean = nestedType.newInstance(); member.setValue(bean, nestedBean); }else{ nestedType = BeanType.of(nestedBean.getClass()); } configure(nestedBean, nestedType, fullKeyPrefix); }