Refine search
private void writeMapEntry(TagWriter tagWriter, @Nullable String valueProperty, @Nullable String labelProperty, Map.Entry<?, ?> entry, int itemIndex) throws JspException { Object mapKey = entry.getKey(); Object mapValue = entry.getValue(); BeanWrapper mapKeyWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapKey); BeanWrapper mapValueWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapValue); Object renderValue = (valueProperty != null ? mapKeyWrapper.getPropertyValue(valueProperty) : mapKey.toString()); Object renderLabel = (labelProperty != null ? mapValueWrapper.getPropertyValue(labelProperty) : mapValue.toString()); writeElementTag(tagWriter, mapKey, renderValue, renderLabel, itemIndex); }
/** * Create a new DirectFieldAccessor for the underlying target object. * @see #getTarget() */ protected ConfigurablePropertyAccessor createDirectFieldAccessor() { if (this.target == null) { throw new IllegalStateException("Cannot access fields on null target instance '" + getObjectName() + "'"); } return PropertyAccessorFactory.forDirectFieldAccess(this.target); }
@Override public ActivationSpec createActivationSpec(ResourceAdapter adapter, JmsActivationSpecConfig config) { Class<?> activationSpecClassToUse = this.activationSpecClass; if (activationSpecClassToUse == null) { activationSpecClassToUse = determineActivationSpecClass(adapter); if (activationSpecClassToUse == null) { throw new IllegalStateException("Property 'activationSpecClass' is required"); } } ActivationSpec spec = (ActivationSpec) BeanUtils.instantiateClass(activationSpecClassToUse); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(spec); if (this.defaultProperties != null) { bw.setPropertyValues(this.defaultProperties); } populateActivationSpecProperties(bw, config); return spec; }
Assert.state(this.mappedClass != null, "Mapped class was not specified"); T mappedObject = BeanUtils.instantiateClass(this.mappedClass); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject); initBeanWrapper(bw); bw.setPropertyValue(pd.getName(), value);
/** * Copy the properties of the supplied {@link Annotation} to the supplied target bean. * Any properties defined in {@code excludedProperties} will not be copied. * <p>A specified value resolver may resolve placeholders in property values, for example. * @param ann the annotation to copy from * @param bean the bean instance to copy to * @param valueResolver a resolve to post-process String property values (may be {@code null}) * @param excludedProperties the names of excluded properties, if any * @see org.springframework.beans.BeanWrapper */ public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, String... excludedProperties) { Set<String> excluded = new HashSet<>(Arrays.asList(excludedProperties)); Method[] annotationProperties = ann.annotationType().getDeclaredMethods(); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean); for (Method annotationProperty : annotationProperties) { String propertyName = annotationProperty.getName(); if (!excluded.contains(propertyName) && bw.isWritableProperty(propertyName)) { Object value = ReflectionUtils.invokeMethod(annotationProperty, ann); if (valueResolver != null && value instanceof String) { value = valueResolver.resolveStringValue((String) value); } bw.setPropertyValue(propertyName, value); } } }
@Test public void testUntypedPropertyWithMapAtRuntime() { class Holder<D> { private final D data; public Holder(D data) { this.data = data; } public D getData() { return this.data; } } Map<String, Object> data = new HashMap<>(); data.put("x", "y"); Holder<Map<String, Object>> context = new Holder<>(data); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(context); assertEquals("y", bw.getPropertyValue("data['x']")); bw.setPropertyValue("data['message']", "it works!"); assertEquals("it works!", data.get("message")); }
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(target); this.value = bw.getPropertyValue(this.expression); this.valueType = bw.getPropertyType(this.expression); this.actualValue = this.value;
if (!pvs.isEmpty()) { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext()); Environment env = this.environment; env = new StandardServletEnvironment(); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, env)); initBeanWrapper(bw); bw.setPropertyValues(pvs, true);
/** * Specify a target object to apply the property path to. * Alternatively, specify a target bean name. * @param targetObject a target object, for example a bean reference * or an inner bean * @see #setTargetBeanName */ public void setTargetObject(Object targetObject) { this.targetBeanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(targetObject); }
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job); MutablePropertyValues pvs = new MutablePropertyValues(); if (this.schedulerContext != null) { if (this.ignoredUnknownProperties != null) { for (String propName : this.ignoredUnknownProperties) { if (pvs.contains(propName) && !bw.isWritableProperty(propName)) { pvs.removePropertyValue(propName); bw.setPropertyValues(pvs); bw.setPropertyValues(pvs, true);
/** * Gets the attribute value. * * @param entity the entity * @param attributeName the attribute name * @return the attribute value */ private String getAttributeValue(OnmsHwEntity entity, String attributeName) { if (attributeName.startsWith("entPhysical")) { BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity); if (wrapper.isWritableProperty(attributeName)) { return (String) wrapper.getPropertyValue(attributeName); } } else { return entity.getAttributeValue(attributeName); } return null; } }
this.targetBeanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean); this.resultType = this.targetBeanWrapper.getPropertyType(this.propertyPath);
/** * <p>getProperties</p> * * @param bean a {@link java.lang.Object} object. * @return a {@link java.util.Collection} object. */ public static Collection<String> getProperties(Object bean) { Collection<String> props = new LinkedList<>(); BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean); for (PropertyDescriptor pd : wrapper.getPropertyDescriptors()) { props.add(pd.getName()); } return props; }
ConfigurablePropertyAccessor accessor = directFieldAccess ? PropertyAccessorFactory.forDirectFieldAccess(model) : PropertyAccessorFactory.forBeanPropertyAccess(model); accessor.setConversionService(formattingService); accessor.setPropertyValue("dates", "10-31-09,11-1-09,11-2-09");
public <T> int[] batchProcess(List<T> batchArgs, Class<T> requiredType) { SqlParameterSource[] batch = new SqlParameterSource[batchArgs.size()]; for (int i = 0; i < batch.length; i++) { T object = batchArgs.get(i); BeanWrapper bw = PropertyAccessorFactory .forBeanPropertyAccess(object); initBeanWrapper(bw); for (String keyName : generateKeys) { Object value = getKeyValue(keyName); String propertyName = getPropertyName(keyName, requiredType); bw.setPropertyValue(propertyName, value); } batch[i] = new BeanPropertySqlParameterSource(bw.getWrappedInstance()); } return simpleJdbcInsert.executeBatch(batch); }
protected void init(Object entity) { this.entity = entity; beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity); PropertyDescriptor[] descriptors = beanWrapper.getPropertyDescriptors(); if (descriptors.length > 1) { for (PropertyDescriptor descriptor : descriptors) { if (beanWrapper.isReadableProperty(descriptor.getName())) { privateFields.add(descriptor.getName()); } } } Field[] fields = BeanFields.get(entity.getClass()); if (fields != null) { for (Field field : fields) { publicFeilds.put(field.getName(), field); } } }
private BeanWrapper getBeanWrapper(Event e) { BeanWrapper bean = PropertyAccessorFactory.forBeanPropertyAccess(e); bean.registerCustomEditor(String.class, new StringPropertyEditor()); return bean; } }
private PropertyEditor findSpringConvertingPropertyEditor(String field, Class<?> valueType) { if (conversionService != null) { String converterId = null; if (field != null) { if (binderConfiguration != null) { converterId = binderConfiguration.getConverterId(field); } if (valueType == null) { valueType = parseFieldExpression(field, false).getValueType(boundObject); } } if (valueType != null) { BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(boundObject); TypeDescriptor typeDescriptor = accessor.getPropertyTypeDescriptor(field); return new ConvertingPropertyEditorAdapter(conversionService, converterId, typeDescriptor); } else { return null; } } else { return null; } }
/** * This implementation applies the passed-in job data map as bean property * values, and delegates to {@code executeInternal} afterwards. * @see #executeInternal */ @Override public final void execute(JobExecutionContext context) throws JobExecutionException { try { BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValues(context.getScheduler().getContext()); pvs.addPropertyValues(context.getMergedJobDataMap()); bw.setPropertyValues(pvs, true); } catch (SchedulerException ex) { throw new JobExecutionException(ex); } executeInternal(context); }
private void setupExternalPathResolver() { BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(this.messageBroker); wrapper.setPropertyValue("externalPathResolver", new MessageBroker.InternalPathResolver() { public InputStream resolve(String filename) throws IOException { try { Resource resource = MessageBrokerFactoryBean.this.resourceLoader.getResource(filename); if (resource.exists()) { return resource.getInputStream(); } else { return null; } } catch (IOException e) { throw new IllegalStateException("Could not resolve Flex internal resource at: " + filename); } } }); }