use of org.directwebremoting.dwrp.ObjectOutboundVariable 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;
}
use of org.directwebremoting.dwrp.ObjectOutboundVariable 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;
}
use of org.directwebremoting.dwrp.ObjectOutboundVariable 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.dwrp.ObjectOutboundVariable 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.dwrp.ObjectOutboundVariable 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;
}
Aggregations