{
ReferenceInfo info = (ReferenceInfo) iter.next();
long msgId = info.getMessageId();
MessageReference ref = ms.reference(msgId);
if (ref != null)
{
refMap.put(msgId, ref);
}
else
{
// Add id to list of msg ids to load
msgIdsToLoad.add(msgId);
}
}
// Load the messages (if any)
List messages = null;
if (!msgIdsToLoad.isEmpty())
{
messages = pm.getMessages(msgIdsToLoad);
if (messages.size() != msgIdsToLoad.size())
{
// Sanity check
throw new IllegalStateException("Did not load correct number of messages, wanted:" +
msgIdsToLoad.size() + " but got:" +
messages.size());
}
// Create references for these messages and add them to the reference map
iter = messages.iterator();
while (iter.hasNext())
{
Message m = (Message)iter.next();
MessageReference ref = ms.reference(m);
refMap.put(new Long(m.getMessageID()), ref);
}
}