@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; }
bw.setPropertyValues(pvs, true);
bw.setPropertyValues(pvs); bw.setPropertyValues(pvs, true);
/** * 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 { // Set bean properties from init parameters. PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); if (!pvs.isEmpty()) { try { 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) { if (logger.isErrorEnabled()) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); } throw ex; } } // Let subclasses do whatever initialization they like. initServletBean(); }
bw.setPropertyValues(mpvs); return; bw.setPropertyValues(new MutablePropertyValues(deepCopy));
@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); }
@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()); }
/** * 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); }
bw.setPropertyValues(pvs, true);
pvs.addPropertyValues(this.schedulerContext); bw.setPropertyValues(pvs, true); return job;
@Test public void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() { TestBean target = new TestBean(); String newName = "tony"; String invalidTouchy = ".valid"; try { BeanWrapper accessor = createAccessor(target); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("age", "foobar")); pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy)); accessor.setPropertyValues(pvs); fail("Should throw exception when everything is valid"); } catch (PropertyBatchUpdateException ex) { assertTrue("Must contain 2 exceptions", ex.getExceptionCount() == 2); // Test validly set property matches assertTrue("Valid set property must stick", target.getName().equals(newName)); assertTrue("Invalid set property must retain old value", target.getAge() == 0); assertTrue("New value of dodgy setter must be available through exception", ex.getPropertyAccessException("touchy").getPropertyChangeEvent().getNewValue().equals(invalidTouchy)); } }
/** * 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 { // Set bean properties from init parameters. PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); if (!pvs.isEmpty()) { try { 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) { if (logger.isErrorEnabled()) { logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex); } throw ex; } } // Let subclasses do whatever initialization they like. initServletBean(); }
/** * 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); }
pvs.add("map[key1]", "e"); pvs.add("map['key2']", "f"); bw.setPropertyValues(pvs); assertEquals("arraya", bean.getArray()[0].getName()); assertEquals("arrayb", bean.getArray()[1].getName());
pvs.add("map[key1].nestedIndexedBean.map[\"key1\"].name", "name1"); pvs.add("map['key2'].nestedIndexedBean.map[key2].name", "name0"); bw.setPropertyValues(pvs); assertEquals("arrayname5", tb0.getNestedIndexedBean().getArray()[0].getName()); assertEquals("name4", tb1.getNestedIndexedBean().getArray()[1].getName());
pvs.add("map[key1]", "e"); pvs.add("map['key2']", "f"); bw.setPropertyValues(pvs); assertEquals("array0a", bean.getArray()[0].getName()); assertEquals("array1b", bean.getArray()[1].getName());
pvs.add("map[key1].nestedIndexedBean.map[\"key1\"].name", "name1"); pvs.add("map['key2'].nestedIndexedBean.map[key2].name", "name0"); bw.setPropertyValues(pvs); assertEquals("arrayname5", tb0.getNestedIndexedBean().getArray()[0].getName()); assertEquals("arrayname4", tb1.getNestedIndexedBean().getArray()[1].getName());
pvs.add("map[key1].name", "name1"); pvs.add("map['key2'].name", "name0"); bw.setPropertyValues(pvs); assertEquals("prefixname5", tb0.getName()); assertEquals("prefixname4", tb1.getName());
pvs.add("map[key1].name", "name1"); pvs.add("map['key2'].name", "name0"); bw.setPropertyValues(pvs); assertEquals("arrayname5", tb0.getName()); assertEquals("arrayname4", tb1.getName());
pvs.add("map[key1].name", "name1"); pvs.add("map['key2'].name", "name0"); bw.setPropertyValues(pvs); assertEquals("array0name5", tb0.getName()); assertEquals("array1name4", tb1.getName());