// index values, since the indices may come in any order in the query parameter,
// while we want to preserve the order.
// - second, DataMap only accepts Data objects as values, so ListMaps cannot
// be stored there, so using an intermediary structure even for maps.
MapMap dataMap = new MapMap();
for (Map.Entry<String, List<String>> entry : queryParameters.entrySet())
{
// As per the notation above, we no longer support multiple occurrences of
// a parameter (considering its full multi-part and indexed name), i.e
// there should be only a single entry in each list. For backward compatibility
// as well as ease of use, repeated parameters are still allowed if they
// are "simple", i.e. they are not multi-part or indexed.
List<String> valueList = entry.getValue();
if (valueList.size() == 1)
{
String[] key = SEGMENT_DELIMITER_PATTERN.split(entry.getKey());
parseParameter(key, valueList.get(0), dataMap);
}
else
{
String parameterName = entry.getKey();
// In case of multiple parameters ensure they are not delimited or
// indexed and then simulate the index for each one.
if(parameterName.indexOf('.') != -1)
throw new PathSegmentSyntaxException("Multiple values of complex query parameter are not supported");
if(parameterName.charAt(parameterName.length()-1) == ']')
throw new PathSegmentSyntaxException("Multiple values of indexed query parameter are not supported");
if(dataMap.containsKey(parameterName))
throw new PathSegmentSyntaxException("Conflicting references to key " + parameterName + "[0]");
else
{
dataMap.put(parameterName, new DataList(valueList));
}
}
}
return (DataMap)convertToDataCollection(dataMap);