From 7a3d0058b8b10b27753452b413e269feda70983a Mon Sep 17 00:00:00 2001 From: win777 Date: Thu, 19 Nov 2015 07:02:19 +0000 Subject: [PATCH] =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EA=B0=80=20?= =?UTF-8?q?=EB=8B=A8=20=EA=B1=B4=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nexacro/spring/data/NexacroResult.java | 18 +- .../data/convert/NexacroConverterFactory.java | 4 + .../support/DataSetToObjectConverter.java | 3 +- .../support/ObjectToDataSetConverter.java | 28 +-- ...exacroHandlerMethodReturnValueHandler.java | 10 +- .../NexacroMethodArgumentResolver.java | 80 ++++-- .../support/DataSetToObjectConverterTest.java | 226 +++++++++++++++++ .../support/ObjectToDataSetConverterTest.java | 236 ++++++++++++++++++ .../spring/resolve/httpRequestForMap.xml | 39 +++ 9 files changed, 589 insertions(+), 55 deletions(-) create mode 100644 src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java create mode 100644 src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java create mode 100644 src/test/java/com/nexacro/spring/resolve/httpRequestForMap.xml diff --git a/src/main/java/com/nexacro/spring/data/NexacroResult.java b/src/main/java/com/nexacro/spring/data/NexacroResult.java index 8e200fb..c8aa6cc 100644 --- a/src/main/java/com/nexacro/spring/data/NexacroResult.java +++ b/src/main/java/com/nexacro/spring/data/NexacroResult.java @@ -1,5 +1,6 @@ package com.nexacro.spring.data; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -23,7 +24,7 @@ public class NexacroResult { private PlatformData platformData; - private Map dataSetMaps; + private Map dataSetMaps; private Map variableMaps; // result status @@ -37,7 +38,7 @@ public class NexacroResult { } private void initResult() { - dataSetMaps = new HashMap(); + dataSetMaps = new HashMap(); variableMaps = new HashMap(); platformData = new PlatformData(); } @@ -54,13 +55,13 @@ public class NexacroResult { /** * - * 입력받은 dataSetName(DataSet 이름)으로 List를 DataSet으로 추가한다. + * 입력받은 dataSetName(DataSet 이름)으로 Object를 DataSet으로 추가한다. *

List의 값은 java.util.Map 혹은 VO class만 설정가능하다. * * @param dataSetName * @param beans */ - public void addDataSet(String dataSetName, List beans) { + public void addDataSet(String dataSetName, Object beans) { checkName(dataSetName); checkBean(beans); @@ -90,7 +91,7 @@ public class NexacroResult { variableMaps.put(variableName, object); } - public Map getDataSets() { + public Map getDataSets() { return Collections.unmodifiableMap(dataSetMaps); } @@ -104,8 +105,11 @@ public class NexacroResult { } } - private void checkBean(List bean) { - } + private void checkBean(Object bean) { + if (bean == null) { + throw new IllegalArgumentException("Bean is null"); + } + } public PlatformData getPlatformData() { return platformData; diff --git a/src/main/java/com/nexacro/spring/data/convert/NexacroConverterFactory.java b/src/main/java/com/nexacro/spring/data/convert/NexacroConverterFactory.java index 3abcbd3..e7ed836 100644 --- a/src/main/java/com/nexacro/spring/data/convert/NexacroConverterFactory.java +++ b/src/main/java/com/nexacro/spring/data/convert/NexacroConverterFactory.java @@ -10,7 +10,9 @@ import org.slf4j.LoggerFactory; import com.nexacro.spring.data.convert.NexacroConverter.ConvertiblePair; import com.nexacro.spring.data.support.DataSetToListConverter; +import com.nexacro.spring.data.support.DataSetToObjectConverter; import com.nexacro.spring.data.support.ListToDataSetConverter; +import com.nexacro.spring.data.support.ObjectToDataSetConverter; import com.nexacro.spring.data.support.ObjectToVariableConverter; import com.nexacro.spring.data.support.VariableToObjectConverter; @@ -39,6 +41,8 @@ public class NexacroConverterFactory { private void addDefaultConverter() { NexacroConverterFactory.register(new DataSetToListConverter()); NexacroConverterFactory.register(new ListToDataSetConverter()); + NexacroConverterFactory.register(new DataSetToObjectConverter()); + NexacroConverterFactory.register(new ObjectToDataSetConverter()); NexacroConverterFactory.register(new VariableToObjectConverter()); NexacroConverterFactory.register(new ObjectToVariableConverter()); } diff --git a/src/main/java/com/nexacro/spring/data/support/DataSetToObjectConverter.java b/src/main/java/com/nexacro/spring/data/support/DataSetToObjectConverter.java index 6e7b0ad..aa98267 100644 --- a/src/main/java/com/nexacro/spring/data/support/DataSetToObjectConverter.java +++ b/src/main/java/com/nexacro/spring/data/support/DataSetToObjectConverter.java @@ -1,6 +1,7 @@ package com.nexacro.spring.data.support; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.nexacro.spring.data.convert.ConvertDefinition; @@ -26,7 +27,7 @@ public class DataSetToObjectConverter extends AbstractDataSetConverter implement } // support type - if(DataSet.class.equals(source) && NexacroConverterHelper.isSupportedBean(target)) { + if(DataSet.class.equals(source) && !List.class.equals(target) && NexacroConverterHelper.isSupportedBean(target)) { return true; } diff --git a/src/main/java/com/nexacro/spring/data/support/ObjectToDataSetConverter.java b/src/main/java/com/nexacro/spring/data/support/ObjectToDataSetConverter.java index 984edbd..961b4e0 100644 --- a/src/main/java/com/nexacro/spring/data/support/ObjectToDataSetConverter.java +++ b/src/main/java/com/nexacro/spring/data/support/ObjectToDataSetConverter.java @@ -1,5 +1,6 @@ package com.nexacro.spring.data.support; +import java.util.List; import java.util.Map; import com.nexacro.spring.data.convert.ConvertDefinition; @@ -20,16 +21,16 @@ public class ObjectToDataSetConverter extends AbstractDataSetConverter implement @Override public boolean canConvert(Class source, Class target) { - if(source == null || target == null) { - return false; - } - - // support list sub class - if(NexacroConverterHelper.isSupportedBean(source) && DataSet.class.equals(target)) { - return true; - } - - return false; + if(source == null || target == null) { + return false; + } + + // support type + if(!List.class.isAssignableFrom(source) && NexacroConverterHelper.isSupportedBean(source) && DataSet.class.equals(target)) { + return true; + } + + return false; } @Override @@ -38,10 +39,7 @@ public class ObjectToDataSetConverter extends AbstractDataSetConverter implement if(definition ==null) { throw new IllegalArgumentException(ConvertDefinition.class.getSimpleName()+" must not be null."); } - if(source == null) { - return new DataSet(definition.getName()); - } - + if(source == null) { return new DataSet(definition.getName()); } @@ -54,7 +52,7 @@ public class ObjectToDataSetConverter extends AbstractDataSetConverter implement ds = convertBeanToDataSet(source, definition); } - return null; + return ds; } private DataSet convertBeanToDataSet(Object source, ConvertDefinition definition) throws NexacroConvertException { diff --git a/src/main/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandler.java b/src/main/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandler.java index 2480c84..0f6d15f 100644 --- a/src/main/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandler.java +++ b/src/main/java/com/nexacro/spring/resolve/NexacroHandlerMethodReturnValueHandler.java @@ -168,15 +168,15 @@ public class NexacroHandlerMethodReturnValueHandler implements HandlerMethodRetu private void addDataSetsIntoPlatformData(PlatformData platformData, NexacroResult nexacroResult) throws NexacroConvertException { - Map dataSets = nexacroResult.getDataSets(); + Map dataSets = nexacroResult.getDataSets(); Set dataSetKeySet = dataSets.keySet(); for(String name: dataSetKeySet) { - List list = dataSets.get(name); - if(list == null) { + Object object = dataSets.get(name); + if(object == null) { platformData.addDataSet(new DataSet(name)); } else { - NexacroConverter dataSetConverter = getDataSetConverter(list.getClass()); + NexacroConverter dataSetConverter = getDataSetConverter(object.getClass()); if(dataSetConverter == null) { logger.debug("not found converter {} to List to DataSet({})" , name); continue; @@ -188,7 +188,7 @@ public class NexacroHandlerMethodReturnValueHandler implements HandlerMethodRetu ConvertDefinition definition = new ConvertDefinition(name); - Object convert = dataSetConverter.convert(list, definition); + Object convert = dataSetConverter.convert(object, definition); if(convert != null && convert instanceof DataSet) { platformData.addDataSet((DataSet) convert); diff --git a/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java b/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java index 549db5e..a0116d1 100644 --- a/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java +++ b/src/main/java/com/nexacro/spring/resolve/NexacroMethodArgumentResolver.java @@ -293,10 +293,10 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol return dataSet; } - // support only list parameter - if(!List.class.equals(parameterType)) { - throw new IllegalArgumentException(ParamDataSet.class.getSimpleName()+" annotation support List and DataSet parameter."); - } +// // support only list parameter +// if(!List.class.equals(parameterType)) { +// throw new IllegalArgumentException(ParamDataSet.class.getSimpleName()+" annotation support List and DataSet parameter."); +// } Class convertedGenericType = findGenericType(param); if(convertedGenericType == null) { @@ -304,16 +304,15 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol throw new IllegalArgumentException(ParamDataSet.class.getSimpleName()+" annotation must be List."); } - ConvertDefinition definition = new ConvertDefinition(dsName); definition.setGenericType(convertedGenericType); Class fromType = DataSet.class; Class toType = parameterType; - NexacroConverter converter = NexacroConverterFactory.getConverter(fromType, toType); + NexacroConverter converter = NexacroConverterFactory.getConverter(fromType, toType); if(converter == null) { - throw new IllegalArgumentException("invalid @ParamDataSet. supported type={DataSet, List}"); + throw new IllegalArgumentException("invalid @ParamDataSet. supported type={DataSet, Object}"); } try { @@ -369,28 +368,55 @@ public class NexacroMethodArgumentResolver implements HandlerMethodArgumentResol } +// private Class findGenericType(MethodParameter param) { +// +// // current type -> List +// Type genericParameterType = param.getGenericParameterType(); +// if (genericParameterType instanceof ParameterizedType) { +// +// // current type -> +// Type[] types = ((ParameterizedType) genericParameterType).getActualTypeArguments(); +// +// if(types[0] instanceof ParameterizedType) { +// // List> +// return (Class) ((ParameterizedType) types[0]).getRawType(); +// } else { +// +// // List +// // List +// return (Class) types[0]; +// } +// } +// +// return null; +// } + private Class findGenericType(MethodParameter param) { - - // current type -> List - Type genericParameterType = param.getGenericParameterType(); - if (genericParameterType instanceof ParameterizedType) { - - // current type -> - Type[] types = ((ParameterizedType) genericParameterType).getActualTypeArguments(); - - if(types[0] instanceof ParameterizedType) { - // List> - return (Class) ((ParameterizedType) types[0]).getRawType(); - } else { - - // List - // List - return (Class) types[0]; - } - } - - return null; + + Class parameterType = param.getParameterType(); + + if (!List.class.equals(parameterType)) { + return parameterType; + } else { + Type genericParameterType = param.getGenericParameterType(); + if (genericParameterType instanceof ParameterizedType) { + Type[] types = ((ParameterizedType) genericParameterType).getActualTypeArguments(); + return (Class) types[0]; + +// if(types[0] instanceof ParameterizedType) { +// // List> +// return (Class) ((ParameterizedType) types[0]).getRawType(); +// } else { +// // List +// // List +// return (Class) types[0]; +// } + } + } + + return null; } + protected void handleMissingValue(String name, MethodParameter parameter) throws NexacroConvertException { throw new MissingNexacroParameterException(name, parameter.getParameterType().getSimpleName()); diff --git a/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java b/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java new file mode 100644 index 0000000..8096e52 --- /dev/null +++ b/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java @@ -0,0 +1,226 @@ +package com.nexacro.spring.data.support; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.crypto.Data; + +import junit.framework.Assert; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; + +import com.nexacro.spring.data.convert.ConvertDefinition; +import com.nexacro.spring.data.convert.NexacroConvertException; +import com.nexacro.spring.data.support.NexacroTestUtil.StaticPropertyBean; +import com.nexacro.spring.data.support.bean.DefaultBean; +import com.nexacro.spring.util.ReflectionUtil; +import com.nexacro.xapi.data.ColumnHeader; +import com.nexacro.xapi.data.ConstantColumnHeader; +import com.nexacro.xapi.data.DataSet; +import com.nexacro.xapi.data.PlatformData; +import com.nexacro.xapi.tx.DataDeserializer; +import com.nexacro.xapi.tx.DataSerializerFactory; +import com.nexacro.xapi.tx.PlatformException; +import com.nexacro.xapi.tx.PlatformType; + +public class DataSetToObjectConverterTest { + + private DataSetToObjectConverter converter; + + @Before + public void setUp() { + converter = new DataSetToObjectConverter(); + } + + @Test + public void testSupportedType() { + Class source; + Class target; + boolean canConvert; + + source = DataSet.class; + target = Object.class; + canConvert = converter.canConvert(source, target); + Assert.assertTrue(source + " to " + target + " must be converted", canConvert); + } + + @Test + public void testConvertDataSetBeanToObject() throws IOException, PlatformException { + + String responseFileName = "src/test/java/com/nexacro/spring/resolve/httpRequestForMap.xml"; + InputStream responseInputStream = new FileInputStream(new File(responseFileName)); + + DataDeserializer deserializer = DataSerializerFactory.getDeserializer(PlatformType.CONTENT_TYPE_XML); + PlatformData readData = deserializer.readData(responseInputStream, null, PlatformType.DEFAULT_CHAR_SET); + + DataSet dataSet = readData.getDataSet("ds"); + + ConvertDefinition definition = new ConvertDefinition("ds"); + definition.setGenericType(Object.class); + + Object obj = null; + try { + obj = converter.convert(dataSet, definition); + } catch (NexacroConvertException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + if (!(obj instanceof Object)) { + Assert.fail("It must be Object"); + } + } + + @Test + public void testNullData() { + + DataSet dataSet = null; + + ConvertDefinition definition = new ConvertDefinition("ds"); + definition.setGenericType(Object.class); + + Object ds = null; + try { + ds = converter.convert(dataSet, definition); + } catch (NexacroConvertException e) { + Assert.fail(e.getMessage()); + } + + if (!(ds instanceof Object)) { + Assert.fail("converted object must be implemented DataSet"); + } + } + + @Test + public void testMapConvert() { + + Map beanMap = new HashMap(); + +// Result result = new Result(); +//// List list = result.getList(); +// +// +// DefaultBean bean = new DefaultBean(); +// beanList.add(bean); +// +// Object[] array = beanList.toArray(); +// array[0].getClass(); +// +// Class clazz= beanList.getClass(); +// +// ParameterizedType parameterizedType = (ParameterizedType) clazz.getGenericSuperclass(); +// System.out.println(parameterizedType.getRawType()); +// +// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); +// for(Type type: actualTypeArguments) { +// System.out.println(type); +// } + + DefaultBean bean = new DefaultBean(); + beanMap.put(bean.getClass().getSimpleName(), bean); + + System.out.println("key = " + beanMap); + Class clazz = beanMap.getClass(); + System.out.println("clazz = " + clazz); + ParameterizedType superclass = (ParameterizedType) clazz.getGenericSuperclass(); + Type[] types = superclass.getActualTypeArguments(); + Class actualdataType = null; + if(types != null && types.length >0 && (types[0] instanceof Class) ) { + actualdataType = (Class) (Class) types[0]; + } + System.out.println("actualdataType = " + actualdataType); + } + + private static final String TYPE_CLASS_NAME_PREFIX = "class "; + private static final String TYPE_INTERFACE_NAME_PREFIX = "interface "; + + public static String getClassName(Type type) { + if (type==null) { + return ""; + } + String className = type.toString(); + if (className.startsWith(TYPE_CLASS_NAME_PREFIX)) { + className = className.substring(TYPE_CLASS_NAME_PREFIX.length()); + } else if (className.startsWith(TYPE_INTERFACE_NAME_PREFIX)) { + className = className.substring(TYPE_INTERFACE_NAME_PREFIX.length()); + } + return className; + } + + /** + * Returns the {@code Class} object associated with the given {@link Type} + * depending on its fully qualified name. + * + * @param type the {@code Type} whose {@code Class} is needed. + * @return the {@code Class} object for the class with the specified name. + * + * @throws ClassNotFoundException if the class cannot be located. + * + * @see {@link ReflectionUtil#getClassName(Type)} + */ + public static Class getClass(Type type) throws ClassNotFoundException { + String className = getClassName(type); + if (className==null || className.isEmpty()) { + return null; + } + return Class.forName(className); + } + + public static Type[] getParameterizedTypes(Object object) { + Type superclassType = object.getClass().getGenericSuperclass(); + if (!ParameterizedType.class.isAssignableFrom(superclassType.getClass())) { + return null; + } + + return ((ParameterizedType)superclassType).getActualTypeArguments(); + } + +// public static Class getClass(Type type) { +// if (type instanceof Class) { +// return (Class) type; +// } +// else if (type instanceof ParameterizedType) { +// return getClass(((ParameterizedType) type).getRawType()); +// } +// else if (type instanceof GenericArrayType) { +// Type componentType = ((GenericArrayType) type).getGenericComponentType(); +// Class componentClass = getClass(componentType); +// if (componentClass != null ) { +// return Array.newInstance(componentClass, 0).getClass(); +// } +// else { +// return null; +// } +// } +// else { +// return null; +// } +// } + + + private static class Result { + private List list; + public void setList(List list) { + this.list = list; + } + + public List getList() { + return null; + } + + } + + +} diff --git a/src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java b/src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java new file mode 100644 index 0000000..2da2863 --- /dev/null +++ b/src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java @@ -0,0 +1,236 @@ +package com.nexacro.spring.data.support; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import com.nexacro.spring.data.convert.ConvertDefinition; +import com.nexacro.spring.data.convert.NexacroConvertException; +import com.nexacro.spring.data.support.NexacroTestUtil.StaticPropertyBean; +import com.nexacro.spring.data.support.bean.DefaultBean; +import com.nexacro.spring.util.ReflectionUtil; +import com.nexacro.xapi.data.ColumnHeader; +import com.nexacro.xapi.data.ConstantColumnHeader; +import com.nexacro.xapi.data.DataSet; + +public class ObjectToDataSetConverterTest { + + private ObjectToDataSetConverter converter; + + @Before + public void setUp() { + converter = new ObjectToDataSetConverter(); + } + + @Test + public void testSupportedType() { + Class source; + Class target; + boolean canConvert; + + source = Object.class; + target = DataSet.class; + canConvert = converter.canConvert(source, target); + Assert.assertTrue(source + " to " + target + " must be converted", canConvert); + } + + @Test + public void testConvertObjectBeanToDataSet() { + + DefaultBean defaultBean = new DefaultBean(); + defaultBean.setLastName("Kim"); + + ConvertDefinition definition = new ConvertDefinition("ds"); + + Object ds = null; + try { + ds = converter.convert(defaultBean, definition); + } catch (NexacroConvertException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + if (!(ds instanceof DataSet)) { + Assert.fail("converted object must be implemented DataSet"); + } + + DataSet dataset = (DataSet) ds; + Assert.assertEquals("ds", dataset.getName()); + Assert.assertEquals("Kim", dataset.getObject(0, "lastName")); + } + + @Test + public void testConvertMapToDataSet() { + Map map = new HashMap(); + map.put("firstName", "firstName"); + map.put("lastName", "lastName"); + + ConvertDefinition definition = new ConvertDefinition("ds"); + + Object ds = null; + try { + ds = converter.convert(map, definition); + } catch (NexacroConvertException e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + if (!(ds instanceof DataSet)) { + Assert.fail("converted object must be implemented DataSet"); + } + + DataSet dataset = (DataSet) ds; + Assert.assertEquals("lastName", dataset.getObject(0, "lastName")); + } + + @Test + public void testNullData() { + + Object object = null; + ConvertDefinition definition = new ConvertDefinition("ds"); + + Object ds = null; + try { + ds = converter.convert(object, definition); + } catch (NexacroConvertException e) { + Assert.fail(e.getMessage()); + } + + if (!(ds instanceof DataSet)) { + Assert.fail("converted object must be implemented DataSet"); + } + + DataSet dataset = (DataSet) ds; + Assert.assertNotNull("dataset should not be null", dataset); + Assert.assertEquals("ds", dataset.getName()); + } + + @Test + public void testMapConvert() { + + Map beanMap = new HashMap(); + +// Result result = new Result(); +//// List list = result.getList(); +// +// +// DefaultBean bean = new DefaultBean(); +// beanList.add(bean); +// +// Object[] array = beanList.toArray(); +// array[0].getClass(); +// +// Class clazz= beanList.getClass(); +// +// ParameterizedType parameterizedType = (ParameterizedType) clazz.getGenericSuperclass(); +// System.out.println(parameterizedType.getRawType()); +// +// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); +// for(Type type: actualTypeArguments) { +// System.out.println(type); +// } + + DefaultBean bean = new DefaultBean(); + beanMap.put(bean.getClass().getSimpleName(), bean); + + System.out.println("key = " + beanMap); + Class clazz = beanMap.getClass(); + System.out.println("clazz = " + clazz); + ParameterizedType superclass = (ParameterizedType) clazz.getGenericSuperclass(); + Type[] types = superclass.getActualTypeArguments(); + Class actualdataType = null; + if(types != null && types.length >0 && (types[0] instanceof Class) ) { + actualdataType = (Class) (Class) types[0]; + } + System.out.println("actualdataType = " + actualdataType); + } + + private static final String TYPE_CLASS_NAME_PREFIX = "class "; + private static final String TYPE_INTERFACE_NAME_PREFIX = "interface "; + + public static String getClassName(Type type) { + if (type==null) { + return ""; + } + String className = type.toString(); + if (className.startsWith(TYPE_CLASS_NAME_PREFIX)) { + className = className.substring(TYPE_CLASS_NAME_PREFIX.length()); + } else if (className.startsWith(TYPE_INTERFACE_NAME_PREFIX)) { + className = className.substring(TYPE_INTERFACE_NAME_PREFIX.length()); + } + return className; + } + + /** + * Returns the {@code Class} object associated with the given {@link Type} + * depending on its fully qualified name. + * + * @param type the {@code Type} whose {@code Class} is needed. + * @return the {@code Class} object for the class with the specified name. + * + * @throws ClassNotFoundException if the class cannot be located. + * + * @see {@link ReflectionUtil#getClassName(Type)} + */ + public static Class getClass(Type type) throws ClassNotFoundException { + String className = getClassName(type); + if (className==null || className.isEmpty()) { + return null; + } + return Class.forName(className); + } + + public static Type[] getParameterizedTypes(Object object) { + Type superclassType = object.getClass().getGenericSuperclass(); + if (!ParameterizedType.class.isAssignableFrom(superclassType.getClass())) { + return null; + } + + return ((ParameterizedType)superclassType).getActualTypeArguments(); + } + +// public static Class getClass(Type type) { +// if (type instanceof Class) { +// return (Class) type; +// } +// else if (type instanceof ParameterizedType) { +// return getClass(((ParameterizedType) type).getRawType()); +// } +// else if (type instanceof GenericArrayType) { +// Type componentType = ((GenericArrayType) type).getGenericComponentType(); +// Class componentClass = getClass(componentType); +// if (componentClass != null ) { +// return Array.newInstance(componentClass, 0).getClass(); +// } +// else { +// return null; +// } +// } +// else { +// return null; +// } +// } + + + private static class Result { + private List list; + public void setList(List list) { + this.list = list; + } + + public List getList() { + return null; + } + + } + + +} diff --git a/src/test/java/com/nexacro/spring/resolve/httpRequestForMap.xml b/src/test/java/com/nexacro/spring/resolve/httpRequestForMap.xml new file mode 100644 index 0000000..d1c3e20 --- /dev/null +++ b/src/test/java/com/nexacro/spring/resolve/httpRequestForMap.xml @@ -0,0 +1,39 @@ + + + + 1 + varString + + + + + + + + + + + + + + + + + + + 11 + 11.1 + tobesoft@tobesoft.com + 11 + firstName + 200 + 20090101134516072 + AQE= + lastName + 1 + java.lang.Object@1c7e2da + 11111 + + + + \ No newline at end of file