Author: dkulp
Date: Thu Mar 22 13:52:47 2007
New Revision: 521454
URL: http://svn.apache.org/viewvc?view=rev&rev=521454
Log:
Move DOMStreamReader to common
Fix issues with using non-namespace aware DOM's with XMLStreamReader
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
(with props)
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
(with props)
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
(with props)
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/AbstractUser.java
- copied, changed from r521283,
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/BaseUser.java
Removed:
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/FastStack.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamReader.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/DOMStreamWriter.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamReader.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/W3CDOMStreamWriter.java
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/BaseUser.java
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/Employee.java
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritancePOJOTest.java
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritanceService.java
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java?view=auto&rev=521454
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
(added)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
Thu Mar 22 13:52:47 2007
@@ -0,0 +1,326 @@
+/**
+ * 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.cxf.staxutils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Abstract logic for creating XMLStreamReader from DOM documents. Its works
+ * using adapters for Element, Node and Attribute (
+ *
+ * @see ElementAdapter }
+ * @author <a href="mailto:[EMAIL PROTECTED]">Tomasz Sztelak</a>
+ */
+public abstract class AbstractDOMStreamReader implements XMLStreamReader {
+ private Map properties = new HashMap();
+
+ private FastStack<ElementFrame> frames = new FastStack<ElementFrame>();
+
+ private ElementFrame frame;
+
+ private int currentEvent = XMLStreamConstants.START_DOCUMENT;
+
+ /**
+ *
+ */
+ public static class ElementFrame {
+ Object element;
+
+ boolean started;
+
+ boolean ended;
+
+ int currentChild = -1;
+
+ int currentAttribute = -1;
+
+ int currentNamespace = -1;
+
+ int currentElement = -1;
+ List<String> uris;
+ List<String> prefixes;
+ List<Object> attributes;
+ List<Object> allAttributes;
+
+ final ElementFrame parent;
+
+ public ElementFrame(Object element, ElementFrame parent) {
+ this.element = element;
+ this.parent = parent;
+ }
+
+ public Object getElement() {
+ return element;
+ }
+
+
+ }
+
+ /**
+ * @param element
+ */
+ public AbstractDOMStreamReader(ElementFrame frame) {
+ this.frame = frame;
+ frames.push(this.frame);
+ }
+
+ 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.pop();
+ if (!frames.empty()) {
+ frame = (ElementFrame)frames.peek();
+ } 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.push(this.frame);
+ currentEvent = START_ELEMENT;
+
+ newFrame(newFrame);
+ }
+ } else {
+ frame.ended = true;
+ currentEvent = END_ELEMENT;
+ endElement();
+ }
+ return currentEvent;
+ }
+
+ protected void newFrame(ElementFrame newFrame) {
+ }
+
+ protected void endElement() {
+ }
+
+ protected abstract int moveToChild(int currentChild);
+
+ protected abstract ElementFrame getChildFrame(int currentChild);
+
+ protected abstract int getChildCount();
+
+ /*
+ * (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#getElementText()
+ */
+ public abstract String getElementText() throws XMLStreamException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.xml.stream.XMLStreamReader#nextTag()
+ */
+ public int nextTag() throws XMLStreamException {
+ while (hasNext()) {
+ if (START_ELEMENT == next()) {
+ return START_ELEMENT;
+ }
+ }
+
+ 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#getNamespaceURI(java.lang.String)
+ */
+ public abstract String getNamespaceURI(String prefix);
+
+ /*
+ * (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;
+ }
+}
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java?view=auto&rev=521454
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
(added)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
Thu Mar 22 13:52:47 2007
@@ -0,0 +1,48 @@
+/**
+ * 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.cxf.staxutils;
+
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+
+public class FastStack<T> extends ArrayList<T> {
+ public void push(T o) {
+ add(o);
+ }
+
+ public T pop() {
+ if (empty()) {
+ throw new EmptyStackException();
+ }
+
+ return remove(size() - 1);
+ }
+
+ public boolean empty() {
+ return size() == 0;
+ }
+
+ public T peek() {
+ if (empty()) {
+ throw new EmptyStackException();
+ }
+
+ return get(size() - 1);
+ }
+}
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/FastStack.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Thu Mar 22 13:52:47 2007
@@ -33,6 +33,7 @@
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.*;
@@ -43,22 +44,39 @@
private static final Logger LOG =
Logger.getLogger(StaxUtils.class.getName());
+ private static final XMLInputFactory XML_NS_AWARE_INPUT_FACTORY =
XMLInputFactory.newInstance();
private static final XMLInputFactory XML_INPUT_FACTORY =
XMLInputFactory.newInstance();
private static final XMLOutputFactory XML_OUTPUT_FACTORY =
XMLOutputFactory.newInstance();
private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+ static {
+ XML_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
false);
+
XML_NS_AWARE_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
true);
+ }
+
private StaxUtils() {
}
public static XMLInputFactory getXMLInputFactory() {
- return XML_INPUT_FACTORY;
+ return getXMLInputFactory(true);
+ }
+ public static XMLInputFactory getXMLInputFactory(boolean nsAware) {
+ return nsAware ? XML_NS_AWARE_INPUT_FACTORY : XML_INPUT_FACTORY;
}
public static XMLOutputFactory getXMLOutputFactory() {
return XML_OUTPUT_FACTORY;
}
+ public static XMLStreamWriter createXMLStreamWriter(Writer out) {
+ try {
+ return getXMLOutputFactory().createXMLStreamWriter(out);
+ } catch (XMLStreamException e) {
+ throw new RuntimeException("Cant' create XMLStreamWriter", e);
+ }
+ }
+
public static XMLStreamWriter createXMLStreamWriter(OutputStream out) {
return createXMLStreamWriter(out, null);
}
@@ -639,6 +657,21 @@
public static XMLStreamReader createXMLStreamReader(Source source) {
try {
+ if (source instanceof DOMSource) {
+ DOMSource ds = (DOMSource)source;
+ Node nd = ds.getNode();
+ Element el = null;
+ if (nd instanceof Document) {
+ el = ((Document)nd).getDocumentElement();
+ } else if (nd instanceof Element) {
+ el = (Element)nd;
+ }
+
+ if (null != el) {
+ return new W3CDOMStreamReader(el);
+ }
+ }
+
return getXMLInputFactory().createXMLStreamReader(source);
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java?view=auto&rev=521454
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
(added)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
Thu Mar 22 13:52:47 2007
@@ -0,0 +1,333 @@
+/**
+ * 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.cxf.staxutils;
+
+import java.util.ArrayList;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+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;
+
+import org.apache.cxf.helpers.DOMUtils;
+
+public class W3CDOMStreamReader extends AbstractDOMStreamReader {
+ private Node content;
+
+ private Document document;
+
+ private W3CNamespaceContext context;
+
+ /**
+ * @param element
+ */
+ public W3CDOMStreamReader(Element element) {
+ super(new ElementFrame(element, null));
+ newFrame(getCurrentFrame());
+
+ this.document = element.getOwnerDocument();
+
+ }
+
+ /**
+ * Get the document associated with this stream.
+ *
+ * @return
+ */
+ public Document getDocument() {
+ return document;
+ }
+
+ /**
+ * Find name spaces declaration in atrributes and move them to separate
+ * collection.
+ */
+ @Override
+ protected final void newFrame(ElementFrame frame) {
+ Element element = getCurrentElement();
+ frame.uris = new ArrayList<String>();
+ frame.prefixes = new ArrayList<String>();
+ frame.attributes = new ArrayList<Object>();
+
+ if (context == null) {
+ context = new W3CNamespaceContext();
+ }
+
+ context.setElement(element);
+
+ NamedNodeMap nodes = element.getAttributes();
+
+ String ePrefix = element.getPrefix();
+ if (ePrefix == null) {
+ ePrefix = "";
+ }
+
+ if (nodes != null) {
+ 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 && "xmlns".equals(name)) {
+ frame.uris.add(value);
+ frame.prefixes.add("");
+ } else if (prefix.length() > 0 && "xmlns".equals(prefix)) {
+ 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);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void endElement() {
+ super.endElement();
+ }
+
+ final Element getCurrentElement() {
+ return (Element)getCurrentFrame().element;
+ }
+
+ @Override
+ protected ElementFrame getChildFrame(int currentChild) {
+ return new
ElementFrame(getCurrentElement().getChildNodes().item(currentChild),
getCurrentFrame());
+ }
+
+ @Override
+ protected int getChildCount() {
+ return getCurrentElement().getChildNodes().getLength();
+ }
+
+ @Override
+ 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();
+ }
+
+ @Override
+ public String getElementText() throws XMLStreamException {
+ return DOMUtils.getContent(content);
+ }
+
+ @Override
+ public String getNamespaceURI(String prefix) {
+ ElementFrame frame = getCurrentFrame();
+
+ while (null != frame) {
+ int index = frame.prefixes.indexOf(prefix);
+ if (index != -1) {
+ return frame.uris.get(index);
+ }
+
+ frame = frame.parent;
+ }
+
+ return null;
+ }
+
+ public String getAttributeValue(String ns, String local) {
+ Attr at;
+ if (ns == null || ns.equals("")) {
+ at = getCurrentElement().getAttributeNode(local);
+ } else {
+ at = getCurrentElement().getAttributeNodeNS(ns, local);
+ }
+
+ if (at == null) {
+ return null;
+ }
+
+ return DOMUtils.getContent(at);
+ }
+
+ 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);
+ return getLocalName(attr);
+ }
+
+ 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 getCurrentFrame().prefixes.get(i);
+ }
+
+ public String getNamespaceURI(int i) {
+ return getCurrentFrame().uris.get(i);
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return context;
+ }
+
+ public String getText() {
+ return DOMUtils.getRawContent(getCurrentElement());
+ }
+
+ 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 ln = getCurrentElement().getLocalName();
+ if (ln == null) {
+ ln = getCurrentElement().getNodeName();
+ }
+ return ln;
+ }
+
+ 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();
+ }
+}
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Thu Mar 22 13:52:47 2007
@@ -21,8 +21,15 @@
import java.io.*;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Document;
+
+import org.xml.sax.InputSource;
import org.junit.Assert;
import org.junit.Test;
@@ -86,5 +93,72 @@
input = input.replaceAll("\r\n", "\n");
// compare the input and output string
assertEquals(input, output);
+ }
+
+
+ @Test
+ public void testNonNamespaceAwareParser() throws Exception {
+ String xml = "<blah xmlns=\"http://blah.org/\"
xmlns:snarf=\"http://snarf.org\">"
+ + "<foo snarf:blop=\"blop\">foo</foo></blah>";
+
+
+ StringReader reader = new StringReader(xml);
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(false);
+ dbf.setValidating(false);
+ Document doc = dbf.newDocumentBuilder().parse(new InputSource(reader));
+ Source source = new DOMSource(doc);
+
+ dbf.setNamespaceAware(true);
+ reader = new StringReader(xml);
+ Document docNs = dbf.newDocumentBuilder().parse(new
InputSource(reader));
+ Source sourceNs = new DOMSource(docNs);
+
+
+ XMLStreamReader sreader = StaxUtils.createXMLStreamReader(source);
+
+ StringWriter sw = new StringWriter();
+ XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw);
+
+ //should not throw an exception
+ StaxUtils.copy(sreader, swriter);
+ swriter.flush();
+ swriter.close();
+
+ String output = sw.toString();
+ assertTrue(output.contains("blah"));
+ assertTrue(output.contains("foo"));
+ assertTrue(output.contains("snarf"));
+ assertTrue(output.contains("blop"));
+
+
+ sreader = StaxUtils.createXMLStreamReader(sourceNs);
+ sw = new StringWriter();
+ swriter = StaxUtils.createXMLStreamWriter(sw);
+ //should not throw an exception
+ StaxUtils.copy(sreader, swriter);
+ swriter.flush();
+ swriter.close();
+
+ output = sw.toString();
+ assertTrue(output.contains("blah"));
+ assertTrue(output.contains("foo"));
+ assertTrue(output.contains("snarf"));
+ assertTrue(output.contains("blop"));
+
+
+ sreader = StaxUtils.createXMLStreamReader(source);
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ swriter = StaxUtils.createXMLStreamWriter(bout);
+ StaxUtils.copy(sreader, swriter);
+ swriter.flush();
+ swriter.close();
+
+ output = bout.toString();
+ assertTrue(output.contains("blah"));
+ assertTrue(output.contains("foo"));
+ assertTrue(output.contains("snarf"));
+ assertTrue(output.contains("blop"));
}
}
Modified:
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
Thu Mar 22 13:52:47 2007
@@ -28,7 +28,8 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
-import org.apache.cxf.aegis.util.FastStack;
+import org.apache.cxf.staxutils.AbstractDOMStreamReader;
+import org.apache.cxf.staxutils.FastStack;
import org.jdom.Attribute;
import org.jdom.CDATA;
import org.jdom.Comment;
@@ -44,7 +45,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Tomasz Sztelak</a>
*/
-public class JDOMStreamReader extends DOMStreamReader {
+public class JDOMStreamReader extends AbstractDOMStreamReader {
private Content content;
@@ -182,7 +183,7 @@
}
public Element getCurrentElement() {
- return (Element)getCurrentFrame().element;
+ return (Element)getCurrentFrame().getElement();
}
@Override
Modified:
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamWriter.java
Thu Mar 22 13:52:47 2007
@@ -24,6 +24,7 @@
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
import org.apache.cxf.aegis.util.NamespaceHelper;
import org.jdom.Attribute;
@@ -34,7 +35,7 @@
import org.jdom.EntityRef;
import org.jdom.Namespace;
-public class JDOMStreamWriter extends DOMStreamWriter {
+public class JDOMStreamWriter implements XMLStreamWriter {
private Stack<Element> stack = new Stack<Element>();
private Document document;
@@ -51,6 +52,12 @@
public JDOMStreamWriter(Element e) {
newChild(e);
}
+
+ public void close() throws XMLStreamException {
+ }
+
+ public void flush() throws XMLStreamException {
+ }
public void writeStartElement(String local) throws XMLStreamException {
newChild(new Element(local));
Copied:
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/AbstractUser.java
(from r521283,
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/BaseUser.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/AbstractUser.java?view=diff&rev=521454&p1=incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/BaseUser.java&r1=521283&p2=incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/AbstractUser.java&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/BaseUser.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/AbstractUser.java
Thu Mar 22 13:52:47 2007
@@ -22,7 +22,7 @@
package org.codehaus.xfire.aegis.inheritance;
// @XmlType(namespace="urn:xfire:inheritance")
-public abstract class BaseUser {
+public abstract class AbstractUser {
private String name;
public String getName() {
Modified:
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/Employee.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/Employee.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/Employee.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/Employee.java
Thu Mar 22 13:52:47 2007
@@ -22,7 +22,7 @@
package org.codehaus.xfire.aegis.inheritance;
// @XmlType(namespace="urn:xfire:inheritance")
-public class Employee extends BaseUser {
+public class Employee extends AbstractUser {
private String division;
public String getDivision() {
Modified:
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritancePOJOTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritancePOJOTest.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritancePOJOTest.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritancePOJOTest.java
Thu Mar 22 13:52:47 2007
@@ -68,14 +68,14 @@
// check for Employee as extension
String employeeType = types + "xsd:[EMAIL PROTECTED]'Employee']";
assertValid(employeeType, d);
- String extension = "/xsd:complexContent/xsd:[EMAIL
PROTECTED]'ns1:BaseUser']";
+ String extension = "/xsd:complexContent/xsd:[EMAIL
PROTECTED]'ns1:AbstractUser']";
assertValid(employeeType + extension, d);
assertValid(employeeType + extension + "/xsd:sequence/xsd:[EMAIL
PROTECTED]'division']", d);
// assertValid("count(" + employeeType + extension +
// "/xsd:sequence/*)=1", d);
// check for BaseUser as abstract
- String baseUserType = types + "xsd:complexType[(@name='BaseUser') and
(@abstract='true')]";
+ String baseUserType = types + "xsd:complexType[(@name='AbstractUser')
and (@abstract='true')]";
assertValid(baseUserType, d);
assertValid(baseUserType + "/xsd:sequence/xsd:[EMAIL
PROTECTED]'name']", d);
// assertValid("count(" + baseUserType + "/xsd:sequence/*)=1", d);
Modified:
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritanceService.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritanceService.java?view=diff&rev=521454&r1=521453&r2=521454
==============================================================================
---
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritanceService.java
(original)
+++
incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/codehaus/xfire/aegis/inheritance/InheritanceService.java
Thu Mar 22 13:52:47 2007
@@ -22,14 +22,14 @@
package org.codehaus.xfire.aegis.inheritance;
public class InheritanceService {
- public BaseUser getEmployee() {
+ public AbstractUser getEmployee() {
Employee e = new Employee();
e.setDivision("foo");
e.setName("Dan D. Man");
return e;
}
- public void receiveUser(BaseUser user) {
+ public void receiveUser(AbstractUser user) {
InheritancePOJOTest.assertTrue(user instanceof Employee);
}
}