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 Method getGetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method : methods) { String methodName = method.getName(); if (methodName.matches("^(get|is).*") && method.getParameterTypes().length == 0) { int idx = methodName.startsWith("get") ? 3 : 2; if (Introspector.decapitalize(methodName.substring(idx)).equals(name)) return method; } } throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name); }
Introspector.flushFromCaches(type); // Ensure that we don't get a cached reference, the Groovy class could have been modified PropertyDescriptor[] descs = Introspector.getPropertyDescriptors(type); for (PropertyDescriptor property : descs) { String propertyName = property.getName();
Introspector.flushFromCaches(clazz);
Introspector.flushFromCaches(type); // Ensure that we don't get a cached reference, the Groovy class could have been modified PropertyDescriptor[] descs = Introspector.getPropertyDescriptors(type); for (PropertyDescriptor property : descs) { String propertyName = property.getName();
Introspector.flushFromCaches(clazz);
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 ""; } }
Introspector.flushFromCaches(type); // Ensure that we don't get a cached reference, the Groovy class could have been modified PropertyDescriptor[] descs = Introspector.getPropertyDescriptors(type); for (PropertyDescriptor property : descs) { String propertyName = property.getName();
public static Method getGetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method : methods) { String methodName = method.getName(); if (methodName.matches("^(get|is).*") && method.getParameterTypes().length == 0) { int idx = methodName.startsWith("get") ? 3 : 2; if (Introspector.decapitalize(methodName.substring(idx)).equals(name)) return method; } } throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name); }
Introspector.flushFromCaches(clazz);
PropertyDescriptor[] propertyDescriptors = Introspector.getPropertyDescriptors(persistentClass);
Introspector.flushFromCaches(type); // Ensure that we don't get a cached reference, the Groovy class could have been modified PropertyDescriptor[] descs = Introspector.getPropertyDescriptors(type); for (PropertyDescriptor property : descs) { String propertyName = property.getName();
public static Method getSetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method: methods) { String methodName = method.getName(); if ( methodName.startsWith("set") && method.getParameterTypes().length==1 ) { if ( Introspector.decapitalize( methodName.substring(3) ).equals(name) ) { return method; } } } throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name); }
Introspector.flushFromCaches(clazz);
public static PropertyDescriptor[] getProperties(Class<?> clazz) { try { PropertyDescriptor[] properties = Introspector.getPropertyDescriptors(clazz); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) {
public static Method getSetterMethod(Class<?> clazz, String name) { Method[] methods = clazz.getMethods(); for (Method method: methods) { String methodName = method.getName(); if ( methodName.startsWith("set") && method.getParameterTypes().length==1 ) { if ( Introspector.decapitalize( methodName.substring(3) ).equals(name) ) { return method; } } } throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name); }
public static PropertyDescriptor[] getProperties(Class<?> clazz) { try { PropertyDescriptor[] properties = Introspector.getPropertyDescriptors(clazz); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) {
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }
public static PropertyDescriptor[] getProperties(Class<?> clazz) { try { PropertyDescriptor[] properties = Introspector.getPropertyDescriptors(clazz); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) {
@SuppressWarnings("unchecked") private static void introspectSet(Method method, Map<String, Map<String, Object>> propertyMap) { String methodName = method.getName(); if (!method.getName().startsWith("set")) return; if (method.getParameterTypes().length != 1 || method.getReturnType() != void.class) return; String propertyName = decapitalize(methodName.substring(3)); Map<String, Object> table = propertyMap.get(propertyName); if (table == null) { table = new HashMap<String, Object>(); propertyMap.put(propertyName, table); } List<Method> setters = (List<Method>)table.get("setters"); if (setters == null) { setters = new ArrayList<Method>(); table.put("setters", setters); } // add new setter setters.add(method); }