Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boiler plate code between the web browser and your Java code.
/*
* Copyright 2005 Joe Walker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.directwebremoting.convert;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.directwebremoting.ConversionException;
import org.directwebremoting.extend.ConstructorProperty;
import org.directwebremoting.extend.ConvertUtil;
import org.directwebremoting.extend.ConverterManager;
import org.directwebremoting.extend.InboundContext;
import org.directwebremoting.extend.InboundVariable;
import org.directwebremoting.extend.NamedConverter;
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.LocalUtil;
import org.directwebremoting.util.Pair;
/**
* BasicObjectConverter is a parent to {@link BeanConverter} and
* {@link ObjectConverter} an provides support for include and exclude lists,
* and instanceTypes.
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public abstract class BasicObjectConverter implements NamedConverter
{
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class> paramType, InboundVariable data) throws ConversionException
{
if (data.isNull())
{
return null;
}
String value = data.getValue();
if (value == null)
{
throw new NullPointerException(data.toString());
}
// 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
{
// Loop through the properties passed in
Map tokens = extractInboundTokens(paramType, value);
if (paramsString == null)
{
return createUsingSetterInjection(paramType, data, tokens);
}
else
{
return createUsingConstructorInjection(paramType, data, tokens);
}
}
catch (InvocationTargetException ex)
{
throw new ConversionException(paramType, ex.getTargetException());
}
catch (ConversionException ex)
{
throw ex;
}
catch (Exception ex)
{
throw new ConversionException(paramType, ex);
}
}
/**
* We're using constructor injection, create and populate a bean using
* a constructor
*/
private Object createUsingConstructorInjection(Class> paramType, InboundVariable data, Map tokens) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException
{
Class> type;
if (instanceType != null)
{
type = instanceType;
}
else
{
type = paramType;
}
// Find a constructor to match
List> parameterTypes = new ArrayList>();
for (Pair, String> parameter : parameters)
{
parameterTypes.add(parameter.left);
}
Class>[] paramTypeArray = parameterTypes.toArray(new Class>[parameterTypes.size()]);
Constructor> constructor;
try
{
constructor = type.getConstructor(paramTypeArray);
}
catch (NoSuchMethodException ex)
{
log.error("Can't find a constructor for " + type.getName() + " with params " + parameterTypes);
throw ex;
}
List