/** * Expands nested bean properties by replacing a top-level property with * some or all of its sub-properties. The expansion is not recursive. * * @param propertyId * property id for the property whose sub-properties are to be * expanded, * @param subPropertyIds * sub-properties to expand, all sub-properties are expanded if * not specified */ public void expandProperty(String propertyId, String... subPropertyIds) { Set<String> subPropertySet = new HashSet<String>( Arrays.asList(subPropertyIds)); if (0 == subPropertyIds.length) { // Enumerate all sub-properties Class<?> propertyType = getItemProperty(propertyId).getType(); Map<String, ?> pds = getPropertyDescriptors(propertyType); subPropertySet.addAll(pds.keySet()); } for (String subproperty : subPropertySet) { String qualifiedPropertyId = propertyId + "." + subproperty; addNestedProperty(qualifiedPropertyId); } removeItemProperty(propertyId); }
private void ensureNestedPropertyAdded(Object propertyId) { if (getItemDataSource() != null) { // The data source is set so the property must be found in the item. // If it is not we try to add it. try { getItemProperty(propertyId); } catch (BindException e) { // Not found, try to add a nested property; // BeanItem property ids are always strings so this is safe getItemDataSource().addNestedProperty((String) propertyId); } } }
public static <T> MBeanFieldGroup<T> bind(T bean, Object objectWithMemberFields, String... nestedProperties) { MBeanFieldGroup<T> beanFieldGroup = new MBeanFieldGroup<>((Class<T>) bean.getClass()); beanFieldGroup.setItemDataSource(bean); if(nestedProperties != null) { for (String nestedPropertyId : nestedProperties) { beanFieldGroup.getItemDataSource().addNestedProperty(nestedPropertyId); } } beanFieldGroup.setBuffered(false); beanFieldGroup.bindMemberFields(objectWithMemberFields); beanFieldGroup.configureMaddonDefaults(); return beanFieldGroup; }