Search in sources :

Example 21 with MarshallException

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());
    }
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Unit(javax.measure.unit.Unit) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable)

Example 22 with MarshallException

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);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) HashMap(java.util.HashMap) MarshallException(org.directwebremoting.extend.MarshallException) IntrospectionException(java.beans.IntrospectionException)

Example 23 with MarshallException

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;
}
Also used : JspException(javax.servlet.jsp.JspException) Container(org.directwebremoting.Container) ConverterManager(org.directwebremoting.extend.ConverterManager) MarshallException(org.directwebremoting.extend.MarshallException) ServletContext(javax.servlet.ServletContext) WebContextBuilder(org.directwebremoting.WebContextFactory.WebContextBuilder) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) ScriptBuffer(org.directwebremoting.ScriptBuffer)

Example 24 with MarshallException

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;
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) Calendar(java.util.Calendar) DateTime(org.jaffa.datatypes.DateTime) Time(java.sql.Time) Timestamp(java.sql.Timestamp) DateTime(org.jaffa.datatypes.DateTime) Date(java.util.Date)

Example 25 with MarshallException

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;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) FlexBean(org.jaffa.flexfields.FlexBean) MarshallException(org.directwebremoting.extend.MarshallException) FlexParam(org.jaffa.flexfields.FlexParam) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) Map(java.util.Map) Property(org.directwebremoting.extend.Property)

Aggregations

MarshallException (org.directwebremoting.extend.MarshallException)43 Map (java.util.Map)16 OutboundVariable (org.directwebremoting.extend.OutboundVariable)12 Iterator (java.util.Iterator)10 HashMap (java.util.HashMap)9 TreeMap (java.util.TreeMap)9 Property (org.directwebremoting.extend.Property)9 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)8 InboundVariable (org.directwebremoting.extend.InboundVariable)8 TypeHintContext (org.directwebremoting.extend.TypeHintContext)7 ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)5 IntrospectionException (java.beans.IntrospectionException)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 StringTokenizer (java.util.StringTokenizer)4 Converter (org.directwebremoting.extend.Converter)4 NamedConverter (org.directwebremoting.extend.NamedConverter)4 BeanInfo (java.beans.BeanInfo)3 PropertyDescriptor (java.beans.PropertyDescriptor)3 StringWriter (java.io.StringWriter)3