You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ch...@apache.org on 2006/03/31 20:52:00 UTC
svn commit: r390473 - in /webservices/commons/trunk/modules/axiom:
src/org/apache/axiom/om/ src/org/apache/axiom/om/impl/builder/
src/org/apache/axiom/om/impl/dom/ src/org/apache/axiom/om/impl/llom/
test/org/apache/axiom/om/ test/org/apache/axiom/om/im...
Author: chinthaka
Date: Fri Mar 31 10:51:56 2006
New Revision: 390473
URL: http://svn.apache.org/viewcvs?rev=390473&view=rev
Log:
At last. Fixed default namespace handling. Now Axiom does good enough with default namespaces. Will post an explanation soon to the mailing list.
Added:
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
Removed:
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNamespaceTest.java
Modified:
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMSerializerUtil.java
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/PreserveEnvelopeTest.java
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java Fri Mar 31 10:51:56 2006
@@ -46,6 +46,8 @@
* caller is expected to ensure that the URI is a valid namespace name.
* @param prefix The prefix to associate with the given namespace.
* The caller is expected to ensure that this is a valid XML prefix.
+ * If null is given, first this will check for an existing namespace
+ * with the same uri. If not found, a prefix will be auto-generated.
* @return Returns the created namespace information item.
* @see #declareNamespace(OMNamespace)
* @see #findNamespace(String, String)
@@ -53,10 +55,25 @@
*/
public OMNamespace declareNamespace(String uri, String prefix);
+
+ /**
+ * This will declare a default namespace for this element explicitly
+ * @param uri
+ * @return
+ */
+ public OMNamespace declareDefaultNamespace(String uri);
+
+ /**
+ * This will retrieve the default namespace of this element, if available. null returned if none
+ * is found.
+ * @return
+ */
+ public OMNamespace getDefaultNamespace();
+
/**
* Declares a namespace with the element as its scope.
*
- * @param namespace The namespace to declare
+ * @param namespace The namespace to declare.
* @return Returns the namespace parameter passed.
* @see #declareNamespace(String, String)
* @see #findNamespace(String, String)
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java Fri Mar 31 10:51:56 2006
@@ -26,13 +26,14 @@
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.llom.OMSerializerUtil;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
/**
- * OM should be able to be built from any data source. And the model it builds
- * may be a SOAP specific one or just an XML model. This class will give
+ * OM should be able to be built from any data source. And the model it builds
+ * may be a SOAP specific one or just an XML model. This class will give
* some common functionality of OM Building from StAX.
*/
public abstract class StAXBuilder implements OMXMLParserWrapper {
@@ -76,7 +77,6 @@
protected OMDocument document;
-
/**
* Constructor StAXBuilder.
*
@@ -126,23 +126,29 @@
protected void processAttributes(OMElement node) {
int attribCount = parser.getAttributeCount();
for (int i = 0; i < attribCount; i++) {
- OMNamespace ns = null;
String uri = parser.getAttributeNamespace(i);
String prefix = parser.getAttributePrefix(i);
- if (uri != null && uri.hashCode() != 0) {
- ns = node.findNamespace(uri, prefix);
- if (ns== null) {
- ns = node.declareNamespace(uri, prefix);
+
+ OMNamespace namespace = null;
+ if (uri != null && uri.length() > 0) {
+
+ // prefix being null means this elements has a default namespace or it has inherited
+ // a default namespace from its parent
+ namespace = node.findNamespace(uri, prefix);
+ if (namespace == null) {
+ if (prefix == null || "".equals(prefix)) {
+ prefix = OMSerializerUtil.getNextNSPrefix();
+ }
+ namespace = node.declareNamespace(uri, prefix);
}
}
-
// todo if the attributes are supposed to namespace qualified all the time
// todo then this should throw an exception here
-
+
node.addAttribute(parser.getAttributeLocalName(i),
- parser.getAttributeValue(i), ns);
+ parser.getAttributeValue(i), namespace);
}
}
@@ -159,7 +165,7 @@
} else if (!lastNode.isComplete()) {
node = omfactory.createText((OMElement) lastNode, parser.getText(), textType);
} else if (!(lastNode.getParent() instanceof OMDocument)) {
- node = omfactory.createText((OMElement)lastNode.getParent(), parser.getText(), textType);
+ node = omfactory.createText((OMElement) lastNode.getParent(), parser.getText(), textType);
}
return node;
}
@@ -195,7 +201,7 @@
} while (!parser.getName().equals(element.getQName()));
lastNode = element.getPreviousOMSibling();
if (lastNode != null) {
- ((OMNodeEx)lastNode).setNextOMSibling(null);
+ ((OMNodeEx) lastNode).setNextOMSibling(null);
} else {
OMElement parent = (OMElement) element.getParent();
if (parent == null) {
@@ -223,7 +229,7 @@
}
/**
- * Method getNamespace.
+ * Method getNamespace.
*
* @return Returns String.
* @throws OMException
@@ -358,7 +364,7 @@
* @return Returns Object.
*/
public Object getParser() {
- if (parserAccessed){
+ if (parserAccessed) {
throw new IllegalStateException(
"Parser already accessed!");
}
@@ -392,7 +398,7 @@
* Forwards the parser one step further, if parser is not completed yet.
* If this is called after parser is done, then throw an OMException.
* If the cache is set to false, then returns the event, *without* building the OM tree.
- * If the cache is set to true, then handles all the events within this, and
+ * If the cache is set to true, then handles all the events within this, and
* builds the object structure appropriately and returns the event.
*
* @return Returns int.
@@ -418,7 +424,7 @@
/**
* Method getRegisteredContentHandler.
- *
+ *
* @return Returns Object.
*/
public Object getRegisteredContentHandler() {
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Fri Mar 31 10:51:56 2006
@@ -300,29 +300,40 @@
String namespaceURI = parser.getNamespaceURI();
String prefix = parser.getPrefix();
+
OMNamespace namespace = null;
if (namespaceURI != null && namespaceURI.length() > 0) {
+ System.out.println(prefix+ ":" + namespaceURI);
+
// prefix being null means this elements has a default namespace or it has inherited
// a default namespace from its parent
- prefix = prefix == null ? "" : prefix;
namespace = node.findNamespace(namespaceURI, prefix);
-
if (namespace == null) {
- namespace = node.declareNamespace(namespaceURI, prefix);
+ if (prefix == null || "".equals(prefix)) {
+ namespace = node.declareDefaultNamespace(namespaceURI);
+ } else {
+ namespace = node.declareNamespace(namespaceURI, prefix);
+ }
}
node.setNamespace(namespace);
}
int namespaceCount = parser.getNamespaceCount();
+ String nsprefix;
+ String namespaceURIFromParser;
for (int i = 0; i < namespaceCount; i++) {
- String nsprefix = parser.getNamespacePrefix(i);
- nsprefix = (nsprefix == null ? "" : nsprefix);
-
+ nsprefix = parser.getNamespacePrefix(i);
//if the namespace is not defined already when we write the start tag declare it
- if (!nsprefix.equals(prefix)) {
+ // check whether this is the default namespace and make sure we have not declared that earlier
+ namespaceURIFromParser = parser.getNamespaceURI(i);
+ if (nsprefix == null && namespace != null && !namespaceURIFromParser.equals(namespace.getName()))
+ {
+ node.declareDefaultNamespace(parser.getNamespaceURI(i));
+ } else if (nsprefix != null && !"".equals(nsprefix) && !nsprefix.equals(prefix)) {
+
node.declareNamespace(parser.getNamespaceURI(i),
parser.getNamespacePrefix(i));
}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java Fri Mar 31 10:51:56 2006
@@ -689,9 +689,16 @@
if (namespaces == null) {
this.namespaces = new HashMap(5);
}
- if (namespace != null
- && (namespace.getPrefix() != null || "".equals(namespace
- .getPrefix()))) {
+
+ if (namespace != null) {
+ String prefix = namespace.getPrefix();
+ if ("".equals(prefix)) {
+ namespace = declareDefaultNamespace(namespace.getName());
+ } else if (prefix == null) {
+ prefix = OMSerializerUtil.getNextNSPrefix();
+ namespace = new NamespaceImpl(namespace.getName(), prefix, this.factory);
+ }
+
if (!namespace.getPrefix().startsWith(OMConstants.XMLNS_NS_PREFIX)) {
namespaces.put(namespace.getPrefix(), namespace);
}
@@ -706,11 +713,43 @@
* String)
*/
public OMNamespace declareNamespace(String uri, String prefix) {
+ if ("".equals(prefix))
+ prefix = OMSerializerUtil.getNextNSPrefix();
NamespaceImpl ns = new NamespaceImpl(uri, prefix, this.factory);
return declareNamespace(ns);
}
/**
+ * We use "" to store the default namespace of this element. As one can see user can not give ""
+ * as the prefix, when he declare a usual namespace.
+ *
+ * @param uri
+ */
+ public OMNamespace declareDefaultNamespace(String uri) {
+ NamespaceImpl ns = new NamespaceImpl(uri, "", this.factory);
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ namespaces.put("", ns);
+ return ns;
+ }
+
+ public OMNamespace getDefaultNamespace() {
+ if (namespaces != null) {
+ NamespaceImpl defaultNS = (NamespaceImpl) namespaces.get("");
+ if (defaultNS != null) {
+ return defaultNS;
+ }
+ }
+
+ if (parentNode instanceof ElementImpl) {
+ ElementImpl element = (ElementImpl) parentNode;
+ element.getDefaultNamespace();
+ }
+ return null;
+ }
+
+ /**
* @see org.apache.axiom.om.OMElement#findNamespace(java.lang.String,
* java.lang.String)
*/
@@ -855,7 +894,7 @@
* @see org.apache.axiom.om.OMElement#getNamespace()
*/
public OMNamespace getNamespace() throws OMException {
- return this.namespace;
+ return namespace != null ? namespace : getDefaultNamespace();
}
/**
@@ -1013,7 +1052,7 @@
protected void serialize(org.apache.axiom.om.impl.OMOutputImpl omOutput,
boolean cache) throws XMLStreamException {
- if (cache) {
+ if (!cache) {
// in this case we don't care whether the elements are built or not
// we just call the serializeAndConsume methods
OMSerializerUtil.serializeStartpart(this, omOutput);
@@ -1101,8 +1140,14 @@
* @see Object#toString()
*/
public String toString() {
- return (this.namespace != null) ? namespace.getPrefix() + ":"
- + this.localName : "" + this.localName;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+// this.build();
+ this.serialize(baos);
+ } catch (XMLStreamException e) {
+ throw new RuntimeException("Can not serialize OM Element " + this.getLocalName(), e);
+ }
+ return new String(baos.toByteArray());
}
/*
@@ -1133,10 +1178,10 @@
}
ArrayList list = new ArrayList();
for (int i = 0; i < attributes.getLength(); i++) {
- OMAttribute item = (OMAttribute)attributes.getItem(i);
+ OMAttribute item = (OMAttribute) attributes.getItem(i);
if (item.getNamespace() == null
|| !(item.getNamespace() != null && OMConstants.XMLNS_NS_URI
- .equals(item.getNamespace().getName()))) {
+ .equals(item.getNamespace().getName()))) {
list.add(item);
}
}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java Fri Mar 31 10:51:56 2006
@@ -156,10 +156,13 @@
*/
if (ns == null) {
String prefix = qname.getPrefix();
+ if ("".equals(prefix)) {
+ prefix = OMSerializerUtil.getNextNSPrefix();
+ }
ns = declareNamespace(namespaceURI, prefix);
}
if (ns != null) {
- this.ns = (ns);
+ this.ns = ns;
}
} else
@@ -287,11 +290,41 @@
* @return Returns namespace.
*/
public OMNamespace declareNamespace(String uri, String prefix) {
+ if ("".equals(prefix))
+ prefix = OMSerializerUtil.getNextNSPrefix();
OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix, this.factory);
return declareNamespace(ns);
}
/**
+ * We use "" to store the default namespace of this element. As one can see user can not give ""
+ * as the prefix, when he declare a usual namespace.
+ *
+ * @param uri
+ */
+ public OMNamespace declareDefaultNamespace(String uri) {
+ OMNamespaceImpl namespace = new OMNamespaceImpl(uri, "", this.factory);
+
+ if (namespaces == null) {
+ this.namespaces = new HashMap(5);
+ }
+ namespaces.put("", namespace);
+ return namespace;
+ }
+
+ public OMNamespace getDefaultNamespace() {
+ OMNamespace defaultNS;
+ if (namespaces != null && (defaultNS = (OMNamespace) namespaces.get("")) != null) {
+ return defaultNS;
+ }
+ if (parent instanceof OMElementImpl) {
+ return ((OMElementImpl) parent).getDefaultNamespace();
+
+ }
+ return null;
+ }
+
+ /**
* @return Returns namespace.
*/
public OMNamespace declareNamespace(OMNamespace namespace) {
@@ -375,8 +408,9 @@
omNamespace.getName().equals(uri)) {
if (ns == null) {
ns = omNamespace;
- } else if (omNamespace.getPrefix() == null || omNamespace.getPrefix().length() == 0) {
- ns = omNamespace;
+ } else
+ if (omNamespace.getPrefix() == null || omNamespace.getPrefix().length() == 0) {
+ ns = omNamespace;
}
}
@@ -821,7 +855,7 @@
* @throws OMException
*/
public OMNamespace getNamespace() throws OMException {
- return ns;
+ return ns != null ? ns : getDefaultNamespace();
}
/**
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMSerializerUtil.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMSerializerUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMSerializerUtil.java Fri Mar 31 10:51:56 2006
@@ -73,7 +73,10 @@
attr.getAttributeValue());
}
} else {
- writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());
+ String localName = attr.getLocalName();
+ String attributeValue = attr.getAttributeValue();
+ System.out.println(localName + ":" +attributeValue);
+ writer.writeAttribute(localName, attributeValue);
}
}
@@ -86,22 +89,27 @@
*/
public static void serializeNamespace(OMNamespace namespace, org.apache.axiom.om.impl.OMOutputImpl omOutput)
throws XMLStreamException {
+ if (namespace == null) {
+ return;
+ }
+ XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+ String uri = namespace.getName();
+ String prefix = namespace.getPrefix();
- if (namespace != null) {
- XMLStreamWriter writer = omOutput.getXmlStreamWriter();
- String uri = namespace.getName();
- String prefix = writer.getPrefix(uri);
- String ns_prefix = namespace.getPrefix();
-
- if (uri != null && !"".equals(uri)) {
- if (prefix == null) {
- ns_prefix = ns_prefix == null ? getNextNSPrefix() : ns_prefix;
- writer.writeNamespace(ns_prefix, uri);
- } else if (ns_prefix != null && !ns_prefix.equals(prefix)) {
- writer.writeNamespace(ns_prefix, uri);
+ String prefixFromWriter = writer.getPrefix(uri);
+
+ if (uri != null && !"".equals(uri)) {
+ // lets see whether we have default namespace now
+ if (prefix != null && "".equals(prefix) && prefixFromWriter == null) {
+ // this has not been declared earlier
+ writer.writeDefaultNamespace(uri);
+ writer.setDefaultNamespace(uri);
+ } else {
+ prefix = prefix == null ? getNextNSPrefix() : prefix;
+ if (prefix != null && !prefix.equals(prefixFromWriter)) {
+ writer.writeNamespace(prefix, uri);
}
}
-
}
}
@@ -129,7 +137,7 @@
writer.writeStartElement(nameSpaceName,
element.getLocalName());
} else {
- prefix = (prefix == null) ? "" : prefix;
+ prefix = (prefix == null) ? getNextNSPrefix() : prefix;
writer.writeStartElement(prefix, element.getLocalName(),
nameSpaceName);
writer.writeNamespace(prefix, nameSpaceName);
@@ -141,12 +149,14 @@
}
} else {
writer.writeStartElement(element.getLocalName());
- // we need to check whether there's a default namespace visible at this point because
- // otherwise this element will go into that namespace unintentionally. So we check
- // whether there is a default NS visible and if so turn it off.
- if (writer.getNamespaceContext().getNamespaceURI("") != null) {
- writer.writeDefaultNamespace("");
- }
+
+ /** // we need to check whether there's a default namespace visible at this point because
+ // otherwise this element will go into that namespace unintentionally. So we check
+ // whether there is a default NS visible and if so turn it off.
+ if (writer.getNamespaceContext().getNamespaceURI("") != null) {
+ writer.writeDefaultNamespace("");
+ } */
+
}
// add the namespaces
Added: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java?rev=390473&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java (added)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java Fri Mar 31 10:51:56 2006
@@ -0,0 +1,108 @@
+package org.apache.axiom.om;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+public class DefaultNSHandlingTest extends TestCase {
+
+ public void testDefaultNamespaceWithSameDefaultNSForAll() {
+ String testXML = "<html xmlns='http://www.w3.org/TR/REC-html40'>" +
+ "<head><title>Frobnostication</title></head>" +
+ "<body><p>Moved to <a href='http://frob.com'>here</a>.</p></body>" +
+ "</html>";
+ try {
+ StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(new ByteArrayInputStream(testXML.getBytes()));
+ OMElement documentElement = stAXOMBuilder.getDocumentElement();
+
+ System.out.println("documentElement = " + documentElement);
+
+ checkNS(documentElement);
+
+ checkNSWithChildren(documentElement);
+
+ } catch (XMLStreamException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ private void checkNSWithChildren(OMElement documentElement) {
+ Iterator childElementsIter = documentElement.getChildElements();
+ while (childElementsIter.hasNext()) {
+ OMElement omElement = (OMElement) childElementsIter.next();
+ checkNS(omElement);
+ checkNSWithChildren(omElement);
+ }
+ }
+
+ private void checkNS(OMElement element) {
+ assertTrue("http://www.w3.org/TR/REC-html40".equals(element.getNamespace().getName()));
+ }
+
+ public void testMultipleDefaultNS() {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
+ OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
+
+ OMElement omElementOne = omFactory.createOMElement("DocumentElement", null);
+ omElementOne.declareDefaultNamespace("http://defaultNS1.org");
+ OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
+
+
+ OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
+ omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
+ OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
+
+ OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
+ omElementThree.declareDefaultNamespace("http://defaultNS1.org");
+
+ assertTrue("http://defaultNS1.org".equals(omElementOneChild.getNamespace().getName()));
+ assertTrue("http://defaultNS2.org".equals(omElementTwoChild.getNamespace().getName()));
+
+
+
+ }
+
+ public static void main(String[] args) {
+ try {
+ XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+
+ xmlStreamWriter.writeStartElement("Foo");
+ System.out.println(xmlStreamWriter.getPrefix("test.org"));
+ xmlStreamWriter.writeDefaultNamespace("test.org");
+ xmlStreamWriter.setDefaultNamespace("test.org");
+ xmlStreamWriter.writeStartElement("Bar");
+ System.out.println("*"+xmlStreamWriter.getPrefix("test.org")+ "*");
+
+ xmlStreamWriter.writeEndElement();
+ xmlStreamWriter.writeEndElement();
+
+ xmlStreamWriter.flush();
+
+
+ } catch (XMLStreamException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+}
+
Modified: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/PreserveEnvelopeTest.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/PreserveEnvelopeTest.java?rev=390473&r1=390472&r2=390473&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/PreserveEnvelopeTest.java (original)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/PreserveEnvelopeTest.java Fri Mar 31 10:51:56 2006
@@ -86,10 +86,21 @@
}
}
-
+ public static void main(String[] args) {
+ String textXML = "<Assertion xmlns=\"urn:oasis:names:tc:SAML:1.0:assertion\">Test</Assertion>";
+ try {
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(textXML.getBytes()));
+ System.out.println("builder.getDoc = " + builder.getDocumentElement());
+ } catch (XMLStreamException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
- }
+ }
+
+
+
+ }