String routingKey = TopicNormalizer.normalize(bindingKey);
if(_bindings.containsKey(binding))
{
Map<String,Object> oldArgs = _bindings.get(binding);
TopicExchangeResult result = _topicExchangeResults.get(routingKey);
if(FilterSupport.argumentsContainFilter(args))
{
if(FilterSupport.argumentsContainFilter(oldArgs))
{
result.replaceQueueFilter(queue,
FilterSupport.createMessageFilter(oldArgs, queue),
FilterSupport.createMessageFilter(args, queue));
}
else
{
result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue));
result.removeUnfilteredQueue(queue);
}
}
else
{
if(FilterSupport.argumentsContainFilter(oldArgs))
{
result.addUnfilteredQueue(queue);
result.removeFilteredQueue(queue, FilterSupport.createMessageFilter(oldArgs, queue));
}
else
{
// TODO - fix control flow
return;
}
}
result.addBinding(binding);
}
else
{
TopicExchangeResult result = _topicExchangeResults.get(routingKey);
if(result == null)
{
result = new TopicExchangeResult();
if(FilterSupport.argumentsContainFilter(args))
{
result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue));
}
else
{
result.addUnfilteredQueue(queue);
}
_parser.addBinding(routingKey, result);
_topicExchangeResults.put(routingKey,result);
}
else
{
if(FilterSupport.argumentsContainFilter(args))
{
result.addFilteredQueue(queue, FilterSupport.createMessageFilter(args, queue));
}
else
{
result.addUnfilteredQueue(queue);
}
}
result.addBinding(binding);
_bindings.put(binding, args);
}
}