cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r731402 [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/ parent/ rt/core/src/main/java/org/apache/cxf/tes...
Date Mon, 05 Jan 2009 01:32:53 GMT
Author: bimargulies
Date: Sun Jan  4 17:32:52 2009
New Revision: 731402

URL: http://svn.apache.org/viewvc?rev=731402&view=rev
Log:
Remove all JAXEN dependencies.

Added:
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/SchemaAddinsTest.java   (with props)
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/parent/pom.xml
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.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/AbstractAegisTest.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/integration/WrappedTest.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
    cxf/trunk/rt/frontend/jaxrs/pom.xml
    cxf/trunk/rt/javascript/pom.xml
    cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/NamespacePrefixAccumulator.java
    cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ParticleInfo.java
    cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/XmlSchemaUtils.java
    cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/AegisTest.java
    cxf/trunk/systests/pom.xml
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/AegisClientServerTest.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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -25,13 +25,14 @@
 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 {
   
@@ -76,7 +77,16 @@
             CachedOutputStream cout = new CachedOutputStream();
             XmlSchema sch = getSchema();
             synchronized (sch) {
-                getSchema().write(cout);
+                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);
             }
             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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -26,9 +26,12 @@
 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;
@@ -148,4 +151,53 @@
         }
         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) {
+        // no need to import nothing or the XSD schema.
+        if ("".equals(namespaceUri) || XmlSchemaConstants.XSD_NAMESPACE_URI.equals(namespaceUri)) {
+            return;
+        }
+            
+        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);
+        schema.getItems().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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -24,9 +24,11 @@
 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;
@@ -39,6 +41,7 @@
 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;
@@ -50,7 +53,6 @@
 
 import org.apache.cxf.common.util.StringUtils;
 
-
 /**
  * Few simple utils to read DOM. This is originally from the Jakarta Commons
  * Modeler.
@@ -58,8 +60,8 @@
  * @author Costin Manolache
  */
 public final class DOMUtils {
-    static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
-    static DocumentBuilder builder;
+    private static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
+    private static DocumentBuilder builder;
     private static final String XMLNAMESPACE = "xmlns";
 
     private DOMUtils() {
@@ -72,8 +74,24 @@
         }
         return builder;
     }
