
org.directwebremoting.convert.MapConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwr Show documentation
Show all versions of dwr Show documentation
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boilerplate code between the web browser and your Java code.
This version 4.0.2 works with Jakarta Servlet 4.0.2.
The newest version!
package org.directwebremoting.convert;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.ConversionException;
import org.directwebremoting.extend.ConvertUtil;
import org.directwebremoting.extend.Converter;
import org.directwebremoting.extend.ConverterManager;
import org.directwebremoting.extend.InboundContext;
import org.directwebremoting.extend.InboundVariable;
import org.directwebremoting.extend.ObjectOutboundVariable;
import org.directwebremoting.extend.OutboundContext;
import org.directwebremoting.extend.OutboundVariable;
import org.directwebremoting.extend.Property;
import org.directwebremoting.extend.ProtocolConstants;
import org.directwebremoting.util.JavascriptUtil;
import org.directwebremoting.util.LocalUtil;
/**
* An implementation of Converter for Maps.
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class MapConverter implements Converter
{
/* (non-Javadoc)
* @see org.directwebremoting.Converter#setConverterManager(org.directwebremoting.ConverterManager)
*/
public void setConverterManager(ConverterManager converterManager)
{
this.converterManager = converterManager;
}
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
@SuppressWarnings("unchecked")
public Object convertInbound(Class> paramType, InboundVariable data) throws ConversionException
{
if (data.isNull())
{
return null;
}
String value = data.getValue();
// If the text is null then the whole bean is null
if (value.trim().equals(ProtocolConstants.INBOUND_NULL))
{
return null;
}
if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START) || !value.endsWith(ProtocolConstants.INBOUND_MAP_END))
{
log.warn("Expected object while converting data for " + paramType.getName() + " in " + data.getContext().getCurrentProperty() + ". Passed: " + value);
throw new ConversionException(paramType, "Data conversion error. See logs for more details.");
}
value = value.substring(1, value.length() - 1);
try
{
// Maybe we ought to check that the paramType isn't expecting a more
// distinct type of Map and attempt to create that?
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy