/** * Creates new {@link JedisClusterNodeResourceProvider}. * * @param cluster must not be {@literal null}. * @param topologyProvider must not be {@literal null}. */ JedisClusterNodeResourceProvider(JedisCluster cluster, ClusterTopologyProvider topologyProvider) { this.cluster = cluster; this.topologyProvider = topologyProvider; if (cluster != null) { PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster); this.connectionHandler = accessor.isReadableProperty("connectionHandler") ? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null; } else { this.connectionHandler = null; } }
PropertyAccessor myAccessor = PropertyAccessorFactory.forBeanPropertyAccess(object); // a `setSomeProperty()` method will be used myAccessor.setPropertyValue("someProperty", "some value");
/** * Copies the unmapped properties of the given {@link MappedProperties} from the source object to the target instance. * * @param properties must not be {@literal null}. * @param source must not be {@literal null}. * @param target must not be {@literal null}. */ private static void copyRemainingProperties(MappedProperties properties, Object source, Object target) { PropertyAccessor sourceFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(source); PropertyAccessor sourcePropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(source); PropertyAccessor targetFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(target); PropertyAccessor targetPropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(target); for (String property : properties.getSpringDataUnmappedProperties()) { // If there's a field we can just copy it. if (targetFieldAccessor.isWritableProperty(property)) { targetFieldAccessor.setPropertyValue(property, sourceFieldAccessor.getPropertyValue(property)); continue; } // Otherwise only copy if there's both a getter and setter. if (targetPropertyAccessor.isWritableProperty(property) && sourcePropertyAccessor.isReadableProperty(property)) { targetPropertyAccessor.setPropertyValue(property, sourcePropertyAccessor.getPropertyValue(property)); } } }
public String fillIn(PropertyAccessor pa) { Matcher m = placeholders.matcher(path); StringBuffer sb = new StringBuffer(); while (m.find()) { String name = m.group(2); if (name == null) { name = m.group(1); } Object value = pa.getPropertyValue(name); m.appendReplacement(sb, String.valueOf(value)); } m.appendTail(sb); return sb.toString(); }
if (paBean.isWritableProperty(key)) { paBean.setPropertyValue(key, value); else if (paDirect.isWritableProperty(key)) { paDirect.setPropertyValue(key, value);
channel = new DirectChannel(); channel.setBeanName("_" + this + ".channel#" + i); Assert.notNull(accessor.getPropertyType(OUTPUT_CHANNEL_PROPERTY), "All handlers except for the last one in the chain must implement property '" + OUTPUT_CHANNEL_PROPERTY + "' of type 'MessageChannel'"); accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, channel); else if (accessor.getPropertyType(OUTPUT_CHANNEL_PROPERTY) != null) { MessageChannel replyChannel = (this.outputChannel != null) ? this.outputChannel : new ReplyForwardingMessageChannel(); accessor.setPropertyValue(OUTPUT_CHANNEL_PROPERTY, replyChannel);
/** * {@inheritDoc} * * Delegates to the configured {@link ConversionService} to potentially convert the current value to the actual type of the property. */ @Override public Object getValue(Object instance, String propertyName) { PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance); Object value = accessor.getPropertyValue(propertyName); if(log.isDebugEnabled()) { getType(instance, propertyName); log.debug("Actual type of value for property '"+propertyName+"' on instance "+instance+" is "+(value != null ? value.getClass() : null)); } TypeDescriptor targetType = accessor.getPropertyTypeDescriptor(propertyName); TypeDescriptor sourceType = value == null ? targetType : TypeDescriptor.valueOf(value.getClass()); if (this.conversionService.canConvert(sourceType, targetType)) { value = this.conversionService.convert(value, sourceType, targetType); } return value; }
/** * {@inheritDoc} */ @Override public boolean isWriteOnly(Object instance, String propertyName) { PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance); return isReadIgnored(instance, propertyName) || (!accessor.isReadableProperty(propertyName) && accessor.isWritableProperty(propertyName)); }
private boolean isReadIgnored(Object instance, String propertyName) { PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance); if (!accessor.isReadableProperty(propertyName)) { return true; } if (this.useDirectFieldAccess) { AmfIgnoreField ignoreField = accessor.getPropertyTypeDescriptor(propertyName).getAnnotation(AmfIgnoreField.class); return ignoreField != null && ignoreField.onSerialization(); } else { PropertyDescriptor pd = ((BeanWrapper)accessor).getPropertyDescriptor(propertyName); return pd.getReadMethod().getAnnotation(AmfIgnore.class) != null; } }
private boolean isWriteIgnored(Object instance, String propertyName) { PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance); if (!accessor.isWritableProperty(propertyName)) { return true; } if (this.useDirectFieldAccess) { AmfIgnoreField ignoreField = accessor.getPropertyTypeDescriptor(propertyName).getAnnotation(AmfIgnoreField.class); return ignoreField != null && ignoreField.onDeserialization(); } else { PropertyDescriptor pd = ((BeanWrapper)accessor).getPropertyDescriptor(propertyName); return pd.getWriteMethod().getAnnotation(AmfIgnore.class) != null; } }
/** * {@inheritDoc} */ @Override public Class<?> getType(Object instance, String propertyName) { return PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance).getPropertyType(propertyName); }
/** * Copies the unmapped properties of the given {@link MappedProperties} from the source object to the target instance. * * @param properties must not be {@literal null}. * @param source must not be {@literal null}. * @param target must not be {@literal null}. */ private static void copyRemainingProperties(MappedProperties properties, Object source, Object target) { PropertyAccessor sourceFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(source); PropertyAccessor sourcePropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(source); PropertyAccessor targetFieldAccessor = PropertyAccessorFactory.forDirectFieldAccess(target); PropertyAccessor targetPropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(target); for (String property : properties.getSpringDataUnmappedProperties()) { // If there's a field we can just copy it. if (targetFieldAccessor.isWritableProperty(property)) { targetFieldAccessor.setPropertyValue(property, sourceFieldAccessor.getPropertyValue(property)); continue; } // Otherwise only copy if there's both a getter and setter. if (targetPropertyAccessor.isWritableProperty(property) && sourcePropertyAccessor.isReadableProperty(property)) { targetPropertyAccessor.setPropertyValue(property, sourcePropertyAccessor.getPropertyValue(property)); } } }
public static Object getProperty(Object bean, String name) { if (bean == null) { return null; } PropertyAccessor wrapper = createAccessor(bean); try { return wrapper.getPropertyValue(name); } catch (NullValueInNestedPathException e) { } return null; }
if (paBean.isWritableProperty(key)) { paBean.setPropertyValue(key, value); else if (paDirect.isWritableProperty(key)) { paDirect.setPropertyValue(key, value);
protected boolean searchMatches(Object item, ListParams params) { if (params.getSearch() == null) { return true; } PropertyAccessor itemAccessor = PropertyUtils.createAccessor(item); for (String prop : getSearchableProperties()) { Object itemValue = itemAccessor.getPropertyValue(prop); if (itemValue != null && itemValue.toString().toLowerCase().indexOf( params.getSearch().toLowerCase()) >= 0) { return true; } } return false; }
public boolean canFillIn(PropertyAccessor pa) { if (pa == null) { return numberOfPlaceholders == 0; } for (String prop : variables) { if (!pa.isReadableProperty(prop) || pa.getPropertyValue(prop) == null) { return false; } } return true; }
PropertyAccessor myAccessor = PropertyAccessorFactory.forDirectFieldAccess(object); // set the property directly, bypassing the mutator (if any) myAccessor.setPropertyValue("someProperty", "some value");
protected boolean filterMatches(Object item, ListParams params) { if (params.getFilteredProperties() != null) { PropertyAccessor itemAccessor = PropertyUtils.createAccessor(item); PropertyAccessor filterAccessor = PropertyUtils.createAccessor(params.getFilter()); for (String prop : params.getFilteredProperties()) { Object filterValue = filterAccessor.getPropertyValue(prop); if (filterValue != null) { Object itemValue = itemAccessor.getPropertyValue(prop); if (itemValue instanceof Collection<?>) { Collection<?> c = (Collection<?>) itemValue; if (!c.contains(filterValue)) { return false; } } else if (!filterValue.equals(itemValue)) { return false; } } } } return true; }
/** * Creates new {@link JedisClusterNodeResourceProvider}. * * @param cluster must not be {@literal null}. * @param topologyProvider must not be {@literal null}. */ JedisClusterNodeResourceProvider(JedisCluster cluster, ClusterTopologyProvider topologyProvider) { this.cluster = cluster; this.topologyProvider = topologyProvider; if (cluster != null) { PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster); this.connectionHandler = accessor.isReadableProperty("connectionHandler") ? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null; } else { this.connectionHandler = null; } }
dfa.setPropertyValue("restTemplate", template);