}
if (!value.startsWith(ProtocolConstants.INBOUND_ARRAY_START) || !value.endsWith(ProtocolConstants.INBOUND_ARRAY_END))
{
log.warn("Expected collection while converting data for " + paramType.getName() + " in " + data.getContext().getCurrentProperty() + ". Passed: " + value);
throw new ConversionException(paramType, "Data conversion error. See logs for more details.");
}
value = value.substring(1, value.length() - 1);
try
{
Property parent = data.getContext().getCurrentProperty();
Property child = parent.createChild(0);
child = converterManager.checkOverride(child);
Class<?> subtype = child.getPropertyType();
// subtype.getMethod("h", null).getTypeParameters();
Collection<Object> col;
// If they want an iterator then just use an array list and fudge
// at the end.
if (Iterator.class.isAssignableFrom(paramType))
{
col = new ArrayList<Object>();
}
// If paramType is concrete then just use whatever we've got.
else if (!paramType.isInterface() && !Modifier.isAbstract(paramType.getModifiers()))
{
// If there is a problem creating the type then we have no way
// of completing this - they asked for a specific type and we
// can't create that type. I don't know of a way of finding
// subclasses that might be instaniable so we accept failure.
//noinspection unchecked
col = (Collection<Object>) paramType.newInstance();
}
// If they want a SortedSet then use TreeSet
else if (SortedSet.class.isAssignableFrom(paramType))
{
col = new TreeSet<Object>();
}
// If they want a Set then use HashSet
else if (Set.class.isAssignableFrom(paramType))
{
col = new HashSet<Object>();
}
// If they want a List then use an ArrayList
else if (List.class.isAssignableFrom(paramType))
{
col = new ArrayList<Object>();
}
// If they just want a Collection then just use an ArrayList
else if (Collection.class.isAssignableFrom(paramType))
{
col = new ArrayList<Object>();
}
else
{
throw new ConversionException(paramType);
}
// We should put the new object into the working map in case it
// is referenced later nested down in the conversion process.
data.getContext().addConverted(data, paramType, col);
StringTokenizer st = new StringTokenizer(value, ProtocolConstants.INBOUND_ARRAY_SEPARATOR);
int size = st.countTokens();
for (int i = 0; i < size; i++)
{
String token = st.nextToken();
String[] split = ConvertUtil.splitInbound(token);
String splitType = split[ConvertUtil.INBOUND_INDEX_TYPE];
String splitValue = split[ConvertUtil.INBOUND_INDEX_VALUE];
InboundVariable nested = new InboundVariable(data.getContext(), null, splitType, splitValue);
nested.dereference();
Object output = converterManager.convertInbound(subtype, nested, child);
col.add(output);
}
// If they wanted an Iterator then give them one otherwise use
// the type we created
if (Iterator.class.isAssignableFrom(paramType))
{
return col.iterator();
}
else
{
return col;
}
}
catch (ConversionException ex)
{
throw ex;
}
catch (Exception ex)
{
throw new ConversionException(paramType, ex);
}
}