public NestedBeanPropertyDefinition(BeanPropertySet<T> propertySet, PropertyDefinition<T, ?> parent, PropertyDescriptor descriptor) { super(propertySet, parent.getType(), descriptor); this.parent = parent; }
/** * Finds the bean type containing the property the given definition refers * to. * * @param beanType * the root beanType * @param definition * the definition for the property * @return the bean type containing the given property */ @SuppressWarnings({ "rawtypes" }) private Class<?> findBeanType(Class<BEAN> beanType, PropertyDefinition<BEAN, ?> definition) { if (definition instanceof NestedBeanPropertyDefinition) { return ((NestedBeanPropertyDefinition) definition).getParent() .getType(); } else { // Non nested properties must be defined in the main type return beanType; } }
private boolean handleProperty(Field field, Object objectWithMemberFields, BiFunction<String, Class<?>, Boolean> propertyHandler) { Optional<PropertyDefinition<BEAN, ?>> descriptor = getPropertyDescriptor( field); if (!descriptor.isPresent()) { return false; } String propertyName = descriptor.get().getName(); if (boundProperties.containsKey(propertyName)) { return false; } BindingBuilder<BEAN, ?> tentativeBinding = getIncompleteMemberFieldBinding( field, objectWithMemberFields); if (tentativeBinding != null) { tentativeBinding.bind(propertyName); return false; } Boolean isPropertyBound = propertyHandler.apply(propertyName, descriptor.get().getType()); assert boundProperties.containsKey(propertyName); return isPropertyBound; }
PropertyDefinition<T, ?> parentProperty = parentDefinitions .get(parentPropertyKey); Class<?> type = parentProperty.getType(); if (type.getPackage() == null || type.isEnum()) { continue;
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Binding<BEAN, TARGET> bind(String propertyName) { Objects.requireNonNull(propertyName, "Property name cannot be null"); checkUnbound(); PropertyDefinition<BEAN, ?> definition = getBinder().propertySet .getProperty(propertyName) .orElseThrow(() -> new IllegalArgumentException( "Could not resolve property name " + propertyName + " from " + getBinder().propertySet)); ValueProvider<BEAN, ?> getter = definition.getGetter(); Setter<BEAN, ?> setter = definition.getSetter().orElse(null); if (setter == null) { getLogger().fine(() -> propertyName + " does not have an accessible setter"); } BindingBuilder<BEAN, ?> finalBinding = withConverter( createConverter(definition.getType()), false); finalBinding = getBinder().configureBinding(finalBinding, definition); try { Binding binding = ((BindingBuilder) finalBinding).bind(getter, setter); getBinder().boundProperties.put(propertyName, binding); return binding; } finally { getBinder().incompleteMemberFieldBindings.remove(getField()); } }
/** * Constructor. * @param beanType Bean type (not null) */ public DefaultBeanListingBuilder(Class<T> beanType) { super(new DefaultBeanListing<>(beanType), String.class); this.beanType = beanType; // read bean property names getInstance().getPropertyDefinitions().forEach(p -> { dataSourceBuilder.withProperty(p.getName(), p.getType(), false); dataSourceBuilder.propertyId(p.getName(), p.getName()); if (p.isReadOnly()) { dataSourceBuilder.readOnly(p.getName(), true); } if (p.getBeanProperty().isPresent()) { dataSourceBuilder.sortable(p.getName(), true); } }); PropertySet<T> propertySet = BeanPropertySet.get(beanType); propertySet.getProperties().forEach(p -> { dataSourceBuilder.withProperty(p.getName(), p.getType()); }); }