Example usage for org.springframework.beans MutablePropertyValues addPropertyValues

List of usage examples for org.springframework.beans MutablePropertyValues addPropertyValues

Introduction

In this page you can find the example usage for org.springframework.beans MutablePropertyValues addPropertyValues.

Prototype

public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) 

Source Link

Document

Add all property values from the given Map.

Usage

From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsQuartzJobBean.java

@SuppressWarnings("rawtypes")
@Override//  ww  w .java 2 s . 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.github.dbourdette.glass.job.GlassJobFactory.java

private void setProperties(TriggerFiredBundle bundle, Job job) {
    MutablePropertyValues pvs = new MutablePropertyValues();

    pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
    pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());

    buildAccessor(job).setPropertyValues(pvs, true);
}

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.
 * /*w w w .  ja v a2s .  c o  m*/
 * @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: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  .ja  v  a2 s  .co 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:com.apporiented.spring.override.BeanOverrideProcessor.java

private void overwriteBeanDefinition(BeanDefinition target, BeanDefinition source) {
    log.debug("Replacing bean [" + ref + "] with a [" + source.getBeanClassName() + "]");

    target.setBeanClassName(source.getBeanClassName());
    ConstructorArgumentValues cas = target.getConstructorArgumentValues();
    cas.clear();/*from w  ww.  ja v a 2 s. c  om*/
    cas.addArgumentValues(source.getConstructorArgumentValues());

    MutablePropertyValues pvs = target.getPropertyValues();
    if (!merge) {
        pvs.getPropertyValueList().clear();
    }
    pvs.addPropertyValues(source.getPropertyValues());
}

From source file:com.saysth.commons.quartz.SpringBeanJobFactory.java

/**
 * Create the job instance, populating it with property values taken from
 * the scheduler context, job data map and trigger data map.
 *//*from  w  w w  .  j a v a  2 s.  c  o m*/
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
    Object job = bundle.getJobDetail().getJobClass().newInstance();
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
    if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
        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) {
            for (String propName : this.ignoredUnknownProperties) {
                if (pvs.contains(propName) && !bw.isWritableProperty(propName)) {
                    pvs.removePropertyValue(propName);
                }
            }
            bw.setPropertyValues(pvs);
        } else {
            bw.setPropertyValues(pvs, true);
        }
    }
    return job;
}

From source file:com.athena.peacock.agent.scheduler.quartz.BaseJob.java

/**
 * <pre>//from  ww w . j  a va 2  s.com
 *   ? ?? {@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.syncope.core.scheduling.SpringBeanJobFactory.java

/**
 * An implementation of SpringBeanJobFactory that retrieves the bean from
 * the Spring context so that autowiring and transactions work.
 *
 * {@inheritDoc}//from w w w  . j a  v a2s.c  o  m
 */
@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:com.alibaba.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar.java

private MutablePropertyValues resolveBeanPropertyValues(String beanName, boolean multiple,
        Map<String, String> properties) {

    MutablePropertyValues propertyValues = new MutablePropertyValues();

    if (multiple) { // For Multiple Beans

        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(new MapPropertySource(beanName, new TreeMap<String, Object>(properties)));

        Map<String, String> subProperties = getSubProperties(propertySources, beanName);

        propertyValues.addPropertyValues(subProperties);

    } else { // For Single Bean

        for (Map.Entry<String, String> entry : properties.entrySet()) {
            String propertyName = entry.getKey();
            if (!propertyName.contains(".")) { // ignore property name with "."
                propertyValues.addPropertyValue(propertyName, entry.getValue());
            }//  www.  j  a v  a2  s. c o  m
        }

    }

    return propertyValues;

}

From source file:com.laxser.blitz.web.paramresolver.ServletRequestDataBinder.java

@Override
protected void doBind(MutablePropertyValues mpvs) {
    // book.author.name?book.authorauthor
    PropertyValue[] pvArray = mpvs.getPropertyValues();
    MutablePropertyValues newMpvs = null;
    for (int i = 0; i < pvArray.length; i++) {
        PropertyValue pv = pvArray[i];/*from w  w  w .j a  v  a  2s  .  c o m*/
        String propertyName = pv.getName();
        int dot = propertyName.indexOf('.');
        while (dot != -1) {
            String field = propertyName.substring(0, dot);
            if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) {
                Class<?> fieldType = getPropertyAccessor().getPropertyType(field);
                if (newMpvs == null) {
                    newMpvs = new MutablePropertyValues();
                }
                newMpvs.addPropertyValue(field, BeanUtils.instantiateClass(fieldType));
            }
            dot = propertyName.indexOf('.', dot + 1);
        }
    }
    if (newMpvs == null) {
        super.doBind(mpvs);
    } else {
        newMpvs.addPropertyValues(mpvs);
        super.doBind(newMpvs);
    }
}