use of org.directwebremoting.dwrp.ObjectOutboundVariable in project ma-core-public by infiniteautomation.
the class MapConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
// First we just collect our converted children
Map ovs = (Map) LocalUtil.classNewInstance("OrderedConvertOutbound", "java.util.LinkedHashMap", Map.class);
if (ovs == null) {
ovs = new HashMap();
}
ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
outctx.put(data, ov);
// Loop through the map outputting any init code and collecting
// converted outbound variables into the ovs map
Map map = (Map) data;
for (Iterator it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
// It would be nice to check for Enums here
if (!(key instanceof String) && !sentNonStringWarning) {
log.warn("--Javascript does not support non string keys. Converting '" + key.getClass().getName() + "' using toString()");
sentNonStringWarning = true;
}
String outkey = JavascriptUtil.escapeJavaScript(key.toString());
// OutboundVariable ovkey = config.convertOutbound(key, outctx);
// buffer.append(ovkey.getInitCode());
// outkey = ovkey.getAssignCode();
OutboundVariable nested = config.convertOutbound(value, outctx);
ovs.put(outkey, nested);
}
ov.init(ovs, null);
return ov;
}
Aggregations