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