You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/09/26 16:11:46 UTC

svn commit: r450054 [5/8] - in /incubator/servicemix/trunk/sandbox/servicemix-soap2: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/servicemix/ src/main/java/org/apache/servicemix/soap/ src/main/j...

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/QNameUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/QNameUtil.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/QNameUtil.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/QNameUtil.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
+/**
+ * Utilities for converting QNames into different representations
+ * 
+ * @author Alex Boisvert
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class QNameUtil {
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(QName qname) {
+        if (qname.getNamespaceURI() == null) {
+            return "{}" + qname.getLocalPart();
+        } else {
+            return "{" + qname.getNamespaceURI() + "}" + qname.getLocalPart();
+        }
+    }
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(Element element) {
+        if (element.getNamespaceURI() == null) {
+            return "{}" + element.getLocalName();
+        } else {
+            return "{" + element.getNamespaceURI() + "}" + element.getLocalName();
+        }
+    }
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(Attr attr) {
+        if (attr.getNamespaceURI() == null) {
+            return "{}" + attr.getLocalName();
+        } else {
+            return "{" + attr.getNamespaceURI() + "}" + attr.getLocalName();
+        }
+    }
+
+    public static String toString(Collection collection) {
+        StringBuffer buf = new StringBuffer();
+        Iterator iter = collection.iterator();
+        while (iter.hasNext()) {
+            QName qname = (QName) iter.next();
+            buf.append(toString(qname));
+            if (iter.hasNext()) {
+                buf.append(", ");
+            }
+        }
+        return buf.toString();
+    }
+    
+    /**
+     * Convert a String back into a QName following the Clark notation
+     */
+    public static QName parse(String name) {
+        int pos = name.indexOf('}');
+        if (name.startsWith("{") && pos > 0) {
+            String ns = name.substring(1, pos);
+            String lname = name.substring(pos + 1, name.length());
+            return new QName(ns, lname);
+        }
+        return null;
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/StreamDataSource.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/StreamDataSource.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/StreamDataSource.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/StreamDataSource.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+/**
+ * Stream DataSource for Mail and message attachments .
+ * @author <a href="mailto:gnodet@logicblaze.com"> Guillaume Nodet</a>
+ * @since 3.0
+ */
+public class StreamDataSource implements DataSource {
+
+	private InputStream in;
+	private String contentType;
+	private String name;
+	
+	public StreamDataSource(InputStream in) {
+		this(in, null, null);
+	}
+
+	public StreamDataSource(InputStream in, String contentType) {
+		this(in, contentType, null);
+	}
+
+	public StreamDataSource(InputStream in, String contentType, String name) {
+		this.in = in;
+		this.contentType = contentType;
+		this.name = name;
+	}
+
+	public InputStream getInputStream() throws IOException {
+		if (in == null) throw new IOException("no data");
+		return in;
+	}
+
+	public OutputStream getOutputStream() throws IOException {
+    	throw new IOException("getOutputStream() not supported");
+	}
+
+	public String getContentType() {
+		return contentType;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public void setContentType(String contentType) {
+		this.contentType = contentType;
+	}
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/DOMStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/DOMStreamReader.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/DOMStreamReader.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/DOMStreamReader.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,629 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+/*
+ * This implementation comes from the XFire project
+ * https://svn.codehaus.org/xfire/trunk/xfire/xfire-core/src/main/org/codehaus/xfire/util/stax/
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Abstract logic for creating XMLStreamReader from DOM documents.
+ * Its works using adapters for Element, Node and Attribute ( @see ElementAdapter }
+ * 
+ * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a>
+ */
+public class DOMStreamReader implements XMLStreamReader {
+    public Map properties = new HashMap();
+
+    private ArrayList<ElementFrame> frames = new ArrayList<ElementFrame>();
+
+    private ElementFrame frame;
+
+    private int currentEvent = XMLStreamConstants.START_DOCUMENT;
+
+    private Node content;
+
+    private Document document;
+
+    private DOMNamespaceContext context;
+
+    /**
+     * @param element
+     */
+    public DOMStreamReader(Element element) {
+        this.frame = new ElementFrame(element, null);
+        frames.add(this.frame);
+        newFrame(frame);
+        this.document = element.getOwnerDocument();
+    }
+
+    protected ElementFrame getCurrentFrame() {
+        return frame;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#getProperty(java.lang.String)
+     */
+    public Object getProperty(String key) throws IllegalArgumentException {
+        return properties.get(key);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#next()
+     */
+    public int next() throws XMLStreamException {
+        if (frame.ended) {
+            frames.remove(frames.size() - 1);
+            if (!frames.isEmpty()) {
+                frame = (ElementFrame) frames.get(frames.size() - 1);
+            } else {
+                currentEvent = END_DOCUMENT;
+                return currentEvent;
+            }
+        }
+
+        if (!frame.started) {
+            frame.started = true;
+            currentEvent = START_ELEMENT;
+        } else if (frame.currentAttribute < getAttributeCount() - 1) {
+            frame.currentAttribute++;
+            currentEvent = ATTRIBUTE;
+        } else if (frame.currentNamespace < getNamespaceCount() - 1) {
+            frame.currentNamespace++;
+            currentEvent = NAMESPACE;
+        } else if (frame.currentChild < getChildCount() - 1) {
+            frame.currentChild++;
+
+            currentEvent = moveToChild(frame.currentChild);
+
+            if (currentEvent == START_ELEMENT) {
+                ElementFrame newFrame = getChildFrame(frame.currentChild);
+                newFrame.started = true;
+                frame = newFrame;
+                frames.add(this.frame);
+                currentEvent = START_ELEMENT;
+
+                newFrame(newFrame);
+            }
+        } else {
+            frame.ended = true;
+            currentEvent = END_ELEMENT;
+            endElement();
+        }
+        return currentEvent;
+    }
+
+    protected void skipFrame() {
+        frame.ended = true;
+        currentEvent = END_ELEMENT;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#require(int, java.lang.String, java.lang.String)
+     */
+    public void require(int arg0, String arg1, String arg2) throws XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#nextTag()
+     */
+    public int nextTag() throws XMLStreamException {
+        while (hasNext()) {
+            int e = next();
+            if (e == START_ELEMENT || e == END_ELEMENT)
+                return e;
+        }
+
+        return currentEvent;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#hasNext()
+     */
+    public boolean hasNext() throws XMLStreamException {
+        return !(frames.size() == 0 && frame.ended);
+
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#close()
+     */
+    public void close() throws XMLStreamException {
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#isStartElement()
+     */
+    public boolean isStartElement() {
+        return (currentEvent == START_ELEMENT);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#isEndElement()
+     */
+    public boolean isEndElement() {
+        return (currentEvent == END_ELEMENT);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#isCharacters()
+     */
+    public boolean isCharacters() {
+        return (currentEvent == CHARACTERS);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.xml.stream.XMLStreamReader#isWhiteSpace()
+     */
+    public boolean isWhiteSpace() {
+        return (currentEvent == SPACE);
+    }
+
+    public int getEventType() {
+        return currentEvent;
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
+        char[] src = getText().toCharArray();
+
+        if (sourceStart + length >= src.length)
+            length = src.length - sourceStart;
+
+        for (int i = 0; i < length; i++) {
+            target[targetStart + i] = src[i + sourceStart];
+        }
+
+        return length;
+    }
+
+    public boolean hasText() {
+        return (currentEvent == CHARACTERS || currentEvent == DTD || currentEvent == ENTITY_REFERENCE
+                        || currentEvent == COMMENT || currentEvent == SPACE);
+    }
+
+    public Location getLocation() {
+        return new Location() {
+
+            public int getCharacterOffset() {
+                return 0;
+            }
+
+            public int getColumnNumber() {
+                return 0;
+            }
+
+            public int getLineNumber() {
+                return 0;
+            }
+
+            public String getPublicId() {
+                return null;
+            }
+
+            public String getSystemId() {
+                return null;
+            }
+
+        };
+    }
+
+    public boolean hasName() {
+        return (currentEvent == START_ELEMENT || currentEvent == END_ELEMENT);
+    }
+
+    public String getVersion() {
+        return null;
+    }
+
+    public boolean isStandalone() {
+        return false;
+    }
+
+    public boolean standaloneSet() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public String getCharacterEncodingScheme() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /**
+     * Get the document associated with this stream.
+     * 
+     * @return
+     */
+    public Document getDocument() {
+        return document;
+    }
+
+    /**
+     * Find name spaces declaration in attributes and move them to separate
+     * collection.
+     */
+    protected void newFrame(ElementFrame frame) {
+        Element element = getCurrentElement();
+        frame.uris = new ArrayList<String>();
+        frame.prefixes = new ArrayList<String>();
+        frame.attributes = new ArrayList<Node>();
+
+        if (context == null)
+            context = new DOMNamespaceContext();
+
+        context.setElement(element);
+
+        NamedNodeMap nodes = element.getAttributes();
+
+        String ePrefix = element.getPrefix();
+        if (ePrefix == null) {
+            ePrefix = "";
+        }
+
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Node node = nodes.item(i);
+            String prefix = node.getPrefix();
+            String localName = node.getLocalName();
+            String value = node.getNodeValue();
+            String name = node.getNodeName();
+
+            if (prefix == null)
+                prefix = "";
+
+            if (name != null && name.equals("xmlns")) {
+                frame.uris.add(value);
+                frame.prefixes.add("");
+            } else if (prefix.length() > 0 && prefix.equals("xmlns")) {
+                frame.uris.add(value);
+                frame.prefixes.add(localName);
+            } else if (name.startsWith("xmlns:")) {
+                prefix = name.substring(6);
+                frame.uris.add(value);
+                frame.prefixes.add(prefix);
+            } else {
+                frame.attributes.add(node);
+            }
+        }
+    }
+
+    protected void endElement() {
+    }
+
+    protected Element getCurrentElement() {
+        return (Element) getCurrentFrame().element;
+    }
+
+    public Element skipElement() {
+        Element e = (Element) getCurrentFrame().element;
+        skipFrame();
+        return e;
+    }
+
+    protected ElementFrame getChildFrame(int currentChild) {
+        return new ElementFrame(getCurrentElement().getChildNodes().item(currentChild), getCurrentFrame());
+    }
+
+    protected int getChildCount() {
+        return getCurrentElement().getChildNodes().getLength();
+    }
+
+    protected int moveToChild(int currentChild) {
+        this.content = getCurrentElement().getChildNodes().item(currentChild);
+
+        if (content instanceof Text)
+            return CHARACTERS;
+        else if (content instanceof Element)
+            return START_ELEMENT;
+        else if (content instanceof CDATASection)
+            return CDATA;
+        else if (content instanceof Comment)
+            return CHARACTERS;
+        else if (content instanceof EntityReference)
+            return ENTITY_REFERENCE;
+
+        throw new IllegalStateException();
+    }
+
+    public String getElementText() throws XMLStreamException {
+        return getText();
+    }
+
+    public String getNamespaceURI(String prefix) {
+        ElementFrame frame = getCurrentFrame();
+
+        while (null != frame) {
+            int index = frame.prefixes.indexOf(prefix);
+            if (index != -1) {
+                return (String) frame.uris.get(index);
+            }
+
+            frame = frame.parent;
+        }
+
+        return null;
+    }
+
+    public String getAttributeValue(String ns, String local) {
+        if (ns == null || ns.equals(""))
+            return getCurrentElement().getAttribute(local);
+        else
+            return getCurrentElement().getAttributeNS(ns, local);
+    }
+
+    public int getAttributeCount() {
+        return getCurrentFrame().attributes.size();
+    }
+
+    Attr getAttribute(int i) {
+        return (Attr) getCurrentFrame().attributes.get(i);
+    }
+
+    private String getLocalName(Attr attr) {
+
+        String name = attr.getLocalName();
+        if (name == null) {
+            name = attr.getNodeName();
+        }
+        return name;
+    }
+
+    public QName getAttributeName(int i) {
+        Attr at = getAttribute(i);
+
+        String prefix = at.getPrefix();
+        String ln = getLocalName(at);
+        // at.getNodeName();
+        String ns = at.getNamespaceURI();
+
+        if (prefix == null) {
+            return new QName(ns, ln);
+        } else {
+            return new QName(ns, ln, prefix);
+        }
+    }
+
+    public String getAttributeNamespace(int i) {
+        return getAttribute(i).getNamespaceURI();
+    }
+
+    public String getAttributeLocalName(int i) {
+        Attr attr = getAttribute(i);
+        String name = getLocalName(attr);
+        return name;
+    }
+
+    public String getAttributePrefix(int i) {
+        return getAttribute(i).getPrefix();
+    }
+
+    public String getAttributeType(int i) {
+        return toStaxType(getAttribute(i).getNodeType());
+    }
+
+    public static String toStaxType(short jdom) {
+        switch (jdom) {
+        default:
+            return null;
+        }
+    }
+
+    public String getAttributeValue(int i) {
+        return getAttribute(i).getValue();
+    }
+
+    public boolean isAttributeSpecified(int i) {
+        return getAttribute(i).getValue() != null;
+    }
+
+    public int getNamespaceCount() {
+        return getCurrentFrame().prefixes.size();
+    }
+
+    public String getNamespacePrefix(int i) {
+        return (String) getCurrentFrame().prefixes.get(i);
+    }
+
+    public String getNamespaceURI(int i) {
+        return (String) getCurrentFrame().uris.get(i);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        return context;
+    }
+
+    public String getText() {
+        Node node = getCurrentElement().getChildNodes().item(getCurrentFrame().currentChild);
+        return node.getNodeValue();
+    }
+
+    public char[] getTextCharacters() {
+        return getText().toCharArray();
+    }
+
+    public int getTextStart() {
+        return 0;
+    }
+
+    public int getTextLength() {
+        return getText().length();
+    }
+
+    public String getEncoding() {
+        return null;
+    }
+
+    public QName getName() {
+        Element el = getCurrentElement();
+
+        String prefix = getPrefix();
+        String ln = getLocalName();
+
+        if (prefix == null) {
+            return new QName(el.getNamespaceURI(), ln);
+        } else {
+            return new QName(el.getNamespaceURI(), ln, prefix);
+        }
+    }
+
+    public String getLocalName() {
+        String name = getCurrentElement().getLocalName();
+        // When the element has no namespaces, null is returned
+        if (name == null) {
+            name = getCurrentElement().getNodeName();
+        }
+        return name;
+    }
+
+    public String getNamespaceURI() {
+        return getCurrentElement().getNamespaceURI();
+    }
+
+    public String getPrefix() {
+        String prefix = getCurrentElement().getPrefix();
+        if (prefix == null) {
+            prefix = "";
+        }
+        return prefix;
+    }
+
+    public String getPITarget() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getPIData() {
+        throw new UnsupportedOperationException();
+    }
+
+    public class DOMNamespaceContext implements NamespaceContext {
+        private Element currentNode;
+
+        public String getNamespaceURI(String prefix) {
+            String name = prefix;
+            if (name.length() == 0)
+                name = "xmlns";
+            else
+                name = "xmlns:" + prefix;
+
+            return getNamespaceURI(currentNode, name);
+        }
+
+        private String getNamespaceURI(Element e, String name) {
+            Attr attr = e.getAttributeNode(name);
+            if (attr == null) {
+                Node n = e.getParentNode();
+                if (n instanceof Element && n != e) {
+                    return getNamespaceURI((Element) n, name);
+                }
+            } else {
+                return attr.getValue();
+            }
+
+            return null;
+        }
+
+        public String getPrefix(String uri) {
+            return getPrefix(currentNode, uri);
+        }
+
+        private String getPrefix(Element e, String uri) {
+            NamedNodeMap attributes = e.getAttributes();
+            for (int i = 0; i < attributes.getLength(); i++) {
+                Attr a = (Attr) attributes.item(i);
+
+                String val = a.getValue();
+                if (val != null && val.equals(uri)) {
+                    String name = a.getNodeName();
+                    if (name.equals("xmlns"))
+                        return "";
+                    else
+                        return name.substring(6);
+                }
+            }
+
+            Node n = e.getParentNode();
+            if (n instanceof Element && n != e) {
+                return getPrefix((Element) n, uri);
+            }
+
+            return null;
+        }
+
+        public Iterator<String> getPrefixes(String uri) {
+            List<String> prefixes = new ArrayList<String>();
+
+            String prefix = getPrefix(uri);
+            if (prefix != null)
+                prefixes.add(prefix);
+
+            return prefixes.iterator();
+        }
+
+        public Element getElement() {
+            return currentNode;
+        }
+
+        public void setElement(Element currentNode) {
+            this.currentNode = currentNode;
+        }
+    }
+
+    public static class ElementFrame {
+        public ElementFrame(Object element, ElementFrame parent) {
+            this.element = element;
+            this.parent = parent;
+        }
+
+        final Object element;
+        final ElementFrame parent;
+        boolean started = false;
+        boolean ended = false;
+        int currentChild = -1;
+        int currentAttribute = -1;
+        int currentNamespace = -1;
+        int currentElement = -1;
+        List<String> uris;
+        List<String> prefixes;
+        List<Node> attributes;
+        List allAttributes;
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedNamespaceContext.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedNamespaceContext.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedNamespaceContext.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedNamespaceContext.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+
+public interface ExtendedNamespaceContext extends NamespaceContext {
+
+	/**
+	 * Returns an {@link Iterator} of all namespace prefixes in scope within this
+	 * context, including those inherited from ancestor contexts.
+	 * 
+	 * @return An {@link Iterator} of prefix {@link String}s.
+	 */
+    public Collection<String> getPrefixes();
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedXMLStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedXMLStreamReader.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedXMLStreamReader.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/ExtendedXMLStreamReader.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+public class ExtendedXMLStreamReader extends StreamReaderDelegate {
+
+	private SimpleNamespaceContext context = new SimpleNamespaceContext();
+	
+	public ExtendedXMLStreamReader(XMLStreamReader delegate) {
+		super(delegate);
+	}
+
+	public NamespaceContext getNamespaceContext() {
+		return context;
+	}
+	
+    public int nextTag() throws XMLStreamException {
+    	int eventType = next();
+    	 while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
+	    	 || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) 
+	    	 // skip whitespace
+	    	 || eventType == XMLStreamConstants.SPACE
+	    	 || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+	    	 || eventType == XMLStreamConstants.COMMENT
+	    	 ) {
+	    	 eventType = next();
+    	 }
+    	 if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
+    	 	throw new XMLStreamException("expected start or end tag", getLocation());
+    	 }
+    	 return eventType;
+    }
+
+	public int next() throws XMLStreamException {
+		int next = super.next();
+		if (next == START_ELEMENT) {
+			context = new SimpleNamespaceContext(context, getNamespaces());
+		} else if (next == END_ELEMENT) {
+			context = context.getParent();
+		}
+		return next;
+	}
+
+	private Map<String, String> getNamespaces() {
+		Map<String,String> ns = new HashMap<String,String>();
+		for (int i = 0; i < getNamespaceCount(); i++) {
+			ns.put(getNamespacePrefix(i), getNamespaceURI(i));
+		}
+		return ns;
+	}
+	
+	public static class SimpleNamespaceContext implements ExtendedNamespaceContext {
+
+		private SimpleNamespaceContext parent;
+		private Map<String,String> namespaces;
+		
+		public SimpleNamespaceContext() {
+			namespaces = new HashMap<String,String>();
+		}
+
+		public SimpleNamespaceContext(SimpleNamespaceContext parent, Map<String,String> namespaces) {
+			this.parent = parent;
+			this.namespaces = namespaces;
+		}
+
+		public SimpleNamespaceContext getParent() {
+			return parent;
+		}
+		
+		public Collection<String> getPrefixes() {
+			HashSet<String> prefixes = new HashSet<String>();
+			for (SimpleNamespaceContext context = this; context != null; context = context.parent) {
+				prefixes.addAll(context.namespaces.keySet());
+			}
+			return prefixes;
+		}
+
+		public String getNamespaceURI(String prefix) {
+			String uri = namespaces.get(prefix);
+			if (uri == null && parent != null) {
+				uri = parent.getNamespaceURI(prefix);
+			}
+			return uri;
+		}
+
+		public String getPrefix(String namespaceURI) {
+			for (SimpleNamespaceContext context = this; context != null; context = context.parent) {
+                for (Map.Entry<String, String> entry : context.namespaces.entrySet()) {
+					if (entry.getValue().equals(namespaceURI)) {
+						return entry.getKey();
+					}
+				}
+			}
+			return null;
+		}
+
+		public Iterator<String> getPrefixes(String namespaceURI) {
+			HashSet<String> prefixes = new HashSet<String>();
+            for (SimpleNamespaceContext context = this; context != null; context = context.parent) {
+                for (Map.Entry<String, String> entry : context.namespaces.entrySet()) {
+                    if (entry.getValue().equals(namespaceURI)) {
+						prefixes.add(entry.getKey());
+					}
+				}
+			}
+			return prefixes.iterator();
+		}
+		
+	}
+
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/FragmentStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/FragmentStreamReader.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/FragmentStreamReader.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/FragmentStreamReader.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+public class FragmentStreamReader extends StreamReaderDelegate implements XMLStreamReader {
+
+	private static final int STATE_START_DOC = 0;
+	private static final int STATE_FIRST_ELEM = 1;
+	private static final int STATE_FIRST_RUN = 2;
+	private static final int STATE_RUN = 3;
+	private static final int STATE_END_DOC = 4;
+	
+	private int depth;
+	private int state = STATE_START_DOC;
+	private int event = START_DOCUMENT;
+    private List<String> rootPrefixes;
+	
+	public FragmentStreamReader(XMLStreamReader parent) {
+		super(parent);
+        NamespaceContext ctx = getParent().getNamespaceContext();
+        if (ctx instanceof ExtendedNamespaceContext) {
+            rootPrefixes = new ArrayList<String>(((ExtendedNamespaceContext) ctx).getPrefixes());
+        }
+	}
+	
+	public int getEventType() {
+		return event;
+	}
+
+	public int next() throws XMLStreamException {
+		switch (state) {
+		case STATE_START_DOC:
+			state = STATE_FIRST_ELEM;
+			event = START_DOCUMENT;
+			break;
+		case STATE_FIRST_ELEM:
+			state = STATE_FIRST_RUN;
+			depth++;
+			event = START_ELEMENT;
+			break;
+		case STATE_FIRST_RUN:
+			state = STATE_RUN;
+			// do not break
+		case STATE_RUN:
+			event = getParent().next();
+			if (event == START_ELEMENT) {
+				depth++;
+			} else if (event == END_ELEMENT) {
+				depth--;
+				if (depth == 0) {
+					state = STATE_END_DOC;
+				}
+			}
+			break;
+		case STATE_END_DOC:
+			event = END_DOCUMENT;
+			break;
+		default:
+			throw new IllegalStateException();
+		}
+		return event;
+	}
+
+    public int nextTag() throws XMLStreamException {
+        int eventType = next();
+        while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
+            || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace
+            || eventType == XMLStreamConstants.SPACE
+            || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+            || eventType == XMLStreamConstants.COMMENT) {
+            eventType = next();
+         }
+         if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
+             throw new XMLStreamException("expected start or end tag", getLocation());
+         }
+         return eventType;    
+    }
+    
+    public int getNamespaceCount() {
+        if (state == STATE_FIRST_RUN && rootPrefixes != null) {
+            return rootPrefixes.size();
+        } else {
+            return getParent().getNamespaceCount();
+        }
+    }
+    
+    public String getNamespacePrefix(int i) {
+        if (state == STATE_FIRST_RUN && rootPrefixes != null) {
+            return (String) rootPrefixes.get(i);
+        } else {
+            return getParent().getNamespacePrefix(i);
+        }
+    }
+    
+    public String getNamespaceURI(int i) {
+        if (state == STATE_FIRST_RUN) {
+            return getParent().getNamespaceContext().getNamespaceURI(rootPrefixes.get(i));
+        } else {
+            return getParent().getNamespaceURI(i);
+        }
+    }
+    
+    public String getNamespaceURI(String prefix) {
+        if (state == STATE_FIRST_RUN) {
+            return getParent().getNamespaceContext().getNamespaceURI(prefix);
+        } else {
+            return getParent().getNamespaceURI(prefix);
+        }
+    }
+    
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxSource.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import javax.xml.XMLConstants;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.sax.SAXSource;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.AttributesImpl;
+
+public class StaxSource extends SAXSource implements XMLReader {
+
+    private XMLStreamReader streamReader;
+
+    private ContentHandler contentHandler;
+
+    public StaxSource(XMLStreamReader streamReader) {
+        this.streamReader = streamReader;
+        setInputSource(new InputSource());
+    }
+
+    public XMLReader getXMLReader() {
+        return this;
+    }
+
+    protected void parse() throws SAXException {
+        try {
+            contentHandler.startDocument();
+            while (true) {
+                switch (streamReader.getEventType()) {
+                case XMLStreamConstants.ATTRIBUTE:
+                case XMLStreamConstants.CDATA:
+                    break;
+                case XMLStreamConstants.CHARACTERS:
+                    if (!streamReader.isWhiteSpace()) {
+                        
+                        int length = streamReader.getTextLength();
+                        int start = streamReader.getTextStart();
+                        char[] chars = streamReader.getTextCharacters();
+                        contentHandler.characters(chars, start, length);
+                        /*
+                        for (int textLength = streamReader.getTextLength(); textLength > 0; textLength -= chars.length) {
+                            int l = Math.min(textLength, chars.length);
+                            streamReader.getTextCharacters(0, chars, 0, l);
+                            contentHandler.characters(chars, 0, l);
+                        }
+                        */
+                    }
+                    break;
+                case XMLStreamConstants.COMMENT:
+                case XMLStreamConstants.DTD:
+                    break;
+                case XMLStreamConstants.END_DOCUMENT:
+                    contentHandler.endDocument();
+                    return;
+                case XMLStreamConstants.END_ELEMENT: {
+                    String uri = streamReader.getNamespaceURI();
+                    String localName = streamReader.getLocalName();
+                    String prefix = streamReader.getPrefix();
+                    String qname = prefix != null && prefix.length() > 0 ? prefix + ":" + localName : localName;
+                    contentHandler.endElement(uri, localName, qname);
+                    for (int i = 0; i < streamReader.getNamespaceCount(); i++) {
+                        //contentHandler.endPrefixMapping(streamReader.getNamespaceURI(i));
+                    }
+                    break;
+                }
+                case XMLStreamConstants.ENTITY_DECLARATION:
+                case XMLStreamConstants.ENTITY_REFERENCE:
+                case XMLStreamConstants.NAMESPACE:
+                case XMLStreamConstants.NOTATION_DECLARATION:
+                case XMLStreamConstants.PROCESSING_INSTRUCTION:
+                case XMLStreamConstants.SPACE:
+                case XMLStreamConstants.START_DOCUMENT:
+                    break;
+                case XMLStreamConstants.START_ELEMENT: {
+                    for (int i = 0; i < streamReader.getNamespaceCount(); i++) {
+                        //contentHandler.startPrefixMapping(streamReader.getNamespacePrefix(i),
+                        //                                  streamReader.getNamespaceURI(i));
+                    }
+                    String uri = streamReader.getNamespaceURI();
+                    String localName = streamReader.getLocalName();
+                    String prefix = streamReader.getPrefix();
+                    String qname = prefix != null && prefix.length() > 0 ? prefix + ":" + localName : localName;
+                    contentHandler.startElement(uri, localName, qname, getAttributes());
+                    break;
+                }
+                }
+                streamReader.next();
+            }
+        } catch (XMLStreamException e) {
+            if (e.getLocation() != null) {
+                throw new SAXParseException(e.getMessage(), null, null, e.getLocation().getLineNumber(), e.getLocation()
+                        .getColumnNumber(), e);
+            } else {
+                throw new SAXParseException(e.getMessage(), null, null, -1, -1, e);
+            }
+        }
+    }
+
+    protected String getQualifiedName() {
+        String prefix = streamReader.getPrefix();
+        if (prefix != null && prefix.length() > 0) {
+            return prefix + ":" + streamReader.getLocalName();
+        } else {
+            return streamReader.getLocalName();
+        }
+    }
+
+    protected Attributes getAttributes() {
+        AttributesImpl attrs = new AttributesImpl();
+        // Adding namespace declaration as attributes is necessary because
+        // the xalan implementation that ships with SUN JDK 1.4 is bugged
+        // and does not handle the startPrefixMapping method
+        for (int i = 0; i < streamReader.getNamespaceCount(); i++) {
+            String prefix = streamReader.getNamespacePrefix(i);
+            String uri = streamReader.getNamespaceURI(i);
+            if (uri == null) {
+                uri = "";
+            }
+            // Default namespace
+            if (prefix == null || prefix.length() == 0) {
+                attrs.addAttribute(XMLConstants.DEFAULT_NS_PREFIX, 
+                                   null, 
+                                   XMLConstants.XMLNS_ATTRIBUTE, 
+                                   "CDATA", 
+                                   uri);
+            } else {
+                attrs.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, 
+                                   prefix, 
+                                   XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, 
+                                   "CDATA", 
+                                   uri);
+            }
+        }
+        for (int i = 0; i < streamReader.getAttributeCount(); i++) {
+            String uri = streamReader.getAttributeNamespace(i);
+            String localName = streamReader.getAttributeLocalName(i);
+            String prefix = streamReader.getAttributePrefix(i);
+            String qName;
+            if (prefix != null && prefix.length() > 0) {
+                qName = prefix + ':' + localName;
+            } else {
+                qName = localName;
+            }
+            String type = streamReader.getAttributeType(i);
+            String value = streamReader.getAttributeValue(i);
+            if (value == null) {
+                value = "";
+            }
+            attrs.addAttribute(uri, localName, qName, type, value);
+        }
+        return attrs;
+    }
+
+    public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+        return false;
+    }
+
+    public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
+    }
+
+    public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+        return null;
+    }
+
+    public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
+    }
+
+    public void setEntityResolver(EntityResolver resolver) {
+    }
+
+    public EntityResolver getEntityResolver() {
+        return null;
+    }
+
+    public void setDTDHandler(DTDHandler handler) {
+    }
+
+    public DTDHandler getDTDHandler() {
+        return null;
+    }
+
+    public void setContentHandler(ContentHandler handler) {
+        this.contentHandler = handler;
+    }
+
+    public ContentHandler getContentHandler() {
+        return this.contentHandler;
+    }
+
+    public void setErrorHandler(ErrorHandler handler) {
+    }
+
+    public ErrorHandler getErrorHandler() {
+        return null;
+    }
+
+    public void parse(InputSource input) throws SAXException {
+        StaxSource.this.parse();
+    }
+
+    public void parse(String systemId) throws SAXException {
+        StaxSource.this.parse();
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxUtil.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxUtil.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/util/stax/StaxUtil.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,459 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.util.stax;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.soap.api.Fault;
+import org.apache.servicemix.soap.util.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Stax related utilities.
+ * 
+ * Some of this code has been borrowed from the XFire project
+ * 
+ * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
+ * @author Dan Diephouse
+ */
+public class StaxUtil {
+
+    private static XMLOutputFactory xof;
+    private static XMLInputFactory xif;
+    
+    public static XMLStreamReader createReader(InputStream is) {
+        return createReader(is, null);
+    }
+    
+    public static XMLStreamReader createReader(InputStream is, String encoding) {
+        try {
+            return getXMLInputFactory().createXMLStreamReader(is, encoding);
+        } catch (XMLStreamException e) {
+            throw new Fault(e);
+        }
+    }
+    
+    public static XMLStreamReader createReader(Source source) {
+        if (source instanceof DOMSource) {
+            Node node = ((DOMSource) source).getNode();
+            if (node instanceof Element) {
+                return new DOMStreamReader((Element) node);
+            } else {
+                return new DOMStreamReader(DomUtil.getFirstChildElement(node));
+            }
+        } else {
+            try {
+                return getXMLInputFactory().createXMLStreamReader(source);
+            } catch (XMLStreamException e) {
+                throw new Fault(e);
+            }
+        }
+    }
+    
+    public static Source createSource(XMLStreamReader reader) {
+        if (reader instanceof DOMStreamReader) {
+            return new DOMSource(((DOMStreamReader) reader).skipElement());
+        } else {
+            return new StaxSource(new FragmentStreamReader(reader));
+        }
+    }
+    
+    public static Element createElement(XMLStreamReader reader) {
+        if (reader instanceof DOMStreamReader) {
+            return ((DOMStreamReader) reader).skipElement();
+        } else {
+            Source src = new StaxSource(new FragmentStreamReader(reader));
+            return DomUtil.parse(src).getDocumentElement();
+        }
+    }
+    
+    public static XMLInputFactory getXMLInputFactory() {
+        if (xif == null) {
+            xif = XMLInputFactory.newInstance();
+        }
+        return xif;
+    }
+
+    public static XMLStreamWriter createWriter(OutputStream os) {
+        return createWriter(os, null);
+    }
+    
+    public static XMLStreamWriter createWriter(OutputStream os, String encoding) {
+        try {
+            return getXMLOutputFactory().createXMLStreamWriter(os, encoding);
+        } catch (XMLStreamException e) {
+            throw new Fault(e);
+        }
+    }
+
+    public static XMLOutputFactory getXMLOutputFactory() {
+        if (xof == null) {
+            xof = XMLOutputFactory.newInstance();
+        }
+        return xof;
+    }
+    
+    /**
+     * Reads a QName from the element text. Reader must be positioned at the
+     * start tag.
+     */
+    public static QName readQName(XMLStreamReader reader) throws XMLStreamException {
+        String value = reader.getElementText();
+        if (value == null) {
+            return null;
+        }
+        
+        int index = value.indexOf(":");
+
+        if (index == -1) {
+            return new QName(value);
+        }
+
+        String prefix = value.substring(0, index);
+        String localName = value.substring(index + 1);
+        String ns = reader.getNamespaceURI(prefix);
+
+        if (ns == null || localName == null) {
+            throw new RuntimeException("Invalid QName in mapping: " + value);
+        }
+
+        return new QName(ns, localName, prefix);
+    }
+    
+    /**
+     * Copies the reader to the writer.  The start and end document
+     * methods must be handled on the writer manually.
+     * 
+     * TODO: if the namespace on the reader has been declared previously
+     * to where we are in the stream, this probably won't work.
+     * 
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    public static void copy( XMLStreamReader reader, XMLStreamWriter writer ) 
+        throws XMLStreamException
+    {
+        int read = 0; // number of elements read in
+        int event = reader.getEventType();
+        
+        while ( reader.hasNext() )
+        {
+            switch( event )
+            {
+                case XMLStreamConstants.START_ELEMENT:
+                    read++;
+                    writeStartElement( reader, writer );
+                    break;
+                case XMLStreamConstants.END_ELEMENT:
+                    writer.writeEndElement();
+                    read--;
+                    if ( read <= 0 )
+                        return;
+                    break;
+                case XMLStreamConstants.CHARACTERS:
+                    writer.writeCharacters( reader.getText() );  
+                    break;
+                case XMLStreamConstants.START_DOCUMENT:
+                case XMLStreamConstants.END_DOCUMENT:
+                case XMLStreamConstants.ATTRIBUTE:
+                case XMLStreamConstants.NAMESPACE:
+                    break;
+                default:
+                    break;
+            }
+            event = reader.next();
+        }
+    }
+
+    private static void writeStartElement(XMLStreamReader reader, XMLStreamWriter writer) 
+        throws XMLStreamException
+    {
+        String local = reader.getLocalName();
+        String uri = reader.getNamespaceURI();
+        String prefix = reader.getPrefix();
+        if (prefix == null)
+        {
+            prefix = "";
+        }
+        if (uri == null)
+        {
+            uri = "";
+        }
+        
+        String boundPrefix = writer.getPrefix(uri);
+        boolean writeElementNS = false;
+        if ( boundPrefix == null || !prefix.equals(boundPrefix) )
+        {   
+            writeElementNS = true;
+        }
+        
+        // Write out the element name
+        if (uri != null)
+        {
+            if (prefix.length() == 0) 
+            { 
+                
+                writer.writeStartElement(local);
+                writer.setDefaultNamespace(uri); 
+                
+            } 
+            else 
+            { 
+                writer.writeStartElement(prefix, local, uri); 
+                writer.setPrefix(prefix, uri); 
+            } 
+        }
+        else
+        {
+            writer.writeStartElement( local );
+        }
+
+        // Write out the namespaces
+        for ( int i = 0; i < reader.getNamespaceCount(); i++ )
+        {
+            String nsURI = reader.getNamespaceURI(i);
+            String nsPrefix = reader.getNamespacePrefix(i);
+            if (nsPrefix == null) nsPrefix = "";
+            
+            if ( nsPrefix.length() ==  0 )
+            {
+                writer.writeDefaultNamespace(nsURI);
+            }
+            else
+            {
+                writer.writeNamespace(nsPrefix, nsURI);
+            }
+
+            if (nsURI.equals(uri) && nsPrefix.equals(prefix))
+            {
+                writeElementNS = false;
+            }
+        }
+        
+        // Check if the namespace still needs to be written.
+        // We need this check because namespace writing works 
+        // different on Woodstox and the RI.
+        if (writeElementNS)
+        {
+            if ( prefix == null || prefix.length() ==  0 )
+            {
+                writer.writeDefaultNamespace(uri);
+            }
+            else
+            {
+                writer.writeNamespace(prefix, uri);
+            }
+        }
+
+        // Write out attributes
+        for ( int i = 0; i < reader.getAttributeCount(); i++ )
+        {
+            String ns = reader.getAttributeNamespace(i);
+            String nsPrefix = reader.getAttributePrefix(i);
+            if ( ns == null || ns.length() == 0 )
+            {
+                writer.writeAttribute(
+                        reader.getAttributeLocalName(i),
+                        reader.getAttributeValue(i));
+            }
+            else if (nsPrefix == null || nsPrefix.length() == 0)
+            {
+                writer.writeAttribute(
+                    reader.getAttributeNamespace(i),
+                    reader.getAttributeLocalName(i),
+                    reader.getAttributeValue(i));
+            }
+            else
+            {
+                writer.writeAttribute(reader.getAttributePrefix(i),
+                                      reader.getAttributeNamespace(i),
+                                      reader.getAttributeLocalName(i),
+                                      reader.getAttributeValue(i));
+            }
+            
+            
+        }
+    }
+    
+    /**
+     * Write a start element with the specified parameters
+     * @param writer
+     * @param uri
+     * @param local
+     * @param prefix
+     * @throws XMLStreamException
+     */
+    public static void writeStartElement( XMLStreamWriter writer, String uri, String local, String prefix ) 
+        throws XMLStreamException 
+    {
+        if (prefix == null)
+        {
+            prefix = "";
+        }
+        if (uri == null)
+        {
+            uri = "";
+        }
+        
+        String boundPrefix = writer.getPrefix(uri);
+        boolean writeElementNS = false;
+        if ( boundPrefix == null || !prefix.equals(boundPrefix) )
+        {   
+            writeElementNS = true;
+        }
+        
+        // Write out the element name
+        if (uri != null)
+        {
+            if (prefix.length() == 0) 
+            { 
+                
+                writer.writeStartElement(local);
+                writer.setDefaultNamespace(uri); 
+                
+            } 
+            else 
+            { 
+                writer.writeStartElement(prefix, local, uri); 
+                writer.setPrefix(prefix, uri); 
+            } 
+        }
+        else
+        {
+            writer.writeStartElement( local );
+        }
+
+        // Check if the namespace still needs to be written.
+        // We need this check because namespace writing works 
+        // different on Woodstox and the RI.
+        if (writeElementNS)
+        {
+            if ( prefix.length() ==  0 )
+            {
+                writer.writeDefaultNamespace(uri);
+            }
+            else
+            {
+                writer.writeNamespace(prefix, uri);
+            }
+        }
+    }
+
+    /**
+     * Write a start element with the given QName.
+     * However, if a namespace has already been bound to a prefix,
+     * use the existing one, else default to the prefix
+     * in the QName (if specified).  Else, a prefix is generated.
+     * 
+     * @param writer
+     * @param name
+     * @throws XMLStreamException
+     */
+    public static void writeStartElement(XMLStreamWriter writer, QName name) throws XMLStreamException {
+        String prefix = choosePrefix(writer, name, false);
+        writeStartElement(writer, name.getNamespaceURI(), name.getLocalPart(), prefix);
+    }
+
+    /**
+     * 
+     * @param out
+     * @param name
+     * @throws XMLStreamException
+     */
+    public static void writeTextQName(XMLStreamWriter out, QName name) throws XMLStreamException {
+        String prefix = choosePrefix(out, name, true);
+        if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
+            out.writeCharacters(name.getLocalPart());
+        } else {
+            out.writeCharacters(prefix + ":" + name.getLocalPart());
+        }
+    }
+    
+    protected static String choosePrefix(XMLStreamWriter out, QName name, boolean declare) throws XMLStreamException {
+        String uri = name.getNamespaceURI();
+        // If no namespace
+        if (uri == null || XMLConstants.NULL_NS_URI.equals(uri)) {
+            if (!XMLConstants.NULL_NS_URI.equals(out.getNamespaceContext().getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX))) {
+                out.setPrefix(XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.NULL_NS_URI);
+            }
+            return XMLConstants.DEFAULT_NS_PREFIX;
+        // Need to write a prefix
+        } else {
+            String defPrefix = name.getPrefix();
+            // A prefix is specified
+            if (defPrefix != null && !XMLConstants.DEFAULT_NS_PREFIX.equals(defPrefix)) {
+                // if the uri is bound to the specified prefix, good, else
+                if (!uri.equals(out.getNamespaceContext().getNamespaceURI(defPrefix))) {
+                    // if there is a prefix bound to the uri, use it
+                    if (out.getNamespaceContext().getPrefix(uri) != null) {
+                        defPrefix = out.getNamespaceContext().getPrefix(uri);
+                    // get prefix from the writer
+                    } else if (out.getPrefix(uri) != null) {
+                        defPrefix = out.getPrefix(uri);
+                    // we need to bind the prefix
+                    } else if (declare) {
+                        out.setPrefix(defPrefix, uri);
+                        out.writeNamespace(defPrefix, uri);
+                    }
+                }
+            // No prefix specified
+            } else {
+                // if there is a prefix bound to the uri, use it
+                if (out.getNamespaceContext().getPrefix(uri) != null) {
+                    defPrefix = out.getNamespaceContext().getPrefix(uri);
+                // get prefix from the writer
+                } else if (out.getPrefix(uri) != null) {
+                    defPrefix = out.getPrefix(uri);
+                // we need to generate a prefix
+                } else {
+                    defPrefix = getUniquePrefix(out); 
+                    if (declare) {
+                        out.setPrefix(defPrefix, uri);
+                        out.writeNamespace(defPrefix, uri);
+                    }
+                }
+            }
+            return defPrefix;
+        }
+    }
+    
+    protected static String getUniquePrefix(XMLStreamWriter writer) {
+        int n = 1;
+        while (true) {
+            String nsPrefix = "ns" + n;
+            if (writer.getNamespaceContext().getNamespaceURI(nsPrefix) == null) {
+                return nsPrefix;
+            }
+            n++;
+        }
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingInInterceptor.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingInInterceptor.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingInInterceptor.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.addressing;
+
+import java.net.URI;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.soap.api.Message;
+import org.apache.servicemix.soap.bindings.soap.SoapInterceptor;
+import org.apache.servicemix.soap.core.AbstractInterceptor;
+
+public class WsAddressingInInterceptor extends AbstractInterceptor implements SoapInterceptor {
+
+    private final WsAddressingPolicy policy;
+    
+    public WsAddressingInInterceptor(WsAddressingPolicy policy) {
+        this.policy = policy;
+    }
+    
+    public void handleMessage(Message message) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Collection<URI> getRoles() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<QName> getUnderstoodHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingOutInterceptor.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingOutInterceptor.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingOutInterceptor.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.addressing;
+
+import java.net.URI;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.soap.api.Message;
+import org.apache.servicemix.soap.bindings.soap.SoapInterceptor;
+import org.apache.servicemix.soap.core.AbstractInterceptor;
+
+public class WsAddressingOutInterceptor extends AbstractInterceptor implements SoapInterceptor {
+
+    private final WsAddressingPolicy policy;
+    
+    public WsAddressingOutInterceptor(WsAddressingPolicy policy) {
+        this.policy = policy;
+    }
+    
+    public void handleMessage(Message message) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public Collection<URI> getRoles() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<QName> getUnderstoodHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingPolicy.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingPolicy.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingPolicy.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/addressing/WsAddressingPolicy.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.addressing;
+
+import org.apache.servicemix.soap.core.AbstractPolicy;
+
+public class WsAddressingPolicy extends AbstractPolicy {
+
+    public WsAddressingPolicy() {
+        getInterceptors(Phase.ServerIn).add(new WsAddressingInInterceptor(this));
+        
+        getInterceptors(Phase.ServerOut).add(new WsAddressingOutInterceptor(this));
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityInInterceptor.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityInInterceptor.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityInInterceptor.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.security;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.soap.api.Message;
+import org.apache.servicemix.soap.bindings.soap.SoapInterceptor;
+import org.apache.servicemix.soap.core.AbstractInterceptor;
+import org.apache.ws.security.WSConstants;
+
+public class WsSecurityInInterceptor extends AbstractInterceptor implements SoapInterceptor {
+
+    public static QName[] HEADERS = {
+        new QName(WSConstants.WSSE_NS, WSConstants.WSSE_LN),  
+        new QName(WSConstants.WSSE11_NS, WSConstants.WSSE_LN),  
+    };
+    
+    private final WsSecurityPolicy policy;
+    
+    public WsSecurityInInterceptor(WsSecurityPolicy policy) {
+        this.policy = policy;
+    }
+    
+    public void handleMessage(Message message) {
+        boolean required = policy.isRequired();
+        // TODO
+    }
+
+    public Collection<QName> getUnderstoodHeaders() {
+        return Arrays.asList(HEADERS);
+    }
+
+    public Collection<URI> getRoles() {
+        return Collections.emptyList();
+    }
+    
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityOutInterceptor.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityOutInterceptor.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityOutInterceptor.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.security;
+
+import java.net.URI;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.soap.api.Message;
+import org.apache.servicemix.soap.bindings.soap.SoapInterceptor;
+import org.apache.servicemix.soap.core.AbstractInterceptor;
+
+public class WsSecurityOutInterceptor extends AbstractInterceptor implements SoapInterceptor {
+
+    private final WsSecurityPolicy policy;
+    
+    public WsSecurityOutInterceptor(WsSecurityPolicy policy) {
+        this.policy = policy;
+    }
+
+    public void handleMessage(Message message) {
+        boolean required = policy.isRequired();
+        // TODO
+    }
+
+    public Collection<URI> getRoles() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Collection<QName> getUnderstoodHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityPolicy.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityPolicy.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityPolicy.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/ws/security/WsSecurityPolicy.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.ws.security;
+
+import org.apache.servicemix.soap.core.AbstractPolicy;
+import org.apache.servicemix.soap.interceptors.xml.DomInInterceptor;
+
+public class WsSecurityPolicy extends AbstractPolicy {
+
+    public WsSecurityPolicy() {
+        getInterceptors(Phase.ServerIn).add(new DomInInterceptor());
+        getInterceptors(Phase.ServerIn).add(new WsSecurityInInterceptor(this));
+        
+        getInterceptors(Phase.ServerOut).add(new WsSecurityOutInterceptor(this));
+    }
+    
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/BindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/BindingFactory.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/BindingFactory.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/BindingFactory.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.wsdl;
+
+import org.apache.servicemix.soap.api.model.Binding;
+
+public class BindingFactory {
+
+    public static Binding<?> createBinding(javax.wsdl.Port wsdlPort) {
+        return Wsdl1BindingFactory.createBinding(wsdlPort);
+    }
+    
+    public static Binding<?> createBinding(org.apache.woden.wsdl20.Endpoint wsdlEndpoint) {
+        return Wsdl2BindingFactory.createBinding(wsdlEndpoint);
+    }
+
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/WSDLUtils.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/WSDLUtils.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/WSDLUtils.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/WSDLUtils.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,113 @@
+package org.apache.servicemix.soap.wsdl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.wsdl.BindingFault;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ElementExtensible;
+import javax.wsdl.extensions.soap.SOAPBody;
+import javax.wsdl.extensions.soap.SOAPHeader;
+import javax.wsdl.extensions.soap.SOAPHeaderFault;
+import javax.wsdl.extensions.soap12.SOAP12Body;
+import javax.wsdl.extensions.soap12.SOAP12Header;
+import javax.wsdl.extensions.soap12.SOAP12HeaderFault;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+
+import org.apache.servicemix.soap.api.Fault;
+
+import com.ibm.wsdl.Constants;
+
+public class WSDLUtils {
+
+    private static WSDLFactory wsdl11Factory;
+    
+    public static WSDLReader createWSDL11Reader() {
+        WSDLReader reader = getWSDL11Factory().newWSDLReader();
+        reader.setFeature(Constants.FEATURE_VERBOSE, false);
+        return reader;
+    }
+    
+    public static WSDLFactory getWSDL11Factory() {
+        if (wsdl11Factory == null) {
+            try {
+                wsdl11Factory = WSDLFactory.newInstance();
+            } catch (WSDLException e) {
+                throw new Fault(e);
+            }
+        }
+        return wsdl11Factory;
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<String> getParts(SOAPBody body) {
+        return (List<String>) body.getParts();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<String> getParts(SOAP12Body body) {
+        return (List<String>) body.getParts();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static Collection<BindingFault> getBindingFaults(BindingOperation bop) {
+        return (Collection<BindingFault>) bop.getBindingFaults().values();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<SOAPHeaderFault> getSOAPHeaderFaults(SOAPHeader sh) {
+        return (List<SOAPHeaderFault>) sh.getSOAPHeaderFaults();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<SOAP12HeaderFault> getSOAPHeaderFaults(SOAP12Header sh) {
+        return (List<SOAP12HeaderFault>) sh.getSOAP12HeaderFaults();
+    }
+    
+    public static List<ElementExtensible> getElements(BindingOperation bop) {
+        List<ElementExtensible> l = new ArrayList<ElementExtensible>();
+        l.add(bop);
+        l.add(bop.getBindingInput());
+        l.add(bop.getBindingOutput());
+        l.addAll(getBindingFaults(bop));
+        return l;
+    }
+    
+    public static <T> T getExtension(ElementExtensible element, Class<T> format) {
+        if (element != null) {
+            for (Iterator it = element.getExtensibilityElements().iterator(); it.hasNext();) {
+                Object ex = it.next();
+                if (format.isInstance(ex)) {
+                    return format.cast(ex);
+                }
+            }
+        }
+        return null;
+    }
+    
+    public static <T> List<T> getExtensions(ElementExtensible element, Class<T> format) {
+        List<T> l = new ArrayList<T>();
+        if (element != null) {
+            for (Iterator it = element.getExtensibilityElements().iterator(); it.hasNext();) {
+                Object ex = it.next();
+                if (format.isInstance(ex)) {
+                    l.add(format.cast(ex));
+                }
+            }
+        }
+        return l;
+    }
+    
+    public static <T> List<T> getExtensions(List<ElementExtensible> elements, Class<T> format) {
+        List<T> l = new ArrayList<T>();
+        for (ElementExtensible e : elements) {
+            l.addAll(getExtensions(e, format));
+        }
+        return l;
+    }
+    
+}

Added: incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/Wsdl1BindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/Wsdl1BindingFactory.java?view=auto&rev=450054
==============================================================================
--- incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/Wsdl1BindingFactory.java (added)
+++ incubator/servicemix/trunk/sandbox/servicemix-soap2/src/main/java/org/apache/servicemix/soap/wsdl/Wsdl1BindingFactory.java Tue Sep 26 07:11:40 2006
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.soap.wsdl;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.wsdl.extensions.ExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+
+import org.apache.servicemix.soap.api.model.Binding;
+
+public class Wsdl1BindingFactory {
+
+    public static Binding<?> createBinding(javax.wsdl.Port wsdlPort) {
+        List elements = wsdlPort.getExtensibilityElements();
+        for (Iterator iter = elements.iterator(); iter.hasNext();) {
+            ExtensibilityElement element = (ExtensibilityElement) iter.next();
+            if (element instanceof SOAPAddress) {
+                return Wsdl1Soap11BindingFactory.createWsdl1SoapBinding(wsdlPort);
+            } else if (element instanceof SOAP12Address) {
+                return Wsdl1Soap12BindingFactory.createWsdl1SoapBinding(wsdlPort);
+            }
+        }
+        return null;
+    }
+
+}