cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r695096 - in /cxf/trunk/rt/databinding/aegis/src: main/java/org/apache/cxf/aegis/type/ main/java/org/apache/cxf/aegis/type/basic/ main/java/org/apache/cxf/aegis/type/encoded/ test/java/org/apache/cxf/aegis/custom/
Date Sun, 14 Sep 2008 00:42:54 GMT
Author: bimargulies
Date: Sat Sep 13 17:42:54 2008
New Revision: 695096

URL: http://svn.apache.org/viewvc?rev=695096&view=rev
Log:
Fix CXF-1788.

Added:
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
  (with props)
Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/StructType.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java?rev=695096&r1=695095&r2=695096&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMapping.java
Sat Sep 13 17:42:54 2008
@@ -127,6 +127,9 @@
         register(type);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void register(Type type) {
         type.setTypeMapping(this);
         /*

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java?rev=695096&r1=695095&r2=695096&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeMapping.java
Sat Sep 13 17:42:54 2008
@@ -26,21 +26,34 @@
  */
 public interface TypeMapping {
     /**
-     * Checks whether or not type mapping between specified XML type and Java
-     * type is registered.
-     * 
-     * @param javaType Class of the Java type
-     * @param xmlType Qualified name of the XML data type
-     * @return boolean; <code>true</code> if type mapping between the
-     *         specified XML type and Java type is registered; otherwise
-     *         <code>false</code>
+     * Returns a flag indicating if this type mapping has a mapping for a particular Java
class.
+     * @param javaType the class.
+     * @return <code>true</code> if there is a mapping for the type.
      */
     boolean isRegistered(Class javaType);
 
+    /**
+     * Returns a flag indicating if this type mapping has a mapping for a particular
+     * XML Schema QName.
+     * @param xmlType the QName.
+     * @return <code>true</code> if there is a mapping for the type.
+     */
     boolean isRegistered(QName xmlType);
 
+    /**
+     * Register a type, manually specifying the java class, the schema type,
+     * and the Aegis type object that provides serialization, deserialization,
+     * and schema.
+     * @param javaType Java class.
+     * @param xmlType XML Schema type QName.
+     * @param type Aegis type object.
+     */
     void register(Class javaType, QName xmlType, Type type);
 
+    /**
+     * Register a type that self-describes the schema type and the Java class.
+     * @param type Aegis type object that 
+     */
     void register(Type type);
 
     void removeType(Type type);

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=695096&r1=695095&r2=695096&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
Sat Sep 13 17:42:54 2008
@@ -652,7 +652,14 @@
             type = beanType.getTypeInfo().getType(name);
 
             if (type == null) {
-                beanType = beanType.getSuperType();
+                Type superType = beanType.getSuperType(); /* The class might inherit from,
say, 'Integer'.
+                                                             In which case we've got no BeanType

+                                                             to work with. */
+                if (superType instanceof BeanType) {
+                    beanType = (BeanType) superType;
+                } else {
+                    break; // give up.
+                }
             }
         }
 
@@ -660,13 +667,13 @@
         if (beanType != null) {
             elementTypeInfo = beanType.getTypeInfo();
         } else {
-            // didn't find a bean type so just use this bean't type info
+            // didn't find a bean type so just use this bean's type info
             elementTypeInfo = getTypeInfo();
         }
         return elementTypeInfo;
     }
 
-    public BeanType getSuperType() {
+    public Type getSuperType() {
         BeanTypeInfo inf = getTypeInfo();
         Class c = inf.getTypeClass().getSuperclass();
         /*
@@ -674,12 +681,13 @@
          */
         if (c != null && c != Object.class && c != Exception.class &&
c != RuntimeException.class) {
             TypeMapping tm = inf.getTypeMapping();
-            BeanType superType = (BeanType)tm.getType(c);
+            Type superType = tm.getType(c);
             if (superType == null) {
+                // if we call createType, we know that we'll get a BeanType. */
                 superType = (BeanType)getTypeMapping().getTypeCreator().createType(c);
                 Class cParent = c.getSuperclass();
                 if (cParent != null && cParent != Object.class) {
-                    superType.getTypeInfo().setExtension(true);
+                    ((BeanType)superType).getTypeInfo().setExtension(true);
                 }
                 tm.register(superType);
             }
@@ -770,4 +778,12 @@
     public boolean hasMinOccurs() {
         return true;
     }
+
+    @Override
+    public void setTypeMapping(TypeMapping typeMapping) {
+        super.setTypeMapping(typeMapping);
+        if (info != null) {
+            info.setTypeMapping(typeMapping);
+        }
+    }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/StructType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/StructType.java?rev=695096&r1=695095&r2=695096&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/StructType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/StructType.java
Sat Sep 13 17:42:54 2008
@@ -140,7 +140,7 @@
         }
 
         // find the matching property and get it's name
-        for (BeanType sooper = this; sooper != null; sooper = sooper.getSuperType()) {
+        for (BeanType sooper = this; sooper != null; sooper = superBeanType(sooper)) {
             QName qualifiedName = new QName(sooper.getTypeInfo().getDefaultNamespace(), name.getLocalPart());
 
             if (sooper.getTypeInfo().getType(qualifiedName) != null) {
@@ -150,6 +150,17 @@
 
         return name;
     }
+    
+    private BeanType superBeanType(Type t) {
+        if (t instanceof BeanType) {
+            BeanType bt = (BeanType)t;
+            Type supertype = bt.getSuperType();
+            if (supertype instanceof BeanType) {
+                return (BeanType)supertype;
+            }
+        }
+        return null;
+    }
 
     /**
      * When the SoapRef is resolved write the matching property on the target object.

Added: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java?rev=695096&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
(added)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
Sat Sep 13 17:42:54 2008
@@ -0,0 +1,51 @@
+/**
+ * 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.custom;
+
+import java.util.GregorianCalendar;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.aegis.AbstractAegisTest;
+import org.apache.cxf.aegis.AegisContext;
+import org.apache.cxf.aegis.type.TypeMapping;
+import org.apache.cxf.aegis.type.basic.BeanType;
+import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
+import org.jdom.Element;
+import org.junit.Test;
+
+/**
+ * See CXF-1788. Ensure that a mapping that of a type that inherits from a type with a default
mapping works.
+ */
+public class CustomMappingTest extends AbstractAegisTest {
+    @Test
+    public void testInheritedMapping() throws Exception {
+        BeanTypeInfo bti = new BeanTypeInfo(GregorianCalendar.class, "http://util.java");
+        BeanType beanType = new BeanType(bti);
+        beanType.setSchemaType(new QName("http://util.java{GregorianCalendar}"));
+        AegisContext context = new AegisContext();
+        context.initialize();
+        TypeMapping mapping = context.getTypeMapping();
+        // we are replacing the default mapping.
+        mapping.register(beanType);
+        Element root = new Element("dummySchema");
+        beanType.writeSchema(root);
+    }
+
+}

Propchange: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message