+    
     /**
-     * Get the trimed text content of a node or null if there is no text
+     * 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
      */
     public static String getContent(Node n) {
         if (n == null) {
@@ -249,24 +267,63 @@
         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) { 
-        Node n = parent.getFirstChild();
-        while (n != null) {
-            if (ns.equals(n.getNamespaceURI())
-                && lp.equals(n.getLocalName())) {
-                return (Element)n;
+        for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
+            if (n instanceof Element) {
+                Element e = (Element) n;
+                String ens = e.getNamespaceURI();
+                if (ns.equals(ens) && lp.equals(e.getNodeName())) {
+                    return e;
+                }
             }
-            n = n.getNextSibling();
         }
-        return (Element)n;
+        return null;
     }
+
     /**
-     * Get the first direct child with a given type
+     * 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.equals(e.getNamespaceURI()) && localName.equals(e.getLocalName())) {
+                    r.add(e);
+                }
+            }
+        }
+        return r;
+    }
+
+    /**
+     * Get the first child of the specified type.
+     * @param parent
+     * @param type
+     * @return
      */
     public static Node getChild(Node parent, int type) {
         Node n = parent.getFirstChild();
@@ -302,8 +359,7 @@
             if (type >= 0 && node.getNodeType() != type) {
                 continue;
             }
-            // System.out.println("getNode: " + name + " " +
-            // node.getNodeName());
+
             if (name == null) {
                 return node;
             }
@@ -401,6 +457,7 @@
             throw new RuntimeException("Couldn't find a DOM parser.", e);
         }
     }
+    
     public static Document createDocument() {
         try {
             return getBuilder().newDocument();
@@ -429,6 +486,38 @@
         }
         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";
@@ -515,4 +604,36 @@
             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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -29,11 +29,11 @@
 import org.w3c.dom.Node;
 
 public class XPathUtils {
-
-    XPath xpath;
+    private static final XPathFactory FACTORY = XPathFactory.newInstance();
+    private XPath xpath;
 
     public XPathUtils() {
-        xpath = XPathFactory.newInstance().newXPath();
+        xpath = FACTORY.newXPath();
     }
 
     public XPathUtils(final Map<String, String> ns) {
@@ -60,4 +60,8 @@
     public boolean isExist(String xpathExpression, Node node, QName type) {
         return getValue(xpathExpression, node, type) != null;
     }
+
+    public static XPathFactory getFactory() {
+        return FACTORY;
+    }
 }

Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=731402&r1=731401&r2=731402&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Sun Jan  4 17:32:52 2009
@@ -508,37 +508,6 @@
                 </exclusions>
             </dependency>
             <dependency>
-                <groupId>jaxen</groupId>
-                <artifactId>jaxen</artifactId>
-                <version>1.1</version>
-                <exclusions>
-                    <exclusion>
-                        <artifactId>dom4j</artifactId>
-                        <groupId>dom4j</groupId>
-                    </exclusion>
-                    <exclusion>
-                        <artifactId>xmlParserAPIs</artifactId>
-                        <groupId>xerces</groupId>
-                    </exclusion>
-                    <exclusion>
-                        <artifactId>xercesImpl</artifactId>
-                        <groupId>xerces</groupId>
-                    </exclusion>
-                    <exclusion>
-                        <artifactId>xom</artifactId>
-                        <groupId>xom</groupId>
-                    </exclusion>
-                    <exclusion>
-                        <artifactId>xalan</artifactId>
-                        <groupId>xalan</groupId>
-                    </exclusion>
-                    <exclusion>
-                        <artifactId>xml-apis</artifactId>
-                        <groupId>xml-apis</groupId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
                 <groupId>org.codehaus.woodstox</groupId>
                 <artifactId>wstx-asl</artifactId>
                 <version>3.2.6</version>

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java?rev=731402&r1=731401&r2=731402&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/XPathAssert.java Sun Jan  4 17:32:52 2009
@@ -135,7 +135,10 @@
         throws Exception {
         Node result = (Node)createXPath(namespaces).evaluate(xpath, node, XPathConstants.NODE);
         if (result == null) {
-            throw new AssertionFailedError("No nodes were found for expression: " + xpath);
+            throw new AssertionFailedError("No nodes were found for expression: " 
+                                           + xpath 
+                                           + " in document " 
+                                           + writeNodeToString(node));
         }
 
         String value2 = DOMUtils.getContent(result).trim();

Modified: cxf/trunk/rt/databinding/aegis/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/pom.xml?rev=731402&r1=731401&r2=731402&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/pom.xml (original)
+++ cxf/trunk/rt/databinding/aegis/pom.xml Sun Jan  4 17:32:52 2009
@@ -84,11 +84,6 @@
             <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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -46,11 +46,10 @@
 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.helpers.DOMUtils;
-import org.jaxen.JaxenException;
-import org.jaxen.jdom.JDOMXPath;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
+import org.apache.cxf.helpers.XMLUtils;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
 
 /**
  * The Aegis Databinding context object. This object coordinates the data binding process: reading and writing
@@ -74,19 +73,11 @@
 public class AegisContext {
 
     /**
-     * Namespace used for miscellaneous Aegis types.
+     * Namespace used for the miscellaneous Aegis type schema.
      */
-    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);
-        }
-    }
+    public static final String UTILITY_TYPES_SCHEMA_NS = "http://cxf.apache.org/aegisTypes";
+    private Document aegisTypesSchemaDocument;
+    private Document xmimeSchemaDocument;
 
     private boolean writeXsiTypes;
     private boolean readXsiTypes = true;
@@ -103,7 +94,6 @@
     private boolean mtomUseXmime;
     // this URI goes into the type map.
     private String mappingNamespaceURI;
-    private Document typesSchemaDocument;
 
     /**
      * Construct a context.
@@ -248,43 +238,47 @@
         }
     }
 
-    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 static boolean schemaImportsUtilityTypes(XmlSchema schema) {
+        return XmlSchemaTools.schemaImportsNamespace(schema, UTILITY_TYPES_SCHEMA_NS);
     }
-
-    private void ensureTypesSchemaDocument() {
-        if (typesSchemaDocument != null) {
-            return;
-        }
+    
+    private Document getSchemaDocument(String resourcePath) { 
         try {
-            typesSchemaDocument = DOMUtils.readXml(getClass()
-                .getResourceAsStream("/META-INF/cxf/aegisTypes.xsd"));
+            return XMLUtils.parse(getClass().getResourceAsStream(resourcePath));
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
         } 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(Element root) {
-        if (schemaImportsUtilityTypes(root)) {
-            return;
+    
+    // could we make these documents static? What would we synchronize on?
+    private Document getAegisTypesSchemaDocument() { 
+        if (aegisTypesSchemaDocument == null) {
+            aegisTypesSchemaDocument = getSchemaDocument("/META-INF/cxf/aegisTypes.xsd");
+        } 
+        return aegisTypesSchemaDocument;
+    }
+    
+    private Document getXmimeSchemaDocument() {
+        if (xmimeSchemaDocument == null) {
+            xmimeSchemaDocument = getSchemaDocument("/schemas/wsdl/xmime.xsd");
         }
-        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));
+        return xmimeSchemaDocument;
+    }
+
+    public XmlSchema addTypesSchemaDocument(XmlSchemaCollection collection) {
+        return collection.read(getAegisTypesSchemaDocument(), null);
+    }
+    
+    public XmlSchema addXmimeSchemaDocument(XmlSchemaCollection collection) {
+        return collection.read(getXmimeSchemaDocument(), null);
+    }
+
+    public static void addUtilityTypesToSchema(XmlSchema root) {
+        XmlSchemaTools.addImportIfNeeded(root, UTILITY_TYPES_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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.cxf.aegis.databinding;
 
-import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.HashMap;
@@ -29,17 +28,14 @@
 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.SAXException;
-
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.DatabindingException;
-import org.apache.cxf.aegis.type.AbstractTypeCreator.TypeClassInfo;
+import org.apache.cxf.aegis.type.AbstractTypeCreator;
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeCreationOptions;
 import org.apache.cxf.aegis.type.TypeCreator;
@@ -48,34 +44,27 @@
 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.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
@@ -110,7 +99,6 @@
     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;
@@ -120,36 +108,10 @@
     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 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);
-        }
     }
 
     /**
@@ -459,108 +421,93 @@
         }
 
         Map<String, String> namespaceMap = getDeclaredNamespaceMappings();
-        boolean needXmimeSchema = false;
-        // utility types.
-        boolean needTypesSchema = false;
 
-        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);
-            }
-
-            Element e = new Element("schema", xsdPrefix, SOAPConstants.XSD);
-
-            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 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());
+        for (ServiceInfo si : s.getServiceInfos()) {
+            // these two must be recalculated per-service-info!
+            boolean needXmimeSchema = false;
+            boolean needTypesSchema = false;
+
+            for (Map.Entry<String, Set<Type>> entry : tns2Type.entrySet()) {
+                
+                String schemaNamespaceUri = entry.getKey();
+                
+                if (XmlSchemaConstants.XSD_NAMESPACE_URI.equals(schemaNamespaceUri)) {
+                    continue;
+                }
+                
+                if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schemaNamespaceUri)) {
+                    continue; // we handle this separately.
+                }
+                
+                if (AbstractXOPType.XML_MIME_NS.equals(schemaNamespaceUri)) {
+                    continue; // similiarly.
+                }
+                
+                SchemaInfo schemaInfo = si.addNewSchema(entry.getKey());
+                XmlSchema schema = schemaInfo.getSchema(); 
+                NamespaceMap xmlsNamespaceMap = new NamespaceMap();
+
+                // user-requested prefix mappings.
+                if (namespaceMap != null) {
+                    for (Map.Entry<String, String> e : namespaceMap.entrySet()) {
+                        xmlsNamespaceMap.add(e.getValue(), e.getKey());
                     }
                 }
+                
+                // tns: is conventional, and besides we have unit tests that are hardcoded to it.
+                if (!xmlsNamespaceMap.containsKey(WSDLConstants.CONVENTIONAL_TNS_PREFIX)
+                    // if some wants something other than TNS, they get it.
+                    && !xmlsNamespaceMap.containsValue(entry.getKey())) {
+                    xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, entry.getKey());
+                }
+                
+                // ditto for xsd: instead of just namespace= for the schema schema.
+                if (!xmlsNamespaceMap.containsKey("xsd") 
+                    && !xmlsNamespaceMap.containsValue(XmlSchemaConstants.XSD_NAMESPACE_URI)) {
+                    xmlsNamespaceMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
+                }
+
+                schema.setNamespaceContext(xmlsNamespaceMap);
+                schema.setTargetNamespace(entry.getKey());
+                schema.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
+                schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
 
-                org.w3c.dom.Document schema = new DOMOutputter().output(new Document(e));
+                for (Type t : entry.getValue()) {
+                    t.writeSchema(schema);
+                }
 
-                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 (schemaImportsXmime(schema)) {
+                    needXmimeSchema = true;
+                }
+            
+                if (AegisContext.schemaImportsUtilityTypes(schema)) {
+                    needTypesSchema = true;
+                }
             }
 
-        }
-
-        if (needXmimeSchema) {
-            ensureXmimeSchemaDocument();
-            for (ServiceInfo si : s.getServiceInfos()) {
-                SchemaCollection col = si.getXmlSchemaCollection();
-                // invented systemId.
-                addSchemaDocument(si, col, xmimeSchemaDocument, AbstractXOPType.XML_MIME_NS);
+            if (needXmimeSchema) {
+                XmlSchema schema = 
+                    aegisContext.addXmimeSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
+                schemaInfo.setSchema(schema);
+                si.addSchema(schemaInfo);
             }
-        }
-        
-        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);
+            
+            if (needTypesSchema) {
+                XmlSchema schema = 
+                    aegisContext.addTypesSchemaDocument(si.getXmlSchemaCollection().getXmlSchemaCollection());
+                SchemaInfo schemaInfo = new SchemaInfo(schema.getTargetNamespace());
+                schemaInfo.setSchema(schema);
+                si.addSchema(schemaInfo);
             }
         }
         
     }
 
+    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) {
@@ -600,7 +547,7 @@
             OperationInfo op = param.getMessageInfo().getOperation();
 
             Method m = getMethod(s, op);
-            TypeClassInfo info;
+            AbstractTypeCreator.TypeClassInfo info;
             if (paramtype != FAULT_PARAM && m != null) {
                 info = typeCreator.createClassInfo(m, param.getIndex() - offset);
             } else {

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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -26,7 +26,8 @@
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
-import org.jdom.Element;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
 
 /**
  * A Type reads and writes XML fragments to create and write objects.
@@ -76,7 +77,7 @@
      * type object adds it to the schema.
      * @param root root of the XSD document.
      */
-    public void writeSchema(Element root) {
+    public void writeSchema(XmlSchema root) {
     }
     
     /**
@@ -84,7 +85,7 @@
      * xsd:element element, it can implement this. 
      * @param schemaElement
      */
-    public void addToSchemaElement(Element schemaElement) {
+    public void addToSchemaElement(XmlSchemaElement 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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -18,8 +18,6 @@
  */
 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;
@@ -27,10 +25,9 @@
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.apache.cxf.helpers.CastUtils;
-import org.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
+import org.apache.ws.commons.schema.XmlSchema;
+
 
 /**
  * Static methods/constants for Aegis.
@@ -159,26 +156,9 @@
         return type;
     }
     
-    public static Attribute createTypeAttribute(String prefix, Type type, Element root) {
+    
+    public static void setAttributeAttributes(QName name, Type type, XmlSchema root) {
         String ns = type.getSchemaType().getNamespaceURI();
-        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()); 
+        XmlSchemaTools.addImportIfNeeded(root, ns);
     }
-
 }

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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -38,6 +38,12 @@
 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;
@@ -50,12 +56,8 @@
 import org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo;
 import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
-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;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.XPathUtils;
 
 /**
  * Deduce mapping information from an xml file. The xml file should be in the
@@ -113,7 +115,7 @@
         if (is != null) {
             try {
                 aegisDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
-
+                aegisDocumentBuilderFactory.setNamespaceAware(true);
                 
                 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                 aegisSchema = schemaFactory.newSchema(new StreamSource(is));
@@ -132,6 +134,8 @@
             }
         }
     }
+    
+    private XPathUtils xpathUtils = new XPathUtils();
 
     private Document readAegisFile(InputStream is, final String path) throws IOException {
         DocumentBuilder documentBuilder;
@@ -184,7 +188,7 @@
                                                         // above.
             return null;
         }
-        return new DOMBuilder().build(doc);
+        return doc;
     }
 
     protected Document getDocument(Class clazz) {
@@ -321,17 +325,17 @@
         if (mapping != null || mappings.size() > 0) {
             String typeNameAtt = null;
             if (mapping != null) {
-                typeNameAtt = mapping.getAttributeValue("name");
+                typeNameAtt = DOMUtils.getAttributeValueEmptyNull(mapping, "name");
             }
 
             String extensibleElements = null;
             if (mapping != null) {
-                extensibleElements = mapping.getAttributeValue("extensibleElements");
+                extensibleElements = mapping.getAttribute("extensibleElements");
             }
 
             String extensibleAttributes = null;
             if (mapping != null) {
-                extensibleAttributes = mapping.getAttributeValue("extensibleAttributes");
+                extensibleAttributes = mapping.getAttribute("extensibleAttributes");
             }
 
             String defaultNS = NamespaceHelper.makeNamespaceFromClassName(info.getTypeClass().getName(),
@@ -436,7 +440,7 @@
             }
             info.setTypeClass(m.getReturnType());
             // info.setAnnotations(m.getAnnotations());
-            Element rtElement = bestMatch.getChild("return-type");
+            Element rtElement = DOMUtils.getFirstChildWithName(bestMatch, "", "return-type");
             readMetadata(info, mapping, rtElement);
         }
 
@@ -444,24 +448,25 @@
     }
 
     protected void readMetadata(TypeClassInfo info, Element mapping, Element parameter) {
-        info.setTypeName(createQName(parameter, parameter.getAttributeValue("typeName")));
-        info.setMappedName(createQName(parameter, parameter.getAttributeValue("mappedName")));
+        info.setTypeName(createQName(parameter, DOMUtils.getAttributeValueEmptyNull(parameter, "typeName")));
+        info.setMappedName(createQName(parameter, 
+                                       DOMUtils.getAttributeValueEmptyNull(parameter, "mappedName")));
         setComponentType(info, mapping, parameter);
         setKeyType(info, mapping, parameter);
         setValueType(info, mapping, parameter);
         setType(info, parameter);
 
-        String min = parameter.getAttributeValue("minOccurs");
+        String min = DOMUtils.getAttributeValueEmptyNull(parameter, "minOccurs");
         if (min != null) {
             info.setMinOccurs(Long.parseLong(min));
         }
 
-        String max = parameter.getAttributeValue("maxOccurs");
+        String max = DOMUtils.getAttributeValueEmptyNull(parameter, "maxOccurs");
         if (max != null) {
             info.setMaxOccurs(Long.parseLong(max));
         }
 
-        String flat = parameter.getAttributeValue("flat");
+        String flat = DOMUtils.getAttributeValueEmptyNull(parameter, "flat");
         if (flat != null) {
             info.setFlat(Boolean.valueOf(flat.toLowerCase()).booleanValue());
         }
@@ -520,7 +525,7 @@
     }
 
     protected void setComponentType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = parameter.getAttributeValue("componentType");
+        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "componentType");
         if (componentType != null) {
             info.setGenericType(loadGeneric(info, mapping, componentType));
         }
@@ -538,7 +543,7 @@
             TypeClassInfo componentInfo = new TypeClassInfo();
             componentInfo.setDescription("generic component " + componentInfo.getDescription());
             readMetadata(componentInfo, mapping, propertyEl);
-            String className = propertyEl.getAttributeValue("class");
+            String className = DOMUtils.getAttributeValueEmptyNull(propertyEl, "class");
             if (className == null) {
                 throw new DatabindingException("A 'class' attribute must be specified for <component> "
                                                + name);
@@ -561,7 +566,7 @@
     }
 
     protected void setType(TypeClassInfo info, Element parameter) {
-        String type = parameter.getAttributeValue("type");
+        String type = DOMUtils.getAttributeValueEmptyNull(parameter, "type");
         if (type != null) {
             try {
                 info.setType(ClassLoaderUtils.loadClass(type, getClass()));
@@ -572,14 +577,14 @@
     }
 
     protected void setKeyType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = parameter.getAttributeValue("keyType");
+        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "keyType");
         if (componentType != null) {
             info.setKeyType(loadGeneric(info, mapping, componentType));
         }
     }
 
     private void setValueType(TypeClassInfo info, Element mapping, Element parameter) {
-        String componentType = parameter.getAttributeValue("valueType");
+        String componentType = DOMUtils.getAttributeValueEmptyNull(parameter, "valueType");
         if (componentType != null) {
             info.setValueType(loadGeneric(info, mapping, componentType));
         }
@@ -612,10 +617,10 @@
                 Element match = getMatch(element, "parameter[@index='" + i + "']");
                 if (match != null
                 // we check if the type is specified and matches
-                    && match.getAttributeValue("class") != null
+                    && DOMUtils.getAttributeValueEmptyNull(match, "class") != null
                     // if it doesn't match, then we can definitely rule out
                     // this result
-                    && !match.getAttributeValue("class").equals(parameterType.getName())) {
+                    && !DOMUtils.getAttributeValueEmptyNull(match, "class").equals(parameterType.getName())) {
 
                     iterator.remove();
                 }
@@ -632,7 +637,9 @@
         int highestSpecified = 0;
         for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
             Element element = (Element)iterator.next();
-            int availableParameters = element.getChildren("parameter").size();
+
+            List<Element> params = DOMUtils.getChildrenWithName(element, "", "parameter");
+            int availableParameters = params.size();
             if (availableParameters > highestSpecified) {
                 bestCandidate = element;
                 highestSpecified = availableParameters;
@@ -641,23 +648,17 @@
         return bestCandidate;
     }
 
-    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 Element getMatch(Node doc, String xpath) {
+        return (Element)xpathUtils.getValue(xpath, doc, XPathConstants.NODE);
     }
 
-    @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);
+    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));
         }
+        return r;
     }
 
     /**
@@ -676,12 +677,12 @@
 
         String prefix = value.substring(0, index);
         String localName = value.substring(index + 1);
-        Namespace ns = e.getNamespace(prefix);
+        String ns = DOMUtils.getNamespace(e, prefix);
 
         if (ns == null || localName == null) {
             throw new DatabindingException("Invalid QName in mapping: " + value);
         }
 
-        return new QName(ns.getURI(), localName, prefix);
+        return new QName(ns, 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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -22,8 +22,6 @@
 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;
@@ -34,14 +32,13 @@
 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.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.Namespace;
+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;
 
 /**
  * An ArrayType.
@@ -165,8 +162,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;
@@ -189,7 +186,6 @@
 
         String name = type.getSchemaType().getLocalPart();
 
-
         Class arrayType = type.getTypeClass();
 
         boolean oldXsiWrite = context.getGlobalContext().isWriteXsiTypes();
@@ -266,70 +262,50 @@
         } else {
             type.writeObject(value, cwriter, context);
         }
-        
+
         if (type.isWriteOuter()) {
             cwriter.close();
         }
     }
 
     @Override
-    public void writeSchema(Element root) {
-        try {
-            if (hasDefinedArray(root)) {
-                return;
-            }
-
-            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);
-
-            Element element = new Element("element", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
-            seq.addContent(element);
-
-            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));
+    public void writeSchema(XmlSchema root) {
+        if (hasDefinedArray(root)) {
+            return;
+        }
 
-            if (componentType.isNillable()) {
-                element.setAttribute(new Attribute("nillable", "true"));
-            }
+        XmlSchemaComplexType complex = new XmlSchemaComplexType(root);
+        complex.setName(getSchemaType().getLocalPart());
+        root.addType(complex);
+        root.getItems().add(complex);
+
+        XmlSchemaSequence seq = new XmlSchemaSequence();
+        complex.setParticle(seq);
+
+        Type componentType = getComponentType();
+        XmlSchemaElement element = new XmlSchemaElement();
+        element.setName(componentType.getSchemaType().getLocalPart());
+        element.setSchemaTypeName(componentType.getSchemaType());
+        seq.getItems().add(element);
 
-            element.setAttribute(new Attribute("minOccurs", Long.valueOf(getMinOccurs()).toString()));
+        if (componentType.isNillable()) {
+            element.setNillable(true);
+        }
 
-            if (maxOccurs == Long.MAX_VALUE) {
-                element.setAttribute(new Attribute("maxOccurs", "unbounded"));
-            } else {
-                element.setAttribute(new Attribute("maxOccurs", Long.valueOf(getMaxOccurs()).toString()));
-            }
+        element.setMinOccurs(getMinOccurs());
+        element.setMaxOccurs(getMaxOccurs());
 
-        } 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(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;
+    private boolean hasDefinedArray(XmlSchema root) {
+        return root.getTypeByName(getSchemaType().getLocalPart()) != null;
     }
 
     /**
@@ -416,7 +392,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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 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,20 +37,24 @@
 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.util.SOAPConstants;
+import org.apache.cxf.common.xmlschema.XmlSchemaTools;
 import org.apache.cxf.interceptor.Fault;
-import org.jaxen.JaxenException;
-import org.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.Namespace;
+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;
 
 /**
  * Serializes JavaBeans.
- *
+ * 
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  * @author <a href="mailto:jack.xu.hong@gmail.com">Jack Hong</a>
  */
@@ -77,9 +81,8 @@
 
     /*
      * (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 {
@@ -96,8 +99,9 @@
 
                 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 {
@@ -148,7 +152,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.");
 
                         }
@@ -173,11 +177,9 @@
         }
     }
 
-    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
@@ -186,11 +188,10 @@
     }
 
     /**
-     * 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;
@@ -199,16 +200,28 @@
         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();
                 }
@@ -225,7 +238,7 @@
         throws DatabindingException {
 
         if (object instanceof InterfaceInvocationHandler) {
-            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler) object;
+            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler)object;
             delegate.writeProperty(name.getLocalPart(), property);
             return;
         }
@@ -248,7 +261,9 @@
 
             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) {
@@ -261,18 +276,20 @@
     }
 
     /**
-     * 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
@@ -282,38 +299,33 @@
                                    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 (Iterator itr = inf.getAttributes(); itr.hasNext();) {
-            QName name = (QName)itr.next();
+        for (QName name : inf.getAttributes()) {
 
             Object value = readProperty(object, name);
             if (value != null) {
@@ -332,8 +344,7 @@
             }
         }
 
-        for (Iterator itr = inf.getElements(); itr.hasNext();) {
-            QName name = (QName)itr.next();
+        for (QName name : inf.getElements()) {
 
             if (inf.isExtension()
                 && inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
@@ -405,163 +416,6 @@
         }
     }
 
-    /**
-     * @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);
 
@@ -573,23 +427,22 @@
         return type;
     }
 
-    private void writeTypeReference(QName name, String nameWithPrefix, 
-                                    Element element, Type type, String prefix,
-                                    Element root) {
+    private void writeTypeReference(QName name, XmlSchemaElement element, Type type) {
         if (type.isAbstract()) {
-            element.setAttribute(new Attribute("name", nameWithPrefix));
-            element.setAttribute(TypeUtil.createTypeAttribute(prefix, type, root));
+            element.setName(name.getLocalPart());
+            element.setSchemaTypeName(type.getSchemaType());
 
             int minOccurs = getTypeInfo().getMinOccurs(name);
-            if (minOccurs == 0) {
-                element.setAttribute(new Attribute("minOccurs", Integer.valueOf(minOccurs).toString()));
+            /*
+             * Old code had ridiculous '!=0' here, which cannot have been right.
+             */
+            if (minOccurs != -1) {
+                element.setMinOccurs(minOccurs);
             }
 
-            if (getTypeInfo().isNillable(name)) {
-                element.setAttribute(new Attribute("nillable", "true"));
-            }
+            element.setNillable(getTypeInfo().isNillable(name));
         } else {
-            element.setAttribute(new Attribute("ref", prefix + ':' + type.getSchemaType().getLocalPart()));
+            element.setRefName(type.getSchemaType());
         }
     }
 
@@ -602,7 +455,7 @@
 
     /**
      * We need to write a complex type schema for Beans, so return true.
-     *
+     * 
      * @see org.apache.cxf.aegis.type.Type#isComplex()
      */
     @Override
@@ -616,13 +469,11 @@
 
         BeanTypeInfo inf = getTypeInfo();
 
-        for (Iterator itr = inf.getAttributes(); itr.hasNext();) {
-            QName name = (QName)itr.next();
+        for (QName name : inf.getAttributes()) {
             deps.add(inf.getType(name));
         }
 
-        for (Iterator itr = inf.getElements(); itr.hasNext();) {
-            QName name = (QName)itr.next();
+        for (QName name : inf.getElements()) {
             if (inf.isExtension()
                 && inf.getPropertyDescriptorFromMappedName(name).getReadMethod().getDeclaringClass() != inf
                     .getTypeClass()) {
@@ -632,7 +483,7 @@
         }
 
         /*
-         * Automagically add chain of superclasses *if* this is an an extension.
+         * Automagically add chain of superclassesif this is an an extension.
          */
         if (inf.isExtension()) {
             Type sooperType = getSuperType();
@@ -652,11 +503,12 @@
             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.
                 }
@@ -715,19 +567,6 @@
         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();
@@ -744,29 +583,8 @@
         return sb.toString();
     }
 
-    /**
-     * 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));
+    private void addXmimeToSchema(XmlSchema root) {
+        XmlSchemaTools.addImportIfNeeded(root, AbstractXOPType.XML_MIME_NS);
     }
 
     @Override
@@ -786,4 +604,109 @@
             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();
+            element.setName(name.getLocalPart());
+            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();
+            any.setMinOccurs(0);
+            any.setMaxOccurs(Long.MAX_VALUE);
+            sequence.getItems().add(any);
+        }
+
+        // Write out schema for attributes
+        for (QName name : inf.getAttributes()) {
+            XmlSchemaAttribute attribute = new XmlSchemaAttribute();
+            complex.getAttributes().add(attribute);
+            attribute.setName(name.getLocalPart());
+            Type type = getType(inf, name);
+            attribute.setSchemaTypeName(type.getSchemaType());
+            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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -399,12 +399,12 @@
         return mappedName2pdName.get(name);
     }
 
-    public Iterator<QName> getAttributes() {
-        return attributes.iterator();
+    public List<QName> getAttributes() {
+        return attributes;
     }
 
-    public Iterator<QName> getElements() {
-        return elements.iterator();
+    public List<QName> getElements() {
+        return elements;
     }
 
     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=731402&r1=731401&r2=731402&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 Sun Jan  4 17:32:52 2009
@@ -35,8 +35,10 @@
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.jdom.Attribute;
-import org.jdom.Element;
+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;
 
 /**
  * Type for runtime inspection of types. Looks as the class to be written, and
@@ -278,16 +280,15 @@
     }
 
     @Override
-    public void writeSchema(Element root) {
+    public void writeSchema(XmlSchema root) {
         if (serializedWhenUnknown) {
-            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);
+            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);
         }
     }
 }



Mime
View raw message