Search in sources :

Example 1 with OutboundVariable

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

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

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

the class CollectionConverter 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 need to get ourselves the collection data
    Iterator it;
    if (data instanceof Collection) {
        Collection col = (Collection) data;
        it = col.iterator();
    } else if (data instanceof Iterator) {
        it = (Iterator) data;
    } else {
        throw new MarshallException(data.getClass());
    }
    // Stash this bit of data to cope with recursion
    ArrayOutboundVariable ov = new ArrayOutboundVariable(outctx);
    outctx.put(data, ov);
    // Convert all the data members
    List ovs = new ArrayList();
    while (it.hasNext()) {
        Object member = it.next();
        OutboundVariable nested;
        try {
            nested = config.convertOutbound(member, outctx);
        } catch (Exception ex) {
            String errorMessage = "Conversion error for " + data.getClass().getName() + ".";
            log.warn(errorMessage, ex);
            nested = new ErrorOutboundVariable(outctx, errorMessage, true);
        }
        ovs.add(nested);
    }
    // Group the list of converted objects into this OutboundVariable
    ov.init(ovs);
    return ov;
}
Also used : ErrorOutboundVariable(org.directwebremoting.dwrp.ErrorOutboundVariable) OutboundVariable(org.directwebremoting.extend.OutboundVariable) ArrayOutboundVariable(org.directwebremoting.dwrp.ArrayOutboundVariable) ArrayOutboundVariable(org.directwebremoting.dwrp.ArrayOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ErrorOutboundVariable(org.directwebremoting.dwrp.ErrorOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Example 4 with OutboundVariable

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

the class ArrayConverter method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    if (!data.getClass().isArray()) {
        throw new MarshallException(data.getClass());
    }
    // Stash this bit of data to cope with recursion
    ArrayOutboundVariable ov = new ArrayOutboundVariable(outctx);
    outctx.put(data, ov);
    // Convert all the data members
    int size = Array.getLength(data);
    List ovs = new ArrayList();
    for (int i = 0; i < size; i++) {
        OutboundVariable nested;
        try {
            nested = converterManager.convertOutbound(Array.get(data, i), outctx);
        } catch (Exception ex) {
            String errorMessage = "Conversion error for " + data.getClass().getName() + ".";
            log.warn(errorMessage, ex);
            nested = new ErrorOutboundVariable(outctx, errorMessage, true);
        }
        ovs.add(nested);
    }
    // Group the list of converted objects into this OutboundVariable
    ov.init(ovs);
    return ov;
}
Also used : ErrorOutboundVariable(org.directwebremoting.dwrp.ErrorOutboundVariable) OutboundVariable(org.directwebremoting.extend.OutboundVariable) ArrayOutboundVariable(org.directwebremoting.dwrp.ArrayOutboundVariable) ArrayOutboundVariable(org.directwebremoting.dwrp.ArrayOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ErrorOutboundVariable(org.directwebremoting.dwrp.ErrorOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

Example 5 with OutboundVariable

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

the class AbstractOutboundVariable method getChildBuildCodes.

/**
 * Grab all the build codes together
 * @return A build string
 */
private String getChildBuildCodes() {
    if (children == null) {
        return "";
    }
    StringBuffer buffer = new StringBuffer();
    // Make sure the nested things are declared
    for (Iterator it = children.iterator(); it.hasNext(); ) {
        OutboundVariable nested = (OutboundVariable) it.next();
        buffer.append(nested.getBuildCode());
    }
    return buffer.toString();
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) Iterator(java.util.Iterator)

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