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