Search in sources :

Example 1 with ObjectOutboundVariable

use of org.directwebremoting.dwrp.ObjectOutboundVariable in project jaffa-framework by jaffa-projects.

the class FlexCriteriaBeanConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     *
     * Copied from BasicObjectConverter
     *
     * Added custom code to convert the flexCriteriaParams array as root level properties on the javascript object.
     */
@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    FlexCriteriaBean flexCriteriaBean = (FlexCriteriaBean) data;
    // Where we collect out converted children
    Map ovs = new TreeMap();
    // We need to do this before collecing the children to save recurrsion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(flexCriteriaBean, ov);
    try {
        Map properties = getPropertyMapFromObject(flexCriteriaBean, true, false);
        for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String name = (String) entry.getKey();
            Property property = (Property) entry.getValue();
            // CUSTOM CODE: Special handling for flexCriteriaParams
            if ("flexCriteriaParams".equals(name)) {
                FlexCriteriaParam[] flexCriteriaParams = flexCriteriaBean.getFlexCriteriaParams();
                if (flexCriteriaParams != null) {
                    for (FlexCriteriaParam flexCriteriaParam : flexCriteriaParams) {
                        // Instead of the formatted value returned by flexCriteriaParam.getValue(),
                        // use the original value returned by the flexCriteriaBean. This will ensure
                        // standard DWR handling for those value.
                        Object value = flexCriteriaBean.get(flexCriteriaParam.getName());
                        if (value != null) {
                            // Added check to exclude null fields
                            OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
                            ovs.put(flexCriteriaParam.getName(), nested);
                        }
                    }
                }
            } else {
                Object value = property.getValue(flexCriteriaBean);
                if (value != null) {
                    // Added check to exclude null fields
                    OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
                    ovs.put(name, nested);
                }
            }
        }
        // Add the className to the object
        if (flexCriteriaBean != null) {
            String className = flexCriteriaBean.getClass().getSimpleName();
            OutboundVariable var = getConverterManager().convertOutbound(className, outctx);
            ovs.put("className", var);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(flexCriteriaBean.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) MarshallException(org.directwebremoting.extend.MarshallException) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) FlexCriteriaParam(org.jaffa.flexfields.FlexCriteriaParam) Map(java.util.Map) TreeMap(java.util.TreeMap) Property(org.directwebremoting.extend.Property) FlexCriteriaBean(org.jaffa.flexfields.FlexCriteriaBean)

Example 2 with ObjectOutboundVariable

use of org.directwebremoting.dwrp.ObjectOutboundVariable in project jaffa-framework by jaffa-projects.

the class NotNullBeanConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     *
     * Copied from BasicObjectConverter
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    // Where we collect out converted children
    Map ovs = new TreeMap();
    // We need to do this before collecing the children to save recurrsion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(data, ov);
    try {
        Map properties = getPropertyMapFromObject(data, true, false);
        for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String name = (String) entry.getKey();
            Property property = (Property) entry.getValue();
            Object value = property.getValue(data);
            if (value != null || (data instanceof GraphDataObject && ((GraphDataObject) data).hasChanged(name))) {
                // Added check to exclude null fields
                OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
                ovs.put(name, nested);
            }
        }
        // Add the className to the object
        if (data != null) {
            String className = data.getClass().getSimpleName();
            OutboundVariable var = getConverterManager().convertOutbound(className, outctx);
            ovs.put("className", var);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) GraphDataObject(org.jaffa.soa.graph.GraphDataObject) TreeMap(java.util.TreeMap) MarshallException(org.directwebremoting.extend.MarshallException) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) GraphDataObject(org.jaffa.soa.graph.GraphDataObject) TreeMap(java.util.TreeMap) Map(java.util.Map) Property(org.directwebremoting.extend.Property)

Example 3 with ObjectOutboundVariable

use of org.directwebremoting.dwrp.ObjectOutboundVariable in project jaffa-framework by jaffa-projects.

