Search in sources :

Example 1 with ArrayOutboundVariable

use of org.directwebremoting.dwrp.ArrayOutboundVariable 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 2 with ArrayOutboundVariable

use of org.directwebremoting.dwrp.ArrayOutboundVariable 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)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 ArrayOutboundVariable (org.directwebremoting.dwrp.ArrayOutboundVariable)2 ErrorOutboundVariable (org.directwebremoting.dwrp.ErrorOutboundVariable)2 MarshallException (org.directwebremoting.extend.MarshallException)2 OutboundVariable (org.directwebremoting.extend.OutboundVariable)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1