public static Object getProperty(Object bean, String name) { PropertyDescriptor[] pds = getProperties(bean.getClass()); for (PropertyDescriptor pd : pds) { if (pd.getName().equals(name) && pd.getReadMethod() != null) { try { return pd.getReadMethod().invoke(bean); } catch (Exception e) { throw new RuntimeException("Could not get value for property " + name + " on object " + bean, e); } } } throw new RuntimeException("Property " + name + " not found on object " + bean); }
public static Object getProperty(Object bean, String name) { PropertyDescriptor[] pds = getProperties(bean.getClass()); for (PropertyDescriptor pd : pds) { if (pd.getName().equals(name) && pd.getReadMethod() != null) { try { return pd.getReadMethod().invoke(bean); } catch (Exception e) { throw new RuntimeException("Could not get value for property " + name + " on object " + bean, e); } } } throw new RuntimeException("Property " + name + " not found on object " + bean); }
public static Object getProperty(Object bean, String name) { PropertyDescriptor[] pds = getProperties(bean.getClass()); for (PropertyDescriptor pd : pds) { if (pd.getName().equals(name) && pd.getReadMethod() != null) { try { return pd.getReadMethod().invoke(bean); } catch (Exception e) { throw new RuntimeException("Could not get value for property " + name + " on object " + bean, e); } } } throw new RuntimeException("Property " + name + " not found on object " + bean); }
public static String toString(Object component) { try { PropertyDescriptor[] props = Introspector.getPropertyDescriptors(component.getClass()); StringBuilder builder = new StringBuilder(); for (PropertyDescriptor descriptor : props) { builder.append( descriptor.getName() ) .append("=") .append( descriptor.getReadMethod().invoke(component) ) .append("; "); } return builder.toString(); } catch (Exception e) { return ""; } }
public static String toString(Object component) { try { PropertyDescriptor[] props = Introspector.getPropertyDescriptors(component.getClass()); StringBuilder builder = new StringBuilder(); for (PropertyDescriptor descriptor : props) { builder.append( descriptor.getName() ) .append("=") .append( descriptor.getReadMethod().invoke(component) ) .append("; "); } return builder.toString(); } catch (Exception e) { return ""; } }
@Override public void setPropertyValue(Object entity, String name, Object value) { if (entity == null) return; try { boolean found = false; PropertyDescriptor[] pds = Introspector.getPropertyDescriptors(entity.getClass()); for (PropertyDescriptor pd : pds) { if (pd.getName().equals(name) && pd.getWriteMethod() != null) { Object oldValue = null; if (pd.getReadMethod() != null) oldValue = pd.getReadMethod().invoke(entity); pd.getWriteMethod().invoke(entity, value); if (pd.getReadMethod() != null) PropertyChangeHelper.firePropertyChange(entity, name, oldValue, value); found = true; break; } } if (!found) super.setPropertyValue(entity, name, value); } catch (Exception e) { throw new RuntimeException("Could not set property " + name + " on entity " + entity, e); } }
@Override public void defineProperty(String name) { if (type.length() == 0 || instantiator != null) properties.add(new MapProperty(converters, name)); else { try { // Try to find public getter/setter. PropertyDescriptor[] props = Introspector.getPropertyDescriptors(clazz); for (PropertyDescriptor prop : props) { if (name.equals(prop.getName()) && prop.getWriteMethod() != null && prop.getReadMethod() != null) { properties.add(new MethodProperty(converters, name, prop.getWriteMethod(), prop.getReadMethod())); return; } } // Try to find public field. Field field = clazz.getField(name); if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) properties.add(new FieldProperty(converters, field)); } catch (NoSuchFieldException e) { if ("uid".equals(name)) // ObjectProxy specific property... properties.add(new UIDProperty(converters)); else throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } }
if (property.getName().equals(field.getName())) { found = true; if (property.getReadMethod() == null) { try { Method readMethod = clazz.getDeclaredMethod(getIsMethodName(field.getName()));
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
@Override public void defineProperty(String name) { if (type.length() == 0 || instantiator != null) properties.add(new MapProperty(converters, name)); else { try { // Try to find public getter/setter. PropertyDescriptor[] props = Introspector.getPropertyDescriptors(clazz); for (PropertyDescriptor prop : props) { if (name.equals(prop.getName()) && prop.getWriteMethod() != null && prop.getReadMethod() != null) { properties.add(new MethodProperty(converters, name, prop.getWriteMethod(), prop.getReadMethod())); return; } } // Try to find public field. Field field = clazz.getField(name); if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) properties.add(new FieldProperty(converters, field)); } catch (NoSuchFieldException e) { if ("uid".equals(name)) // ObjectProxy specific property... properties.add(new UIDProperty(converters)); else throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public void defineProperty(String name) { if (type.length() == 0 || instantiator != null) properties.add(new MapProperty(converters, name)); else { try { // Try to find public getter/setter. PropertyDescriptor[] props = Introspector.getPropertyDescriptors(clazz); for (PropertyDescriptor prop : props) { if (name.equals(prop.getName()) && prop.getWriteMethod() != null && prop.getReadMethod() != null) { properties.add(new MethodProperty(converters, name, prop.getWriteMethod(), prop.getReadMethod())); return; } } // Try to find public field. Field field = clazz.getField(name); if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) properties.add(new FieldProperty(converters, field)); } catch (NoSuchFieldException e) { if ("uid".equals(name)) // ObjectProxy specific property... properties.add(new UIDProperty(converters)); else throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } } }
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
if (name.equals(prop.getName()) && prop.getWriteMethod() != null && prop.getReadMethod() != null) { properties.add(new MethodProperty(converters, name, prop.getWriteMethod(), prop.getReadMethod())); return;
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
for (PropertyDescriptor property : descs) { String propertyName = property.getName(); if (property.getWriteMethod() != null && property.getReadMethod() != null) { properties.add(new MethodProperty(converters, propertyName, property.getWriteMethod(), property.getReadMethod())); propertyNames.add(propertyName);
if (!properties[i].getName().equals("class")) { String propertyName = properties[i].getName(); Method readMethod = properties[i].getReadMethod(); Object propertyValue = null; if (readMethod == null) {
if (!properties[i].getName().equals("class")) { String propertyName = properties[i].getName(); Method readMethod = properties[i].getReadMethod(); Object propertyValue = null; if (readMethod == null) {