}
@Override
@SuppressWarnings("unchecked")
public List<CompositeData> browse() throws Exception {
MailQueueIterator it = queue.browse();
List<CompositeData> data = new ArrayList<CompositeData>();
String[] names = new String[]{"name", "sender", "state", "recipients", "size", "lastUpdated", "remoteAddress", "remoteHost", "errorMessage", "attributes", "nextDelivery"};
String[] descs = new String[]{"Unique name", "Sender", "Current state", "Recipients", "Size in bytes", "Timestamp of last update", "IPAddress of the sender", "Hostname of the sender", "Errormessage if any", "Attributes stored", "Timestamp of when the next delivery attempt will be make"};
OpenType[] types = new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG};
while (it.hasNext()) {
MailQueueItemView mView = it.next();
Mail m = mView.getMail();
long nextDelivery = mView.getNextDelivery();
Map<String, Object> map = new HashMap<String, Object>();
map.put(names[0], m.getName());
String sender = null;
MailAddress senderAddress = m.getSender();
if (senderAddress != null) {
sender = senderAddress.toString();
}
map.put(names[1], sender);
map.put(names[2], m.getState());
StringBuilder rcptsBuilder = new StringBuilder();
Collection<MailAddress> rcpts = m.getRecipients();
if (rcpts != null) {
Iterator<MailAddress> rcptsIt = rcpts.iterator();
while (rcptsIt.hasNext()) {
rcptsBuilder.append(rcptsIt.next().toString());
if (rcptsIt.hasNext()) {
rcptsBuilder.append(",");
}
}
}
map.put(names[3], rcptsBuilder.toString());
map.put(names[4], m.getMessageSize());
map.put(names[5], m.getLastUpdated().getTime());
map.put(names[6], m.getRemoteAddr());
map.put(names[7], m.getRemoteHost());
map.put(names[8], m.getErrorMessage());
Map<String, String> attrs = new HashMap<String, String>();
Iterator<String> attrNames = m.getAttributeNames();
while (attrNames.hasNext()) {
String attrName = attrNames.next();
String attrValueString = null;
Serializable attrValue = m.getAttribute(attrName);
if (attrValue != null) {
attrValueString = attrValue.toString();
}
attrs.put(attrName, attrValueString);
}
map.put(names[9], attrs.toString());
map.put(names[10], nextDelivery);
CompositeDataSupport c = new CompositeDataSupport(new CompositeType(Mail.class.getName(), "Queue Mail", names, descs, types), map);
data.add(c);
}
it.close();
return data;
}