List of usage examples for org.springframework.beans BeanWrapper setPropertyValue
void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnumArrayWithMultipleValues() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapper bw = new JuffrouSpringBeanWrapper(gb); bw.setPropertyValue("customEnumArray", new String[] { "VALUE_1", "VALUE_2" }); assertEquals(2, gb.getCustomEnumArray().length); assertEquals(CustomEnum.VALUE_1, gb.getCustomEnumArray()[0]); assertEquals(CustomEnum.VALUE_2, gb.getCustomEnumArray()[1]); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnumArrayWithMultipleValuesAsCsv() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapper bw = new JuffrouSpringBeanWrapper(gb); bw.setPropertyValue("customEnumArray", "VALUE_1,VALUE_2"); assertEquals(2, gb.getCustomEnumArray().length); assertEquals(CustomEnum.VALUE_1, gb.getCustomEnumArray()[0]); assertEquals(CustomEnum.VALUE_2, gb.getCustomEnumArray()[1]); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnumSetWithMultipleValues() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapper bw = new JuffrouSpringBeanWrapper(gb); bw.setPropertyValue("customEnumSet", new String[] { "VALUE_1", "VALUE_2" }); assertEquals(2, gb.getCustomEnumSet().size()); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnumSetWithMultipleValuesAsCsv() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapper bw = new JuffrouSpringBeanWrapper(gb); bw.setPropertyValue("customEnumSet", "VALUE_1,VALUE_2"); assertEquals(2, gb.getCustomEnumSet().size()); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnumSetWithGetterSetterMismatch() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapper bw = new JuffrouSpringBeanWrapper(gb); bw.setPropertyValue("customEnumSetMismatch", new String[] { "VALUE_1", "VALUE_2" }); assertEquals(2, gb.getCustomEnumSet().size()); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)); assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)); }
From source file:net.kamhon.ieagle.util.ReflectionUtil.java
/** * search String variavle inside the given object, if Empty then change it to Null. * //from w w w.j a v a 2 s .c o m * @param obj * = this object will not be changed, it will be close. * @return */ public static Object changeEmptyStrToNull(Object obj) { Object newObj = obj; // J.printLine(getAllExProperties(obj, " ", ".vo.")); // try { // newObj = BeanUtils.cloneBean(obj); // } catch (Exception e1) { // e1.printStackTrace(); // } // BeanWrapper beanO1 = new BeanWrapperImpl(newObj); PropertyDescriptor[] proDescriptorsO1 = beanO1.getPropertyDescriptors(); int propertyLength = proDescriptorsO1.length; for (int i = 0; i < propertyLength; i++) { try { Object propertyValueO1 = beanO1.getPropertyValue(proDescriptorsO1[i].getName()); if (propertyValueO1 instanceof String && StringUtils.isEmpty((String) propertyValueO1)) { // password is null. it will not come in because it is not // instance of String // J.printNegetif(proDescriptorsO1[i].getName()+"..."+(String)propertyValueO1); beanO1.setPropertyValue(proDescriptorsO1[i].getName(), null); } } catch (Exception e) { // [exec] java.lang.IllegalAccessException: Class // org.apache.commons.beanutils.BeanUtilsBean can not // access a member of class // com.foremobile.gateway.usermgmt.vo.User with modifiers // "private" // [exec] at sun.reflect.Reflection.ensureMemberAccess(Unknown // Source) } } return newObj; }
From source file:pl.java.scalatech.monetary.DefaultFormattingConversionServiceTest.java
@Test public void testJavaMoney() { BeanWrapper beanWrapper = new BeanWrapperImpl(bean); beanWrapper.setConversionService(conversionService); beanWrapper.setPropertyValue("monetaryAmount", "USD 100,000"); beanWrapper.setPropertyValue("currencyUnit", "USD"); assertThat(bean.getMonetaryAmount().getNumber().intValue(), is(100)); assertThat(bean.getMonetaryAmount().getCurrency().getCurrencyCode(), is("PLN")); assertThat(bean.getCurrencyUnit().getCurrencyCode(), is("USD")); String monetaryAmountString = (String) conversionService.convert(bean.getMonetaryAmount(), beanWrapper.getPropertyTypeDescriptor("monetaryAmount"), TypeDescriptor.valueOf(String.class)); assertThat(monetaryAmountString, is("USD 100")); String currencyUnitString = (String) conversionService.convert(bean.getCurrencyUnit(), beanWrapper.getPropertyTypeDescriptor("currencyUnit"), TypeDescriptor.valueOf(String.class)); assertThat(currencyUnitString, is("USD")); }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperEnumTests.java
@Test public void testCustomEnum() { GenericBean<?> gb = new GenericBean<Object>(); BeanWrapperContext context = BeanWrapperContext.create(GenericBean.class, Object.class); BeanWrapper bw = new JuffrouSpringBeanWrapper(context, gb); bw.setPropertyValue("customEnum", "VALUE_1"); assertEquals(CustomEnum.VALUE_1, gb.getCustomEnum()); }
From source file:org.sakaiproject.metaobj.shared.model.ElementListBeanWrapper.java
protected void setValue(BeanWrapper wrapper, Object key, Object value) { wrapper.setPropertyValue((String) key, value); }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.project.PreferencesUtil.java
/** * Set annotation preferences of users for a given project such as window size, annotation * layers,... reading from the file system. * * @param aUsername// w w w.ja v a 2 s . c o m * The {@link User} for whom we need to read the preference (preferences are stored * per user) * @param aRepositoryService the repository service. * @param aAnnotationService the annotation service. * @param aBModel * The {@link BratAnnotatorModel} that will be populated with preferences from the * file * @param aMode the mode. * @throws BeansException hum? * @throws IOException hum? */ public static void setAnnotationPreference(String aUsername, RepositoryService aRepositoryService, AnnotationService aAnnotationService, BratAnnotatorModel aBModel, Mode aMode) throws BeansException, IOException { AnnotationPreference preference = new AnnotationPreference(); BeanWrapper wrapper = new BeanWrapperImpl(preference); // get annotation preference from file system try { for (Entry<Object, Object> entry : aRepositoryService.loadUserSettings(aUsername, aBModel.getProject()) .entrySet()) { String property = entry.getKey().toString(); int index = property.lastIndexOf("."); String propertyName = property.substring(index + 1); String mode = property.substring(0, index); if (wrapper.isWritableProperty(propertyName) && mode.equals(aMode.getName())) { if (AnnotationPreference.class.getDeclaredField(propertyName) .getGenericType() instanceof ParameterizedType) { List<String> value = Arrays .asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(",")); if (!value.get(0).equals("")) { wrapper.setPropertyValue(propertyName, value); } } else { wrapper.setPropertyValue(propertyName, entry.getValue()); } } } aBModel.setPreferences(preference); // Get tagset using the id, from the properties file aBModel.getAnnotationLayers().clear(); if (preference.getAnnotationLayers() != null) { for (Long id : preference.getAnnotationLayers()) { aBModel.getAnnotationLayers().add(aAnnotationService.getLayer(id)); } } } // no preference found catch (Exception e) { /* * // disable corefernce annotation for correction/curation pages for 0.4.0 release * List<TagSet> tagSets = aAnnotationService.listTagSets(aBModel.getProject()); * List<TagSet> corefTagSets = new ArrayList<TagSet>(); List<TagSet> noFeatureTagSet = * new ArrayList<TagSet>(); for (TagSet tagSet : tagSets) { if (tagSet.getLayer() == * null || tagSet.getFeature() == null) { noFeatureTagSet.add(tagSet); } else if * (tagSet.getLayer().getType().equals(ChainAdapter.CHAIN)) { corefTagSets.add(tagSet); * } } * * if (aMode.equals(Mode.CORRECTION) || aMode.equals(Mode.AUTOMATION) || * aMode.equals(Mode.CURATION)) { tagSets.removeAll(corefTagSets); } * tagSets.remove(noFeatureTagSet); aBModel.setAnnotationLayers(new * HashSet<TagSet>(tagSets)); */ /* * abAnnotatorModel.setAnnotationLayers(new HashSet<TagSet>(aAnnotationService * .listTagSets(abAnnotatorModel.getProject()))); */ List<AnnotationLayer> layers = aAnnotationService.listAnnotationLayer(aBModel.getProject()); aBModel.setAnnotationLayers(layers); } }