cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r745879 [2/4] - in /cxf/branches/2.1.x-fixes: ./ api/src/main/java/org/apache/cxf/ api/src/main/java/org/apache/cxf/service/model/ api/src/main/java/org/apache/cxf/wsdl/ api/src/test/java/org/apache/cxf/ common/common/src/main/java/org/apac...
Date Thu, 19 Feb 2009 14:19:11 GMT
Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ArrayType.java Thu Feb 19 14:18:49 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,51 @@
         } 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 +393,7 @@
         setWriteOuter(!flat);
         this.flat = flat;
     }
-    
+
     @Override
     public boolean hasMaxOccurs() {
         return true;

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java Thu Feb 19 14:18:49 2009
@@ -26,31 +26,36 @@
 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;
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.type.AbstractTypeCreator;
 import org.apache.cxf.aegis.type.Type;
 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.XmlSchemaUtils;
 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 +82,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,7 +100,7 @@
 
                 if (impl == null) {
                     InvocationHandler handler = new InterfaceInvocationHandler();
-                    object = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] {
+                    object = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] {
                         clazz
                     }, handler);
                     target = handler;
@@ -149,7 +153,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.");
 
                         }
@@ -174,11 +178,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
@@ -187,11 +189,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;
@@ -200,16 +201,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();
                 }
@@ -226,7 +239,7 @@
         throws DatabindingException {
 
         if (object instanceof InterfaceInvocationHandler) {
-            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler) object;
+            InterfaceInvocationHandler delegate = (InterfaceInvocationHandler)object;
             delegate.writeProperty(name.getLocalPart(), property);
             return;
         }
@@ -249,7 +262,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) {
@@ -262,18 +277,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
@@ -283,38 +300,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) {
@@ -333,8 +345,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
@@ -406,163 +417,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);
 
@@ -574,23 +428,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());
         }
     }
 
@@ -603,7 +456,7 @@
 
     /**
      * We need to write a complex type schema for Beans, so return true.
-     *
+     * 
      * @see org.apache.cxf.aegis.type.Type#isComplex()
      */
     @Override
@@ -617,13 +470,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()) {
@@ -633,7 +484,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();
@@ -653,11 +504,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.
                 }
@@ -716,19 +568,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();
@@ -745,29 +584,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) {
+        XmlSchemaUtils.addImportIfNeeded(root, AbstractXOPType.XML_MIME_NS);
     }
 
     @Override
@@ -787,4 +605,113 @@
             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);
+            if (AbstractTypeCreator.
+                HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
+                XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
+            }
+
+            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())) {
+                XmlSchemaUtils.addImportIfNeeded(root, ns);
+            }
+        }
+
+        /**
+         * If extensible attributes then add <xsd:anyAttribute/>
+         */
+        if (inf.isExtensibleAttributes()) {
+            sequence.getItems().add(new XmlSchemaAnyAttribute());
+        }
+    }
+
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java Thu Feb 19 14:18:49 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/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ObjectType.java Thu Feb 19 14:18:49 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);
         }
     }
 }

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

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java Thu Feb 19 14:18:49 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.cxf.common.util.SOAPConstants;
-import org.jdom.Attribute;
-import org.jdom.Element;
+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;
 
 public class MapType extends Type {
     private Type keyType;
@@ -176,49 +176,43 @@
     }
 
     @Override
-    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);
+    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);
 
         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);
 
-        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);
+        createElement(evSequence, getKeyName(), kType);
+        createElement(evSequence, getValueName(), vType);
     }
 
     /**
      * Creates a element in a sequence for the key type and the value type.
      */
-    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"));
+    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);
     }
 
     @Override

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java Thu Feb 19 14:18:49 2009
@@ -24,6 +24,8 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
+
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.aegis.DatabindingException;
@@ -56,7 +58,8 @@
     }
 
     public ArrayTypeInfo(MessageReader reader, TypeMapping tm) {
-        this(readAttributeValue(reader, SOAP_ARRAY_TYPE), readAttributeValue(reader, SOAP_ARRAY_OFFSET));
+        this(reader.getXMLStreamReader().getNamespaceContext(),
+             readAttributeValue(reader, SOAP_ARRAY_TYPE), readAttributeValue(reader, SOAP_ARRAY_OFFSET));
 
         // if type is xsd:ur-type replace it with xsd:anyType
         String namespace = reader.getNamespaceForPrefix(typeName.getPrefix());
@@ -85,11 +88,11 @@
         }
     }
 
