From: <fg...@us...> - 2008-01-04 21:39:05
|
Revision: 516 http://openutils.svn.sourceforge.net/openutils/?rev=516&view=rev Author: fgiust Date: 2008-01-04 13:39:07 -0800 (Fri, 04 Jan 2008) Log Message: ----------- more cleanup Modified Paths: -------------- trunk/openutils-bshd5/pom.xml trunk/openutils-configuration-services/pom.xml trunk/openutils-spring/pom.xml trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java trunk/openutils-tags-spring/pom.xml trunk/openutils-testing-testng/pom.xml Modified: trunk/openutils-bshd5/pom.xml =================================================================== --- trunk/openutils-bshd5/pom.xml 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-bshd5/pom.xml 2008-01-04 21:39:07 UTC (rev 516) @@ -35,6 +35,17 @@ </dependency> <dependency> <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> <exclusions> Modified: trunk/openutils-configuration-services/pom.xml =================================================================== --- trunk/openutils-configuration-services/pom.xml 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-configuration-services/pom.xml 2008-01-04 21:39:07 UTC (rev 516) @@ -43,7 +43,7 @@ <dependency> <groupId>net.sourceforge.openutils</groupId> <artifactId>openutils-testing-testng</artifactId> - <version>1.1</version> + <version>1.1.4-SNAPSHOT</version> <scope>test</scope> </dependency> <dependency> @@ -100,6 +100,18 @@ </dependency> <dependency> <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>${spring.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> <scope>test</scope> @@ -123,9 +135,17 @@ <scope>test</scope> <exclusions> <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> + <exclusion> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + </exclusion> </exclusions> </dependency> </dependencies> Modified: trunk/openutils-spring/pom.xml =================================================================== --- trunk/openutils-spring/pom.xml 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-spring/pom.xml 2008-01-04 21:39:07 UTC (rev 516) @@ -79,9 +79,14 @@ <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> - <version>1.2</version> + <version>1.4.3</version> </dependency> <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.2.1.ga</version> Modified: trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java =================================================================== --- trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-spring/src/main/java/it/openutils/spring/remoting/exporters/JSONServiceExporter.java 2008-01-04 21:39:07 UTC (rev 516) @@ -29,225 +29,253 @@ import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; + /** * @author mmolaschi * @version $Id: $ */ -public class JSONServiceExporter extends RemoteInvocationBasedExporter - implements Controller { - private static final String METHOD = "__method__"; +public class JSONServiceExporter extends RemoteInvocationBasedExporter implements Controller +{ - private static final String PARAM_PREFIX = "param"; + private static final String METHOD = "__method__"; - private static final String CONTENT_TYPE = "text/x-json"; + private static final String PARAM_PREFIX = "param"; - /** - * {@inheritDoc} - */ - public ModelAndView handleRequest(HttpServletRequest request, - HttpServletResponse response) throws Exception { - if (request.getParameter(METHOD) != null) { - String methodRequest = request.getParameter(METHOD); - Method[] methods = this.getServiceInterface().getMethods(); - for (Method method : methods) { - if (method.getName().equals(methodRequest)) { - Class[] types = method.getParameterTypes(); - Object[] values = new Object[types.length]; - if (values.length > 0) { - int i = 0; - Enumeration<String> names = request.getParameterNames(); - while (names.hasMoreElements()) { - String name = names.nextElement(); - if (name != null && name.startsWith(PARAM_PREFIX)) { - String posStr = StringUtils.substringAfter( - name, PARAM_PREFIX); - int pos = NumberUtils.toInt(posStr); + private static final String CONTENT_TYPE = "text/x-json"; - String[] reqValues = request - .getParameterValues(name); - if (reqValues != null && reqValues.length > 0) { - if (types[pos].isArray()) { - values[pos] = ConvertUtils.convert( - reqValues, types[pos]); - } else { - values[pos] = ConvertUtils.convert( - reqValues[0], types[pos]); - } - } else { - values[pos] = null; - } + /** + * {@inheritDoc} + */ + public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception + { + if (request.getParameter(METHOD) != null) + { + String methodRequest = request.getParameter(METHOD); + Method[] methods = this.getServiceInterface().getMethods(); + for (Method method : methods) + { + if (method.getName().equals(methodRequest)) + { + Class[] types = method.getParameterTypes(); + Object[] values = new Object[types.length]; + if (values.length > 0) + { + int i = 0; + Enumeration<String> names = request.getParameterNames(); + while (names.hasMoreElements()) + { + String name = names.nextElement(); + if (name != null && name.startsWith(PARAM_PREFIX)) + { + String posStr = StringUtils.substringAfter(name, PARAM_PREFIX); + int pos = NumberUtils.toInt(posStr); - } - } - } + String[] reqValues = request.getParameterValues(name); + if (reqValues != null && reqValues.length > 0) + { + if (types[pos].isArray()) + { + values[pos] = ConvertUtils.convert(reqValues, types[pos]); + } + else + { + values[pos] = ConvertUtils.convert(reqValues[0], types[pos]); + } + } + else + { + values[pos] = null; + } - RemoteInvocation invocation = new RemoteInvocation(); - invocation.setArguments(values); - invocation.setParameterTypes(types); - invocation.setMethodName(methodRequest); + } + } + } - RemoteInvocationResult result = invokeAndCreateResult( - invocation, this.getProxyForService()); + RemoteInvocation invocation = new RemoteInvocation(); + invocation.setArguments(values); + invocation.setParameterTypes(types); + invocation.setMethodName(methodRequest); - response.setContentType(CONTENT_TYPE); - JSON json; - if (result.hasException()) { - JSONObject obj = JSONObject.fromBean(result - .getException()); - obj.put("exception", true); + RemoteInvocationResult result = invokeAndCreateResult(invocation, this.getProxyForService()); - json = obj; - } else { - Object value = cleanLazy(result.getValue()); - if (value != null) { - if (ClassUtils.getAllInterfaces(value.getClass()) - .contains(Collection.class)) { - json = JSONArray - .fromCollection((Collection) value); - } else if (ClassUtils.getAllInterfaces( - value.getClass()).contains(Map.class)) { - json = JSONObject.fromMap((Map) value); - } else if (value.getClass().isArray()) { - json = JSONArray.fromArray((Object[]) value); - } else { - JSONObject obj = JSONObject.fromBean(value); - json = obj; - } - } else { - json = JSONNull.getInstance(); - } - } - json.write(response.getWriter()); + response.setContentType(CONTENT_TYPE); + JSON json; + if (result.hasException()) + { + JSONObject obj = JSONObject.fromBean(result.getException()); + obj.put("exception", true); - break; - } - } + json = obj; + } + else + { + Object value = cleanLazy(result.getValue()); + if (value != null) + { + if (ClassUtils.getAllInterfaces(value.getClass()).contains(Collection.class)) + { + json = JSONArray.fromCollection((Collection) value); + } + else if (ClassUtils.getAllInterfaces(value.getClass()).contains(Map.class)) + { + json = JSONObject.fromMap((Map) value); + } + else if (value.getClass().isArray()) + { + json = JSONArray.fromArray((Object[]) value); + } + else + { + JSONObject obj = JSONObject.fromBean(value); + json = obj; + } + } + else + { + json = JSONNull.getInstance(); + } + } + json.write(response.getWriter()); - } - return null; - } + break; + } + } - public Object cleanLazy(Object bean) throws IllegalAccessException, - InstantiationException, IntrospectionException, - InvocationTargetException { - if (bean == null) { - return null; - } - Class<?> clazz = bean.getClass(); - if (bean instanceof Collection) { - Collection collection = (Collection) bean; + } + return null; + } - Collection newCollection; - newCollection = collection.getClass().newInstance(); - for (Object myObject : collection) { - newCollection.add(cleanLazy(myObject)); - } - collection.clear(); - collection.addAll(newCollection); - } - if (bean instanceof Map) { - Map<Object, Object> map = (Map<Object, Object>) bean; - Map<Object, Object> newMap = map.getClass().newInstance(); - for (Map.Entry entry : map.entrySet()) { - Object key = cleanLazy(entry.getKey()); - Object value = cleanLazy(entry.getValue()); - newMap.put(key, value); - } - map.clear(); - map.putAll(newMap); - } - if (clazz.isArray()) { - Object[] array = (Object[]) bean; - for (int i = 0; i < array.length; i++) { - array[i] = cleanLazy(array[i]); - } - } - boolean isHibernate = !clazz.equals(Hibernate.getClass(bean)); - if (isHibernate) { - Class<?> noProxyClass = Hibernate.getClass(bean); - Object noHibernateBean = noProxyClass.newInstance(); - BeanInfo info = Introspector.getBeanInfo(noProxyClass); - PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); - for (PropertyDescriptor descriptor : descriptors) { - String name = descriptor.getName(); + public Object cleanLazy(Object bean) throws IllegalAccessException, InstantiationException, IntrospectionException, + InvocationTargetException + { + if (bean == null) + { + return null; + } + Class< ? > clazz = bean.getClass(); + if (bean instanceof Collection) + { + Collection collection = (Collection) bean; - if ("class".equals(name)) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } + Collection newCollection; + newCollection = collection.getClass().newInstance(); + for (Object myObject : collection) + { + newCollection.add(cleanLazy(myObject)); + } + collection.clear(); + collection.addAll(newCollection); + } + if (bean instanceof Map) + { + Map<Object, Object> map = (Map<Object, Object>) bean; + Map<Object, Object> newMap = map.getClass().newInstance(); + for (Map.Entry entry : map.entrySet()) + { + Object key = cleanLazy(entry.getKey()); + Object value = cleanLazy(entry.getValue()); + newMap.put(key, value); + } + map.clear(); + map.putAll(newMap); + } + if (clazz.isArray()) + { + Object[] array = (Object[]) bean; + for (int i = 0; i < array.length; i++) + { + array[i] = cleanLazy(array[i]); + } + } + boolean isHibernate = !clazz.equals(Hibernate.getClass(bean)); + if (isHibernate) + { + Class< ? > noProxyClass = Hibernate.getClass(bean); + Object noHibernateBean = noProxyClass.newInstance(); + BeanInfo info = Introspector.getBeanInfo(noProxyClass); + PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); + for (PropertyDescriptor descriptor : descriptors) + { + String name = descriptor.getName(); - if ("hibernateLazyInitializer".equals(name)) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } + if ("class".equals(name)) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } - if (descriptor.getReadMethod() == null - || descriptor.getWriteMethod() == null) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } + if ("hibernateLazyInitializer".equals(name)) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } - Method method = findGetter(bean, name); + if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } - if (method == null) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } + Method method = findGetter(bean, name); - if (!Hibernate.isPropertyInitialized(bean, name)) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } + if (method == null) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } - // This might be a lazy-collection so we need to double check - Object retval = method.invoke(bean); - if (!Hibernate.isInitialized(retval)) { - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { null }); - continue; - } - descriptor.getWriteMethod().invoke(noHibernateBean, - new Object[] { cleanLazy(bean) }); + if (!Hibernate.isPropertyInitialized(bean, name)) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } - } + // This might be a lazy-collection so we need to double check + Object retval = method.invoke(bean); + if (!Hibernate.isInitialized(retval)) + { + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{null }); + continue; + } + descriptor.getWriteMethod().invoke(noHibernateBean, new Object[]{cleanLazy(bean) }); - bean = noHibernateBean; - } else { - BeanInfo info = Introspector.getBeanInfo(clazz); - PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); - for (PropertyDescriptor descriptor : descriptors) { - Object value = descriptor.getReadMethod().invoke(bean, null); - descriptor.getWriteMethod().invoke(bean, - new Object[] { cleanLazy(bean) }); - } - } - return bean; - } + } - protected Method findGetter(Object bean, String name) - throws IntrospectionException { - Class<?> clazz = Hibernate.getClass(bean); - // String key = clazz.getName() + ":" + property; + bean = noHibernateBean; + } + else + { + BeanInfo info = Introspector.getBeanInfo(clazz); + PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); + for (PropertyDescriptor descriptor : descriptors) + { + Object value = descriptor.getReadMethod().invoke(bean, null); + descriptor.getWriteMethod().invoke(bean, new Object[]{cleanLazy(bean) }); + } + } + return bean; + } - Method method = null; // methods.get(key); - // if (method == null) - // { - PropertyDescriptor[] props = Introspector.getBeanInfo(clazz) - .getPropertyDescriptors(); - for (PropertyDescriptor prop : props) { - if (prop.getName().equalsIgnoreCase(name)) { - method = prop.getReadMethod(); - } - } + protected Method findGetter(Object bean, String name) throws IntrospectionException + { + Class< ? > clazz = Hibernate.getClass(bean); + // String key = clazz.getName() + ":" + property; - // methods.put(key, method); - // } + Method method = null; // methods.get(key); + // if (method == null) + // { + PropertyDescriptor[] props = Introspector.getBeanInfo(clazz).getPropertyDescriptors(); + for (PropertyDescriptor prop : props) + { + if (prop.getName().equalsIgnoreCase(name)) + { + method = prop.getReadMethod(); + } + } - return method; - } + // methods.put(key, method); + // } + + return method; + } } Modified: trunk/openutils-tags-spring/pom.xml =================================================================== --- trunk/openutils-tags-spring/pom.xml 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-tags-spring/pom.xml 2008-01-04 21:39:07 UTC (rev 516) @@ -75,6 +75,16 @@ </exclusions> </dependency> <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl104-over-slf4j</artifactId> + <version>1.4.3</version> + </dependency> + <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.13</version> Modified: trunk/openutils-testing-testng/pom.xml =================================================================== --- trunk/openutils-testing-testng/pom.xml 2008-01-04 21:22:28 UTC (rev 515) +++ trunk/openutils-testing-testng/pom.xml 2008-01-04 21:39:07 UTC (rev 516) @@ -68,9 +68,17 @@ <optional>true</optional> <exclusions> <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> + <exclusion> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + </exclusion> </exclusions> </dependency> <dependency> @@ -78,7 +86,28 @@ <artifactId>testng</artifactId> <classifier>jdk15</classifier> <version>5.1</version> + <exclusions> + <exclusion> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </exclusion> + </exclusions> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate</artifactId> + <version>3.2.1.ga</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> <properties> <spring.version>2.5</spring.version> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |