/** * Creates a new binder that uses reflection based on the provided bean type * to resolve bean properties. * * @param beanType * the bean type to use, not <code>null</code> */ public Binder(Class<BEAN> beanType) { this(BeanPropertySet.get(beanType)); }
/** * Gets a {@link BeanPropertySet} for the given bean type. * * @param beanType * the bean type to get a property set for, not <code>null</code> * @return the bean property set, not <code>null</code> */ @SuppressWarnings("unchecked") public static <T> PropertySet<T> get(Class<? extends T> beanType) { Objects.requireNonNull(beanType, "Bean type cannot be null"); InstanceKey key = new InstanceKey(beanType, false, 0, null); // Cache the reflection results return (PropertySet<T>) INSTANCES .computeIfAbsent(key, ignored -> new BeanPropertySet<>(key)) .copy(); }
private BeanPropertySet(InstanceKey<T> instanceKey, boolean checkNestedDefinitions, PropertyFilterDefinition propertyFilterDefinition) { this(instanceKey); if (checkNestedDefinitions) { Objects.requireNonNull(propertyFilterDefinition, "You must define a property filter callback if using nested property scan."); findNestedDefinitions(definitions, 0, propertyFilterDefinition); } }
private BeanPropertySet<T> copy() { return new BeanPropertySet<>(instanceKey, definitions); }
/** * Constructor for setting the immutable descriptor, property set and * property holder type used by this instance. * * @param propertySet * property set this property belongs to * @param parent * parent property for this nested property * @param descriptor * property descriptor */ public AbstractBeanPropertyDefinition(BeanPropertySet<T> propertySet, Class<?> propertyHolderType, PropertyDescriptor descriptor) { this.propertySet = propertySet; this.propertyHolderType = propertyHolderType; this.descriptor = descriptor; if (descriptor.getReadMethod() == null) { throw new IllegalArgumentException( "Bean property has no accessible getter: " + propertySet.getBeanType() + "." + descriptor.getName()); } }
try { String parentName = name.substring(0, name.lastIndexOf('.')); Optional<PropertyDefinition<T, ?>> parent = getProperty( parentName); if (!parent.isPresent()) {
/** * Creates a new grid that uses custom data communicator and provided bean * type * * It uses reflection of the provided bean type to automatically set up an * initial set of columns. All columns will be configured using the same * {@link Object#toString()} renderer that is used by * {@link #addColumn(ValueProvider)}. * * @param beanType * the bean type to use, not <code>null</code> * @param dataCommunicator * the data communicator to use, not<code>null</code> * @since 8.0.7 */ protected Grid(Class<T> beanType, DataCommunicator<T> dataCommunicator) { this(BeanPropertySet.get(beanType), dataCommunicator); this.beanType = beanType; }
/** * Gets a {@link BeanPropertySet} for the given bean type. * * @param beanType * the bean type to get a property set for, not <code>null</code> * @param checkNestedDefinitions * whether to scan for nested definitions in beanType * @param filterDefinition * filtering conditions for nested properties * @return the bean property set, not <code>null</code> * @since 8.2 */ @SuppressWarnings("unchecked") public static <T> PropertySet<T> get(Class<? extends T> beanType, boolean checkNestedDefinitions, PropertyFilterDefinition filterDefinition) { Objects.requireNonNull(beanType, "Bean type cannot be null"); InstanceKey key = new InstanceKey(beanType, false, filterDefinition.getMaxNestingDepth(), filterDefinition.getIgnorePackageNamesStartingWith()); return (PropertySet<T>) INSTANCES .computeIfAbsent(key, k -> new BeanPropertySet<>(key, checkNestedDefinitions, filterDefinition)) .copy(); }
findNestedDefinitions(moreProps, ++depth, filterCallback);
private Object readResolve() { /* * When this instance is deserialized, it will be replaced with a * property set for the corresponding bean type and property name. */ return get(instanceKey.type, instanceKey.checkNestedDefinitions, new PropertyFilterDefinition(instanceKey.depth, instanceKey.ignorePackageNames)); } }
private Object readResolve() throws IOException { /* * When this instance is deserialized, it will be replaced with a * property definition for the corresponding bean type and property * name. */ return get(beanType).getProperty(propertyName) .orElseThrow(() -> new IOException( beanType + " no longer has a property named " + propertyName)); } }
/** * Creates a new binder that uses reflection based on the provided bean type * to resolve bean properties. * * @param beanType * the bean type to use, not {@code null} * @param scanNestedDefinitions * if {@code true}, scan for nested property definitions as well * @since 8.2 */ public Binder(Class<BEAN> beanType, boolean scanNestedDefinitions) { this(BeanPropertySet.get(beanType, scanNestedDefinitions, PropertyFilterDefinition.getDefaultFilter())); }
/** * Sets the bean type to use for property mapping. * <p> * This method is responsible also for setting or updating the property set * so that it matches the given bean type. * <p> * Protected mostly for Designer needs, typically should not be overridden * or even called. * * @param beanType * the bean type class * * @since 8.0.3 */ protected void setBeanType(Class<T> beanType) { this.beanType = beanType; setPropertySet(BeanPropertySet.get(beanType)); }
public TableDefinition( final Class<T> entity, final String entityViewName) { this.entity = entity; this.propertySet = BeanPropertySet.get(entity); this.entityViewName = entityViewName; }
/** * 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()); }); }