List of usage examples for org.springframework.beans BeanWrapper setPropertyValues
void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown) throws BeansException;
From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsQuartzJobBean.java
@SuppressWarnings("rawtypes") @Override//from ww w . j a v a 2s. c o 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:com.saysth.commons.quartz.QuartzJobBean.java
/** * This implementation applies the passed-in job data map as bean property * values, and delegates to <code>executeInternal</code> afterwards. * //from w w w. j a v a 2s. com * @see #executeInternal */ 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); }
From source file:com.athena.peacock.agent.scheduler.quartz.BaseJob.java
/** * <pre>//from w w w. ja v a2 s.c o m * ? ?? {@link JobExecutionContext}? . * </pre> * @param context * @throws JobExecutionException */ public void initializingContext(JobExecutionContext context) throws JobExecutionException { try { this.context = (ApplicationContext) context.getScheduler().getContext().get(APPLICAITON_CONTEXT_KEY); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValues(context.getScheduler().getContext()); pvs.addPropertyValues(context.getMergedJobDataMap()); resolveDependenciesOfJobObject(context, pvs); bw.setPropertyValues(pvs, true); } catch (SchedulerException ex) { throw new JobExecutionException(ex); } }
From source file:org.solmix.wmix.web.servlet.AbstractWmixFilter.java
@Override public void init(FilterConfig config) throws ServletException { filterConfig = config;/*from w ww. j a v a2s . c om*/ logInBothServletAndLoggingSystem("Initializing filter: " + getFilterName()); try { PropertyValues pvs = new FilterConfigPropertyValues(getFilterConfig(), requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader)); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (Exception e) { throw new ServletException("Failed to set bean properties on filter: " + getFilterName(), e); } try { init(); } catch (Exception e) { throw new ServletException("Failed to init filter: " + getFilterName(), e); } logInBothServletAndLoggingSystem( getClass().getSimpleName() + " - " + getFilterName() + ": initialization completed"); }
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 ww.j a va2s. c o m * @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; }
From source file:org.jasig.springframework.web.portlet.filter.GenericPortletFilterBean.java
@Override public void init(FilterConfig filterConfig) throws PortletException { Assert.notNull(filterConfig, "FilterConfig must not be null"); if (logger.isDebugEnabled()) { logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'"); }//from ww w.j av a 2s . c o m this.filterConfig = filterConfig; // Set bean properties from init parameters. try { PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new PortletContextResourceLoader(filterConfig.getPortletContext()); bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment)); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } catch (BeansException ex) { String msg = "Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': " + ex.getMessage(); logger.error(msg, ex); throw new PortletException(msg, ex); } // Let subclasses do whatever initialization they like. initFilterBean(); if (logger.isDebugEnabled()) { logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully"); } }
From source file:org.syncope.core.scheduling.SpringBeanJobFactory.java
/** * An implementation of SpringBeanJobFactory that retrieves the bean from * the Spring context so that autowiring and transactions work. * * {@inheritDoc}/* ww w . java 2 s . com*/ */ @Override protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception { final ApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext .get("applicationContext")); // Try to re-create job bean from underlying task (useful for managing // failover scenarios) if (!ctx.containsBean(bundle.getJobDetail().getName())) { Long taskId = JobInstanceLoader.getTaskIdFromJobName(bundle.getJobDetail().getName()); if (taskId != null) { TaskDAO taskDAO = ctx.getBean(TaskDAO.class); SchedTask task = taskDAO.find(taskId); JobInstanceLoader jobInstanceLoader = ctx.getBean(JobInstanceLoader.class); jobInstanceLoader.registerJob(task, task.getJobClassName(), task.getCronExpression()); } Long reportId = JobInstanceLoader.getReportIdFromJobName(bundle.getJobDetail().getName()); if (reportId != null) { ReportDAO reportDAO = ctx.getBean(ReportDAO.class); Report report = reportDAO.find(reportId); JobInstanceLoader jobInstanceLoader = ctx.getBean(JobInstanceLoader.class); jobInstanceLoader.registerJob(report); } } 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; }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testIgnoringIndexedProperty() { MutablePropertyValues values = new MutablePropertyValues(); values.add("toBeIgnored[0]", new Integer(42)); BeanWrapper bw = new JuffrouSpringBeanWrapper(new Object()); bw.setPropertyValues(values, true); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testSetPropertyValuesIgnoresInvalidNestedOnRequest() { ITestBean rod = new TestBean(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("name", "rod")); pvs.addPropertyValue(new PropertyValue("graceful.rubbish", "tony")); pvs.addPropertyValue(new PropertyValue("more.garbage", new Object())); BeanWrapper bw = new JuffrouSpringBeanWrapper(rod); bw.setPropertyValues(pvs, true); assertTrue("Set valid and ignored invalid", rod.getName().equals("rod")); try {//w w w. jav a 2 s.c om // Don't ignore: should fail bw.setPropertyValues(pvs, false); fail("Shouldn't have ignored invalid updates"); } catch (NotWritablePropertyException ex) { // OK: but which exception?? } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testIgnoringIndexedProperty() { MutablePropertyValues values = new MutablePropertyValues(); values.add("toBeIgnored[0]", new Integer(42)); BeanWrapper bw = new BeanWrapperImpl(new Object()); bw.setPropertyValues(values, true); }