List of usage examples for org.springframework.beans BeanWrapper getPropertyValue
@Nullable
Object getPropertyValue(String propertyName) throws BeansException;
From source file:net.sourceforge.vulcan.web.struts.actions.ManagePluginAction.java
public final ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final PluginConfigForm configForm = (PluginConfigForm) form; final String target = configForm.getTarget(); final String[] split = target.split("\\["); final String arrayProperty = split[0]; final int index = Integer.parseInt(split[1].substring(0, split[1].length() - 1)); final BeanWrapper bw = new BeanWrapperImpl(form); final Class<?> type = PropertyUtils.getPropertyType(form, arrayProperty).getComponentType(); Object[] array = (Object[]) bw.getPropertyValue(arrayProperty); Object[] tmp = (Object[]) Array.newInstance(type, array.length - 1); System.arraycopy(array, 0, tmp, 0, index); System.arraycopy(array, index + 1, tmp, index, array.length - index - 1); bw.setPropertyValue(arrayProperty, tmp); configForm.putBreadCrumbsInRequest(request); return mapping.findForward("configure"); }
From source file:org.zilverline.web.TestCustomCollectionEditor.java
public void testCustomCollectionEditorWithString() { CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); assertNotNull(colMan);/* ww w. j av a2 s . co m*/ assertTrue("collections must exist", colMan.getCollections().size() > 0); SearchForm sf = new SearchForm(); BeanWrapper bw = new BeanWrapperImpl(sf); bw.registerCustomEditor(CollectionTriple[].class, "collections", new CustomCollectionEditor(colMan)); try { bw.setPropertyValue("collections", "problems"); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } CollectionTriple[] col3s = (CollectionTriple[]) bw.getPropertyValue("collections"); assertEquals(colMan.getCollections().size(), col3s.length); assertEquals("testdata", col3s[0].getName()); }
From source file:com.yosanai.java.swing.editor.ObjectEditorTableModel.java
@SuppressWarnings("rawtypes") protected void addRows(BeanWrapper beanWrapper, PropertyDescriptor propertyDescriptor, String prefix, Set<Integer> visited) { if (StringUtils.isBlank(prefix)) { prefix = ""; } else if (!prefix.endsWith(".")) { prefix += "."; }/*from w w w. j a v a 2 s .co m*/ Object propertyValue = beanWrapper.getPropertyValue(propertyDescriptor.getName()); if (isPrimitive(propertyDescriptor.getPropertyType())) { String value = ""; if (null != propertyValue) { if (propertyDescriptor.getPropertyType().isEnum()) { value = ((Enum) propertyValue).name(); } else { value = propertyValue.toString(); } } addRow(new Object[] { prefix + propertyDescriptor.getName(), value }); } else if (expandAllProperties) { addRows(propertyValue, prefix + propertyDescriptor.getName(), visited); } }
From source file:org.ambraproject.testutils.DummyHibernateDataStore.java
@Override @SuppressWarnings("unchecked") public <T> T get(final Class<T> clazz, final Serializable id) { return (T) hibernateTemplate.execute(new HibernateCallback() { @Override//from w w w.ja v a 2s. c om public Object doInHibernate(Session session) throws HibernateException, SQLException { T object = (T) session.get(clazz, id); if (object == null) { return null; } else { //Load up all the object's collection attributes in a session to make sure they aren't lazy-loaded BeanWrapper wrapper = new BeanWrapperImpl(object); for (PropertyDescriptor propertyDescriptor : wrapper.getPropertyDescriptors()) { if (Collection.class.isAssignableFrom(propertyDescriptor.getPropertyType())) { Iterator iterator = ((Collection) wrapper .getPropertyValue(propertyDescriptor.getName())).iterator(); while (iterator.hasNext()) { iterator.next(); } } } } return object; } }); }
From source file:org.zilverline.web.TestCustomCollectionEditor.java
public void testCustomCollectionEditorWithStrings() { CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); assertNotNull(colMan);/*w ww . ja v a2 s. c o m*/ assertTrue("collections must exist", colMan.getCollections().size() > 0); log.debug("test"); SearchForm sf = new SearchForm(); BeanWrapper bw = new BeanWrapperImpl(sf); bw.registerCustomEditor(CollectionTriple[].class, "collections", new CustomCollectionEditor(colMan)); try { bw.setPropertyValue("collections", "problems, testdata"); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } CollectionTriple[] col3s = (CollectionTriple[]) bw.getPropertyValue("collections"); log.debug(col3s); assertEquals(colMan.getCollections().size(), col3s.length); for (int i = 0; i < colMan.getCollections().size(); i++) { assertTrue(col3s[0].isSelected()); } }
From source file:org.zilverline.web.TestCustomCollectionEditor.java
public void testCustomCollectionEditorWithStringArrayOfOne() { CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); assertNotNull(colMan);//from w w w .ja va2 s .c o m assertTrue("collections must exist", colMan.getCollections().size() > 0); SearchForm sf = new SearchForm(); BeanWrapper bw = new BeanWrapperImpl(sf); bw.registerCustomEditor(CollectionTriple[].class, "collections", new CustomCollectionEditor(colMan)); try { bw.setPropertyValue("collections", new String[] { "problems" }); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } CollectionTriple[] col3s = (CollectionTriple[]) bw.getPropertyValue("collections"); assertEquals(colMan.getCollections().size(), col3s.length); assertEquals("testdata", col3s[0].getName()); }
From source file:net.sourceforge.vulcan.web.struts.actions.ManagePluginAction.java
public final ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final PluginConfigForm configForm = (PluginConfigForm) form; final String target = configForm.getTarget(); final BeanWrapper bw = new BeanWrapperImpl(form); final Class<?> type = PropertyUtils.getPropertyType(form, target).getComponentType(); final int i; Object[] array = (Object[]) bw.getPropertyValue(target); if (array == null) { array = (Object[]) Array.newInstance(type, 1); i = 0;// w w w .ja va2 s . co m } else { i = array.length; Object[] tmp = (Object[]) Array.newInstance(type, i + 1); System.arraycopy(array, 0, tmp, 0, i); array = tmp; } array[i] = stateManager.getPluginManager().createObject(configForm.getPluginId(), type.getName()); bw.setPropertyValue(target, array); configForm.setFocus(target + "[" + i + "]"); configForm.introspect(request); setHelpAttributes(request, configForm); return mapping.findForward("configure"); }
From source file:org.zilverline.web.TestCustomCollectionEditor.java
public void testCustomCollectionEditorWithStringArrayOfTwo() { CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); assertNotNull(colMan);//from w w w . ja v a 2 s . c o m assertTrue("collections must exist", colMan.getCollections().size() > 0); SearchForm sf = new SearchForm(); BeanWrapper bw = new BeanWrapperImpl(sf); bw.registerCustomEditor(CollectionTriple[].class, "collections", new CustomCollectionEditor(colMan)); try { bw.setPropertyValue("collections", new String[] { "problems", "testdata" }); } catch (BeansException ex) { fail("Should not throw BeansException: " + ex.getMessage()); } CollectionTriple[] col3s = (CollectionTriple[]) bw.getPropertyValue("collections"); assertEquals(colMan.getCollections().size(), col3s.length); assertEquals("testdata", col3s[0].getName()); }
From source file:com.aw.support.beans.PropertyComparator.java
/** * Get the SortDefinition's property value for the given object. * * @param obj the object to get the property value for * @return the property value/* ww w . j a v a2 s . co m*/ */ protected Object getPropertyValue(Object obj) { BeanWrapper bw = (BeanWrapper) this.cachedBeanWrappers.get(obj); if (bw == null) { bw = new BeanWrapperImpl(obj); this.cachedBeanWrappers.put(obj, bw); } // If a nested property cannot be read, simply return null // (similar to JSTL EL). If the property doesn't exist in the // first place, let the exception through. try { return bw.getPropertyValue(this.sortDefinition.getProperty()); } catch (BeansException ex) { logger.info("PropertyComparator could not access property - treating as null for sorting", ex); return null; } }
From source file:com.sshdemo.common.schedule.generate.quartz.EwcmsMethodInvokingJobDetailFactoryBean.java
@Override public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException { prepare();//from w ww . j av a 2s. c o m String name = this.name == null ? beanName : this.name; Class<? extends MethodInvokingJob> jobClass = concurrent ? EwcmsMethodInvokingJobDetailFactoryBean.MethodInvokingJob.class : EwcmsMethodInvokingJobDetailFactoryBean.StatefulMethodInvokingJob.class; if (jobDetailImplClass != null) { jobDetail = (JobDetail) BeanUtils.instantiate(jobDetailImplClass); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(jobDetail); bw.setPropertyValue("name", name); bw.setPropertyValue("group", group); bw.setPropertyValue("jobClass", jobClass); bw.setPropertyValue("durability", Boolean.valueOf(true)); ((JobDataMap) bw.getPropertyValue("jobDataMap")).put("methodInvoker", this); } else { jobDetail = newJob(jobClass).withIdentity(name, group).build(); if (!(jobDetail instanceof JobDetailImpl)) throw new RuntimeException("Expected JobDetail to be an instance of '" + JobDetailImpl.class + "' but instead we got '" + jobDetail.getClass().getName() + "'"); ((JobDetailImpl) jobDetail).setDurability(true); jobDetail.getJobDataMap().put("methodInvoker", this); } if (jobListenerNames != null) { String as[]; int j = (as = jobListenerNames).length; for (int i = 0; i < j; i++) { String jobListenerName = as[i]; if (jobDetailImplClass != null) throw new IllegalStateException( "Non-global JobListeners not supported on Quartz 2 - manually register a Matcher against the Quartz ListenerManager instead"); JobKey jk = jobDetail.getKey(); Matcher<JobKey> matcher = KeyMatcher.keyEquals(jk); try { getScheduler().getListenerManager().addJobListenerMatcher(jobListenerName, matcher); } catch (org.quartz.SchedulerException e) { throw new RuntimeException("Error adding Quartz Trigger Listener: " + e.getMessage()); } //jobDetail.addJobListener(jobListenerName); } } postProcessJobDetail(jobDetail); }