/** * 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; } }
/** * 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(); }
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; }
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; }
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; }
/** * 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; } }
/** * 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; } }
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; }
Object o2 = propAccessor.getPropertyValue( fieldEntry.getKey() ); if( o2 != null )
/** * {@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; }
@Test public void overrideNormalSuffix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.normalSuffix:.nor"); assertThat(accessor.getPropertyValue("normalSuffix")).isEqualTo(".nor"); }
@Test public void overrideMobileSuffix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.mobileSuffix:.mob"); assertThat(accessor.getPropertyValue("mobileSuffix")).isEqualTo(".mob"); }
@Test public void overrideNormalPrefix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.normalPrefix:normal/"); assertThat(accessor.getPropertyValue("normalPrefix")).isEqualTo("normal/"); }
@Test public void overrideMobilePrefix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.mobilePrefix:mob/"); assertThat(accessor.getPropertyValue("mobilePrefix")).isEqualTo("mob/"); }
@Test public void overrideEnableFallback() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.enableFallback:true"); assertThat(accessor.getPropertyValue("enableFallback")).isEqualTo(Boolean.TRUE); }
@Test public void overrideTabletPrefix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.tabletPrefix:tab/"); assertThat(accessor.getPropertyValue("tabletPrefix")).isEqualTo("tab/"); }
@Test public void overrideTabletSuffix() throws Exception { PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor( "spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.tabletSuffix:.tab"); assertThat(accessor.getPropertyValue("tabletSuffix")).isEqualTo(".tab"); }
@Override public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) { if (value == null) { return true; } final PropertyAccessor bean = new BeanWrapperImpl(value); final String propertyValue = String.valueOf(bean.getPropertyValue(property)); @SuppressWarnings({"rawtypes", "unchecked"}) final Class<WithId> modelClass = (Class) value.getKind().modelClass; @SuppressWarnings("unchecked") final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue); final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false); if (!isUnique) { if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) { return true; } context.disableDefaultConstraintViolation(); context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue) .buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()) .addPropertyNode(property).addConstraintViolation(); } return isUnique; }
/** * 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)); } } }