当前位置: 首页>>代码示例>>Java>>正文


Java BeanWrapper.setPropertyValues方法代码示例

本文整理汇总了Java中org.springframework.beans.BeanWrapper.setPropertyValues方法的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapper.setPropertyValues方法的具体用法?Java BeanWrapper.setPropertyValues怎么用?Java BeanWrapper.setPropertyValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.BeanWrapper的用法示例。


在下文中一共展示了BeanWrapper.setPropertyValues方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initJob

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
protected void initJob(TriggerFiredBundle bundle, Object job) {
	// The following code is copied from SpringBeanJobFactory in spring-context-support-4.2.5.RELEASE
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
	if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (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);
		}
	}
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:24,代码来源:YadaQuartzJobFactory.java

示例2: createJobInstance

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SpringBeanJobFactory.java

示例3: execute

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * 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 {
		// Reflectively adapting to differences between Quartz 1.x and Quartz 2.0...
		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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:QuartzJobBean.java

示例4: createJobInstance

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * Create the job instance, populating it with property values taken
 * from the scheduler context, job data map and trigger data map.
 */
@Override
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
	Object job = super.createJobInstance(bundle);
	BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(job);
	if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) {
		MutablePropertyValues pvs = new MutablePropertyValues();
		if (this.schedulerContext != null) {
			pvs.addPropertyValues(this.schedulerContext);
		}
		pvs.addPropertyValues(getJobDetailDataMap(bundle));
		pvs.addPropertyValues(getTriggerDataMap(bundle));
		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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:SpringBeanJobFactory.java

示例5: createActivationSpec

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:StandardJmsActivationSpecFactory.java

示例6: testComplexObject

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testComplexObject() {
	TestBean tb = new TestBean();
	String newName = "Rod";
	String tbString = "Kerry_34";

	BeanWrapper bw = new BeanWrapperImpl(tb);
	bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
	pvs.addPropertyValue(new PropertyValue("name", newName));
	pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
	pvs.addPropertyValue(new PropertyValue("spouse", tbString));
	bw.setPropertyValues(pvs);
	assertTrue("spouse is non-null", tb.getSpouse() != null);
	assertTrue("spouse name is Kerry and age is 34",
			tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CustomEditorTests.java

示例7: testComplexObjectWithOldValueAccess

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testComplexObjectWithOldValueAccess() {
	TestBean tb = new TestBean();
	String newName = "Rod";
	String tbString = "Kerry_34";

	BeanWrapper bw = new BeanWrapperImpl(tb);
	bw.setExtractOldValueForEditor(true);
	bw.registerCustomEditor(ITestBean.class, new OldValueAccessingTestBeanEditor());
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
	pvs.addPropertyValue(new PropertyValue("name", newName));
	pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
	pvs.addPropertyValue(new PropertyValue("spouse", tbString));

	bw.setPropertyValues(pvs);
	assertTrue("spouse is non-null", tb.getSpouse() != null);
	assertTrue("spouse name is Kerry and age is 34",
			tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
	ITestBean spouse = tb.getSpouse();

	bw.setPropertyValues(pvs);
	assertSame("Should have remained same object", spouse, tb.getSpouse());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:CustomEditorTests.java

示例8: init

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * Standard way of initializing this filter.
 * Map config parameters onto bean properties of this filter, and
 * invoke subclass initialization.
 * @param filterConfig the configuration for this filter
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 * @see #initFilterBean
 */
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
	Assert.notNull(filterConfig, "FilterConfig must not be null");
	if (logger.isDebugEnabled()) {
		logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'");
	}

	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 ServletContextResourceLoader(filterConfig.getServletContext());
		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 NestedServletException(msg, ex);
	}

	// Let subclasses do whatever initialization they like.
	initFilterBean();

	if (logger.isDebugEnabled()) {
		logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:GenericFilterBean.java

示例9: init

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * Map config parameters onto bean properties of this portlet, and
 * invoke subclass initialization.
 * @throws PortletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 */
@Override
public final void init() throws PortletException {
	if (logger.isInfoEnabled()) {
		logger.info("Initializing portlet '" + getPortletName() + "'");
	}

	// Set bean properties from init parameters.
	try {
		PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties);
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext());
		bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
		initBeanWrapper(bw);
		bw.setPropertyValues(pvs, true);
	}
	catch (BeansException ex) {
		logger.error("Failed to set bean properties on portlet '" + getPortletName() + "'", ex);
		throw ex;
	}

	// let subclasses do whatever initialization they like
	initPortletBean();

	if (logger.isInfoEnabled()) {
		logger.info("Portlet '" + getPortletName() + "' configured successfully");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:GenericPortletBean.java

示例10: init

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * Map config parameters onto bean properties of this servlet, and
 * invoke subclass initialization.
 * @throws ServletException if bean properties are invalid (or required
 * properties are missing), or if subclass initialization fails.
 */
@Override
public final void init() throws ServletException {
	if (logger.isDebugEnabled()) {
		logger.debug("Initializing servlet '" + getServletName() + "'");
	}

	// Set bean properties from init parameters.
	try {
		PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
		BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
		ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
		bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
		initBeanWrapper(bw);
		bw.setPropertyValues(pvs, true);
	}
	catch (BeansException ex) {
		logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
		throw ex;
	}

	// Let subclasses do whatever initialization they like.
	initServletBean();

	if (logger.isDebugEnabled()) {
		logger.debug("Servlet '" + getServletName() + "' configured successfully");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:HttpServletBean.java

示例11: execute

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:QuartzJobBean.java

示例12: afterPropertiesSet

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() {
	if (this.name == null) {
		this.name = this.beanName;
	}
	if (this.group == null) {
		this.group = Scheduler.DEFAULT_GROUP;
	}
	if (this.applicationContextJobDataKey != null) {
		if (this.applicationContext == null) {
			throw new IllegalStateException(
				"JobDetailBean needs to be set up in an ApplicationContext " +
				"to be able to handle an 'applicationContextJobDataKey'");
		}
		getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext);
	}

	/*
	JobDetailImpl jdi = new JobDetailImpl();
	jdi.setName(this.name);
	jdi.setGroup(this.group);
	jdi.setJobClass(this.jobClass);
	jdi.setJobDataMap(this.jobDataMap);
	jdi.setDurability(this.durability);
	jdi.setDescription(this.description);
	this.jobDetail = jdi;
	*/

	Class<?> jobDetailClass;
	try {
		jobDetailClass = ClassUtils.forName("org.quartz.impl.JobDetailImpl", getClass().getClassLoader());
	}
	catch (ClassNotFoundException ex) {
		jobDetailClass = JobDetail.class;
	}
	BeanWrapper bw = new BeanWrapperImpl(jobDetailClass);
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", this.name);
	pvs.add("group", this.group);
	pvs.add("jobClass", this.jobClass);
	pvs.add("jobDataMap", this.jobDataMap);
	pvs.add("durability", this.durability);
	pvs.add("requestsRecovery", this.requestsRecovery);
	pvs.add("description", this.description);
	bw.setPropertyValues(pvs);
	this.jobDetail = (JobDetail) bw.getWrappedInstance();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:JobDetailFactoryBean.java

示例13: testIndexedPropertiesWithCustomEditorForType

import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testIndexedPropertiesWithCustomEditorForType() {
	IndexedTestBean bean = new IndexedTestBean();
	BeanWrapper bw = new BeanWrapperImpl(bean);
	bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			setValue("prefix" + text);
		}
	});
	TestBean tb0 = bean.getArray()[0];
	TestBean tb1 = bean.getArray()[1];
	TestBean tb2 = ((TestBean) bean.getList().get(0));
	TestBean tb3 = ((TestBean) bean.getList().get(1));
	TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
	TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
	assertEquals("name0", tb0.getName());
	assertEquals("name1", tb1.getName());
	assertEquals("name2", tb2.getName());
	assertEquals("name3", tb3.getName());
	assertEquals("name4", tb4.getName());
	assertEquals("name5", tb5.getName());
	assertEquals("name0", bw.getPropertyValue("array[0].name"));
	assertEquals("name1", bw.getPropertyValue("array[1].name"));
	assertEquals("name2", bw.getPropertyValue("list[0].name"));
	assertEquals("name3", bw.getPropertyValue("list[1].name"));
	assertEquals("name4", bw.getPropertyValue("map[key1].name"));
	assertEquals("name5", bw.getPropertyValue("map[key2].name"));
	assertEquals("name4", bw.getPropertyValue("map['key1'].name"));
	assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name"));

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("array[0].name", "name5");
	pvs.add("array[1].name", "name4");
	pvs.add("list[0].name", "name3");
	pvs.add("list[1].name", "name2");
	pvs.add("map[key1].name", "name1");
	pvs.add("map['key2'].name", "name0");
	bw.setPropertyValues(pvs);
	assertEquals("prefixname5", tb0.getName());
	assertEquals("prefixname4", tb1.getName());
	assertEquals("prefixname3", tb2.getName());
	assertEquals("prefixname2", tb3.getName());
	assertEquals("prefixname1", tb4.getName());
	assertEquals("prefixname0", tb5.getName());
	assertEquals("prefixname5", bw.getPropertyValue("array[0].name"));
	assertEquals("prefixname4", bw.getPropertyValue("array[1].name"));
	assertEquals("prefixname3", bw.getPropertyValue("list[0].name"));
	assertEquals("prefixname2", bw.getPropertyValue("list[1].name"));
	assertEquals("prefixname1", bw.getPropertyValue("map[\"key1\"].name"));
	assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:53,代码来源:CustomEditorTests.java


注:本文中的org.springframework.beans.BeanWrapper.setPropertyValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。