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;
}
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;
}
Aggregations