cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r612882 - in /incubator/cxf/branches/2.0.x-fixes: ./ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
Date Thu, 17 Jan 2008 17:34:56 GMT
Author: dkulp
Date: Thu Jan 17 09:34:55 2008
New Revision: 612882

URL: http://svn.apache.org/viewvc?rev=612882&view=rev
Log:
Merged revisions 612580 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r612580 | dkulp | 2008-01-16 16:50:28 -0500 (Wed, 16 Jan 2008) | 2 lines
  
  [CXF-1382] Have aegis properly put import elements into it's schema
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
    incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java?rev=612882&r1=612881&r2=612882&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
Thu Jan 17 09:34:55 2008
@@ -291,10 +291,8 @@
             String prefix = NamespaceHelper.getUniquePrefix(root, componentType.getSchemaType()
                 .getNamespaceURI());
 
-            String typeName = prefix + ":" + componentType.getSchemaType().getLocalPart();
-
             element.setAttribute(new Attribute("name", componentType.getSchemaType().getLocalPart()));
-            element.setAttribute(new Attribute("type", typeName));
+            element.setAttribute(BeanType.createTypeAttribute(prefix, componentType, root));
 
             if (componentType.isNillable()) {
                 element.setAttribute(new Attribute("nillable", "true"));

Modified: incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=612882&r1=612881&r2=612882&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
Thu Jan 17 09:34:55 2008
@@ -26,6 +26,7 @@
 import java.lang.reflect.Proxy;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -40,9 +41,11 @@
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.jdom.Attribute;
 import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
  * Serializes JavaBeans.
@@ -475,7 +478,7 @@
 
             String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
 
-            writeTypeReference(name, nameWithPrefix, element, type, prefix);
+            writeTypeReference(name, nameWithPrefix, element, type, prefix, root);
         }
 
         /**
@@ -503,7 +506,7 @@
 
             String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
             element.setAttribute(new Attribute("name", nameWithPrefix));
-            element.setAttribute(new Attribute("type", prefix + ':' + type.getSchemaType().getLocalPart()));
+            element.setAttribute(createTypeAttribute(prefix, type, root));
         }
 
         /**
@@ -514,6 +517,27 @@
         }
     }
 
+    static Attribute createTypeAttribute(String prefix, Type type, Element root) {
+        String ns = type.getSchemaType().getNamespaceURI();
+        if (!ns.equals(root.getAttributeValue("targetNamespace"))
+            && !ns.equals(XmlConstants.XSD)) {
+            //find import statement
+            List<Element> l = CastUtils.cast(root.getChildren("import", 
+                                                              Namespace.getNamespace(XmlConstants.XSD)));
+            boolean found = false;
+            for (Element e : l) {
+                if (ns.equals(e.getAttributeValue("namespace"))) {
+                    found = true;
+                }
+            }
+            if (!found) {
+                Element element = new Element("import", XmlConstants.XSD_PREFIX, XmlConstants.XSD);
+                root.addContent(0, element);
+                element.setAttribute("namespace", ns);
+            }
+        }
+        return new Attribute("type", prefix + ':' + type.getSchemaType().getLocalPart());

+    }
     private String getNameWithPrefix(Element root, String nameNS, String localName) {
         if (!nameNS.equals(getSchemaType().getNamespaceURI())) {
             String prefix = NamespaceHelper.getUniquePrefix((Element)root.getParent(), nameNS);
@@ -548,11 +572,12 @@
         return type;
     }
 
-    private void writeTypeReference(QName name, String nameWithPrefix, Element element, Type
type,
-                                    String prefix) {
+    private void writeTypeReference(QName name, String nameWithPrefix, 
+                                    Element element, Type type, String prefix,
+                                    Element root) {
         if (type.isAbstract()) {
             element.setAttribute(new Attribute("name", nameWithPrefix));
-            element.setAttribute(new Attribute("type", prefix + ':' + type.getSchemaType().getLocalPart()));
+            element.setAttribute(createTypeAttribute(prefix, type, root));
 
             int minOccurs = getTypeInfo().getMinOccurs(name);
             if (minOccurs != 1) {



Mime
View raw message