if (m_classMessageMap == null)
{
m_classMessageMap = new HashTab();
}
Message other = (Message)m_classMessageMap.put(clazz, mappedMessage);
Message baseMessage;
if (other == null)
{
// No collision, add mapping to parent as well.
if ((baseMessage = m_message.getBaseMessage()) != null)
{
((ObjectMessagePartMapping)baseMessage.getRoot().getMapping()).addClassMessage(clazz, mappedMessage);
}
}
else
{
// If old entry is base of new entry, new entry is left in map: it is more specific.
// Otherwise, update map with a more general entry.
if (!other.isUpcast(mappedMessage))
{
if (!mappedMessage.isUpcast(other))
{
// The old entry and new entry do not inherit from each other.
ObjectMessagePartMapping mappedMessageMapping = (ObjectMessagePartMapping)other.getRoot().getMapping();
ObjectMessagePartMapping otherMapping = (ObjectMessagePartMapping)other.getRoot().getMapping();
if (otherMapping.isPrimary() ^ mappedMessageMapping.isPrimary())
{
if (otherMapping.isPrimary())
{
// The old entry takes precedence over the new entry.
m_classMessageMap.put(clazz, mappedMessage = other);
}
}
else
{
// Unable to disambiguate; map to their common base.
assert m_message.isUpcast(other) && m_message.isUpcast(mappedMessage);
m_classMessageMap.put(clazz, mappedMessage = m_message);
}
}
// Add the mapping to our parent as well.
if ((baseMessage = m_message.getBaseMessage()) != null)
{
((ObjectMessagePartMapping)baseMessage.getRoot().getMapping()).addClassMessage(clazz, mappedMessage);
}
}
}
}