} else if (File.class.isAssignableFrom(obj.getClass())) {
File f = (File)obj;
ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA)
? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null;
try {
return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, new FileInputStream(f), cd);
} catch (FileNotFoundException ex) {
throw new WebApplicationException(ex);
}
} else if (Attachment.class.isAssignableFrom(obj.getClass())) {
Attachment att = (Attachment)obj;
if (att.getObject() == null) {
return att;
}
dh = getHandlerForObject(att.getObject(), att.getObject().getClass(),
att.getObject().getClass(), new Annotation[]{},
att.getContentType().toString(), id);
return new Attachment(att.getContentId(), dh, att.getHeaders());
} else if (byte[].class.isAssignableFrom(obj.getClass())) {
ByteDataSource source = new ByteDataSource((byte[])obj);
source.setContentType(mimeType);
dh = new DataHandler(source);
} else {
dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id);
}
String contentId = getContentId(anns, id);
return new Attachment(contentId, dh, new MetadataMap<String, String>());
}