// Create object and bind it
if (factory instanceof Session) {
JavaMailSessionRef javamailSession = new JavaMailSessionRef();
javaMailRef = javamailSession;
} else if (factory instanceof MimePart) {
JavaMailMimePartDataSourceRef mimePartDataSourceRef = new JavaMailMimePartDataSourceRef();
javaMailRef = mimePartDataSourceRef;
// Set properties of this factory.
MimePart mimePart = (MimePart) factory;
// Set subject
mimePartDataSourceRef.setSubject(mimePart.getSubject());
// Define addresses
List<Address> toAddresses = new ArrayList<Address>();
List<Address> ccAddresses = new ArrayList<Address>();
List<Address> bccAddresses = new ArrayList<Address>();
// Get value
for (MailAddress mail : mimePart.getMailAddresses()) {
// Build address object from the string
Address address = null;
try {
address = new InternetAddress(mail.getName());
} catch (AddressException e) {
throw new EZBComponentException("Cannot build an internet address with given value '" + mail.getName()
+ "'.", e);
}
// Add address in the correct list
if ("CC".equalsIgnoreCase(mail.getType())) {
ccAddresses.add(address);
} else if ("BCC".equalsIgnoreCase(mail.getType())) {
bccAddresses.add(address);
} else {
// Default is TO
toAddresses.add(address);
}
}
// Set recipients
mimePartDataSourceRef.setToRecipients(toAddresses.toArray(new Address[toAddresses.size()]));
mimePartDataSourceRef.setCcRecipients(ccAddresses.toArray(new Address[ccAddresses.size()]));
mimePartDataSourceRef.setBccRecipients(bccAddresses.toArray(new Address[bccAddresses.size()]));
} else {
throw new EZBComponentException("Unknown factory '" + factory + "'.");
}