/** * Store the name for currently working field. Given <code>fieldName</code> is not checked for existence but just stored * into {@link #fieldName}. * * @param fieldName current working field name. */ public final void setFieldName(String fieldName) { this.fieldName = Strings.toMemberName(fieldName); }
/** * Return named form field or null if there is none with requested name. Given name supports both dashed case or Java member * name formats. * * @param name form field name. * @return named form field or null if not found. */ private FormField getFormField(String name) { // key of the form fields map is normalized to Java member name return fields.get(Strings.toMemberName(name)); } }
@Override public UploadedFile getUploadedFile(String partName) { Params.notNullOrEmpty(partName, "Form part name"); // key of the uploaded files map is normalized to Java member name return uploadedFiles.get(Strings.toMemberName(partName)); }
@Override public boolean is(String name) { Params.notNull(name, "Name"); return name.equals(Strings.toMemberName(name)); }
@Override public boolean is(String name) { Params.notNull(name, "Name"); return name.equals(Strings.toMemberName(name)); }
public PartImpl(FileItemStream fileItemStream) { this.fileItemStream = fileItemStream; this.name = Strings.toMemberName(this.fileItemStream.getFieldName()); }
/** * Get child node by name creating it on the fly if not set. This method attempt to retrieve child node for wrapped * object field with requested name; it returns null if there is no object field with requested child name. If field * value is null create child node and set it. * * @param childName child name. * @return child node, newly created or retrieved from wrapped object field. */ @Override public Node getChild(String childName) throws IllegalAccessException { Field field = null; try { field = Classes.getFieldEx(object.getClass(), Strings.toMemberName(childName)); } catch (NoSuchFieldException e) { // best effort approach: form to object mapping is not so strictly but still log missing fields log.debug("Missing field |%s| from object |%s|.", childName, object.getClass()); return null; } Object child = field.get(object); // not test coverable condition: if child is null child instanceof Collection cannot be true if (child == null || (child instanceof Collection<?> && ((Collection<?>) child).size() == 0)) { child = FormObject.this.factory.newInstance(field.getType()); field.set(object, child); } return FormObject.this.factory.createNode(child, type(field)); }
/** * Set value to wrapped object field identified by requested child name. Given string value is converted to wrapped * object type using {@link Converter}. * * @param childName wrapped object field name, * @param value string value loaded from form field, null and empty accepted. * @throws ConverterException if field value conversion fails. * @throws IllegalAccessException this exception is required by reflective field signature but never thrown. */ @Override public void setValue(String childName, Object value) throws ConverterException, IllegalAccessException { Field field = null; try { field = Classes.getFieldEx(object.getClass(), Strings.toMemberName(childName)); } catch (NoSuchFieldException e) { // best effort approach: form to object mapping is not so strictly - i.e. ignores missing fields log.debug("Missing field |%s| from object |%s|.", childName, object.getClass()); return; } if (value instanceof UploadedFile) { if (Types.isKindOf(field.getType(), File.class)) { field.set(object, ((UploadedFile) value).getFile()); } else { field.set(object, value); } } else { field.set(object, converter.asObject((String) value, field.getType())); } } }
return Classes.getFieldEx(object.getClass(), Strings.toMemberName(property)).get(object); } catch (NoSuchFieldException expectedMissingField) { return getContentObject(object, property);
Object object = Classes.newInstance(type); for (Parameter parameter : parameters) { Field field = Classes.getField(type, Strings.toMemberName(parameter.getName())); Classes.setFieldValue(object, field, asObject(parameter.getValue(), field.getType()));