public static Field getField(Class<?> clazz, String fieldName) { return getField(clazz, fieldName, clazz); }
public static Field getField(Class<?> clazz, String fieldName) { return getField(clazz, fieldName, clazz); }
private static Field getField(Class<?> clazz, String fieldName, Class<?> original) { Field field = null; try { field = clazz.getDeclaredField(fieldName); if (LOG.isLoggable(Level.FINE)) { LOG.fine("found field " + fieldName + " in " + clazz.getName()); } } catch (SecurityException e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_RU_8", clazz.getName(), fieldName); throw new BonitaRuntimeException(message, e); } catch (NoSuchFieldException e) { if (clazz.getSuperclass() != null) { return getField(clazz.getSuperclass(), fieldName, original); } else { String message = ExceptionManager.getInstance().getFullMessage( "bp_RU_9", original.getName(), fieldName); throw new BonitaRuntimeException(message, e); } } return field; }
private static Field getField(Class<?> clazz, String fieldName, Class<?> original) { Field field = null; try { field = clazz.getDeclaredField(fieldName); if (LOG.isLoggable(Level.FINE)) { LOG.fine("found field " + fieldName + " in " + clazz.getName()); } } catch (SecurityException e) { String message = ExceptionManager.getInstance().getFullMessage( "bp_RU_8", clazz.getName(), fieldName); throw new BonitaRuntimeException(message, e); } catch (NoSuchFieldException e) { if (clazz.getSuperclass() != null) { return getField(clazz.getSuperclass(), fieldName, original); } else { String message = ExceptionManager.getInstance().getFullMessage( "bp_RU_9", original.getName(), fieldName); throw new BonitaRuntimeException(message, e); } } return field; }
@Override public void apply(final Object target, final WireContext wireContext) { if (target != null) { // Get field synchronized (this) { if (field == null) { final Class<?> clazz = target.getClass(); field = ReflectUtil.getField(clazz, fieldName); } } // Create value final Object value = wireContext.create(descriptor, true); // Set the field value try { ReflectUtil.set(field, target, value); } catch (final Exception e) { final String message = ExceptionManager.getInstance().getFullMessage("bp_FO_1", fieldName, value); throw new WireException(message, e); } } }