}
if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START) || !value.endsWith(ProtocolConstants.INBOUND_MAP_END))
{
log.warn("Expected object 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
{
// Maybe we ought to check that the paramType isn't expecting a more
// distinct type of Map and attempt to create that?
Map<Object, Object> map;
// If paramType is concrete then just use whatever we've got.
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.
map = (Map<Object, Object>) paramType.newInstance();
}
else
{
map = new HashMap<Object, Object>();
}
// Get the extra type info
Property parent = data.getContext().getCurrentProperty();
Property keyProp = parent.createChild(0);
keyProp = converterManager.checkOverride(keyProp);
Class<?> keyType = keyProp.getPropertyType();
Property valProp = parent.createChild(1);
valProp = converterManager.checkOverride(valProp);
Class<?> valType = valProp.getPropertyType();
// 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, map);
InboundContext incx = data.getContext();
// Loop through the property declarations
StringTokenizer st = new StringTokenizer(value, ",");
int size = st.countTokens();
for (int i = 0; i < size; i++)
{
String token = st.nextToken();
if (token.trim().length() == 0)
{
continue;
}
int colonpos = token.indexOf(ProtocolConstants.INBOUND_MAP_ENTRY);
if (colonpos == -1)
{
throw new ConversionException(paramType, "Missing " + ProtocolConstants.INBOUND_MAP_ENTRY + " in object description: {1}" + token);
}
// Convert the value part of the token by splitting it into the
// type and value (as passed in by Javascript)
String valStr = token.substring(colonpos + 1).trim();
String[] splitIv = ConvertUtil.splitInbound(valStr);
String splitIvValue = splitIv[ConvertUtil.INBOUND_INDEX_VALUE];
String splitIvType = splitIv[ConvertUtil.INBOUND_INDEX_TYPE];
InboundVariable valIv = new InboundVariable(incx, null, splitIvType, splitIvValue);
valIv.dereference();
Object val = converterManager.convertInbound(valType, valIv, valProp);
// Keys (unlike values) do not have type info passed with them
// Could we have recursive key? - I don't think so because keys
// must be strings in Javascript
String keyStr = token.substring(0, colonpos).trim();
//String[] keySplit = LocalUtil.splitInbound(keyStr);
//InboundVariable keyIv = new InboundVariable(incx, splitIv[LocalUtil.INBOUND_INDEX_TYPE], splitIv[LocalUtil.INBOUND_INDEX_VALUE]);
InboundVariable keyIv = new InboundVariable(incx, null, ProtocolConstants.TYPE_STRING, keyStr);
keyIv.dereference();
Object key = converterManager.convertInbound(keyType, keyIv, keyProp);
map.put(key, val);
}
return map;
}
catch (ConversionException ex)
{
throw ex;
}
catch (Exception ex)
{
throw new ConversionException(paramType, ex);
}
}