List of usage examples for org.springframework.beans PropertyAccessor isWritableProperty
boolean isWritableProperty(String propertyName);
From source file:net.solarnetwork.node.power.modbus.ModbusPowerDatumDataSource.java
private void setRegisterAddressValue(final PropertyAccessor bean, final Integer addr, final String propertyName, final Integer propertyValue) { if (bean.isWritableProperty(propertyName)) { Number value = propertyValue; if (registerScaleFactor != null && registerScaleFactor.containsKey(addr)) { value = Double.valueOf(value.intValue() * registerScaleFactor.get(addr)); }/*from w ww . ja va2s . co m*/ log.trace("Setting property {} for address 0x{} to [{}]", propertyName, Integer.toHexString(addr), value); try { bean.setPropertyValue(propertyName, value); } catch (PropertyAccessException e) { log.warn("Unable to set property {} to {} for address 0x{}: {}", propertyName, value, Integer.toHexString(addr), e.getMostSpecificCause().getMessage()); } } else { log.warn("Property {} not available; bad configuration", propertyName); } }
From source file:net.solarnetwork.node.rfxcom.RFXCOMTransceiver.java
/** * Update the settings of this class./*from w w w.j a v a2 s . c o m*/ * * <p>This method is designed to work with Spring's bean-managed OSGi Configuration * Admin service, rather than the container-managed approach of setting properties * directly. This is because many of the supported properties require communicating * with the RFXCOM device, but those can all be set via a single call. Thus the * supported properties of this method are those properties directly available on * this class itself, and those available on the {@link SetModeMessage} class. * * @param properties the properties to change */ public void updateConfiguration(Map<String, ?> properties) { Map<String, Object> setModeProperties = new HashMap<String, Object>(properties); PropertyAccessor bean = PropertyAccessorFactory.forBeanPropertyAccess(this); // if this is NOT something that must be handled via a SetMode command, apply those directly... for (Map.Entry<String, ?> me : properties.entrySet()) { if (bean.isWritableProperty(me.getKey())) { bean.setPropertyValue(me.getKey(), me.getValue()); } else { setModeProperties.put(me.getKey(), me.getValue()); } } // and now apply remaining properties via single SetMode, so we only have to talk to // device one time if (this.status == null) { updateStatus(); } if (this.status != null) { SetModeMessage msg = new SetModeMessage(mf.incrementAndGetSequenceNumber(), this.status); bean = PropertyAccessorFactory.forBeanPropertyAccess(msg); boolean changed = false; for (Map.Entry<String, Object> me : setModeProperties.entrySet()) { if (bean.isReadableProperty(me.getKey())) { Object currValue = bean.getPropertyValue(me.getKey()); if (me.getValue() != null && me.getValue().equals(currValue)) { continue; } } if (bean.isWritableProperty(me.getKey())) { bean.setPropertyValue(me.getKey(), me.getValue()); changed = true; } } if (changed) { log.debug("Updating RFXCOM settings to {}", msg); setMode(msg); } } }
From source file:org.dkpro.lab.engine.impl.DefaultLifeCycleManager.java
@Override public void configure(TaskContext aParentContext, Task aTask, Map<String, Object> aConfiguration) { PropertyAccessor paBean = PropertyAccessorFactory.forBeanPropertyAccess(aTask); PropertyAccessor paDirect = PropertyAccessorFactory.forDirectFieldAccess(aTask); for (Entry<String, Object> property : aConfiguration.entrySet()) { String key = property.getKey(); Object value = property.getValue(); // Find all fields that are annotated with a discriminator/property that have // a non-default name and might apply. for (String prop : ParameterUtil.findBeanPropertiesWithName(aTask, key)) { // Try setter - there may be extra logic in the setter if (paBean.isWritableProperty(prop)) { paBean.setPropertyValue(prop, value); }/*from ww w .ja va 2 s.c o m*/ // Otherwise try direct access else if (paDirect.isWritableProperty(prop)) { paDirect.setPropertyValue(prop, value); } } // And try once again for all fields where the name is not explicitly set // Try setter - there may be extra logic in the setter if (paBean.isWritableProperty(key)) { paBean.setPropertyValue(key, value); } // Otherwise try direct access else if (paDirect.isWritableProperty(key)) { paDirect.setPropertyValue(key, value); } } if (aTask instanceof ConfigurationAware) { ((ConfigurationAware) aTask).setConfiguration(aConfiguration); } if (aParentContext != null) { aParentContext.message("Injected parameters into [" + aTask.getType() + "]"); } }
From source file:com.nestedbird.modules.formparser.FormParse.java
/** * Can the field be written to and read from? * This is according to the springs accessor, if it has no setter or getter it still can somehow be read to... * apparently//from w w w . j a va 2 s . co m * * @param accessor - The spring propertyAccessor - * @param fieldName - The fieldName * @return boolean boolean */ private Boolean isFieldInteractable(final PropertyAccessor accessor, final String fieldName) { return accessor.isReadableProperty(fieldName) && accessor.isWritableProperty(fieldName); }
From source file:org.springframework.flex.core.io.SpringPropertyProxy.java
/** * {@inheritDoc}//from w w w . j ava 2 s .c om */ @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)); }
From source file:org.springframework.flex.core.io.SpringPropertyProxy.java
private boolean isWriteIgnored(Object instance, String propertyName) { PropertyAccessor accessor = PropertyProxyUtils.getPropertyAccessor(this.conversionService, this.useDirectFieldAccess, instance); if (!accessor.isWritableProperty(propertyName)) { return true; }/*from ww w .j av a2 s . co m*/ 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; } }