/** * Adds an element to a public or protected collection of an Object given the field name. * * @param o the Object * @param fieldName the name of the relevant collection * @param element the element to add to the collection */ public static void addCollectionElement(Object o, String fieldName, Object element) { try { getAdder(o.getClass(), fieldName).invoke(o, element); } catch (Exception e) { String type = null; try { type = getFieldInfo(o.getClass(), fieldName).getElementType().getName(); } catch (Exception e3) { IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " - not an accessible collection"); e2.initCause(e); throw e2; } IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a " + element.getClass().getName() + ")"); e2.initCause(e); throw e2; } }
/** * Adds an element to a public or protected collection of an Object given the field name. * * @param o the Object * @param fieldName the name of the relevant collection * @param element the element to add to the collection */ public static void addCollectionElement(Object o, String fieldName, Object element) { try { getAdder(o.getClass(), fieldName).invoke(o, element); } catch (Exception e) { String type = null; try { type = getFieldInfo(o.getClass(), fieldName).getElementType().getName(); } catch (Exception e3) { IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " - not an accessible collection"); e2.initCause(e); throw e2; } IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a " + element.getClass().getName() + ")"); e2.initCause(e); throw e2; } }
/** * Returns the element type of a collection given the field name. * * @param c the Class * @param fieldName the name of the relevant collection * @return the class of the field, or null if the field is not found * @throws IllegalArgumentException if the field is not a collection */ public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { try { return info.getElementType(); } catch (NullPointerException e) { IllegalArgumentException e2 = new IllegalArgumentException("Field " + Util.getFriendlyName(c) + "." + fieldName + " is not a collection"); e2.initCause(e); throw e2; } } return null; }
/** * Returns the element type of a collection given the field name. * * @param c the Class * @param fieldName the name of the relevant collection * @return the class of the field, or null if the field is not found * @throws IllegalArgumentException if the field is not a collection */ public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { try { return info.getElementType(); } catch (NullPointerException e) { IllegalArgumentException e2 = new IllegalArgumentException("Field " + Util.getFriendlyName(c) + "." + fieldName + " is not a collection"); e2.initCause(e); throw e2; } } return null; }