Search in sources :

Example 1 with Converter

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

the class DefaultConverterManager method convertInbound.

/* (non-Javadoc)
     * @see org.directwebremoting.ConverterManager#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext, org.directwebremoting.TypeHintContext)
     */
public Object convertInbound(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 2 with Converter

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

the class DefaultConverterManager method convertOutbound.

/* (non-Javadoc)
     * @see org.directwebremoting.ConverterManager#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object object, OutboundContext outctx) throws MarshallException {
    if (object == null) {
        return new SimpleOutboundVariable("null", outctx, true);
    }
    // Check to see if we have done this one already
    OutboundVariable ov = outctx.get(object);
    if (ov != null) {
        // So the object as been converted already, we just need to refer to it.
        return ov.getReferenceVariable();
    }
    // So we will have to do the conversion
    Converter converter = getConverter(object);
    if (converter == null) {
        log.error(Messages.getString("DefaultConverterManager.MissingConverter", object.getClass().getName()));
        return new SimpleOutboundVariable("null", outctx, true);
    }
    return converter.convertOutbound(object, outctx);
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter)

Example 3 with Converter

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

the class DefaultConverterManager method addConverter.

/* (non-Javadoc)
     * @see org.directwebremoting.ConverterManager#addConverter(java.lang.String, java.lang.String, java.util.Map)
     */
public void addConverter(String match, String type, Map params) throws IllegalArgumentException, InstantiationException, IllegalAccessException {
    Class clazz = (Class) converterTypes.get(type);
    if (clazz == null) {
        log.info("Probably not an issue: " + match + " is not available so the " + type + " converter will not load. This is only a problem if you wanted to use it.");
        return;
    }
    Converter converter = (Converter) clazz.newInstance();
    converter.setConverterManager(this);
    LocalUtil.setParams(converter, params, ignore);
    // add the converter for the specified match
    addConverter(match, converter);
}
Also used : NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter)

Example 4 with Converter

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

the class BlabberConverterManager method convertOutbound.

/*
     * (non-Javadoc)
     * 
     * @see org.directwebremoting.ConverterManager#convertOutbound(java.lang.Object,
     * org.directwebremoting.OutboundContext)
     */
public OutboundVariable convertOutbound(Object object, OutboundContext outctx) throws MarshallException {
    if (object == null) {
        return new SimpleOutboundVariable("null", outctx, true);
    }
    // Check to see if we have done this one already
    OutboundVariable ov = outctx.get(object);
    if (ov != null) {
        // So the object as been converted already, we just need to refer to it.
        return ov.getReferenceVariable();
    }
    // So we will have to do the conversion
    Converter converter = getConverter(object);
    if (converter == null) {
        log.error(Messages.getString("DefaultConverterManager.MissingConverter", object.getClass().getName()));
        return new SimpleOutboundVariable("null", outctx, true);
    }
    return converter.convertOutbound(object, outctx);
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable) NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter) SimpleOutboundVariable(org.directwebremoting.dwrp.SimpleOutboundVariable)

Example 5 with Converter

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

the class BlabberConverterManager method addConverter.

/*
     * (non-Javadoc)
     * 
     * @see org.directwebremoting.ConverterManager#addConverter(java.lang.String, java.lang.String, java.util.Map)
     */
public void addConverter(String match, String type, @SuppressWarnings("rawtypes") Map params) throws IllegalArgumentException, InstantiationException, IllegalAccessException {
    Class<Converter> clazz = converterTypes.get(type);
    if (clazz == null) {
        log.info("Probably not an issue: " + match + " is not available so the " + type + " converter will not load. This is only an problem if you wanted to use it.");
        return;
    }
    // TODO fix this by modifying the ma-priv code, but until we have a good copy this is my plan!
    // String js = match.substring(match.lastIndexOf(".")+1);
    // params.put("javascript", js);
    Converter converter = clazz.newInstance();
    converter.setConverterManager(this);
    LocalUtil.setParams(converter, params, ignore);
    // add the converter for the specified match
    addConverter(match, converter);
}
Also used : NamedConverter(org.directwebremoting.extend.NamedConverter) Converter(org.directwebremoting.extend.Converter)

Aggregations

Converter (org.directwebremoting.extend.Converter)16 NamedConverter (org.directwebremoting.extend.NamedConverter)16 MarshallException (org.directwebremoting.extend.MarshallException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Iterator (java.util.Iterator)2 OutboundVariable (org.directwebremoting.extend.OutboundVariable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 SimpleOutboundVariable (org.directwebremoting.dwrp.SimpleOutboundVariable)1 Creator (org.directwebremoting.extend.Creator)1 Property (org.directwebremoting.extend.Property)1