org.directwebremoting.convert.CollectionConverter Maven / Gradle / Ivy
package org.directwebremoting.convert;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.ConversionException;
import org.directwebremoting.extend.AbstractConverter;
import org.directwebremoting.extend.ArrayOutboundVariable;
import org.directwebremoting.extend.ConvertUtil;
import org.directwebremoting.extend.ConverterManager;
import org.directwebremoting.extend.InboundVariable;
import org.directwebremoting.extend.OutboundContext;
import org.directwebremoting.extend.OutboundVariable;
import org.directwebremoting.extend.Property;
import org.directwebremoting.extend.ProtocolConstants;
/**
* An implementation of Converter for Collections of Strings.
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class CollectionConverter extends AbstractConverter
{
/* (non-Javadoc)
* @see org.directwebremoting.convert.BaseV20Converter#setConverterManager(org.directwebremoting.ConverterManager)
*/
@Override
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_ARRAY_START) || !value.endsWith(ProtocolConstants.INBOUND_ARRAY_END))
{
log.warn("Expected collection 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
{
Property parent = data.getContext().getCurrentProperty();
Property child = parent.createChild(0);
child = converterManager.checkOverride(child);
Class> subtype = child.getPropertyType();
// subtype.getMethod("h", null).getTypeParameters();
Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy