Search in sources :

Example 11 with OutboundVariable

use of org.directwebremoting.extend.OutboundVariable in project ma-core-public by infiniteautomation.

the class UnitBeanConverter method convertOutbound.

/* (non-Javadoc)
	 * @see org.directwebremoting.extend.Converter#convertOutbound(java.lang.Object, org.directwebremoting.extend.OutboundContext)
	 */
@Override
public OutboundVariable convertOutbound(Object paramObject, OutboundContext paramOutboundContext) throws MarshallException {
    // Convert from Unit to String
    // Check to see if we have done this one already
    OutboundVariable ov = paramOutboundContext.get(paramObject);
    if (ov != null) {
        // So the object as been converted already, we just need to refer to it.
        return ov.getReferenceVariable();
    }
    if (paramObject instanceof Unit<?>) {
        Unit<?> unit = (Unit<?>) paramObject;
        String unitString = UnitUtil.formatLocal(unit);
        if (unit == unit.ONE)
            unitString = "ONE";
        return new SimpleOutboundVariable("'" + unitString + "';", paramOutboundContext, false);
    } else {
        throw new MarshallException(paramObject.getClass());
    }
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Unit(javax.measure.unit.Unit) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable)

Example 12 with OutboundVariable

use of org.directwebremoting.extend.OutboundVariable 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 13 with OutboundVariable

use of org.directwebremoting.extend.OutboundVariable 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 14 with OutboundVariable

use of org.directwebremoting.extend.OutboundVariable 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)

Example 15 with OutboundVariable

use of org.directwebremoting.extend.OutboundVariable in project ma-core-public by infiniteautomation.

the class DOM4JConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    try {
        // Using XSLT to convert to a stream. Setup the source
        if (!(data instanceof Node)) {
            throw new MarshallException(data.getClass());
        }
        Node node = (Node) data;
        OutputFormat outformat = OutputFormat.createCompactFormat();
        outformat.setEncoding("UTF-8");
        // Setup the destination
        StringWriter xml = new StringWriter();
        XMLWriter writer = new XMLWriter(xml, outformat);
        writer.write(node);
        writer.flush();
        xml.flush();
        String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
        OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
        outctx.put(data, ov);
        return ov;
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(data.getClass(), ex);
    }
}
Also used : StringWriter(java.io.StringWriter) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Aggregations

OutboundVariable (org.directwebremoting.extend.OutboundVariable)21 MarshallException (org.directwebremoting.extend.MarshallException)12 Iterator (java.util.Iterator)10 Map (java.util.Map)7 ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)6 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)6 TreeMap (java.util.TreeMap)5 Property (org.directwebremoting.extend.Property)5 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ArrayOutboundVariable (org.directwebremoting.dwrp.ArrayOutboundVariable)2 ErrorOutboundVariable (org.directwebremoting.dwrp.ErrorOutboundVariable)2 Converter (org.directwebremoting.extend.Converter)2 NamedConverter (org.directwebremoting.extend.NamedConverter)2 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1 Unit (javax.measure.unit.Unit)1 Source (javax.xml.transform.Source)1