cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r730862 [1/2] - in /cxf/trunk: api/src/main/java/org/apache/cxf/service/model/ common/common/src/main/java/org/apache/cxf/common/xmlschema/ common/common/src/main/java/org/apache/cxf/helpers/ rt/databinding/aegis/ rt/databinding/aegis/src/m...
Date Fri, 02 Jan 2009 23:10:35 GMT
Author: bimargulies
Date: Fri Jan  2 15:10:34 2009
New Revision: 730862

URL: http://svn.apache.org/viewvc?rev=730862&view=rev
Log:
Undo unwanted set of changes originally destined  for another branch.

Removed:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathBooleanEvaluator.java
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
    cxf/trunk/rt/databinding/aegis/pom.xml
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.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/basic/BeanTypeInfo.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/AnnotatedTypeTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/EnumTypeTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/JaxbTypeTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/XFireTypeTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java Fri Jan  2 15:10:34 2009
@@ -25,14 +25,13 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaForm;
-import org.apache.ws.commons.schema.utils.NamespaceMap;
+
 
 public final class SchemaInfo extends AbstractPropertiesHolder {
   
@@ -77,16 +76,7 @@
             CachedOutputStream cout = new CachedOutputStream();
             XmlSchema sch = getSchema();
             synchronized (sch) {
-                XmlSchema schAgain = getSchema();
-                // XML Schema blows up when the context is null as opposed to empty.
-                // Some unit tests really want to see 'tns:'.
-                if (schAgain.getNamespaceContext() == null) {
-                    NamespaceMap nsMap = new NamespaceMap();
-                    nsMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
-                    nsMap.add("tns", schAgain.getTargetNamespace());
-                    schAgain.setNamespaceContext(nsMap);
-                }
-                schAgain.write(cout);
+                getSchema().write(cout);
             }
             Document sdoc = null;
             try {

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/XmlSchemaTools.java Fri Jan  2 15:10:34 2009
@@ -26,12 +26,9 @@
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
 import org.apache.ws.commons.schema.XmlSchemaFacet;
-import org.apache.ws.commons.schema.XmlSchemaImport;
-import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent;
@@ -151,47 +148,4 @@
         }
         return values;
     }
-    
-    /**
-     * Is there an import for a particular namespace in a schema?
-     * @param schema
-     * @param namespaceUri
-     * @return
-     */
-    public static boolean schemaImportsNamespace(XmlSchema schema, String namespaceUri) {
-        XmlSchemaObjectCollection inc = schema.getIncludes();
-        for (int x = 0; x < inc.getCount(); x++) {
-            XmlSchemaObject what = inc.getItem(x);
-            if (what instanceof XmlSchemaImport) {
-                XmlSchemaImport imp = (XmlSchemaImport)what;
-                // already there.
-                if (namespaceUri.equals(imp.getNamespace())) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * Assist in managing the required <import namespace='uri'> for imports of peer schemas.
-     * @param schema
-     * @param namespaceUri
-     */
-    public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) {
-        XmlSchemaObjectCollection inc = schema.getIncludes();
-        for (int x = 0; x < inc.getCount(); x++) {
-            XmlSchemaObject what = inc.getItem(x);
-            if (what instanceof XmlSchemaImport) {
-                XmlSchemaImport imp = (XmlSchemaImport)what;
-                // already there.
-                if (namespaceUri.equals(imp.getNamespace())) {
-                    return;
-                }
-            }
-        }
-        XmlSchemaImport imp = new XmlSchemaImport();
-        imp.setNamespace(namespaceUri);
-        inc.add(imp);
-    }
 }

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Fri Jan  2 15:10:34 2009
@@ -24,11 +24,9 @@
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
-import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
-import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -41,7 +39,6 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -53,6 +50,7 @@
 
 import org.apache.cxf.common.util.StringUtils;
 
+
 /**
  * Few simple utils to read DOM. This is originally from the Jakarta Commons
  * Modeler.
@@ -60,8 +58,8 @@
  * @author Costin Manolache
  */
 public final class DOMUtils {
-    private static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
-    private static DocumentBuilder builder;
+    static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
+    static DocumentBuilder builder;
     private static final String XMLNAMESPACE = "xmlns";
 
     private DOMUtils() {
@@ -74,24 +72,8 @@
         }
         return builder;
     }
-    
-    /**
-     * This function is much like getAttribute, but returns null, not "", for a nonexistent attribute.
-     * @param e
-     * @param attributeName
-     * @return
-     */
-    public static String getAttributeValueEmptyNull(Element e, String attributeName) {
-        Attr node = e.getAttributeNode(attributeName);
-        if (node == null) {
-            return null;
-        }
-        return node.getValue();
-    }
-    
-    
     /**
-     * Get the trimmed text content of a node or null if there is no text
+     * Get the trimed text content of a node or null if there is no text
      */
     public static String getContent(Node n) {
         if (n == null) {
@@ -267,65 +249,24 @@
         return null;
     }
     
-    /**
-     * Return the first element child with the specified qualified name.
-     * @param parent
-     * @param q
-     * @return
-     */
     public static Element getFirstChildWithName(Element parent, QName q) { 
         String ns = q.getNamespaceURI();
         String lp = q.getLocalPart();
         return getFirstChildWithName(parent, ns, lp);
     }
-    
-    /**
-     * Return the first element child with the specified qualified name.
-     * @param parent
-     * @param ns
-     * @param lp
-     * @return
-     */
     public static Element getFirstChildWithName(Element parent, String ns, String lp) { 
-        for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
-            if (n instanceof Element) {
-                Element e = (Element) n;
-                if (((ns == null && e.getNamespaceURI() == null)
-                    || (ns != null && ns.equals(e.getNamespaceURI())))
-                    && lp.equals(e.getNodeName())) {
-                    return e;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Return child elements with specified name.
-     * @param parent
-     * @param ns
-     * @param localName
-     * @return
-     */
-    public static List<Element> getChildrenWithName(Element parent, String ns, String localName) {
-        List<Element> r = new ArrayList<Element>();
-        for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
-            if (n instanceof Element) {
-                Element e = (Element) n;
-                if ((ns == null && e.getNamespaceURI() == null)
-                    || ns.equals(e.getNamespaceURI())) {
-                    r.add(e);
-                }
+        Node n = parent.getFirstChild();
+        while (n != null) {
+            if (ns.equals(n.getNamespaceURI())
+                && lp.equals(n.getLocalName())) {
+                return (Element)n;
             }
+            n = n.getNextSibling();
         }
-        return r;
+        return (Element)n;
     }
-
     /**
-     * Get the first child of the specified type.
-     * @param parent
-     * @param type
-     * @return
+     * Get the first direct child with a given type
      */
     public static Node getChild(Node parent, int type) {
         Node n = parent.getFirstChild();
@@ -460,7 +401,6 @@
             throw new RuntimeException("Couldn't find a DOM parser.", e);
         }
     }
-    
     public static Document createDocument() {
         try {
             return getBuilder().newDocument();
@@ -489,38 +429,6 @@
         }
         return null;
     }
-    
-    /**
-     * Get all prefixes defined, up to the root, for a namespace URI.
-     * @param element
-     * @param namespaceUri
-     * @param prefixes
-     */
-    public static void getPrefixesRecursive(Element element, String namespaceUri, List<String> prefixes) {
-        getPrefixes(element, namespaceUri, prefixes);
-        Node parent = element.getParentNode();
-        if (parent instanceof Element) {
-            getPrefixesRecursive((Element)parent, namespaceUri, prefixes);
-        }
-    }
-    
-    /**
-     * Get all prefixes defined on this element for the specified namespace.
-     * @param element
-     * @param namespaceUri
-     * @param prefixes
-     */
-    public static void getPrefixes(Element element, String namespaceUri, List<String> prefixes) {
-        NamedNodeMap atts = element.getAttributes();
-        for (int i = 0; i < atts.getLength(); i++) {
-            Node node = atts.item(i);
-            String name = node.getNodeName();
-            if (namespaceUri.equals(node.getNodeValue()) 
-                && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) {
-                prefixes.add(node.getPrefix());
-            }
-        }
-    }
 
     public static String createNamespace(Element el, String ns) {
         String p = "ns1";
@@ -607,36 +515,4 @@
             elem = getNextElement(elem);
         }
     }
-    
-
-    /**
-     * Set a namespace/prefix on an element if it is not set already. First off, it
-     * searches for the element for the prefix associated with the specified
-     * namespace. If the prefix isn't null, then this is returned. Otherwise, it
-     * creates a new attribute using the namespace/prefix passed as parameters.
-     * 
-     * @param element
-     * @param namespace
-     * @param prefix
-     * @return the prefix associated with the set namespace
-     */
-    public static String setNamespace(Element element, String namespace,
-            String prefix) {
-        String pre = getPrefixRecursive(element, namespace);
-        if (pre != null) {
-            return pre;
-        }
-        element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespace);
-        return prefix;
-    }
-    
-    /**
-     * Add a namespace prefix definition to an element.
-     * @param element
-     * @param namespaceUri
-     * @param prefix
-     */
-    public static void addNamespacePrefix(Element element, String namespaceUri, String prefix) {
-        element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespaceUri);
-    }
 }

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/XPathUtils.java Fri Jan  2 15:10:34 2009
@@ -29,11 +29,11 @@
 import org.w3c.dom.Node;
 
 public class XPathUtils {
-    private static final XPathFactory FACTORY = XPathFactory.newInstance();
-    private XPath xpath;
+
+    XPath xpath;
 
     public XPathUtils() {
-        xpath = FACTORY.newXPath();
+        xpath = XPathFactory.newInstance().newXPath();
     }
 
     public XPathUtils(final Map<String, String> ns) {
@@ -60,8 +60,4 @@
     public boolean isExist(String xpathExpression, Node node, QName type) {
         return getValue(xpathExpression, node, type) != null;
     }
-
-    public static XPathFactory getFactory() {
-        return FACTORY;
-    }
 }

Modified: cxf/trunk/rt/databinding/aegis/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/pom.xml?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/pom.xml (original)
+++ cxf/trunk/rt/databinding/aegis/pom.xml Fri Jan  2 15:10:34 2009
@@ -84,6 +84,11 @@
             <version>${jdom.version}</version>
         </dependency>
         <dependency>
+            <groupId>jaxen</groupId>
+            <artifactId>jaxen</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java Fri Jan  2 15:10:34 2009
@@ -18,16 +18,20 @@
  */
 package org.apache.cxf.aegis;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.xml.sax.InputSource;
+import org.w3c.dom.Document;
+
+import org.xml.sax.SAXException;
 
 import org.apache.cxf.aegis.type.AbstractTypeCreator;
 import org.apache.cxf.aegis.type.DefaultTypeCreator;
@@ -42,9 +46,11 @@
 import org.apache.cxf.aegis.type.java5.Java5TypeCreator;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaTools;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.cxf.helpers.DOMUtils;
+import org.jaxen.JaxenException;
+import org.jaxen.jdom.JDOMXPath;
+import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
  * The Aegis Databinding context object. This object coordinates the data binding process: reading and writing
@@ -71,6 +77,16 @@
      * Namespace used for miscellaneous Aegis types.
      */
     public static final String SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
+    private static JDOMXPath importTypesXpath;
+
+    static {
+        try {
+            importTypesXpath = new JDOMXPath("xsd:import[@namespace='" + SCHEMA_NS + "']");
+            importTypesXpath.addNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+    }
 
     private boolean writeXsiTypes;
     private boolean readXsiTypes = true;
@@ -87,6 +103,7 @@
     private boolean mtomUseXmime;
     // this URI goes into the type map.
     private String mappingNamespaceURI;
+    private Document typesSchemaDocument;
 
     /**
      * Construct a context.
@@ -231,18 +248,43 @@
         }
     }
 
-    public static boolean schemaImportsUtilityTypes(XmlSchema schema) {
-        return XmlSchemaTools.schemaImportsNamespace(schema, SCHEMA_NS);
+    public static boolean schemaImportsUtilityTypes(Element schemaElement) {
+        try {
+            return importTypesXpath.selectSingleNode(schemaElement) != null;
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public Document getTypesSchemaDocument() {
+        ensureTypesSchemaDocument();
+        return typesSchemaDocument;
     }
 
-    public void addTypesSchemaDocument(XmlSchemaCollection collection) {
-        collection.read(new 
-                        InputSource(getClass().getResourceAsStream("/META-INF/cxf/aegisTypes.xsd")),
-                        null);
+    private void ensureTypesSchemaDocument() {
+        if (typesSchemaDocument != null) {
+            return;
+        }
+        try {
+            typesSchemaDocument = DOMUtils.readXml(getClass()
+                .getResourceAsStream("/META-INF/cxf/aegisTypes.xsd"));
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
+        }
     }
 
-    public static void addUtilityTypesToSchema(XmlSchema root) {
-        XmlSchemaTools.addImportIfNeeded(root, SCHEMA_NS);
+    public static void addUtilityTypesToSchema(Element root) {
+        if (schemaImportsUtilityTypes(root)) {
+            return;
+        }
+        Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        root.addContent(0, element);
+        element.setAttribute("namespace", SCHEMA_NS);
+        root.addNamespaceDeclaration(Namespace.getNamespace("aegisTypes", SCHEMA_NS));
     }
 
     /**

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java Fri Jan  2 15:10:34 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.aegis.databinding;
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.HashMap;
@@ -28,12 +29,13 @@
 import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Node;
 
-import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.DatabindingException;
@@ -46,26 +48,34 @@
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.common.xmlschema.SchemaCollection;
-import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaTools;
 import org.apache.cxf.databinding.AbstractDataBinding;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.frontend.MethodDispatcher;
 import org.apache.cxf.frontend.SimpleMethodDispatcher;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.OperationInfo;
-import org.apache.cxf.service.model.SchemaInfo;
 import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.wsdl.WSDLConstants;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotated;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaForm;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
+import org.jaxen.JaxenException;
+import org.jaxen.jdom.JDOMXPath;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.output.DOMOutputter;
 
 /**
  * CXF databinding object for Aegis. By default, this creates an AegisContext object. To customize
@@ -100,6 +110,7 @@
     protected static final int FAULT_PARAM = 2;
 
     private static final Logger LOG = LogUtils.getL7dLogger(AegisDatabinding.class);
+    private static org.w3c.dom.Document xmimeSchemaDocument;
 
     private AegisContext aegisContext;
     private Map<MessagePartInfo, Type> part2Type;
@@ -109,15 +120,36 @@
     private TypeCreationOptions configuration;
     private boolean mtomEnabled;
     private boolean mtomUseXmime;
+    private JDOMXPath importXmimeXpath;
 
     public AegisDatabinding() {
         super();
         part2Type = new HashMap<MessagePartInfo, Type>();
+        // we have this also in AbstractXOPType. There has to be a better way.
+        importXmimeXpath = AbstractXOPType.getXmimeXpathImport();
     }
 
-    private void addXmimeSchema(XmlSchemaCollection collection) {
-        collection.read(new 
-                        InputSource(getClass().getResourceAsStream("/schemas/wsdl/xmime.xsd")), null);
+    private boolean schemaImportsXmime(Element schemaElement) {
+        try {
+            return importXmimeXpath.selectSingleNode(schemaElement) != null;
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private void ensureXmimeSchemaDocument() {
+        if (xmimeSchemaDocument != null) {
+            return;
+        }
+        try {
+            xmimeSchemaDocument = DOMUtils.readXml(getClass().getResourceAsStream("/schemas/wsdl/xmime.xsd"));
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     /**
@@ -426,51 +458,109 @@
             }
         }
 
+        Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
         boolean needXmimeSchema = false;
+        // utility types.
         boolean needTypesSchema = false;
-        
-        for (ServiceInfo si : s.getServiceInfos()) {
-            for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
-                String schemaNamespaceUri = entry.getKey();
-                if (XmlSchemaConstants.XSD_NAMESPACE_URI.equals(schemaNamespaceUri)) {
-                    continue;
-                }
-                SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
-                XmlSchema schema = schemaInfo.getSchema();
-                schema.setTargetNamespace(entry.getKey());
-                schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
-                schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
 
+        for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
+            String xsdPrefix = SOAPConstants.XSD_PREFIX;
+            if (namespaceMap != null && namespaceMap.containsKey(SOAPConstants.XSD)) {
+                xsdPrefix = namespaceMap.get(SOAPConstants.XSD);
+            }
 
-                for (Type t : entry.getValue()) {
-                    t.writeSchema(schema);
-                }
+            Element e = new Element("schema", xsdPrefix, SOAPConstants.XSD);
 
-                if (schemaImportsXmime(schema)) {
-                    needXmimeSchema = true;
+            e.setAttribute(new Attribute(WSDLConstants.ATTR_TNS, entry.getKey()));
+
+            if (null != namespaceMap) { // did application hand us some
+                                        // additional namespaces?
+                for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
+                    // user gives us namespace->prefix mapping.
+                    e.addNamespaceDeclaration(Namespace.getNamespace(mapping.getValue(), mapping.getKey()));
                 }
-            
-                if (AegisContext.schemaImportsUtilityTypes(schema)) {
-                    needTypesSchema = true;
+            }
+
+            // if the user didn't pick something else, assign 'tns' as the
+            // prefix.
+            if (namespaceMap == null || !namespaceMap.containsKey(entry.getKey())) {
+                // Schemas are more readable if there is a specific prefix for
+                // the TNS.
+                e.addNamespaceDeclaration(Namespace.getNamespace(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry
+                    .getKey()));
+            }
+            e.setAttribute(new Attribute("elementFormDefault", "qualified"));
+            e.setAttribute(new Attribute("attributeFormDefault", "qualified"));
+
+            for (Type t : entry.getValue()) {
+                t.writeSchema(e);
+            }
+
+            if (e.getChildren().size() == 0) {
+                continue;
+            }
+
+            if (schemaImportsXmime(e)) {
+                needXmimeSchema = true;
+            }
+            if (AegisContext.schemaImportsUtilityTypes(e)) {
+                needTypesSchema = true;
+            }
+
+            try {
+                NamespaceMap nsMap = new NamespaceMap();
+
+                nsMap.add(xsdPrefix, SOAPConstants.XSD);
+
+                // We prefer explicit prefixes over those generated in the
+                // types.
+                // This loop may have intended to support prefixes from
+                // individual aegis files,
+                // but that isn't a good idea.
+                for (Iterator itr = e.getAdditionalNamespaces().iterator(); itr.hasNext();) {
+                    Namespace n = (Namespace)itr.next();
+                    if (!nsMap.containsValue(n.getURI())) {
+                        nsMap.add(n.getPrefix(), n.getURI());
+                    }
                 }
 
+                org.w3c.dom.Document schema = new DOMOutputter().output(new Document(e));
+
+                for (ServiceInfo si : s.getServiceInfos()) {
+                    SchemaCollection col = si.getXmlSchemaCollection();
+                    col.setNamespaceContext(nsMap);
+                    XmlSchema xmlSchema = addSchemaDocument(si, col, schema, entry.getKey());
+                    // Work around bug in JDOM DOMOutputter which fails to
+                    // correctly
+                    // assign namespaces to attributes. If JDOM worked right,
+                    // the collection object would get the prefixes for itself.
+                    xmlSchema.setNamespaceContext(nsMap);
+                }
+            } catch (JDOMException e1) {
+                throw new ServiceConstructionException(e1);
             }
 
-            if (needXmimeSchema) {
-                addXmimeSchema(si.getXmlSchemaCollection().getXmlSchemaCollection());
+        }
+
+        if (needXmimeSchema) {
+            ensureXmimeSchemaDocument();
+            for (ServiceInfo si : s.getServiceInfos()) {
+                SchemaCollection col = si.getXmlSchemaCollection();
+                // invented systemId.
+                addSchemaDocument(si, col, xmimeSchemaDocument, AbstractXOPType.XML_MIME_NS);
             }
-            
-            if (needTypesSchema) {
-                aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+        }
+        
+        if (needTypesSchema) {
+            org.w3c.dom.Document schema = aegisContext.getTypesSchemaDocument(); 
+            for (ServiceInfo si : s.getServiceInfos()) {
+                SchemaCollection col = si.getXmlSchemaCollection();
+                addSchemaDocument(si, col, schema, AegisContext.SCHEMA_NS);
             }
         }
         
     }
 
-    private boolean schemaImportsXmime(XmlSchema schema) {
-        return XmlSchemaTools.schemaImportsNamespace(schema, AbstractXOPType.XML_MIME_NS);
-    }
-
     public QName getSuggestedName(Service s, TypeMapping tm, OperationInfo op, int param) {
         Method m = getMethod(s, op);
         if (m == null) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java Fri Jan  2 15:10:34 2009
@@ -26,8 +26,7 @@
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.jdom.Element;
 
 /**
  * A Type reads and writes XML fragments to create and write objects.
@@ -77,7 +76,7 @@
      * type object adds it to the schema.
      * @param root root of the XSD document.
      */
-    public void writeSchema(XmlSchema root) {
+    public void writeSchema(Element root) {
     }
     
     /**
@@ -85,7 +84,7 @@
      * xsd:element element, it can implement this. 
      * @param schemaElement
      */
-    public void addToSchemaElement(XmlSchemaElement schemaElement) {
+    public void addToSchemaElement(Element schemaElement) {
     }
 
     /**

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java Fri Jan  2 15:10:34 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.aegis.type;
 
+import java.util.List;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 import org.apache.commons.logging.Log;
@@ -25,9 +27,10 @@
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaTools;
-import org.apache.ws.commons.schema.XmlSchema;
-
+import org.apache.cxf.helpers.CastUtils;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
  * Static methods/constants for Aegis.
@@ -156,9 +159,26 @@
         return type;
     }
     
-    
-    public static void setAttributeAttributes(QName name, Type type, XmlSchema root) {
+    public static Attribute createTypeAttribute(String prefix, Type type, Element root) {
         String ns = type.getSchemaType().getNamespaceURI();
-        XmlSchemaTools.addImportIfNeeded(root, ns);
+        if (!ns.equals(root.getAttributeValue("targetNamespace"))
+            && !ns.equals(SOAPConstants.XSD)) {
+            //find import statement
+            List<Element> l = CastUtils.cast(root.getChildren("import", 
+                                                              Namespace.getNamespace(SOAPConstants.XSD)));
+            boolean found = false;
+            for (Element e : l) {
+                if (ns.equals(e.getAttributeValue("namespace"))) {
+                    found = true;
+                }
+            }
+            if (!found) {
+                Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+                root.addContent(0, element);
+                element.setAttribute("namespace", ns);
+            }
+        }
+        return new Attribute("type", prefix + ':' + type.getSchemaType().getLocalPart()); 
     }
+
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/XMLTypeCreator.java Fri Jan  2 15:10:34 2009
@@ -38,12 +38,6 @@
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
-import javax.xml.xpath.XPathConstants;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
@@ -56,8 +50,12 @@
 import org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo;
 import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
-import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.helpers.XPathUtils;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.DOMBuilder;
+import org.jdom.xpath.XPath;
 
 /**
  * Deduce mapping information from an xml file. The xml file should be in the
@@ -134,8 +132,6 @@
             }
         }
     }
-    
-    private XPathUtils xpathUtils = new XPathUtils();
 
     private Document readAegisFile(InputStream is, final String path) throws IOException {
         DocumentBuilder documentBuilder;
@@ -188,7 +184,7 @@
                                                         // above.
             return null;
         }
-        return doc;
+        return new DOMBuilder().build(doc);
     }
 
     protected Document getDocument(Class clazz) {
@@ -325,17 +321,17 @@
         if (mapping != null || mappings.size() > 0) {
             String typeNameAtt = null;
             if (mapping != null) {
-                typeNameAtt = DOMUtils.getAttributeValueEmptyNull(mapping, "name");
+                typeNameAtt = mapping.getAttributeValue("name");
             }
 
             String extensibleElements = null;
             if (mapping != null) {
-                extensibleElements = mapping.getAttribute("extensibleElements");
+                extensibleElements = mapping.getAttributeValue("extensibleElements");
             }
 
             String extensibleAttributes = null;
             if (mapping != null) {
-                extensibleAttributes = mapping.getAttribute("extensibleAttributes");
+                extensibleAttributes = mapping.getAttributeValue("extensibleAttributes");
             }
 
             String defaultNS = NamespaceHelper.makeNamespaceFromClassName(info.getTypeClass().getName(),
@@ -440,7 +436,7 @@
             }
             info.setTypeClass(m.getReturnType());
             // info.setAnnotations(m.getAnnotations());
-            Element rtElement = DOMUtils.getFirstChildWithName(bestMatch, null, "return-type");
+            Element rtElement = bestMatch.getChild("return-type");
             readMetadata(info, mapping, rtElement);
         }
 
@@ -448,25 +444,24 @@
     }
 
     protected void readMetadata(TypeClassInfo info, Element mapping, Element parameter) {
-        info.setTypeName(createQName(parameter, DOMUtils.getAttributeValueEmptyNull(parameter, "typeName")));
-        info.setMappedName(createQName(parameter, 
-                                       DOMUtils.getAttributeValueEmptyNull(parameter, "mappedName")));
+        info.setTypeName(createQName(parameter, parameter.getAttributeValue("typeName")));
+        info.setMappedName(createQName(parameter, parameter.getAttributeValue("mappedName")));
         setComponentType(info, mapping, parameter);
         setKeyType(info, mapping, parameter);
         setValueType(info, mapping, parameter);
         setType(info, parameter);
 
-        String min = DOMUtils.getAttributeValueEmptyNull(parameter, "minOccurs");
+        String min = parameter.getAttributeValue("minOccurs");
         if (min != null) {
             info.setMinOccurs(Long.parseLong(min));
         }
 
-        String max = DOMUtils.getAttributeValueEmptyNull(parameter, "maxOccurs");
+        String max = parameter.getAttributeValue("maxOccurs");
         if (max != null) {
             info.setMaxOccurs(Long.parseLong(max));
         }
 
-        String flat = DOMUtils.getAttributeValueEmptyNull(parameter, "flat");
+        String flat = parameter.getAttributeValue("flat");
         if (flat != null) {
             info.setFlat(Boolean.valueOf(flat.toLowerCase()).booleanValue());
         }
@@ -525,7 +520,7 @@
     }
 
     protected void setComponentType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "componentType");
+        String componentType = parameter.getAttributeValue("componentType");
         if (componentType != null) {
             info.setGenericType(loadGeneric(info, mapping, componentType));
         }
@@ -543,7 +538,7 @@
             TypeClassInfo componentInfo = new TypeClassInfo();
             componentInfo.setDescription("generic component " + componentInfo.getDescription());
             readMetadata(componentInfo, mapping, propertyEl);
-            String className = DOMUtils.getAttributeValueEmptyNull(propertyEl, "class");
+            String className = propertyEl.getAttributeValue("class");
             if (className == null) {
                 throw new DatabindingException("A 'class' attribute must be specified for <component> "
                                                + name);
@@ -566,7 +561,7 @@
     }
 
     protected void setType(TypeClassInfo info, Element parameter) {
-        String type = DOMUtils.getAttributeValueEmptyNull(parameter, "type");
+        String type = parameter.getAttributeValue("type");
         if (type != null) {
             try {
                 info.setType(ClassLoaderUtils.loadClass(type, getClass()));
@@ -577,14 +572,14 @@
     }
 
     protected void setKeyType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "keyType");
+        String componentType = parameter.getAttributeValue("keyType");
         if (componentType != null) {
             info.setKeyType(loadGeneric(info, mapping, componentType));
         }
     }
 
     private void setValueType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "valueType");
+        String componentType = parameter.getAttributeValue("valueType");
         if (componentType != null) {
             info.setValueType(loadGeneric(info, mapping, componentType));
         }
@@ -617,10 +612,10 @@
                 Element match = getMatch(element, "parameter[@index='" + i + "']");
                 if (match != null
                 // we check if the type is specified and matches
-                    && DOMUtils.getAttributeValueEmptyNull(match, "class") != null
+                    && match.getAttributeValue("class") != null
                     // if it doesn't match, then we can definitely rule out
                     // this result
-                    && !DOMUtils.getAttributeValueEmptyNull(match, "class").equals(parameterType.getName())) {
+                    && !match.getAttributeValue("class").equals(parameterType.getName())) {
 
                     iterator.remove();
                 }
@@ -637,9 +632,7 @@
         int highestSpecified = 0;
         for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
             Element element = (Element)iterator.next();
-
-            List<Element> params = DOMUtils.getChildrenWithName(element, null, "parameter");
-            int availableParameters = params.size();
+            int availableParameters = element.getChildren("parameter").size();
             if (availableParameters > highestSpecified) {
                 bestCandidate = element;
                 highestSpecified = availableParameters;
@@ -648,17 +641,23 @@
         return bestCandidate;
     }
 
-    private Element getMatch(Node doc, String xpath) {
-        return (Element)xpathUtils.getValue(xpath, doc, XPathConstants.NODE);
+    private Element getMatch(Object doc, String xpath) {
+        try {
+            XPath path = XPath.newInstance(xpath);
+            return (Element)path.selectSingleNode(doc);
+        } catch (JDOMException e) {
+            throw new DatabindingException("Error evaluating xpath " + xpath, e);
+        }
     }
 
-    private List<Element> getMatches(Node doc, String xpath) {
-        NodeList nl = (NodeList)xpathUtils.getValue(xpath, doc, XPathConstants.NODESET);
-        List<Element> r = new ArrayList<Element>();
-        for (int x = 0; x < nl.getLength(); x++) {
-            r.add((Element)nl.item(x));
+    @SuppressWarnings("unchecked")
+    private List<Element> getMatches(Object doc, String xpath) {
+        try {
+            XPath path = XPath.newInstance(xpath);
+            return path.selectNodes(doc);
+        } catch (JDOMException e) {
+            throw new DatabindingException("Error evaluating xpath " + xpath, e);
         }
-        return r;
     }
 
     /**
@@ -677,12 +676,12 @@
 
         String prefix = value.substring(0, index);
         String localName = value.substring(index + 1);
-        String ns = DOMUtils.getNamespace(e, prefix);
+        Namespace ns = e.getNamespace(prefix);
 
         if (ns == null || localName == null) {
             throw new DatabindingException("Invalid QName in mapping: " + value);
         }
 
-        return new QName(ns, localName, prefix);
+        return new QName(ns.getURI(), localName, prefix);
     }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java Fri Jan  2 15:10:34 2009
@@ -22,6 +22,8 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
@@ -32,13 +34,14 @@
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
  * An ArrayType.
@@ -162,8 +165,8 @@
     }
 
     @Override
-    public void writeObject(Object values, MessageWriter writer, 
-                            Context context) throws DatabindingException {
+    public void writeObject(Object values, MessageWriter writer, Context context) 
+        throws DatabindingException {
         boolean forceXsiWrite = false;
         if (values == null) {
             return;
@@ -186,6 +189,7 @@
 
         String name = type.getSchemaType().getLocalPart();
 
+
         Class arrayType = type.getTypeClass();
 
         boolean oldXsiWrite = context.getGlobalContext().isWriteXsiTypes();
@@ -262,48 +266,70 @@
         } else {
             type.writeObject(value, cwriter, context);
         }
-
+        
         if (type.isWriteOuter()) {
             cwriter.close();
         }
     }
 
     @Override
-    public void writeSchema(XmlSchema root) {
-        if (hasDefinedArray(root)) {
-            return;
-        }
+    public void writeSchema(Element root) {
+        try {
+            if (hasDefinedArray(root)) {
+                return;
+            }
 
-        XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
-        complex.setName(getSchemaType().getLocalPart());
-        root.addType(complex);
-        root.getItems().add(complex);
+            Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+            root.addContent(complex);
 
-        XmlSchemaSequence seq = new XmlSchemaSequence();
-        complex.setParticle(seq);
+            Element seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            complex.addContent(seq);
 
-        Type componentType = getComponentType();
-        XmlSchemaElement element = new XmlSchemaElement();
-        element.setSchemaTypeName(componentType.getSchemaType());
+            Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            seq.addContent(element);
 
-        if (componentType.isNillable()) {
-            element.setNillable(true);
-        }
+            Type componentType = getComponentType();
+            String prefix = NamespaceHelper.getUniquePrefix(root, componentType.getSchemaType()
+                .getNamespaceURI());
+
+            element.setAttribute(new Attribute("name", componentType.getSchemaType().getLocalPart()));
+            element.setAttribute(TypeUtil.createTypeAttribute(prefix, componentType, root));
+
+            if (componentType.isNillable()) {
+                element.setAttribute(new Attribute("nillable", "true"));
+            }
 
-        element.setMinOccurs(getMinOccurs());
-        element.setMaxOccurs(getMaxOccurs());
+            element.setAttribute(new Attribute("minOccurs", Long.valueOf(getMinOccurs()).toString()));
 
+            if (maxOccurs == Long.MAX_VALUE) {
+                element.setAttribute(new Attribute("maxOccurs", "unbounded"));
+            } else {
+                element.setAttribute(new Attribute("maxOccurs", Long.valueOf(getMaxOccurs()).toString()));
+            }
+
+        } catch (IllegalArgumentException e) {
+            throw new DatabindingException("Illegal argument.", e);
+        }
     }
 
     /**
-     * Since both an Array and a List can have the same type definition, double check that there isn't already
-     * a defined type already.
+     * Since both an Array and a List can have the same type definition, double
+     * check that there isn't already a defined type already.
      * 
      * @param root
      * @return
      */
-    private boolean hasDefinedArray(XmlSchema root) {
-        return root.getTypeByName(getSchemaType().getLocalPart()) != null;
+    private boolean hasDefinedArray(Element root) {
+        List children = root.getChildren("complexType", Namespace.getNamespace(SOAPConstants.XSD));
+        for (Iterator itr = children.iterator(); itr.hasNext();) {
+            Element e = (Element)itr.next();
+
+            if (e.getAttributeValue("name").equals(getSchemaType().getLocalPart())) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**
@@ -390,7 +416,7 @@
         setWriteOuter(!flat);
         this.flat = flat;
     }
-
+    
     @Override
     public boolean hasMaxOccurs() {
         return true;

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=730862&r1=730861&r2=730862&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 Fri Jan  2 15:10:34 2009
@@ -26,8 +26,8 @@
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
-
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.aegis.AegisContext;
@@ -37,24 +37,20 @@
 import org.apache.cxf.aegis.type.TypeMapping;
 import org.apache.cxf.aegis.type.TypeUtil;
 import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
+import org.apache.cxf.aegis.util.NamespaceHelper;
 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.common.xmlschema.XmlSchemaTools;
+import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.interceptor.Fault;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaAny;
-import org.apache.ws.commons.schema.XmlSchemaAnyAttribute;
-import org.apache.ws.commons.schema.XmlSchemaAttribute;
-import org.apache.ws.commons.schema.XmlSchemaComplexContent;
-import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.jaxen.JaxenException;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
  * Serializes JavaBeans.
- * 
+ *
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  * @author <a href="mailto:jack.xu.hong@gmail.com">Jack Hong</a>
  */
@@ -81,8 +77,9 @@
 
     /*
      * (non-Javadoc)
+     * 
      * @see org.codehaus.xfire.aegis.type.Type#readObject(org.codehaus.xfire.aegis.MessageReader,
-     * org.codehaus.xfire.MessageContext)
+     *      org.codehaus.xfire.MessageContext)
      */
     @Override
     public Object readObject(MessageReader reader, Context context) throws DatabindingException {
@@ -99,9 +96,8 @@
 
                 if (impl == null) {
                     InvocationHandler handler = new InterfaceInvocationHandler();
-                    object = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {
-                        clazz
-                    }, handler);
+                    object = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {clazz},
+                                                    handler);
                     target = handler;
                 } else {
                     try {
@@ -152,7 +148,7 @@
                         writeProperty(name, target, writeObj, clazz, propertyTypeInfo);
                     } else {
                         if (!propertyTypeInfo.isNillable(name)) {
-                            throw new DatabindingException(name.getLocalPart() 
+                            throw new DatabindingException(name.getLocalPart()
                                                            + " is nil, but not nillable.");
 
                         }
@@ -177,9 +173,11 @@
         }
     }
 
-    protected Type getElementType(QName name, BeanTypeInfo beanTypeInfo, 
-                                  MessageReader reader, Context context) {
-
+    protected Type getElementType(QName name,
+            BeanTypeInfo beanTypeInfo,
+            MessageReader reader,
+            Context context) {
+        
         Type type = beanTypeInfo.getType(name);
 
         // Type can be overriden with a xsi:type attribute
@@ -188,10 +186,11 @@
     }
 
     /**
-     * If the class is an exception, this will try and instantiate it with information from the XFireFault (if
-     * it exists).
+     * If the class is an exception, this will try and instantiate it with
+     * information from the XFireFault (if it exists).
      */
-    protected Object createFromFault(Context context) throws SecurityException, InstantiationException,
+    protected Object createFromFault(Context context)
+        throws SecurityException, InstantiationException,
         IllegalAccessException, IllegalArgumentException, InvocationTargetException {
         Class<?> clazz = getTypeClass();
         Constructor ctr;
@@ -200,28 +199,16 @@
         Fault fault = context.getFault();
 
         try {
-            ctr = clazz.getConstructor(new Class[] {
-                String.class, Throwable.class
-            });
-            o = ctr.newInstance(new Object[] {
-                fault.getMessage(), fault
-            });
+            ctr = clazz.getConstructor(new Class[] {String.class, Throwable.class});
+            o = ctr.newInstance(new Object[] {fault.getMessage(), fault});
         } catch (NoSuchMethodException e) {
             try {
-                ctr = clazz.getConstructor(new Class[] {
-                    String.class, Exception.class
-                });
-                o = ctr.newInstance(new Object[] {
-                    fault.getMessage(), fault
-                });
+                ctr = clazz.getConstructor(new Class[] {String.class, Exception.class});
+                o = ctr.newInstance(new Object[] {fault.getMessage(), fault});
             } catch (NoSuchMethodException e1) {
                 try {
-                    ctr = clazz.getConstructor(new Class[] {
-                        String.class
-                    });
-                    o = ctr.newInstance(new Object[] {
-                        fault.getMessage()
-                    });
+                    ctr = clazz.getConstructor(new Class[] {String.class});
+                    o = ctr.newInstance(new Object[] {fault.getMessage()});
                 } catch (NoSuchMethodException e2) {
                     return clazz.newInstance();
                 }
@@ -238,7 +225,7 @@
         throws DatabindingException {
 
         if (object instanceof InterfaceInvocationHandler) {
-            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler)object;
+            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler) object;
             delegate.writeProperty(name.getLocalPart(), property);
             return;
         }
@@ -261,9 +248,7 @@
 
             Class propertyType = desc.getPropertyType();
             if ((property == null && !propertyType.isPrimitive()) || (property != null)) {
-                m.invoke(object, new Object[] {
-                    property
-                });
+                m.invoke(object, new Object[] {property});
             }
         } catch (Exception e) {
             if (e instanceof DatabindingException) {
@@ -276,20 +261,18 @@
     }
 
     /**
-     * This is a hack to get the write method from the implementation class for an interface.
+     * This is a hack to get the write method from the implementation class for
+     * an interface.
      */
     private Method getWriteMethodFromImplClass(Class<?> impl, PropertyDescriptor pd) throws Exception {
         String name = pd.getName();
         name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
 
-        return impl.getMethod(name, new Class[] {
-            pd.getPropertyType()
-        });
+        return impl.getMethod(name, new Class[] {pd.getPropertyType()});
     }
-
+    
     /**
      * To avoid double-writing xsi:type attributes, ObjectType uses this special entrypoint.
-     * 
      * @param object
      * @param writer
      * @param context
@@ -299,33 +282,38 @@
                                    Context context, boolean wroteXsiType) {
         writeObjectInternal(object, writer, context, wroteXsiType);
     }
-
+    
     /**
      * {@inheritDoc}
      */
     @Override
-    public void writeObject(Object object, MessageWriter writer, 
-                            Context context) throws DatabindingException {
+    public void writeObject(Object object, MessageWriter writer, Context context)
+        throws DatabindingException {
         writeObjectInternal(object, writer, context, false);
     }
 
-    private void writeObjectInternal(Object object, MessageWriter writer, Context context,
-                                     boolean wroteXsiType) throws DatabindingException {
+    private void writeObjectInternal(Object object, MessageWriter writer, Context context, 
+                                     boolean wroteXsiType)
+        throws DatabindingException {
         if (object == null) {
             return;
         }
 
         BeanTypeInfo inf = getTypeInfo();
 
-        if (!wroteXsiType && object.getClass() == getTypeClass() && context.isWriteXsiTypes()) {
+        if (!wroteXsiType 
+            && object.getClass() == getTypeClass()
+            && context.isWriteXsiTypes()) {
             writer.writeXsiType(getSchemaType());
         }
 
         /*
-         * TODO: Replace this method with one split into two pieces so that we can front-load the attributes
-         * and traverse down the list of super classes.
+         * TODO: Replace this method with one split into two pieces so that we
+         * can front-load the attributes and traverse down the list of super
+         * classes.
          */
-        for (QName name : inf.getAttributes()) {
+        for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+            QName name = (QName)itr.next();
 
             Object value = readProperty(object, name);
             if (value != null) {
@@ -344,7 +332,8 @@
             }
         }
 
-        for (QName name : inf.getElements()) {
+        for (Iterator itr = inf.getElements(); itr.hasNext();) {
+            QName name = (QName)itr.next();
 
             if (inf.isExtension()
                 && inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
@@ -416,6 +405,163 @@
         }
     }
 
+    /**
+     * @see org.apache.cxf.aegis.type.Type#writeSchema(org.jdom.Element)
+     */
+    @Override
+    public void writeSchema(Element root) {
+        BeanTypeInfo inf = getTypeInfo();
+        Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+        root.addContent(complex);
+
+        Type sooperType = getSuperType();
+
+        /*
+         * See Java Virtual Machine specification:
+         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
+         */
+        if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
+            && !inf.getTypeClass().isInterface()) {
+            complex.setAttribute(new Attribute("abstract", "true"));
+        }
+
+        if (inf.isExtension() && sooperType != null) {
+            Element complexContent = new Element("complexContent",
+                                                 SOAPConstants.XSD_PREFIX,
+                                                 SOAPConstants.XSD);
+            complex.addContent(complexContent);
+            complex = complexContent;
+        }
+
+        /*
+         * Decide if we're going to extend another type. If we are going to
+         * defer, then make sure that we extend the type for our superclass.
+         */
+        boolean isExtension = inf.isExtension();
+
+        Element dummy = complex;
+
+        if (isExtension && sooperType != null) {
+
+            Element extension = new Element("extension", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            complex.addContent(extension);
+            QName baseType = sooperType.getSchemaType();
+            extension.setAttribute(new Attribute("base", getNameWithPrefix2(root, baseType
+                .getNamespaceURI(), baseType.getLocalPart())));
+
+            dummy = extension;
+        }
+
+        Element seq = null;
+        boolean needXmime = false;
+        boolean needUtilityTypes = false;
+        
+        // Write out schema for elements
+        for (Iterator itr = inf.getElements(); itr.hasNext();) {
+
+            QName name = (QName)itr.next();
+
+            if (isExtension) {
+                PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);
+
+                assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
+                if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
+                    continue;
+                }
+            }
+
+            if (seq == null) {
+                seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+                dummy.addContent(seq);
+            }
+
+            Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            seq.addContent(element);
+
+            Type type = getType(inf, name);
+
+            String nameNS = name.getNamespaceURI();
+            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
+
+            String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
+
+            writeTypeReference(name, nameWithPrefix, element, type, prefix, root);
+            needXmime |= type.usesXmime();
+            needUtilityTypes |= type.usesUtilityTypes();
+        }
+        
+        if (needXmime) {
+            addXmimeToSchema(root);
+        }
+        
+        if (needUtilityTypes) {
+            AegisContext.addUtilityTypesToSchema(root);
+        }
+
+        /**
+         * if future proof then add <xsd:any/> element
+         */
+        if (inf.isExtensibleElements()) {
+            if (seq == null) {
+                seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+                dummy.addContent(seq);
+            }
+            seq.addContent(createAnyElement());
+        }
+
+        // Write out schema for attributes
+        for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+            QName name = (QName)itr.next();
+
+            Element element = new Element("attribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            dummy.addContent(element);
+
+            Type type = getType(inf, name);
+
+            String nameNS = name.getNamespaceURI();
+            String nameWithPrefix = getNameWithPrefix(root, nameNS, name.getLocalPart());
+
+            String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
+            element.setAttribute(new Attribute("name", nameWithPrefix));
+            element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
+        }
+
+        /**
+         * If extensible attributes then add <xsd:anyAttribute/>
+         */
+        if (inf.isExtensibleAttributes()) {
+            dummy.addContent(createAnyAttribute());
+        }
+    }
+
+    private String getNameWithPrefix(Element root, String nameNS, String localName) {
+        if (!"".equals(nameNS) && !nameNS.equals(getSchemaType().getNamespaceURI())) {
+            Element rootElement = (Element)root.getParent();
+            String prefix = null;
+            if (rootElement != null) { // can happen with doc/lit/bare
+                prefix = NamespaceHelper.getUniquePrefix(rootElement, nameNS);
+            }
+
+            if (prefix == null || prefix.length() == 0) {
+                prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+            }
+
+            return prefix + ":" + localName;
+        }
+        return localName;
+    }
+
+    private String getNameWithPrefix2(Element root, String nameNS, String localName) {
+        String prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+
+        if (prefix == null || prefix.length() == 0) {
+            prefix = NamespaceHelper.getUniquePrefix(root, nameNS);
+        }
+
+        return prefix + ":" + localName;
+    }
+
     private Type getType(BeanTypeInfo inf, QName name) {
         Type type = inf.getType(name);
 
@@ -427,21 +573,23 @@
         return type;
     }
 
-    private void writeTypeReference(QName name, XmlSchemaElement element, Type type) {
+    private void writeTypeReference(QName name, String nameWithPrefix, 
+                                    Element element, Type type, String prefix,
+                                    Element root) {
         if (type.isAbstract()) {
-            element.setName(name.getLocalPart());
-            element.setSchemaTypeName(type.getSchemaType());
+            element.setAttribute(new Attribute("name", nameWithPrefix));
+            element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
 
             int minOccurs = getTypeInfo().getMinOccurs(name);
-            if (minOccurs != 0) {
-                element.setMinOccurs(minOccurs);
+            if (minOccurs == 0) {
+                element.setAttribute(new Attribute("minOccurs", Integer.valueOf(minOccurs).toString()));
             }
 
             if (getTypeInfo().isNillable(name)) {
-                element.setNillable(true);
+                element.setAttribute(new Attribute("nillable", "true"));
             }
         } else {
-            element.setRefName(type.getSchemaType());
+            element.setAttribute(new Attribute("ref", prefix + ':' + type.getSchemaType().getLocalPart()));
         }
     }
 
@@ -454,7 +602,7 @@
 
     /**
      * We need to write a complex type schema for Beans, so return true.
-     * 
+     *
      * @see org.apache.cxf.aegis.type.Type#isComplex()
      */
     @Override
@@ -468,11 +616,13 @@
 
         BeanTypeInfo inf = getTypeInfo();
 
-        for (QName name : inf.getAttributes()) {
+        for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
+            QName name = (QName)itr.next();
             deps.add(inf.getType(name));
         }
 
-        for (QName name : inf.getElements()) {
+        for (Iterator itr = inf.getElements(); itr.hasNext();) {
+            QName name = (QName)itr.next();
             if (inf.isExtension()
                 && inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
                     .getTypeClass()) {
@@ -482,7 +632,7 @@
         }
 
         /*
-         * Automagically add chain of superclassesif this is an an extension.
+         * Automagically add chain of superclasses *if* this is an an extension.
          */
         if (inf.isExtension()) {
             Type sooperType = getSuperType();
@@ -502,12 +652,11 @@
             type = beanType.getTypeInfo().getType(name);
 
             if (type == null) {
-                Type superType = beanType.getSuperType(); /*
-                                                           * The class might inherit from, say, 'Integer'. In
-                                                           * which case we've got no BeanType to work with.
-                                                           */
+                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;
+                    beanType = (BeanType) superType;
                 } else {
                     break; // give up.
                 }
@@ -566,6 +715,19 @@
         return inf;
     }
 
+    /**
+     * Create an element to represent any future elements that might get added
+     * to the schema <xsd:any minOccurs="0" maxOccurs="unbounded"/>
+     *
+     * @return
+     */
+    private Element createAnyElement() {
+        Element result = new Element("any", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        result.setAttribute(new Attribute("minOccurs", "0"));
+        result.setAttribute(new Attribute("maxOccurs", "unbounded"));
+        return result;
+    }
+
     @Override
     public String toString() {
         StringBuffer sb = new StringBuffer();
@@ -582,8 +744,29 @@
         return sb.toString();
     }
 
-    private void addXmimeToSchema(XmlSchema root) {
-        XmlSchemaTools.addImportIfNeeded(root, AbstractXOPType.XML_MIME_NS);
+    /**
+     * Create an element to represent any future attributes that might get added
+     * to the schema <xsd:anyAttribute/>
+     * 
+     * @return
+     */
+    private Element createAnyAttribute() {
+        return new Element("anyAttribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+    }
+    
+    private void addXmimeToSchema(Element root) {
+        try {
+            Object node = AbstractXOPType.getXmimeXpathImport().selectSingleNode(root);
+            if (node != null) {
+                return;
+            }
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+        Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        root.addContent(0, element);
+        element.setAttribute("namespace", AbstractXOPType.XML_MIME_NS);
+        root.addNamespaceDeclaration(Namespace.getNamespace("xmime", AbstractXOPType.XML_MIME_NS));
     }
 
     @Override
@@ -603,104 +786,4 @@
             info.setTypeMapping(typeMapping);
         }
     }
-    
-    @Override
-    public void writeSchema(XmlSchema root) {
-        BeanTypeInfo inf = getTypeInfo();
-        XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
-        complex.setName(getSchemaType().getLocalPart());
-        root.addType(complex);
-        root.getItems().add(complex);
-
-        Type sooperType = getSuperType();
-
-        /*
-         * See Java Virtual Machine specification:
-         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
-         */
-        if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0)
-            && !inf.getTypeClass().isInterface()) {
-            complex.setAbstract(true);
-        }
-
-        XmlSchemaSequence sequence = new XmlSchemaSequence();
-        /*
-         * Decide if we're going to extend another type. If we are going to defer, then make sure that we
-         * extend the type for our superclass.
-         */
-        boolean isExtension = inf.isExtension();
-
-        if (isExtension && sooperType != null) {
-            // if sooperType is null, things are confused.
-            XmlSchemaComplexContent content = new XmlSchemaComplexContent();
-            complex.setContentModel(content);
-            XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
-            content.setContent(extension);
-            extension.setBaseTypeName(sooperType.getSchemaType());
-            extension.setParticle(sequence);
-        } else {
-            complex.setParticle(sequence);
-        }
-
-        boolean needXmime = false;
-        boolean needUtilityTypes = false;
-
-        // Write out schema for elements
-        for (QName name : inf.getElements()) {
-
-            if (isExtension) {
-                PropertyDescriptor pd = inf.getPropertyDescriptorFromMappedName(name);
-
-                // assert pd.getReadMethod() != null && pd.getWriteMethod() != null;
-
-                if (pd.getReadMethod().getDeclaringClass() != inf.getTypeClass()) {
-                    continue;
-                }
-            }
-
-            XmlSchemaElement element = new XmlSchemaElement();
-            sequence.getItems().add(element);
-
-            Type type = getType(inf, name);
-
-            writeTypeReference(name, element, type);
-            needXmime |= type.usesXmime();
-            needUtilityTypes |= type.usesUtilityTypes();
-        }
-
-        if (needXmime) {
-            addXmimeToSchema(root);
-        }
-
-        if (needUtilityTypes) {
-            AegisContext.addUtilityTypesToSchema(root);
-        }
-
-        /**
-         * if future proof then add <xsd:any/> element
-         */
-        if (inf.isExtensibleElements()) {
-            XmlSchemaAny any = new XmlSchemaAny();
-            sequence.getItems().add(any);
-        }
-
-        // Write out schema for attributes
-        for (QName name : inf.getAttributes()) {
-            XmlSchemaAttribute attribute = new XmlSchemaAttribute();
-            sequence.getItems().add(attribute);
-            attribute.setName(name.getLocalPart());
-            String ns = name.getNamespaceURI();
-            if (!ns.equals(root.getTargetNamespace())) {
-                XmlSchemaTools.addImportIfNeeded(root, ns);
-            }
-        }
-
-        /**
-         * If extensible attributes then add <xsd:anyAttribute/>
-         */
-        if (inf.isExtensibleAttributes()) {
-            sequence.getItems().add(new XmlSchemaAnyAttribute());
-        }
-    }
-
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java Fri Jan  2 15:10:34 2009
@@ -399,12 +399,12 @@
         return mappedName2pdName.get(name);
     }
 
-    public List<QName> getAttributes() {
-        return attributes;
+    public Iterator<QName> getAttributes() {
+        return attributes.iterator();
     }
 
-    public List<QName> getElements() {
-        return elements;
+    public Iterator<QName> getElements() {
+        return elements.iterator();
     }
 
     public boolean isExtensibleElements() {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java Fri Jan  2 15:10:34 2009
@@ -35,10 +35,8 @@
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaSimpleType;
-import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
+import org.jdom.Attribute;
+import org.jdom.Element;
 
 /**
  * Type for runtime inspection of types. Looks as the class to be written, and
@@ -280,15 +278,16 @@
     }
 
     @Override
-    public void writeSchema(XmlSchema root) {
+    public void writeSchema(Element root) {
         if (serializedWhenUnknown) {
-            XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root);
-            simple.setName("serializedJavaObject");
-            root.addType(simple);
-            root.getItems().add(simple);
-            XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();    
-            simple.setContent(restriction);
-            restriction.setBaseTypeName(XmlSchemaConstants.BASE64BINARY_QNAME);
+            Element simple = new Element("simpleType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            simple.setAttribute(new Attribute("name", "serializedJavaObject"));
+            root.addContent(simple);
+
+            Element restriction = new Element("restriction", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+            restriction.setAttribute(new Attribute("base", SOAPConstants.XSD_PREFIX + ":base64Binary"));
+
+            simple.addContent(restriction);
         }
     }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/XMLBeanTypeInfo.java Fri Jan  2 15:10:34 2009
@@ -26,13 +26,11 @@
 
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Element;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.util.NamespaceHelper;
-import org.apache.cxf.helpers.DOMUtils;
+import org.jdom.Element;
 
 public class XMLBeanTypeInfo extends BeanTypeInfo {
     private static final Log LOG = LogFactory.getLog(XMLBeanTypeInfo.class);
@@ -52,7 +50,7 @@
     @Override
     protected boolean registerType(PropertyDescriptor desc) {
         Element e = getPropertyElement(desc.getName());
-        if (e != null && DOMUtils.getAttributeValueEmptyNull(e, "type") != null) {
+        if (e != null && e.getAttributeValue("type") != null) {
             return false;
         }
 
@@ -66,14 +64,14 @@
         QName mappedName = null;
 
         if (e != null) {
-            String ignore = e.getAttribute("ignore");
+            String ignore = e.getAttributeValue("ignore");
             if (ignore != null && ignore.equals("true")) {
                 return;
             }
 
             LOG.debug("Found mapping for property " + pd.getName());
 
-            style = e.getAttribute("style");
+            style = e.getAttributeValue("style");
         }
 
         if (style == null) {
@@ -93,7 +91,7 @@
         }
         
         if (e != null) {
-            mappedName = NamespaceHelper.createQName(e, e.getAttribute("mappedName"),
+            mappedName = NamespaceHelper.createQName(e, e.getAttributeValue("mappedName"),
                                                      namespace);
         }
 
@@ -102,18 +100,18 @@
         }
 
         if (e != null) {
-            QName mappedType = NamespaceHelper.createQName(e, e.getAttribute("typeName"),
+            QName mappedType = NamespaceHelper.createQName(e, e.getAttributeValue("typeName"),
                                                            getDefaultNamespace());
             if (mappedType != null) {
                 mapTypeName(mappedName, mappedType);
             }
 
-            String nillableVal = e.getAttribute("nillable");
+            String nillableVal = e.getAttributeValue("nillable");
             if (nillableVal != null && nillableVal.length() > 0) {
                 ensurePropertyInfo(mappedName).setNillable(Boolean.valueOf(nillableVal).booleanValue());
             }
 
-            String minOccurs = e.getAttribute("minOccurs");
+            String minOccurs = e.getAttributeValue("minOccurs");
             if (minOccurs != null && minOccurs.length() > 0) {
                 ensurePropertyInfo(mappedName).setMinOccurs(Integer.parseInt(minOccurs));
             }
@@ -139,10 +137,10 @@
     private Element getPropertyElement(String name2) {
         for (Iterator itr = mappings.iterator(); itr.hasNext();) {
             Element mapping2 = (Element)itr.next();
-            List<Element> elements = DOMUtils.getChildrenWithName(mapping2, null, "property");
+            List elements = mapping2.getChildren("property");
             for (int i = 0; i < elements.size(); i++) {
                 Element e = (Element)elements.get(i);
-                String name = e.getAttribute("name");
+                String name = e.getAttributeValue("name");
 
                 if (name != null && name.equals(name2)) {
                     return e;

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java?rev=730862&r1=730861&r2=730862&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java Fri Jan  2 15:10:34 2009
@@ -31,12 +31,12 @@
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaComplexType;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.cxf.common.util.SOAPConstants;
+import org.jdom.Attribute;
+import org.jdom.Element;
 
 public class MapType extends Type {
     private Type keyType;
@@ -176,43 +176,49 @@
     }
 
     @Override
-    public void writeSchema(XmlSchema root) {
-        XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
-        complex.setName(getSchemaType().getLocalPart());
-        root.addType(complex);
-        root.getItems().add(complex);
-        XmlSchemaSequence sequence = new XmlSchemaSequence();
-        complex.setParticle(sequence);
+    public void writeSchema(Element root) {
+        Element complex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        complex.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
+        root.addContent(complex);
+
+        Element seq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        complex.addContent(seq);
 
         Type kType = getKeyType();
         Type vType = getValueType();
-        
-        XmlSchemaElement element = new XmlSchemaElement();
-        sequence.getItems().add(element);
-        element.setName(getEntryName().getLocalPart());
-        element.setMinOccurs(0);
-        element.setMaxOccurs(Long.MAX_VALUE);
-        
-        XmlSchemaComplexType evType = new XmlSchemaComplexType(root);
-        element.setType(evType);
-        
-        XmlSchemaSequence evSequence = new XmlSchemaSequence();
-        evType.setParticle(evSequence);
 
-        createElement(evSequence, getKeyName(), kType);
-        createElement(evSequence, getValueName(), vType);
+        Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        seq.addContent(element);
+
+        element.setAttribute(new Attribute("name", getEntryName().getLocalPart()));
+        element.setAttribute(new Attribute("minOccurs", "0"));
+        element.setAttribute(new Attribute("maxOccurs", "unbounded"));
+
+        Element evComplex = new Element("complexType", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        element.addContent(evComplex);
+
+        Element evseq = new Element("sequence", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        evComplex.addContent(evseq);
+
+        createElement(root, evseq, getKeyName(), kType);
+        createElement(root, evseq, getValueName(), vType);
     }
 
     /**
      * Creates a element in a sequence for the key type and the value type.
      */
-    private void createElement(XmlSchemaSequence seq, QName name, Type type) {
-        XmlSchemaElement element = new XmlSchemaElement();
-        seq.getItems().add(element);
-        element.setName(name.getLocalPart());
-        element.setSchemaTypeName(type.getSchemaType());
-        element.setMinOccurs(0);
-        element.setMaxOccurs(1);
+    private void createElement(Element root, Element seq, QName name, Type type) {
+        Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        seq.addContent(element);
+
+        String prefix = NamespaceHelper.getUniquePrefix((Element)root, type.getSchemaType()
+            .getNamespaceURI());
+
+        element.setAttribute(new Attribute("name", name.getLocalPart()));
+        element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
+
+        element.setAttribute(new Attribute("minOccurs", "0"));
+        element.setAttribute(new Attribute("maxOccurs", "1"));
     }
 
     @Override



Mime
View raw message