ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
boolean stop = false;
// Tag processing
while (!stop && argumentsIter.hasNext()) {
Argument argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
// [ADDRESS-PART]?
if (null == addressPart
&& (tag.equals(LOCALPART_TAG) || tag.equals(DOMAIN_TAG) || tag
.equals(ALL_TAG)))
addressPart = tag;
// [COMPARATOR]?
else if (null == comparator && tag.equals(COMPARATOR_TAG)) {
// The next argument must be a stringlist
if (argumentsIter.hasNext()) {
argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
List stringList = ((StringListArgument) argument)
.getList();
if (stringList.size() != 1)
throw new SyntaxException(
"Expecting exactly one String");
comparator = (String) stringList.get(0);
} else
throw new SyntaxException("Expecting a StringList");
}
}
// [MATCH-TYPE]?
else if (null == matchType
&& (tag.equals(IS_TAG) || tag.equals(CONTAINS_TAG) || tag
.equals(MATCHES_TAG)))
matchType = tag;
else
throw context.getCoordinate().syntaxException(
"Found unexpected TagArgument");
} else {
// Stop when a non-tag argument is encountered
argumentsIter.previous();
stop = true;
}
}
// The next argument MUST be a string-list of header names
if (argumentsIter.hasNext()) {
Argument argument = argumentsIter.next();
if (argument instanceof StringListArgument)
headerNames = ((StringListArgument) argument).getList();
}
if (null == headerNames)
throw context.getCoordinate().syntaxException(
"Expecting a StringList of header names");
// The next argument MUST be a string-list of keys
if (argumentsIter.hasNext()) {
Argument argument = argumentsIter.next();
if (argument instanceof StringListArgument)
keys = ((StringListArgument) argument).getList();
} else if (null == keys)
throw context.getCoordinate().syntaxException(
"Expecting a StringList of keys");