本文整理匯總了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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例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);
}
示例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();
}
示例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"));
}