Search in sources :

Example 6 with ObjectOutboundVariable

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;
}
Also used : ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)6 OutboundVariable (org.directwebremoting.extend.OutboundVariable)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)5 MarshallException (org.directwebremoting.extend.MarshallException)5 Property (org.directwebremoting.extend.Property)5 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)1 FlexBean (org.jaffa.flexfields.FlexBean)1 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)1 FlexCriteriaParam (org.jaffa.flexfields.FlexCriteriaParam)1 FlexParam (org.jaffa.flexfields.FlexParam)1 GraphDataObject (org.jaffa.soa.graph.GraphDataObject)1 DoublePoint (ubic.basecode.dataStructure.DoublePoint)1