Search in sources :

Example 31 with MarshallException

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

Example 32 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class XOMConverter method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
     */
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
    String value = LocalUtil.decode(iv.getValue());
    try {
        Builder builder = new Builder();
        Document doc = builder.build(new StringReader(value));
        if (paramType == Document.class) {
            return doc;
        } else if (paramType == Element.class) {
            return doc.getRootElement();
        }
        throw new MarshallException(paramType);
    } catch (MarshallException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new MarshallException(paramType, ex);
    }
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) Builder(nu.xom.Builder) Element(nu.xom.Element) StringReader(java.io.StringReader) Document(nu.xom.Document) MarshallException(org.directwebremoting.extend.MarshallException)

Example 33 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class H3BeanConverter method getPropertyMapFromObject.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.directwebremoting.convert.BeanConverter#getPropertyMapFromObject(
	 * java.lang.Object, boolean, boolean)
	 */
public Map getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws MarshallException {
    Class clazz = 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;
            }
            // And this is something added by hibernate
            if (name.equals("hibernateLazyInitializer")) {
                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;
            }
            if (!assumeSession) {
                // We don't marshall un-initialized properties for
                // Hibernate3
                String propertyName = descriptor.getName();
                Method method = findGetter(example, propertyName);
                if (method == null) {
                    log.warn("Failed to find property: " + propertyName);
                    properties.put(name, new PlainProperty(propertyName, null));
                    continue;
                }
                if (!Hibernate.isPropertyInitialized(example, propertyName)) {
                    properties.put(name, new PlainProperty(propertyName, null));
                    continue;
                }
                // This might be a lazy-collection so we need to double
                // check
                Object retval = method.invoke(example, new Object[] {});
                if (!Hibernate.isInitialized(retval)) {
                    properties.put(name, new PlainProperty(propertyName, null));
                    continue;
                }
            }
            properties.put(name, new H3PropertyDescriptorProperty(descriptor));
        }
        return properties;
    } catch (Exception ex) {
        throw new MarshallException(clazz, ex);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) PlainProperty(org.directwebremoting.convert.PlainProperty) BeanInfo(java.beans.BeanInfo) Method(java.lang.reflect.Method) MarshallException(org.directwebremoting.extend.MarshallException) IntrospectionException(java.beans.IntrospectionException) MarshallException(org.directwebremoting.extend.MarshallException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with MarshallException

use of org.directwebremoting.extend.MarshallException in project ma-core-public by infiniteautomation.

the class BlabberConverterManager method convertInbound.

/*
     * (non-Javadoc)
     * 
     * @see org.directwebremoting.ConverterManager#convertInbound(java.lang.Class,
     * org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext,
     * org.directwebremoting.TypeHintContext)
     */
public Object convertInbound(@SuppressWarnings("rawtypes") Class paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc) throws MarshallException {
    Object converted = inctx.getConverted(iv, paramType);
    if (converted == null) {
        // Was the inbound variable marshalled as an Object in the client
        // (could mean that this is an instance of one of our generated
        // JavaScript classes)
        Converter converter = getNamedConverter(paramType, iv.getType());
        // didn't find anything above
        if (converter == null) {
            converter = getConverter(paramType);
        }
        if (converter == null) {
            throw new MarshallException(paramType, Messages.getString("DefaultConverterManager.MissingConverter", paramType));
        }
        // from passing null to things they are not allowed to convert
        if (iv.isNull()) {
            return null;
        }
        inctx.pushContext(incc);
        converted = converter.convertInbound(paramType, iv, inctx);
        inctx.popContext();
    }
    return converted;
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter)

Example 35 with MarshallException

use of org.directwebremoting.extend.MarshallException 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);
    }
}
Also used : StringWriter(java.io.StringWriter) OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException)

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