@Override public Object value(Object root, String name) { return PropertyUtils.getProperty(root, name); } }
public int compare(Object o1, Object o2) { if ((o1 == null && o2 == null) || o1 == o2) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } Comparable p1 = (Comparable) PropertyUtils.getProperty( o1, indexProperty); Comparable p2 = (Comparable) PropertyUtils.getProperty( o2, indexProperty); return (p1 == null) ? -1 : p1.compareTo(p2); } };
/** * Extracts property value from an object using JavaBean-compatible * introspection with one addition - a property can be a dot-separated * property name path. */ @SuppressWarnings("unchecked") public E getFrom(Object bean) { return (E) PropertyUtils.getProperty(bean, getName()); }
protected int getIndexValue(Object object) { Number n = (Number) PropertyUtils.getProperty(object, indexProperty); if (n == null) { throw new CayenneRuntimeException("Null index property '%s' for object %s" , indexProperty, object); } return n.intValue(); }
private final Object readSimpleProperty(String property) { // side effect - resolves HOLLOW object Object object = readProperty(property); // if a null value is returned, there is still a chance to // find a non-persistent property via reflection if (object == null && !values.containsKey(property)) { object = PropertyUtils.getProperty(this, property); } return object; }
/** * Returns the "name" property of the object. * * @since 1.1 */ public static String getObjectName(Object object) { if (object == null) { return null; } else if (object instanceof CayenneMapEntry) { return ((CayenneMapEntry) object).getName(); } else if (object instanceof String) { return (String) object; } else { try { // use reflection return (String) PropertyUtils.getProperty(object, "name"); } catch (Exception ex) { return null; } } }
public static ValidationFailure validateMandatory(Object bean, String attribute) { if (bean == null) { throw new NullPointerException("Null bean."); } try { Object result = PropertyUtils.getProperty(bean, attribute); return validateMandatory(bean, attribute, result); } catch (Exception ex) { throw new CayenneRuntimeException("Error validationg bean property: " + bean.getClass().getName() + "." + attribute, ex); } }
@Override protected Object evaluateNode(Object o) throws Exception { return (o instanceof DataObject) ? ((DataObject) o).readNestedProperty(path) : (o instanceof Entity) ? evaluateEntityNode((Entity) o) : PropertyUtils.getProperty(o, path); }
private static final Object readSimpleProperty(Object o, String propertyName) { if (o instanceof Persistent) { PropertyDescriptor property = getProperty((Persistent) o, propertyName); if (property != null) { return property.readProperty(o); } } // handling non-persistent property return PropertyUtils.getProperty(o, propertyName); }
return String.valueOf(PropertyUtils.getProperty(value, "className")); return (value != null) ? String.valueOf(PropertyUtils.getProperty(value, "name")) : ""; } catch (Exception e) { String objectClass = (value == null) ? "(unknown)" : value.getClass().getName();