List of usage examples for org.springframework.beans PropertyAccessorFactory forBeanPropertyAccess
public static BeanWrapper forBeanPropertyAccess(Object target)
From source file:org.jdal.vaadin.data.BeanWrapperItem.java
public BeanWrapperItem(Object bean, List<String> properties) { this.beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(bean); if (properties == null) { for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(bean.getClass())) this.properties.add(pd.getName()); } else {/*from w w w.j a v a 2 s . c om*/ this.properties = properties; } }
From source file:org.gageot.excel.beans.BeanSetterImpl.java
protected BeanWrapper getWrapper(Object bean) { if (bean != currentBean) { currentBean = bean;//from w ww.j a va2 s . co m currentWrapper = PropertyAccessorFactory.forBeanPropertyAccess(currentBean); // To make sure that Double values can be converted into an int. // currentWrapper.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, NumberFormat.getInstance(), false)); } return currentWrapper; }
From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsQuartzJobBean.java
@SuppressWarnings("rawtypes") @Override/*from w w w . j ava2 s .co m*/ public void execute(JobExecutionContext context) throws JobExecutionException { try { Scheduler scheduler = (Scheduler) ReflectionUtils.invokeMethod(getSchedulerMethod, context); Map mergedJobDataMap = (Map) ReflectionUtils.invokeMethod(getMergedJobDataMapMethod, context); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValues(scheduler.getContext()); pvs.addPropertyValues(mergedJobDataMap); bw.setPropertyValues(pvs, true); } catch (SchedulerException ex) { throw new JobExecutionException(ex); } executeInternal(context); }
From source file:org.jdal.swing.action.ComboLinker.java
/** * {@inheritDoc}//ww w . ja va2s . com * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent e) { Object selected = primary.getSelectedItem(); if (selected != null) { BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected); Collection<Object> collection = (Collection<Object>) wrapper.getPropertyValue(propertyName); DefaultComboBoxModel model = new DefaultComboBoxModel(new Vector<Object>(collection)); dependent.setModel(model); } }
From source file:org.jdto.spring.BeanWrapperBeanModifier.java
/** * Read a property value using the property path by invoking a spring {@link BeanWrapper} * @param propertyPath/*from ww w .j a v a 2 s . c om*/ * @param instance * @return the property value found on the property path applied to the provided instance. */ @Override public Object doReadPropertyValue(String propertyPath, Object instance) { BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(instance); //check if it's safe to write the property. if (!beanWrapper.isReadableProperty(propertyPath)) { return null; } return beanWrapper.getPropertyValue(propertyPath); }
From source file:org.grails.datastore.mapping.engine.EntityAccess.java
public EntityAccess(PersistentEntity persistentEntity, Object entity) { this.entity = entity; this.persistentEntity = persistentEntity; beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity); }
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 www. j a v a2s. 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:am.ik.categolj2.infra.codelist.MethodInvokingCodeList.java
@Override protected Map<String, String> retrieveMap() { try {/*from w w w .jav a 2 s . c om*/ methodInvoker.prepare(); List<?> targetList = (List<?>) methodInvoker.invoke(); Map<String, String> map = new LinkedHashMap<>(); for (Object target : targetList) { BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(target); Object valueObject = beanWrapper.getPropertyValue(valueField); Object labelObject = beanWrapper.getPropertyValue(labelField); String value = conversionService.convert(valueObject, String.class); String label = conversionService.convert(labelObject, String.class); map.put(value, label); } return map; } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:org.codehaus.griffon.runtime.quartz.CustomTriggerFactoryBean.java
public void afterPropertiesSet() throws ParseException { customTrigger = BeanUtils.instantiateClass(triggerClass); if (triggerAttributes.containsKey(QuartzConstants.START_DELAY)) { Number startDelay = (Number) triggerAttributes.remove(QuartzConstants.START_DELAY); customTrigger.setStartTime(new Date(System.currentTimeMillis() + startDelay.longValue())); }// ww w .java 2s .c o m if (jobDetail != null) { customTrigger.setJobName(jobDetail.getName()); customTrigger.setJobGroup(jobDetail.getGroup()); } BeanWrapper customTriggerWrapper = PropertyAccessorFactory.forBeanPropertyAccess(customTrigger); customTriggerWrapper.registerCustomEditor(String.class, new StringEditor()); customTriggerWrapper.setPropertyValues(triggerAttributes); }
From source file:net.tirasa.blog.springquartz.SpringBeanJobFactory.java
/** * An implementation of SpringBeanJobFactory that retrieves the bean from * the Spring context so that autowiring and transactions work * * This method is overriden.//from w w w . jav a 2 s .com * @see org.springframework.scheduling.quartz.SpringBeanJobFactory#createJobInstance(org.quartz.spi.TriggerFiredBundle) */ @Override protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception { final ConfigurableApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext .get("applicationContext")); final Object job = ctx.getBean(bundle.getJobDetail().getName()); final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(job); if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) { final MutablePropertyValues pvs = new MutablePropertyValues(); if (this.schedulerContext != null) { pvs.addPropertyValues(this.schedulerContext); } pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap()); pvs.addPropertyValues(bundle.getTrigger().getJobDataMap()); if (this.ignoredUnknownProperties == null) { wrapper.setPropertyValues(pvs, true); } else { for (String propName : this.ignoredUnknownProperties) { if (pvs.contains(propName) && !wrapper.isWritableProperty(propName)) { pvs.removePropertyValue(propName); } } wrapper.setPropertyValues(pvs); } } return job; }