the class FlexBeanConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     *
     * Copied from BasicObjectConverter
     *
     * Added custom code to convert the flexParams array as root level properties on the javascript object.
     */
@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    FlexBean flexBean = (FlexBean) data;
    // Where we collect out converted children
    Map ovs = new TreeMap();
    // We need to do this before collecing the children to save recurrsion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(flexBean, ov);
    try {
        Map properties = getPropertyMapFromObject(flexBean, true, false);
        for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String name = (String) entry.getKey();
            Property property = (Property) entry.getValue();
            // CUSTOM CODE: Special handling for flexParams
            if ("flexParams".equals(name)) {
                FlexParam[] flexParams = flexBean.getFlexParams();
                if (flexParams != null) {
                    for (FlexParam flexParam : flexParams) {
                        // Instead of the formatted value returned by flexParam.getValue(),
                        // use the original value returned by the flexBean. This will ensure
                        // standard DWR handling for those value.
                        Object value = flexBean.get(flexParam.getName());
                        if (value != null) {
                            // Added check to exclude null fields
                            OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
                            ovs.put(flexParam.getName(), nested);
                        }
                    }
                }
            } else {
                Object value = property.getValue(flexBean);
                if (value != null) {
                    // Added check to exclude null fields
                    OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
                    ovs.put(name, nested);
                }
            }
        }
        // Add the className to the object
        if (flexBean != null) {
            String className = flexBean.getClass().getSimpleName();
            OutboundVariable var = getConverterManager().convertOutbound(className, outctx);
            ovs.put("className", var);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(flexBean.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) FlexBean(org.jaffa.flexfields.FlexBean) MarshallException(org.directwebremoting.extend.MarshallException) FlexParam(org.jaffa.flexfields.FlexParam) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) Map(java.util.Map) Property(org.directwebremoting.extend.Property)

Example 4 with ObjectOutboundVariable

use of org.directwebremoting.dwrp.ObjectOutboundVariable in project Gemma by PavlidisLab.

the class DoublePointConverter method convertOutbound.

@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    if (!(data instanceof DoublePoint))
        return super.convertOutbound(data, outctx);
    // Where we collect out converted children
    Map<String, OutboundVariable> ovs = new TreeMap<String, OutboundVariable>();
    // We need to do this before collecting the children to save recursion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(data, ov);
    try {
        Map<String, Property> properties = getPropertyMapFromObject(data, true, false);
        for (Iterator<Entry<String, Property>> it = properties.entrySet().iterator(); it.hasNext(); ) {
            Entry<String, Property> entry = it.next();
            String name = entry.getKey();
            Property property = entry.getValue();
            Object value = property.getValue(data);
            OutboundVariable nested;
            if (value instanceof Double) {
                // Reduce precision to save bandwidth
                Double v = Double.parseDouble(String.format("%.3f", value));
                nested = getConverterManager().convertOutbound(v, outctx);
            } else {
                nested = getConverterManager().convertOutbound(value, outctx);
            }
            ovs.put(name, nested);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) MarshallException(org.directwebremoting.extend.MarshallException) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) Entry(java.util.Map.Entry) MarshallException(org.directwebremoting.extend.MarshallException) DoublePoint(ubic.basecode.dataStructure.DoublePoint) Property(org.directwebremoting.extend.Property)

Example 5 with ObjectOutboundVariable

use of org.directwebremoting.dwrp.ObjectOutboundVariable in project ma-core-public by infiniteautomation.

the class BasicObjectConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    // Where we collect out converted children
    Map ovs = new TreeMap();
    // We need to do this before collecing the children to save recurrsion
    ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
    outctx.put(data, ov);
    try {
        Map properties = getPropertyMapFromObject(data, true, false);
        for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String name = (String) entry.getKey();
            Property property = (Property) entry.getValue();
            Object value = property.getValue(data);
            OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
            ovs.put(name, nested);
        }
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
    ov.init(ovs, getJavascript());
    return ov;
}
Also used : ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Property(org.directwebremoting.extend.Property) MarshallException(org.directwebremoting.extend.MarshallException)

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