You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/10/24 23:11:42 UTC
svn commit: r1401882 - in /cxf/branches/2.6.x-fixes:
api/src/main/java/org/apache/cxf/common/util/
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/
rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/
Author: dkulp
Date: Wed Oct 24 21:11:42 2012
New Revision: 1401882
URL: http://svn.apache.org/viewvc?rev=1401882&view=rev
Log:
Merged revisions 1401880 via git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1401880 | dkulp | 2012-10-24 17:08:47 -0400 (Wed, 24 Oct 2012) | 3 lines
[CXF-3613] Update to show how to use Class as a param/type with Aegis
Fix potential NPE via a null in the PropertyDescriptor[]
........
Added:
cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/ClassTest.java
Modified:
cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=1401882&r1=1401881&r2=1401882&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java (original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java Wed Oct 24 21:11:42 2012
@@ -203,17 +203,17 @@ public final class ReflectionUtil {
}
if (springBeanUtilsDescriptorFetcher != null) {
- PropertyDescriptor[] descriptors = null;
if (propertyDescriptors != null) {
- descriptors = new PropertyDescriptor[propertyDescriptors.length];
+ List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>(propertyDescriptors.length);
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
try {
- descriptors[i] =
- (PropertyDescriptor)
- springBeanUtilsDescriptorFetcher.invoke(null,
- beanClass,
- propertyDescriptor.getName());
+ propertyDescriptor = (PropertyDescriptor)springBeanUtilsDescriptorFetcher.invoke(null,
+ beanClass,
+ propertyDescriptor.getName());
+ if (propertyDescriptor != null) {
+ descriptors.add(propertyDescriptor);
+ }
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
@@ -222,8 +222,9 @@ public final class ReflectionUtil {
throw new RuntimeException(e);
}
}
+ return descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
}
- return descriptors;
+ return null;
} else {
return beanInfo.getPropertyDescriptors();
}
Modified: cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java?rev=1401882&r1=1401881&r2=1401882&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java (original)
+++ cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/AbstractTypeCreator.java Wed Oct 24 21:11:42 2012
@@ -133,6 +133,9 @@ public abstract class AbstractTypeCreato
type = getTypeMapping().getType(info.getTypeName());
}
if (type == null) {
+ type = getTypeMapping().getType(javaClass);
+ }
+ if (type == null) {
type = createDefaultType(info);
} else {
newType = false;
Added: cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/ClassTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/ClassTest.java?rev=1401882&view=auto
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/ClassTest.java (added)
+++ cxf/branches/2.6.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/ClassTest.java Wed Oct 24 21:11:42 2012
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cxf.aegis.type.java5;
+
+import java.io.Serializable;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.aegis.AbstractAegisTest;
+import org.apache.cxf.aegis.AegisContext;
+import org.apache.cxf.aegis.Context;
+import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.aegis.type.AegisType;
+import org.apache.cxf.aegis.type.basic.StringType;
+import org.apache.cxf.aegis.xml.MessageReader;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.common.util.XMLSchemaQNames;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClassTest extends AbstractAegisTest {
+ Server server;
+
+ @Before
+ public void startServer() throws Exception {
+ AegisContext context = new AegisContext();
+ context.initialize();
+ context.getTypeMapping().register(new ClassAsStringType());
+
+ ServerFactoryBean b = new ServerFactoryBean();
+ b.setDataBinding(new AegisDatabinding(context));
+ b.setServiceClass(GenericsService.class);
+ b.setAddress("local://GenericsService");
+ server = b.create();
+ }
+ @After
+ public void stopServer() {
+ server.stop();
+ server.destroy();
+ server = null;
+ }
+
+ @Test
+ public void testType() throws Exception {
+ Document doc = getWSDLDocument("GenericsService");
+ assertNotNull(doc);
+ this.assertValidBoolean("//xsd:simpleType[@name='class']/xsd:restriction", doc.getDocumentElement());
+ }
+
+ public static class GenericsService {
+
+ public <T extends Serializable> T createInstance(Class<T> type)
+ throws InstantiationException, IllegalAccessException {
+ return type.newInstance();
+ }
+ }
+
+
+ public static class ClassAsStringType extends AegisType {
+
+ public static final QName CLASS_AS_STRING_TYPE_QNAME
+ = new QName("http://cxf.apache.org/my/class/test", "class");
+
+ private StringType stringType;
+
+ public ClassAsStringType() {
+ stringType = new StringType();
+ super.setTypeClass(Class.class);
+ super.setSchemaType(CLASS_AS_STRING_TYPE_QNAME);
+ }
+
+ public Object readObject(MessageReader reader, Context context)
+ throws DatabindingException {
+ String className = (String) stringType.readObject(reader, context);
+ Class<?> cls = null;
+ try {
+ context.getClass().getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException x) {
+ throw new DatabindingException("Unable to dynamically load class '"
+ + className + "'", x);
+ }
+ return cls;
+ }
+
+ public void writeObject(Object object, MessageWriter writer, Context context)
+ throws DatabindingException {
+ if (object == null) {
+ stringType.writeObject(null, writer, context);
+ } else {
+ Class<?> cls = (Class<?>) object;
+ stringType.writeObject(cls.getName(), writer, context);
+ }
+ }
+ public void writeSchema(XmlSchema root) {
+ XmlSchemaSimpleType xst = new XmlSchemaSimpleType(root, true);
+ xst.setName("class");
+
+ XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
+ content.setBaseTypeName(XMLSchemaQNames.XSD_STRING);
+ xst.setContent(content);
+ }
+
+ public boolean usesUtilityTypes() {
+ return true;
+ }
+ }
+
+}