use of org.directwebremoting.extend.MarshallException 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.MarshallException in project ma-core-public by infiniteautomation.
the class H2BeanConverter method getPropertyMapFromObject.
/* (non-Javadoc)
* @see org.directwebremoting.extend.NamedConverter#getPropertyMapFromObject(java.lang.Object, boolean, boolean)
*/
public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException {
Class clazz = Hibernate.getClass(example);
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
Map properties = new HashMap();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
// We don't marshall getClass()
if (name.equals("class")) {
continue;
}
// Access rules mean we might not want to do this one
if (!isAllowedByIncludeExcludeRules(name)) {
continue;
}
if (readRequired && descriptor.getReadMethod() == null) {
continue;
}
if (writeRequired && descriptor.getWriteMethod() == null) {
continue;
}
properties.put(name, new H2PropertyDescriptorProperty(descriptor));
}
return properties;
} catch (Exception ex) {
throw new MarshallException(clazz, ex);
}
}
use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.
the class DwrConvertTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletContext servletContext = pageContext.getServletContext();
Container container = (Container) servletContext.getAttribute("DwrContainer");
if (container == null)
throw new JspException("Can't find 'DwrContainer' in servlet context");
ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
final ScriptBuffer scriptBuffer = new ScriptBuffer();
scriptBuffer.appendScript("return ");
scriptBuffer.appendData(obj);
WebContextBuilder webContextBuilder = (WebContextBuilder) servletContext.getAttribute(WebContextBuilder.class.getName());
try {
webContextBuilder.set((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(), null, servletContext, container);
JspWriter out = pageContext.getOut();
out.write("function() {");
out.write(ScriptBufferUtil.createOutput(scriptBuffer, converterManager));
out.write(";}()");
} catch (IOException e) {
throw new JspException("Error writing tag content", e);
} catch (MarshallException e) {
throw new JspException("Error marshalling object data", e);
} finally {
webContextBuilder.unset();
}
return EVAL_PAGE;
}
use of org.directwebremoting.extend.MarshallException in project jaffa-framework by jaffa-projects.
the class DateConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
@Override
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
// Error out if an unsupported class is passed
if (paramType != Date.class && paramType != java.sql.Date.class && paramType != Time.class && paramType != Timestamp.class && paramType != Calendar.class) {
log.warn("Unsupported input. Class=" + paramType);
throw new MarshallException(paramType);
}
// invoke the base routine, which will convert the input to a DateTime after taking timezone differences into consideration
DateTime dt = (DateTime) super.convertInbound(DateTime.class, iv, inctx);
// now convert DateTime to the desired type
Object output = null;
if (dt != null) {
if (paramType == Date.class)
output = dt.getUtilDate();
else if (paramType == java.sql.Date.class)
output = dt.sqlDate();
else if (paramType == Time.class)
output = dt.sqlTime();
else if (paramType == Timestamp.class)
output = dt.timestamp();
else if (paramType == Calendar.class)
output = dt.calendar();
}
if (log.isDebugEnabled())
log.debug("Inbound '" + iv.getValue() + "' converted to '" + output + '\'');
return output;
}
use of org.directwebremoting.extend.MarshallException 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;
}
Aggregations