-    public ArrayTypeInfo(String arrayTypeValue) {
-        this(arrayTypeValue, null);
+    public ArrayTypeInfo(NamespaceContext namespaceContext, String arrayTypeValue) {
+        this(namespaceContext, arrayTypeValue, null);
     }
 
-    public ArrayTypeInfo(String arrayTypeValue, String offsetString) {
+    public ArrayTypeInfo(NamespaceContext namespaceContext, String arrayTypeValue, String offsetString) {
         if (arrayTypeValue == null) {
             throw new NullPointerException("arrayTypeValue is null");
         }
@@ -110,7 +113,8 @@
             throw new DatabindingException("Invalid ArrayType value " + arrayTypeValue);
         }
         if (tokens.get(1).equals(":")) {
-            typeName = new QName("", tokens.get(2), tokens.get(0));
+            typeName = 
+                new QName(namespaceContext.getNamespaceURI(tokens.get(0)), tokens.get(2), tokens.get(0));
             tokens = tokens.subList(3, tokens.size());
         } else {
             typeName = new QName("", tokens.get(0));
@@ -218,6 +222,11 @@
 
     public String toString() {
         StringBuilder string = new StringBuilder();
+        
+        // no prefix handed to us by someone else ...
+        if ("".equals(typeName.getPrefix()) && !"".equals(typeName.getNamespaceURI())) {
+            throw new RuntimeException("No prefix provided in QName for " + typeName.getNamespaceURI());
+        }
 
         // typeName: foo:bar
         if (typeName.getPrefix() != null && typeName.getPrefix().length() > 0) {

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java Thu Feb 19 14:18:49 2009
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Set;
 import java.util.StringTokenizer;
+
 import javax.xml.namespace.QName;
 
 import org.apache.commons.logging.Log;
@@ -39,7 +40,7 @@
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.helpers.CastUtils;
-import org.jdom.Element;
+import org.apache.ws.commons.schema.XmlSchema;
 
 import static org.apache.cxf.aegis.type.encoded.SoapEncodingUtil.readAttributeValue;
 
@@ -135,7 +136,7 @@
                 sparse = position != null;
             }
 
-            // nested element names can specifiy a type
+            // nested element names can specify a type
             Type compType = getTypeMapping().getType(creader.getName());
             if (compType == null) {
                 // use the type declared in the arrayType attribute
@@ -290,6 +291,9 @@
         // Root component's schema type
         QName rootType = getRootType();
         String prefix = writer.getPrefixForNamespace(rootType.getNamespaceURI(), rootType.getPrefix());
+        if (prefix == null) {
+            prefix = "";
+        }
         rootType = new QName(rootType.getNamespaceURI(), rootType.getLocalPart(), prefix);
 
 
@@ -297,6 +301,9 @@
         ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(rootType,
                 getDimensions() - 1,
                 Array.getLength(values));
+        // ensure that the writer writes out this prefix...
+        writer.getPrefixForNamespace(arrayTypeInfo.getTypeName().getNamespaceURI(), 
+                                     arrayTypeInfo.getTypeName().getPrefix());
         arrayTypeInfo.writeAttribute(writer);
 
         // write each element
@@ -333,7 +340,7 @@
      * Throws UnsupportedOperationException
      */
     @Override
-    public void writeSchema(Element root) {
+    public void writeSchema(XmlSchema root) {
         throw new UnsupportedOperationException();
     }
 

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapRefType.java Thu Feb 19 14:18:49 2009
@@ -19,6 +19,7 @@
 package org.apache.cxf.aegis.type.encoded;
 
 import java.util.Set;
+
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.aegis.Context;
@@ -27,7 +28,7 @@
 import org.apache.cxf.aegis.type.TypeMapping;
 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;
 
 /**
  * SoapRefType reads and writes SoapRef objects.
@@ -77,8 +78,9 @@
         SoapEncodingUtil.writeRef(writer, refId);
     }
 
-    public void writeSchema(Element root) {
-        baseType.writeSchema(root);
+    @Override
+    public void writeSchema(XmlSchema schema) {
+        baseType.writeSchema(schema);
     }
 
     public TypeMapping getTypeMapping() {

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/EnumType.java Thu Feb 19 14:18:49 2009
@@ -23,10 +23,12 @@
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
-import org.apache.cxf.common.util.SOAPConstants;
-import org.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
 
 public class EnumType extends Type {
     @SuppressWarnings("unchecked")
@@ -53,23 +55,23 @@
     }
 
     @Override
-    public void writeSchema(Element root) {
-        Namespace xsd = Namespace.getNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
-
-        Element simple = new Element("simpleType", xsd);
-        simple.setAttribute(new Attribute("name", getSchemaType().getLocalPart()));
-        root.addContent(simple);
-
-        Element restriction = new Element("restriction", xsd);
-        restriction.setAttribute(new Attribute("base", SOAPConstants.XSD_PREFIX + ":string"));
-        simple.addContent(restriction);
+    public void writeSchema(XmlSchema root) {
+        
+        XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root);
+        simple.setName(getSchemaType().getLocalPart());
+        root.addType(simple);
+        root.getItems().add(simple);
+        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
+        restriction.setBaseTypeName(XmlSchemaConstants.STRING_QNAME);
+        simple.setContent(restriction);
 
         Object[] constants = getTypeClass().getEnumConstants();
 
+        XmlSchemaObjectCollection facets = restriction.getFacets();
         for (Object constant : constants) {
-            Element enumeration = new Element("enumeration", xsd);
-            enumeration.setAttribute(new Attribute("value", ((Enum)constant).name()));
-            restriction.addContent(enumeration);
+            XmlSchemaEnumerationFacet f = new XmlSchemaEnumerationFacet();
+            f.setValue(((Enum)constant).name());
+            facets.add(f);
         }
     }
 

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java Thu Feb 19 14:18:49 2009
@@ -21,23 +21,25 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.basic.Base64Type;
 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.helpers.DOMUtils;
 import org.apache.cxf.message.Attachment;
-import org.jaxen.JaxenException;
-import org.jaxen.jdom.JDOMXPath;
-import org.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.Namespace;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.constants.Constants;
 
 /**
  * Base class for MtoM types.
@@ -51,18 +53,6 @@
     public static final QName XML_MIME_CONTENT_TYPE = new QName(XML_MIME_NS, "contentType");
     public static final QName XOP_HREF = new QName("href");
     public static final QName XML_MIME_BASE64 = new QName(XML_MIME_NS, "base64Binary", "xmime");
-    private static JDOMXPath importXmimeXpath;
-    
-    static {
-        try {
-            importXmimeXpath = new JDOMXPath("xsd:import[@namespace='"
-                                             + XML_MIME_NS
-                                             + "']");
-            importXmimeXpath.addNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
-        } catch (JaxenException e) {
-            throw new RuntimeException(e);
-        }
-    }
     
     private String expectedContentTypes;
     // the base64 type knows how to deal with just plain base64 here, which is essentially always 
@@ -87,10 +77,6 @@
         }
     }
     
-    public static JDOMXPath getXmimeXpathImport() {
-        return importXmimeXpath;
-    }
-
     /**
      * This is called from base64Type when it recognizes an XOP attachment.
      * @param reader
@@ -208,13 +194,13 @@
     protected abstract byte[] getBytes(Object object);
 
     @Override
-    public void addToSchemaElement(Element schemaElement) {
+    public void addToSchemaElement(XmlSchemaElement schemaElement) {
         if (expectedContentTypes != null) {
-            Namespace ns = Namespace.getNamespace("xmime", XML_MIME_NS);
-            Attribute expectedContentTypeAttribute = new Attribute(XML_MIME_ATTR_LOCAL_NAME, 
-                                                                   expectedContentTypes,
-                                                                   ns);
-            schemaElement.setAttribute(expectedContentTypeAttribute);
+            Map<String, Node> extAttrMap = new HashMap<String, Node>();
+            Attr theAttr = DOMUtils.createDocument().createAttributeNS(XML_MIME_NS, "xmime");
+            theAttr.setNodeValue(expectedContentTypes);
+            extAttrMap.put("xmime", theAttr);
+            schemaElement.addMetaInfo(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES, extAttrMap);
         }
     }
     

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java Thu Feb 19 14:18:49 2009
@@ -20,7 +20,6 @@
 
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -30,10 +29,11 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.JavaUtils;
-import org.jdom.Element;
-import org.jdom.Namespace;
 
 /**
  * Namespace utilities.
@@ -62,60 +62,26 @@
                 return "";
             }
             prefix = getUniquePrefix(element);
-            element.addNamespaceDeclaration(Namespace.getNamespace(prefix, namespaceURI));
+            DOMUtils.addNamespacePrefix(element, namespaceURI, prefix);
         }
         return prefix;
     }
 
     public static String getPrefix(Element element, String namespaceURI) {
-        if (element.getNamespaceURI().equals(namespaceURI)) {
-            return element.getNamespacePrefix();
-        }
-
-        List namespaces = element.getAdditionalNamespaces();
-
-        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
-            Namespace ns = (Namespace)itr.next();
-
-            if (ns.getURI().equals(namespaceURI)) {
-                return ns.getPrefix();
-            }
-        }
-
-        if (element.getParentElement() != null) {
-            return getPrefix(element.getParentElement(), namespaceURI);
-        } else {
-            return null;
-        }
+        return DOMUtils.getPrefixRecursive(element, namespaceURI);
     }
 
     public static void getPrefixes(Element element, String namespaceURI, List<String> prefixes) {
-        if (element.getNamespaceURI().equals(namespaceURI)) {
-            prefixes.add(element.getNamespacePrefix());
-        }
-
-        List namespaces = element.getAdditionalNamespaces();
-
-        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
-            Namespace ns = (Namespace)itr.next();
-
-            if (ns.getURI().equals(namespaceURI)) {
-                prefixes.add(ns.getPrefix());
-            }
-        }
-
-        if (element.getParentElement() != null) {
-            getPrefixes(element.getParentElement(), namespaceURI, prefixes);
-        }
+        DOMUtils.getPrefixesRecursive(element, namespaceURI, prefixes);
     }
 
-    private static String getUniquePrefix(Element el) {
+    public static String getUniquePrefix(Element el) {
         int n = 1;
 
         while (true) {
             String nsPrefix = "ns" + n;
 
-            if (el.getNamespace(nsPrefix) == null) {
+            if (DOMUtils.getNamespace(el, nsPrefix) == null) {
                 return nsPrefix;
             }
 
@@ -373,17 +339,15 @@
 
         String prefix = value.substring(0, index);
         String localName = value.substring(index + 1);
-        Namespace jNS = e.getNamespace(prefix);
+        String jNS = DOMUtils.getNamespace(e, prefix);
         if (jNS == null) {
             throw new DatabindingException("No namespace was found for prefix: " + prefix);
         }
         
-        String ns = jNS.getURI();
-
-        if (ns == null || localName == null) {
+        if (jNS == null || localName == null) {
             throw new DatabindingException("Invalid QName in mapping: " + value);
         }
 
-        return new QName(ns, localName, prefix);
+        return new QName(jNS, localName, prefix);
     }
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMNamespaceContext.java Thu Feb 19 14:18:49 2009
@@ -24,7 +24,6 @@
 
 import javax.xml.namespace.NamespaceContext;
 
-import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.jdom.Element;
 import org.jdom.Namespace;
 
@@ -41,12 +40,12 @@
     }
 
     public String getPrefix(String uri) {
-        return NamespaceHelper.getPrefix(element, uri);
+        return rawGetPrefix(element, uri);
     }
 
     public Iterator<String> getPrefixes(String uri) {
         List<String> prefixes = new ArrayList<String>();
-        NamespaceHelper.getPrefixes(element, uri, prefixes);
+        rawGetPrefixes(element, uri, prefixes);
         return prefixes.iterator();
     }
 
@@ -57,4 +56,46 @@
     public void setElement(Element element) {
         this.element = element;
     }
+    
+    public static String rawGetPrefix(Element element, String namespaceURI) {
+        if (element.getNamespaceURI().equals(namespaceURI)) {
+            return element.getNamespacePrefix();
+        }
+
+        List namespaces = element.getAdditionalNamespaces();
+
+        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
+            Namespace ns = (Namespace)itr.next();
+
+            if (ns.getURI().equals(namespaceURI)) {
+                return ns.getPrefix();
+            }
+        }
+
+        if (element.getParentElement() != null) {
+            return rawGetPrefix(element.getParentElement(), namespaceURI);
+        } else {
+            return null;
+        }
+    }
+    
+    static void rawGetPrefixes(Element element, String namespaceURI, List<String> prefixes) {
+        if (element.getNamespaceURI().equals(namespaceURI)) {
+            prefixes.add(element.getNamespacePrefix());
+        }
+
+        List namespaces = element.getAdditionalNamespaces();
+
+        for (Iterator itr = namespaces.iterator(); itr.hasNext();) {
+            Namespace ns = (Namespace)itr.next();
+
+            if (ns.getURI().equals(namespaceURI)) {
+                prefixes.add(ns.getPrefix());
+            }
+        }
+
+        if (element.getParentElement() != null) {
+            rawGetPrefixes(element.getParentElement(), namespaceURI, prefixes);
+        }
+    }
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java Thu Feb 19 14:18:49 2009
@@ -26,7 +26,6 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.jdom.Attribute;
 import org.jdom.CDATA;
 import org.jdom.Comment;
@@ -184,7 +183,7 @@
     }
 
     public String getPrefix(String uri) throws XMLStreamException {
-        return NamespaceHelper.getPrefix(currentNode, uri);
+        return JDOMNamespaceContext.rawGetPrefix(currentNode, uri);
     }
 
     public void setPrefix(String arg0, String arg1) throws XMLStreamException {

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java Thu Feb 19 14:18:49 2009
@@ -21,7 +21,7 @@
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.apache.cxf.aegis.util.NamespaceHelper;
+import org.apache.cxf.aegis.util.stax.JDOMNamespaceContext;
 import org.apache.cxf.aegis.xml.AbstractMessageWriter;
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.jdom.Attribute;
@@ -44,7 +44,7 @@
     }
 
     public void writeValue(Object value, String ns, String attr) {
-        String prefix = NamespaceHelper.getUniquePrefix(element, ns);
+        String prefix = getUniquePrefix(element, ns);
 
         element.setAttribute(new Attribute(attr, value.toString(), Namespace.getNamespace(prefix, ns)));
     }
@@ -54,7 +54,7 @@
     }
 
     public MessageWriter getElementWriter(String name, String namespace) {
-        String prefix = NamespaceHelper.getUniquePrefix(element, namespace);
+        String prefix = getUniquePrefix(element, namespace);
 
         Element child = new Element(name, Namespace.getNamespace(prefix, namespace));
         element.addContent(child);
@@ -67,17 +67,17 @@
     }
 
     public String getPrefixForNamespace(String namespace) {
-        return NamespaceHelper.getUniquePrefix(element, namespace);
+        return getUniquePrefix(element, namespace);
     }
 
     public XMLStreamWriter getXMLStreamWriter() {
-        throw new UnsupportedOperationException("Stream writing not supported from a JDOMWriter.");
+        throw new UnsupportedOperationException("Stream writing not supported from a W3CDOMWriter.");
     }
 
     public String getPrefixForNamespace(String namespace, String hint) {
         // todo: this goes for the option of ignoring the hint - we should
         // probably at least attempt to honour it
-        return NamespaceHelper.getUniquePrefix(element, namespace);
+        return getUniquePrefix(element, namespace);
     }
 
     public MessageWriter getAttributeWriter(String name) {
@@ -89,7 +89,7 @@
     public MessageWriter getAttributeWriter(String name, String namespace) {
         Attribute att;
         if (namespace != null && namespace.length() > 0) {
-            String prefix = NamespaceHelper.getUniquePrefix(element, namespace);
+            String prefix = getUniquePrefix(element, namespace);
             att = new Attribute(name, "", Namespace.getNamespace(prefix, namespace));
         } else {
             att = new Attribute(name, "");
@@ -105,4 +105,32 @@
 
     public void close() {
     }
+    
+    private static String getUniquePrefix(Element el) {
+        int n = 1;
+
+        while (true) {
+            String nsPrefix = "ns" + n;
+
+            if (el.getNamespace(nsPrefix) == null) {
+                return nsPrefix;
+            }
+
+            n++;
+        }
+    }
+    
+    private static String getUniquePrefix(Element element, String namespaceURI) {
+        String prefix = JDOMNamespaceContext.rawGetPrefix(element, namespaceURI);
+
+        // it is OK to have both namespace URI and prefix be empty. 
+        if (prefix == null) {
+            if ("".equals(namespaceURI)) {
+                return "";
+            }
+            prefix = getUniquePrefix(element);
+            element.addNamespaceDeclaration(Namespace.getNamespace(prefix, namespaceURI));
+        }
+        return prefix;
+    }
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java Thu Feb 19 14:18:49 2009
@@ -162,6 +162,7 @@
     public void close() {
         try {
             writer.writeEndElement();
+            writer.flush();
         } catch (XMLStreamException e) {
             throw new DatabindingException("Error writing document.", e);
         }
@@ -207,13 +208,18 @@
     public String getPrefixForNamespace(String ns, String hint) {
         try {
             String pfx = writer.getPrefix(ns);
+            String contextPfx = writer.getNamespaceContext().getPrefix(ns);
 
             if (pfx == null) {
                 String ns2 = writer.getNamespaceContext().getNamespaceURI(hint);
-                if (ns2 == null) {
+                // if the hint is "" (the default) and the context does 
+                if (ns2 == null && !"".equals(hint)) { 
                     pfx = hint;
-                } else if (ns2.equals(ns)) {
-                    return pfx;
+                } else if (ns.equals(ns2)) {
+                    // just because it's in the context, doesn't mean it has been written.
+                    pfx = hint;
+                } else if (contextPfx != null) {
+                    pfx = contextPfx;
                 } else {
                     pfx = NamespaceHelper.getUniquePrefix(writer);
                 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java Thu Feb 19 14:18:49 2009
@@ -26,27 +26,40 @@
 import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMResult;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.binding.soap.SoapBindingConstants;
 import org.apache.cxf.binding.soap.SoapBindingFactory;
 import org.apache.cxf.binding.soap.SoapTransportFactory;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.util.SOAPConstants;
+import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerRegistry;
 import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
 import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.MapNamespaceContext;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.test.AbstractCXFTest;
 import org.apache.cxf.transport.ConduitInitiatorManager;
 import org.apache.cxf.transport.DestinationFactoryManager;
@@ -55,13 +68,13 @@
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
 import org.apache.cxf.wsdl11.WSDLDefinitionBuilder;
 import org.apache.cxf.wsdl11.WSDLManagerImpl;
-import org.jdom.Element;
-import org.jdom.output.DOMOutputter;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.junit.Before;
 
 public abstract class AbstractAegisTest extends AbstractCXFTest {
     protected LocalTransportFactory localTransport;
-
+    private boolean enableJDOM;
 
     @Before
     public void setUp() throws Exception {
@@ -80,7 +93,7 @@
         dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/", soapDF);
         dfm.registerDestinationFactory(SoapBindingConstants.SOAP11_BINDING_ID, soapDF);
         dfm.registerDestinationFactory("http://cxf.apache.org/transports/local", soapDF);
-        
+
         localTransport = new LocalTransportFactory();
         dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", localTransport);
         dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", localTransport);
@@ -92,15 +105,13 @@
         extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", localTransport);
         extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport);
         extension.registerConduitInitiator(SoapBindingConstants.SOAP11_BINDING_ID, localTransport);
-        
+
         bus.setExtension(new WSDLManagerImpl(), WSDLManager.class);
-        
 
         addNamespace("wsdl", SOAPConstants.WSDL11_NS);
         addNamespace("wsdlsoap", SOAPConstants.WSDL11_SOAP_NS);
         addNamespace("xsd", SOAPConstants.XSD);
 
-
     }
 
     @Override
@@ -109,87 +120,108 @@
         BusFactory.setDefaultBus(bus);
         return bus;
     }
-    
+
     protected Node invoke(String service, String message) throws Exception {
         return invoke("local://" + service, LocalTransportFactory.TRANSPORT_ID, message);
     }
-    
+
     public Server createService(Class serviceClass, QName name) {
         return createService(serviceClass, null, name);
     }
-    
+
     public Server createService(Class serviceClass, Object serviceBean, QName name) {
         return createService(serviceClass, serviceBean, serviceClass.getSimpleName(), name);
     }
-    
+
     protected Server createService(Class serviceClass, QName name, AegisDatabinding binding) {
         return createService(serviceClass, serviceClass.getSimpleName(), name, binding);
     }
 
-    protected Server createService(Class serviceClass, 
-                                   String address, QName name, 
-                                    AegisDatabinding binding) {
+    protected Server createService(Class serviceClass, String address, QName name, AegisDatabinding binding) {
         ServerFactoryBean sf = createServiceFactory(serviceClass, null, address, name, binding);
         return sf.create();
     }
-    
+
     protected Server createService(Class serviceClass, String address) {
         ServerFactoryBean sf = createServiceFactory(serviceClass, null, address, null, null);
         return sf.create();
     }
-    
+
     protected Server createService(Class serviceClass) {
-        ServerFactoryBean sf = createServiceFactory(serviceClass, null, 
-                                                    serviceClass.getSimpleName(), null, null);
+        ServerFactoryBean sf = createServiceFactory(serviceClass, null, serviceClass.getSimpleName(), null,
+                                                    null);
         return sf.create();
     }
-    
-    public Server createService(Class serviceClass,
-                                Object serviceBean, 
-                                String address,
-                                QName name) {
+
+    protected Server createJaxwsService(Class serviceClass, Object serviceBean, String address, QName name) {
+        if (address == null) {
+            address = serviceClass.getSimpleName();
+        }
+        JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean();
+        sf.setDataBinding(new AegisDatabinding());
+        JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
+        serverFactoryBean.setServiceClass(serviceClass);
+        
+        if (serviceBean != null) {
+            serverFactoryBean.setServiceBean(serviceBean);
+        }
+
+        serverFactoryBean.setAddress("local://" + address);
+            
+        serverFactoryBean.setServiceFactory(sf);
+        if (name != null) {
+            serverFactoryBean.setEndpointName(name);
+        }
+        return serverFactoryBean.create();
+    }
+
+    public Server createService(Class serviceClass, Object serviceBean, String address, QName name) {
         ServerFactoryBean sf = createServiceFactory(serviceClass, serviceBean, address, name, null);
         return sf.create();
     }
-    
-    public Server createService(Class serviceClass,
-                                Object serviceBean, 
-                                String address,
+
+    public Server createService(Class serviceClass, Object serviceBean, String address,
                                 AegisDatabinding binding) {
         ServerFactoryBean sf = createServiceFactory(serviceClass, serviceBean, address, null, binding);
         return sf.create();
     }
 
-    protected ServerFactoryBean createServiceFactory(Class serviceClass, 
-                                                     Object serviceBean, 
-                                                     String address, 
-                                                     QName name,
-                                                     AegisDatabinding binding) {
+    protected ServerFactoryBean createServiceFactory(Class serviceClass, Object serviceBean, String address,
+                                                     QName name, AegisDatabinding binding) {
         ServerFactoryBean sf = new ServerFactoryBean();
         sf.setServiceClass(serviceClass);
         if (serviceBean != null) {
             sf.setServiceBean(serviceBean);
-        }    
+        }
         sf.getServiceFactory().setServiceName(name);
         sf.setAddress("local://" + address);
         setupAegis(sf, binding);
         return sf;
     }
-    protected void setupAegis(AbstractWSDLBasedEndpointFactory sf) { 
+
+    protected void setupAegis(AbstractWSDLBasedEndpointFactory sf) {
         setupAegis(sf, null);
     }
+
     @SuppressWarnings("deprecation")
     protected void setupAegis(AbstractWSDLBasedEndpointFactory sf, AegisDatabinding binding) {
         if (binding == null) {
+            AegisContext context = new AegisContext();
+            if (enableJDOM) {
+                context.setEnableJDOMMappings(true);
+            }
             binding = new AegisDatabinding();
+            if (enableJDOM) { // this preserves pre-2.1 behavior.
+                binding.setAegisContext(context);
+            }
         }
-        sf.getServiceFactory().getServiceConfigurations().add(0, 
-            new org.apache.cxf.aegis.databinding.AegisServiceConfiguration());
+        sf.getServiceFactory().getServiceConfigurations()
+            .add(0, new org.apache.cxf.aegis.databinding.AegisServiceConfiguration());
         sf.getServiceFactory().setDataBinding(binding);
     }
 
     protected Collection<Document> getWSDLDocuments(String string) throws WSDLException {
-        WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();        
+        WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
 
         Collection<Document> docs = new ArrayList<Document>();
         Definition definition = getWSDLDefinition(string);
@@ -197,7 +229,7 @@
             return null;
         }
         docs.add(writer.getDocument(definition));
-        
+
         for (Import wsdlImport : WSDLDefinitionBuilder.getImports(definition)) {
             docs.add(writer.getDocument(wsdlImport.getDefinition()));
         }
@@ -214,26 +246,9 @@
             }
         }
         return null;
-        
-    }
-    
-    protected void assertXPathEquals(String xpath, String value, Element element) throws Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-        assertXPathEquals(xpath, value, doc);
-    }
-    
-    protected NodeList assertValid(String xpath, Element element) throws Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-        
-        return assertValid(xpath, doc);
-    }
 
-    protected void assertInvalid(String xpath, Element element) throws Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-        
-        assertInvalid(xpath, doc);
     }
-    
+
     protected Document getWSDLDocument(String string) throws WSDLException {
         Definition definition = getWSDLDefinition(string);
         if (definition == null) {
@@ -242,10 +257,76 @@
         WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
         return writer.getDocument(definition);
     }
-    
+
     protected Context getContext() {
         AegisContext globalContext = new AegisContext();
         globalContext.initialize();
         return new Context(globalContext);
     }
+    
+    protected XmlSchema newXmlSchema(String targetNamespace) {
+        XmlSchema s = new XmlSchema();
+        s.setTargetNamespace(targetNamespace);
+        NamespaceMap xmlsNamespaceMap = new NamespaceMap();
+        s.setNamespaceContext(xmlsNamespaceMap);
+
+        // tns: is conventional, and besides we have unit tests that are hardcoded to it.
+        xmlsNamespaceMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, targetNamespace);
+        
+        // ditto for xsd: instead of just namespace= for the schema schema.
+        xmlsNamespaceMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
+        return s;
+    }
+    
+    protected Element createElement(String namespace, String name) {
+        return createElement(namespace, name, null);
+    }
+
+    protected Element createElement(String namespace, String name, String namespacePrefix) {
+        Document doc = DOMUtils.createDocument();
+
+        Element element = doc.createElementNS(namespace, name);
+        if (namespacePrefix != null) {
+            element.setPrefix(namespacePrefix);
+            DOMUtils.addNamespacePrefix(element, namespace, namespacePrefix);
+        }
+
+        doc.appendChild(element);
+        return element;
+    }
+    
+    protected ElementWriter getElementWriter(Element element) {
+        return getElementWriter(element, new MapNamespaceContext());
+    }
+
+    protected ElementWriter getElementWriter(Element element, NamespaceContext namespaceContext) {
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(new DOMResult(element));
+        try {
+            writer.setNamespaceContext(namespaceContext);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return new ElementWriter(writer);
+    }
+
+    protected Element writeObjectToElement(Type type, Object bean) {
+        return writeObjectToElement(type, bean, getContext());
+    }
+
+    protected Element writeObjectToElement(Type type, Object bean, Context context) {
+        Element element = createElement("urn:Bean", "root", "b");
+        ElementWriter writer = getElementWriter(element, new MapNamespaceContext());
+        type.writeObject(bean, writer, getContext());
+        writer.close();
+        return element;
+    }
+
+    protected boolean isEnableJDOM() {
+        return enableJDOM;
+    }
+
+    protected void setEnableJDOM(boolean enableJDOM) {
+        this.enableJDOM = enableJDOM;
+    }
+    
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/custom/CustomMappingTest.java Thu Feb 19 14:18:49 2009
@@ -27,7 +27,8 @@
 import org.apache.cxf.aegis.type.TypeMapping;
 import org.apache.cxf.aegis.type.basic.BeanType;
 import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
-import org.jdom.Element;
+import org.apache.ws.commons.schema.XmlSchema;
+
 import org.junit.Test;
 
 /**
@@ -44,8 +45,9 @@
         TypeMapping mapping = context.getTypeMapping();
         // we are replacing the default mapping.
         mapping.register(beanType);
-        Element root = new Element("dummySchema");
-        beanType.writeSchema(root);
+        XmlSchema schema = newXmlSchema("http://util.java");
+        beanType.writeSchema(schema);
+        // well, test?
     }
 
 }

Modified: cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/ParameterMappingTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/ParameterMappingTest.java?rev=745879&r1=745878&r2=745879&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/ParameterMappingTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/integration/ParameterMappingTest.java Thu Feb 19 14:18:49 2009
@@ -40,6 +40,7 @@
     @Before 
     public void setUp() throws Exception {
         super.setUp();
+        setEnableJDOM(true); // there are JDOM types in here.
         createService(AddNumbers.class, "AddNumbers", null);
         createService(ArrayService.class, "ArrayService", null);
     }
@@ -70,7 +71,7 @@
         WSDLFactory.newInstance().newWSDLWriter().writeWSDL(def, sink);
         assertXPathEquals("/wsdl:definitions/wsdl:types/"
                     + "xsd:schema[@targetNamespace= 'http://services.aegis.cxf.apache.org']"
-                    + "/xsd:complexType[@name='ArrayOfString-50-2']" 
+                    + "/xsd:complexType[@name='ArrayOfString-2-50']" 
                     + "/xsd:sequence" 
                     + "/xsd:element[@name='string']/@minOccurs", "2", doc);
     }



Mime
View raw message