diff --git a/src/main/java/com/nexacro/spring/data/support/NexacroBeanWrapper.java b/src/main/java/com/nexacro/spring/data/support/NexacroBeanWrapper.java index f77a65a..9f8c15c 100644 --- a/src/main/java/com/nexacro/spring/data/support/NexacroBeanWrapper.java +++ b/src/main/java/com/nexacro/spring/data/support/NexacroBeanWrapper.java @@ -204,6 +204,27 @@ public class NexacroBeanWrapper { return mapping; } + /** + * java.beans.Introspector 의 property name 변환

+ * get/set 메서드의 이름 중 첫번째 두번째 모두 대문자 일 경우 대문자 반환 + * 아닐 경우 첫번째 글자만 소문자로 변환한다. + * + *
+public static String decapitalize(String name) {
+if (name == null || name.length() == 0) {
+    return name;
+}
+if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
+		Character.isUpperCase(name.charAt(0))){
+    return name;
+}
+char chars[] = name.toCharArray();
+chars[0] = Character.toLowerCase(chars[0]);
+return new String(chars);
+}
+    	 * 
+ * @param beanWrapper + */ private void initBeanPropertyNames(BeanWrapper beanWrapper) { propertyCache = new HashMap(); diff --git a/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java b/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java index 8096e52..67d55b3 100644 --- a/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java +++ b/src/test/java/com/nexacro/spring/data/support/DataSetToObjectConverterTest.java @@ -1,226 +1,316 @@ -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; - } - - } - - -} +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.data.support.bean.UpperCaseBean; +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.data.datatype.PlatformDataType; +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 testUpperCase() { + + String[] columnNames = { + "firstOnly" + , "FIrstAndSecond" + , "ALL" + }; + + String[] columnValues = { + "first" + , "second" + , "all" + }; + + DataSet ds = new DataSet("dsUpper"); + for(int i=0; i 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 index ab1409d..e2c90c2 100644 --- a/src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java +++ b/src/test/java/com/nexacro/spring/data/support/ObjectToDataSetConverterTest.java @@ -1,233 +1,281 @@ -package com.nexacro.spring.data.support; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -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.bean.DefaultBean; -import com.nexacro.spring.util.ReflectionUtil; -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(map.get("firstName"), dataset.getObject(0, "firstName")); - Assert.assertEquals(map.get("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; - } - - } - - -} +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.bean.DefaultBean; +import com.nexacro.spring.data.support.bean.UpperCaseBean; +import com.nexacro.spring.util.ReflectionUtil; +import com.nexacro.xapi.data.ColumnHeader; +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(map.get("firstName"), dataset.getObject(0, "firstName")); + Assert.assertEquals(map.get("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 testUpperCase() { + + String[] expectedColumnNames = { + "firstOnly" + , "FIrstAndSecond" + , "ALL" + }; + + String[] expectecColumnValues = { + "first" + , "second" + , "all" + }; + + UpperCaseBean upperCaseBean = new UpperCaseBean(); + upperCaseBean.setFirstOnly(expectecColumnValues[0]); + upperCaseBean.setFIrstAndSecond(expectecColumnValues[1]); + upperCaseBean.setALL(expectecColumnValues[2]); + + ConvertDefinition definition = new ConvertDefinition("ds"); + DataSet ds = null; + try { + ds = converter.convert(upperCaseBean, definition); + } catch (NexacroConvertException e) { + Assert.fail(e.getMessage()); + } + + Assert.assertNotNull("converted list should not be null.", ds); + + + + Assert.assertEquals("three columns must be exist.", expectedColumnNames.length, ds.getColumnCount()); + + for(int i=0; i 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/bean/UpperCaseBean.java b/src/test/java/com/nexacro/spring/data/support/bean/UpperCaseBean.java new file mode 100644 index 0000000..9471af8 --- /dev/null +++ b/src/test/java/com/nexacro/spring/data/support/bean/UpperCaseBean.java @@ -0,0 +1,33 @@ +package com.nexacro.spring.data.support.bean; + +public class UpperCaseBean { + + private String FirstOnly; + private String FIrstAndSecond; + private String ALL; + + public String getFirstOnly() { + return FirstOnly; + } + + public void setFirstOnly(String firstOnly) { + FirstOnly = firstOnly; + } + + public String getFIrstAndSecond() { + return FIrstAndSecond; + } + + public void setFIrstAndSecond(String fIrstAndSecond) { + FIrstAndSecond = fIrstAndSecond; + } + + public String getALL() { + return ALL; + } + + public void setALL(String aLL) { + ALL = aLL; + } + +}