Author: dkulp
Date: Tue Jan 5 02:11:00 2010
New Revision: 895849
URL: http://svn.apache.org/viewvc?rev=895849&view=rev
Log:
Merged revisions 894074 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r894074 | bimargulies | 2009-12-27 11:19:11 -0500 (Sun, 27 Dec 2009) | 2 lines
CXF-2593. When you have Collection<double[]>, for some crazy reason the JRE
represents this the double[] as a
GenericArrayType and not a Class<double[]>. Add code to concoct and use the
later when presented with the former.
........
Added:
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionService.java
- copied unchanged from r894074,
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionService.java
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTestsWithService.java
- copied unchanged from r894074,
cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTestsWithService.java
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionServiceInterface.java
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTest.java
Propchange: cxf/branches/2.2.x-fixes/
('svn:mergeinfo' removed)
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=895849&r1=895848&r2=895849&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
Tue Jan 5 02:11:00 2010
@@ -18,6 +18,9 @@
*/
package org.apache.cxf.aegis.type;
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
@@ -182,4 +185,81 @@
String ns = type.getSchemaType().getNamespaceURI();
XmlSchemaUtils.addImportIfNeeded(root, ns);
}
+
+ /**
+ * Utility function to cast a Type to a Class. This throws an unchecked
exception if the Type is
+ * not a Class. The idea here is that these Type references should have
been checked for
+ * reasonableness before the point of calls to this function.
+ * @param type Reflection type.
+ * @param throwForNonClass whether to throw (true) or return null (false)
if the Type
+ * is not a class.
+ * @return the Class
+ */
+ public static Class<?> getTypeClass(java.lang.reflect.Type type, boolean
throwForNonClass) {
+ if (type instanceof Class) {
+ return (Class) type;
+ } else if (throwForNonClass) {
+ throw new RuntimeException("Attempt to derive Class from
reflection Type " + type);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Insist that a Type is a parameterized type of one parameter.
+ * This is used to decompose Holders, for example.
+ * @param type the type
+ * @return the parameter, or null if the type is not what we want.
+ */
+ public static java.lang.reflect.Type
getSingleTypeParameter(java.lang.reflect.Type type) {
+ return getSingleTypeParameter(type, 0);
+ }
+
+ /**
+ * Insist that a Type is a parameterized type of one parameter.
+ * This is used to decompose Holders, for example.
+ * @param type the type
+ * @param index which parameter
+ * @return the parameter, or null if the type is not what we want.
+ */
+ public static java.lang.reflect.Type
getSingleTypeParameter(java.lang.reflect.Type type, int index) {
+ if (type instanceof ParameterizedType) {
+ ParameterizedType pType = (ParameterizedType) type;
+ java.lang.reflect.Type[] params = pType.getActualTypeArguments();
+ if (params.length > index) {
+ return params[index];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * If a Type is a class, return it as a class.
+ * If it is a ParameterizedType, return the raw type as a class.
+ * Otherwise return null.
+ * @param type
+ * @return
+ */
+ public static Class<?> getTypeRelatedClass(java.lang.reflect.Type type) {
+ Class<?> directClass = getTypeClass(type, false);
+ if (directClass != null) {
+ return directClass;
+ }
+
+ if (type instanceof ParameterizedType) {
+ ParameterizedType pType = (ParameterizedType) type;
+ return getTypeRelatedClass(pType.getRawType());
+ }
+
+ if (type instanceof GenericArrayType) {
+ GenericArrayType gat = (GenericArrayType) type;
+ java.lang.reflect.Type compType = gat.getGenericComponentType();
+ Class<?> arrayBaseType = getTypeRelatedClass(compType);
+ // belive it or not, this seems to be the only way to get the
+ // Class object for an array of primitive type.
+ Object instance = Array.newInstance(arrayBaseType, 0);
+ return instance.getClass();
+ }
+ return null;
+ }
}
Modified:
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionServiceInterface.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionServiceInterface.java?rev=895849&r1=895848&r2=895849&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionServiceInterface.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionServiceInterface.java
Tue Jan 5 02:11:00 2010
@@ -49,4 +49,6 @@
void method1(List<String> headers1);
void mapOfMapWithStringAndPojo(Map<String, Map<String,
BeanWithGregorianDate>> bigParam);
+
+ Collection<double[]> returnCollectionOfPrimitiveArrays();
}
Modified:
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTest.java?rev=895849&r1=895848&r2=895849&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTest.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/CollectionTest.java
Tue Jan 5 02:11:00 2010
@@ -21,24 +21,14 @@
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedSet;
-import java.util.Stack;
-import java.util.TreeSet;
import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.apache.cxf.aegis.AbstractAegisTest;
-import org.apache.cxf.aegis.databinding.AegisDatabinding;
-import org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration;
import org.apache.cxf.aegis.type.DefaultTypeMapping;
import org.apache.cxf.aegis.type.Type;
import org.apache.cxf.aegis.type.TypeCreationOptions;
@@ -48,7 +38,6 @@
import org.apache.cxf.aegis.type.java5.dto.DTOService;
import org.apache.cxf.aegis.type.java5.dto.ObjectDTO;
import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.junit.Before;
import org.junit.Test;
@@ -231,32 +220,7 @@
doc);
}
- @Test
- public void testListTypes() throws Exception {
- createService(CollectionServiceInterface.class, new
CollectionService(), null);
-
- ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
- proxyFac.getServiceFactory().getServiceConfigurations().add(0,
- new
XFireCompatibilityServiceConfiguration());
- proxyFac.setServiceClass(CollectionServiceInterface.class);
- proxyFac.setDataBinding(new AegisDatabinding());
- proxyFac.setAddress("local://CollectionServiceInterface");
- proxyFac.setBus(getBus());
-
- CollectionServiceInterface csi =
(CollectionServiceInterface)proxyFac.create();
- SortedSet<String> strings = new TreeSet<String>();
- strings.add("Able");
- strings.add("Baker");
- String first = csi.takeSortedStrings(strings);
- assertEquals("Able", first);
-
- //CHECKSTYLE:OFF
- HashSet<String> hashedSet = new HashSet<String>();
- hashedSet.addAll(strings);
- String countString = csi.takeUnsortedSet(hashedSet);
- assertEquals("2", countString);
- //CHECKSTYLE:ON
- }
+
@Test
public void testNestedMapType() throws Exception {
@@ -269,101 +233,4 @@
Type valueType = mapType.getValueType();
assertFalse(valueType.getSchemaType().getLocalPart().contains("any"));
}
-
- /**
- * CXF-2017
- * @throws Exception
- */
- @Test
- public void testNestedMap() throws Exception {
- CollectionService impl = new CollectionService();
- createService(CollectionServiceInterface.class, impl, null);
-
- ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
- proxyFac.getServiceFactory().getServiceConfigurations().add(0,
- new
XFireCompatibilityServiceConfiguration());
- proxyFac.setServiceClass(CollectionServiceInterface.class);
- proxyFac.setDataBinding(new AegisDatabinding());
- proxyFac.setAddress("local://CollectionServiceInterface");
- proxyFac.setBus(getBus());
-
- CollectionServiceInterface csi =
(CollectionServiceInterface)proxyFac.create();
-
- Map<String, Map<String, BeanWithGregorianDate>> complexMap;
- complexMap = new HashMap<String, Map<String, BeanWithGregorianDate>>();
- Map<String, BeanWithGregorianDate> innerMap = new HashMap<String,
BeanWithGregorianDate>();
- BeanWithGregorianDate bean = new BeanWithGregorianDate();
- bean.setName("shem bean");
- bean.setId(42);
- innerMap.put("firstBean", bean);
- complexMap.put("firstKey", innerMap);
- csi.mapOfMapWithStringAndPojo(complexMap);
-
- Map<String, Map<String, BeanWithGregorianDate>> gotMap =
impl.getLastComplexMap();
- assertTrue(gotMap.containsKey("firstKey"));
- Map<String, BeanWithGregorianDate> v = gotMap.get("firstKey");
- BeanWithGregorianDate b = v.get("firstBean");
- assertNotNull(b);
-
- }
-
- public class CollectionService implements CollectionServiceInterface {
-
- private Map<String, Map<String, BeanWithGregorianDate>> lastComplexMap;
-
- /** {...@inheritdoc}*/
- public Collection<String> getStrings() {
- return null;
- }
-
- /** {...@inheritdoc}*/
- public void setLongs(Collection<Long> longs) {
- }
-
- /** {...@inheritdoc}*/
- public Collection getUnannotatedStrings() {
- return null;
- }
-
- /** {...@inheritdoc}*/
- public Collection<Collection<String>> getStringCollections() {
- return null;
- }
-
- /** {...@inheritdoc}*/
- public void takeDoubleList(List<Double> doublesList) {
- }
-
- /** {...@inheritdoc}*/
- public String takeSortedStrings(SortedSet<String> strings) {
- return strings.first();
- }
-
- public void method1(List<String> headers1) {
- // do nothing, this is purely for schema issues.
- }
-
- public String takeStack(Stack<String> strings) {
- return strings.firstElement();
- }
-
- //CHECKSTYLE:OFF
- public String takeUnsortedSet(HashSet<String> strings) {
- return Integer.toString(strings.size());
- }
-
- public String takeArrayList(ArrayList<String> strings) {
- return strings.get(0);
- }
- //CHECKSTYLE:ON
-
- public void mapOfMapWithStringAndPojo(Map<String, Map<String,
BeanWithGregorianDate>> bigParam) {
- lastComplexMap = bigParam;
- }
-
- protected Map<String, Map<String, BeanWithGregorianDate>>
getLastComplexMap() {
- return lastComplexMap;
- }
-
- }
}