List of usage examples for org.apache.commons.beanutils PropertyUtils getSimpleProperty
public static Object getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified simple property of the specified bean, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:Main.java
public static void main(String[] args) { MyClass track = new MyClass(); track.setTitle("this is a test"); String title = (String) PropertyUtils.getSimpleProperty(track, "title"); System.out.println("Title = " + title); }
From source file:com.qagen.osfe.core.utils.ValueToString.java
public static String valueToString(Object bean, String fieldId, String type, String pattern) { try {/* ww w .jav a2s . c o m*/ final Object value = PropertyUtils.getSimpleProperty(bean, fieldId); switch (AttributeType.valueOf(type)) { case Integer: case Long: case Float: case Double: return formatNumber(value, pattern); case Time: case Date: case Timestamp: return formatTimestamp(value, pattern); } return value.toString(); } catch (IllegalAccessException e) { throw new FeedErrorException(e); } catch (InvocationTargetException e) { throw new FeedErrorException(e); } catch (NoSuchMethodException e) { throw new FeedErrorException(e); } }
From source file:com.bstek.dorado.data.entity.PropertyPathUtils.java
public static Object getValueByPath(EntityDataType dataType, Object object, String propertyPath) throws Exception { String[] paths = StringUtils.split(propertyPath, '.'); Object value = object;/* ww w. ja va 2 s .c o m*/ for (int i = 0; i < paths.length; i++) { String path = paths[i]; if (EntityUtils.isEntity(value)) { value = EntityUtils.getValue(value, path); } else if (value instanceof Map<?, ?>) { value = ((Map<?, ?>) value).get(path); } else { value = PropertyUtils.getSimpleProperty(value, path); } if (value == null) { break; } } return value; }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.TransferDomainObjectProperty.java
@Atomic public static void run(DomainObject srcObject, DomainObject dstObject, String slotName) throws FenixServiceException { check(RolePredicates.MANAGER_PREDICATE); try {// w w w. j av a 2 s. c om Object srcProperty = PropertyUtils.getSimpleProperty(srcObject, slotName); if (srcProperty != null && srcProperty instanceof Collection) { Collection srcCollection = (Collection) srcProperty; Object dstProperty = PropertyUtils.getSimpleProperty(dstObject, slotName); if (dstProperty instanceof Collection) { Collection dstCollection = (Collection) dstProperty; dstCollection.addAll(srcCollection); } } else { PropertyUtils.setSimpleProperty(dstObject, slotName, srcProperty); } } catch (InvocationTargetException e) { if (e.getTargetException() != null) { if (e.getTargetException() instanceof WriteOnReadError) { throw ((WriteOnReadError) e.getTargetException()); } throw new FenixServiceException(e.getTargetException()); } throw new FenixServiceException(e); } catch (IllegalAccessException e) { throw new FenixServiceException(e); } catch (NoSuchMethodException e) { throw new FenixServiceException(e); } }
From source file:com.reizes.shiva.etl.core.transformer.ModelToMySqlDumpTransformer.java
@Override public Object doProcess(Object input) throws Exception { String[] output = new String[columns.length]; for (int i = 0; i < columns.length; i++) { String name = StringUtil.camelize(columns[i]); if (PropertyUtils.isReadable(input, name)) { Object data = PropertyUtils.getSimpleProperty(input, name); if (data != null) { if (data instanceof Date) { output[i] = String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", data); } else if (data instanceof Boolean) { output[i] = (Boolean) data ? "1" : "0"; } else { output[i] = "\"" + StringUtils.replaceEach(data.toString().trim(), new String[] { "\"", "\\", "\t" }, new String[] { "\\\"", "\\\\", "\\t" }) + "\""; }/*from www. ja va2s.c o m*/ } else { output[i] = "NULL"; } } } String str = StringUtil.join(output, '\t') + '\n'; return str; }
From source file:com.kuzumeji.framework.standard.TesteeTest.java
/** @see PropertyUtils#getSimpleProperty(Object, String) */ @Test/*w w w. ja va 2 s . c om*/ public void test() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Testee testee = new Testee("foo#0", "bar#0", "baz#0"); assertThat(testee, is(not(nullValue()))); assertThat((String) PropertyUtils.getSimpleProperty(testee, "foo"), is("foo#0")); }
From source file:com.agimatec.validation.util.PropertyAccess.java
public static Object getProperty(Object bean, String property) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { if (bean instanceof Map) { return ((Map) bean).get(property); } else { // supports DynaBean and standard Objects return PropertyUtils.getSimpleProperty(bean, property); }//from w w w. j av a2 s . c om }
From source file:arena.utils.ReflectionUtils.java
public static Object getAttributeUsingGetter(String attributeName, Object entity) { try {/*from ww w .ja v a 2 s. co m*/ return PropertyUtils.getSimpleProperty(entity, attributeName); } catch (NoSuchMethodException err) { LogFactory.getLog(ReflectionUtils.class).error(err); throw new RuntimeException("Error in getter", err); } catch (IllegalAccessException err) { LogFactory.getLog(ReflectionUtils.class).error(err); throw new RuntimeException("Error in getter", err); } catch (InvocationTargetException err) { LogFactory.getLog(ReflectionUtils.class).error(err); throw new RuntimeException("Error in getter", err); } }
From source file:fr.isima.reflexbench.architecture.ApacheReflect.java
@Override public void searchForFields(Object obj) { String fieldToSearch = ((SampleSourceCode) obj).getSearchingField(); try {/*from www . j a v a 2 s. c o m*/ PropertyUtils.getSimpleProperty(obj, fieldToSearch); } catch (IllegalAccessException ex) { Logger.getLogger(ApacheReflect.class.getName()).log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { Logger.getLogger(ApacheReflect.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchMethodException ex) { Logger.getLogger(ApacheReflect.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.discursive.jccook.bean.SimplePropertyExample.java
private void start() { // Create an author Author wolfe = new Author("Tom Wolfe", "Green"); try {//from w ww.java 2s . c om String name = (String) PropertyUtils.getSimpleProperty(wolfe, "name"); String favoriteColor = (String) PropertyUtils.getSimpleProperty(wolfe, "favoriteColor"); System.out.println("The Author has some properties: " + name + ", " + favoriteColor); } catch (IllegalAccessException e) { System.out.println("You are not allowed to access a property!"); } catch (InvocationTargetException e) { System.out.println("There was a problem invoking the method."); } catch (NoSuchMethodException e) { System.out.println("The is no method to get a property."); } }