Merged latest changes from trunk.
diff --git a/modules/adb/src/org/apache/axis2/databinding/AbstractADBDataSource.java b/modules/adb/src/org/apache/axis2/databinding/AbstractADBDataSource.java
index c83767d..0c3263f 100644
--- a/modules/adb/src/org/apache/axis2/databinding/AbstractADBDataSource.java
+++ b/modules/adb/src/org/apache/axis2/databinding/AbstractADBDataSource.java
@@ -18,31 +18,14 @@
*/
package org.apache.axis2.databinding;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.HashMap;
-
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMDataSourceExt;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.QNameAwareOMDataSource;
-import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axis2.databinding.utils.writer.MTOMAwareOMBuilder;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
-public abstract class AbstractADBDataSource implements OMDataSourceExt, QNameAwareOMDataSource {
+public abstract class AbstractADBDataSource extends AbstractPushOMDataSource implements QNameAwareOMDataSource {
protected QName parentQName;
-
- HashMap map = null; // Map of properties
public AbstractADBDataSource(QName parentQName) {
this.parentQName = parentQName;
@@ -61,51 +44,6 @@
}
/**
- * @param output
- * @param format
- * @throws XMLStreamException
- * @see OMDataSource#serialize(java.io.OutputStream, org.apache.axiom.om.OMOutputFormat)
- */
- public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
- serialize(xmlStreamWriter);
- xmlStreamWriter.flush();
- }
-
- /**
- * @param writer
- * @param format
- * @throws XMLStreamException
- * @see OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
- */
- public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
- XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
- serialize(xmlStreamWriter);
- xmlStreamWriter.flush();
- }
-
- /**
- * @throws XMLStreamException
- * @see org.apache.axiom.om.OMDataSource#getReader()
- */
- public XMLStreamReader getReader() throws XMLStreamException {
- MTOMAwareOMBuilder mtomAwareOMBuilder = new MTOMAwareOMBuilder();
- serialize(mtomAwareOMBuilder);
- return mtomAwareOMBuilder.getOMElement().getXMLStreamReader();
- }
-
- /**
- * Returns true if reading the backing object is destructive.
- * An example of an object with a destructive read is an InputSteam.
- * The owning OMSourcedElement uses this information to detemine if OM tree
- * expansion is needed when reading the OMDataSourceExt.
- * @return boolean
- */
- public boolean isDestructiveRead() {
- return false;
- }
-
- /**
* Returns true if writing the backing object is destructive.
* An example of an object with a destructive write is an InputStream.
* The owning OMSourcedElement uses this information to detemine if OM tree
@@ -116,55 +54,7 @@
return false;
}
- /**
- * Returns a InputStream representing the xml data
- * @param encoding String encoding of InputStream
- * @return InputStream
- */
- public InputStream getXMLInputStream(String encoding) throws UnsupportedEncodingException {
- return new ByteArrayInputStream(getXMLBytes(encoding));
- }
-
- /**
- * Returns a byte[] representing the xml data
- * @param encoding String encoding of InputStream
- * @return byte[]
- * @see getXMLInputStream
- */
- public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OMOutputFormat format = new OMOutputFormat();
- format.setCharSetEncoding(encoding);
- try {
- serialize(baos, format);
- } catch (XMLStreamException e) {
- new OMException(e);
- }
- return baos.toByteArray();
- }
-
public OMDataSourceExt copy() {
return null;
}
-
- public Object getProperty(String key) {
- if (map == null) {
- return null;
- }
- return map.get(key);
- }
-
- public Object setProperty(String key, Object value) {
- if (map == null) {
- map = new HashMap();
- }
- return map.put(key, value);
- }
-
- public boolean hasProperty(String key) {
- if (map == null) {
- return false;
- }
- return map.containsKey(key);
- }
}
diff --git a/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java b/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
deleted file mode 100644
index eecfe1e..0000000
--- a/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * 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.axis2.databinding.utils.writer;
-
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMText;
-
-import javax.activation.DataHandler;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import java.io.IOException;
-import java.util.*;
-
-
-public class MTOMAwareOMBuilder implements XMLStreamWriter, DataHandlerWriter {
- // this is the om Element we are going to create
- private OMElement rootElement;
- private OMFactory omFactory;
-
- private OMElement currentOMElement;
-
- private Stack omElementStack;
-
- // this map contains the namespace key and OMNamespace
- private Map namespaceOMNamesapceMap;
-
- private int prefixNum;
-
- private OMStreamNamespaceContext omStreamNamespaceContext;
-
- /**
- * this stack keeps the name spaces added to the oMElementStack at a pirticular element
- * when end element is written the namspeces added at a pirticulare element is removed.
- */
- private Stack<List<String>> namespacesListStack;
-
-
- public MTOMAwareOMBuilder() {
- omFactory = OMAbstractFactory.getOMFactory();
- omElementStack = new Stack();
- currentOMElement = null;
- omStreamNamespaceContext = new OMStreamNamespaceContext();
- namespaceOMNamesapceMap = new HashMap();
- prefixNum = 0;
- namespacesListStack = new Stack<List<String>>();
-
- }
-
- // serailizer must have finish serializing when we call this method.
- public OMElement getOMElement() throws XMLStreamException {
- if (!omElementStack.isEmpty()) {
- throw new XMLStreamException("This is an invalid Xml ");
- }
- return rootElement;
- }
-
- private OMNamespace getOMNamespace(String namespace, String prefix) throws XMLStreamException {
- OMNamespace omNamespace = null;
- if (namespace != null) {
- if (namespaceOMNamesapceMap.containsKey(namespace)) {
- omNamespace = (OMNamespace) namespaceOMNamesapceMap.get(namespace);
- } else {
- if (prefix == null) {
- prefix = "ns" + ++prefixNum;
- }
- omNamespace = omFactory.createOMNamespace(namespace, prefix);
- this.omStreamNamespaceContext.registerNamespace(namespace, prefix);
- namespaceOMNamesapceMap.put(namespace, omNamespace);
- // add this namespce to top list as well
- namespacesListStack.peek().add(namespace);
- }
- }
- return omNamespace;
- }
-
- public void writeStartElement(String localName) throws XMLStreamException {
- writeStartElement(null, localName, null);
- }
-
- public void writeStartElement(String namespace, String localName) throws XMLStreamException {
- writeStartElement(null, localName, namespace);
- }
-
- public void writeStartElement(String prefix, String localName, String namespace) throws XMLStreamException {
- // add a new stack element at the start of a new element
- namespacesListStack.push(new ArrayList<String>());
- OMNamespace omNamespace = getOMNamespace(namespace, prefix);
- currentOMElement = omFactory.createOMElement(localName, omNamespace);
- if (!omElementStack.isEmpty()) {
- // we always keep the parent at the top of the stack
- OMElement parent = (OMElement) omElementStack.peek();
- parent.addChild(currentOMElement);
- } else {
- // i.e this must be an start root element
- rootElement = currentOMElement;
- }
- // set this as the top element
- omElementStack.push(currentOMElement);
- }
-
- public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
- writeEmptyElement(null, localName, namespaceURI);
- }
-
- public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
- writeStartElement(prefix, localName, namespaceURI);
- writeEndElement();
- }
-
- public void writeEmptyElement(String localName) throws XMLStreamException {
- writeEmptyElement(null, localName, null);
- }
-
- public void writeEndElement() throws XMLStreamException {
- omElementStack.pop();
- // remove the namespaces declared by this element
- List<String> addedNamespaces = namespacesListStack.pop();
- for (String namespace : addedNamespaces){
- namespaceOMNamesapceMap.remove(namespace);
- omStreamNamespaceContext.removeNamespce(namespace);
- }
- }
-
- public void writeEndDocument() throws XMLStreamException {
- // nothing to do
- }
-
- public void close() throws XMLStreamException {
- // nothing to do
- }
-
- public void flush() throws XMLStreamException {
- // nothing to do
-
-
- }
-
- public void writeAttribute(String attributeName, String attributeValue) throws XMLStreamException {
- writeAttribute(null, null, attributeName, attributeValue);
- }
-
- public void writeAttribute(String prefix, String namespace, String attributeName, String attributeValue) throws XMLStreamException {
- currentOMElement.addAttribute(attributeName, attributeValue, getOMNamespace(namespace, prefix));
- }
-
- public void writeAttribute(String namespace, String attributeName, String attributeValue) throws XMLStreamException {
- writeAttribute(null, namespace, attributeName, attributeValue);
- }
-
- public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
- if (namespaceURI != null) {
- OMNamespace omNamespace = getOMNamespace(namespaceURI, prefix);
- currentOMElement.declareNamespace(omNamespace);
- }
- }
-
- public void writeDefaultNamespace(String namespace) throws XMLStreamException {
- rootElement.declareDefaultNamespace(namespace);
- getOMNamespace(namespace, "");
- }
-
- public void writeComment(String string) throws XMLStreamException {
- omFactory.createOMComment(currentOMElement, string);
- }
-
- public void writeProcessingInstruction(String string) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public void writeProcessingInstruction(String string, String string1) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public void writeCData(String string) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public void writeDTD(String string) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public void writeEntityRef(String string) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public void writeStartDocument() throws XMLStreamException {
- // nothing to do
- }
-
- public void writeStartDocument(String string) throws XMLStreamException {
- // nothing to do
- }
-
- public void writeStartDocument(String string, String string1) throws XMLStreamException {
- // nothing to do
- }
-
- public void writeCharacters(String string) throws XMLStreamException {
- currentOMElement.setText(string);
- }
-
- public void writeCharacters(char[] chars, int i, int i1) throws XMLStreamException {
- writeCharacters(new String(chars, i, i1));
- }
-
- public String getPrefix(String namespace) throws XMLStreamException {
- return this.omStreamNamespaceContext.getPrefix(namespace);
- }
-
- public void setPrefix(String prefix, String uri) throws XMLStreamException {
- // this method will add the namespace correctly.
- getOMNamespace(uri, prefix);
- }
-
- public void setDefaultNamespace(String namespace) throws XMLStreamException {
- rootElement.declareDefaultNamespace(namespace);
- getOMNamespace(namespace, "");
- }
-
- public void setNamespaceContext(NamespaceContext namespaceContext) throws XMLStreamException {
- throw new UnsupportedOperationException("this method has not yet been implemented");
- }
-
- public NamespaceContext getNamespaceContext() {
- return this.omStreamNamespaceContext;
- }
-
- public Object getProperty(String name) throws IllegalArgumentException {
- if (DataHandlerWriter.PROPERTY.equals(name)) {
- return this;
- } else {
- throw new IllegalArgumentException("Property " + name + " not supported");
- }
- }
-
- public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize)
- throws IOException, XMLStreamException {
- OMText omText = omFactory.createOMText(dataHandler, optimize);
- if (contentID != null) {
- omText.setContentID(contentID);
- }
- currentOMElement.addChild(omText);
- }
-
- public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID,
- boolean optimize) throws IOException, XMLStreamException {
- OMText omText = omFactory.createOMText(contentID, dataHandlerProvider, optimize);
- currentOMElement.addChild(omText);
- }
-}
diff --git a/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java b/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java
deleted file mode 100644
index e947b9c..0000000
--- a/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.axis2.databinding.utils.writer;
-
-import javax.xml.namespace.NamespaceContext;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-
-public class OMStreamNamespaceContext implements NamespaceContext {
-
- private Map namespaceToPrefixMap;
- private Map prefixToNamespaceMap;
-
- public OMStreamNamespaceContext() {
- this.namespaceToPrefixMap = new HashMap();
- this.prefixToNamespaceMap = new HashMap();
- }
-
- public void registerNamespace(String namespace,String prefix){
- this.namespaceToPrefixMap.put(namespace,prefix);
- this.prefixToNamespaceMap.put(prefix,namespace);
- }
-
- public String getNamespaceURI(String prefix) {
- return (String) prefixToNamespaceMap.get(prefix);
- }
-
- public String getPrefix(String namespaceURI) {
- return (String) namespaceToPrefixMap.get(namespaceURI);
- }
-
- public Iterator getPrefixes(String namespaceURI) {
- return prefixToNamespaceMap.keySet().iterator();
- }
-
- public void removeNamespce(String namespaceURI){
- String prefix = (String) this.namespaceToPrefixMap.remove(namespaceURI);
- this.prefixToNamespaceMap.remove(prefix);
- }
-
-
-}
diff --git a/modules/adb/test/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilderTest.java b/modules/adb/test/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilderTest.java
deleted file mode 100644
index 8eea492..0000000
--- a/modules/adb/test/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilderTest.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * 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.axis2.databinding.utils.writer;
-
-import junit.framework.TestCase;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axis2.databinding.utils.BeanUtil;
-import org.apache.axis2.databinding.utils.ConverterUtil;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-
-public class MTOMAwareOMBuilderTest extends TestCase {
-
- private int prefixNum;
-
- public void testGetOMElement() {
-
- MTOMAwareOMBuilder writer = new MTOMAwareOMBuilder();
-
- try {
-
- writeStartElement(null, "test1", writer);
- writeStartElement("http://apach.temp.uri", "test2", writer);
- writeStartElement("http://apach.temp.uri1", "test3", writer);
- writer.writeCharacters("test string3");
- writeAttribute("http://apach.temp.uri", "attribute1", "attrubteValue1", writer);
- writeQNames(new QName[]{new QName("http://axis2.apach.org1", "testQName"),
- new QName("http://axis2.apach.org2", "testQName2")}, writer);
- writer.writeEndElement();
- writeStartElement("http://apach.temp.uri1", "test4", writer);
- writeAttribute(null, "attribute1", "attrubteValue1", writer);
- writeAttribute("ns1", "http://apach.temp.uri", "attribute1", "attrubteValue1", writer);
- writer.writeCharacters("test string4");
- writer.writeEndElement();
- writeStartElement("http://temp.new.org", "testattributeElement", writer);
- writeQNameAttribute(null, "testQname", new QName("http://temp.new.org", "testQName"), writer);
- writeQName(new QName("http://axis2.apach.org", "testQName"), writer);
- writer.writeEndElement();
- writer.writeEndElement();
- writer.writeEndElement();
-
- OMElement omElement = writer.getOMElement();
- System.out.println("OM String ==> " + omElement.toString());
-
- XMLStreamReader xmlReader = omElement.getXMLStreamReader();
- StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(xmlReader);
- OMElement result = stAXOMBuilder.getDocumentElement();
-
- System.out.println("OM result ==> " + result.toString());
- } catch (XMLStreamException e) {
- fail();
- }
-
- }
-
- private String generatePrefix(String string) {
- return "ns" + ++prefixNum;
- }
-
- private void writeStartElement(String namespace, String localName, XMLStreamWriter xmlWriter) throws XMLStreamException {
-
- if ((namespace != null) && ! namespace.equals("")) {
- java.lang.String prefix = xmlWriter.getPrefix(namespace);
-
- if (prefix == null) {
- prefix = "ns" + ++prefixNum;
- xmlWriter.writeStartElement(prefix, localName, namespace);
- xmlWriter.writeNamespace(prefix, namespace);
- xmlWriter.setPrefix(prefix, namespace);
- } else {
- xmlWriter.writeStartElement(namespace, localName);
- }
- } else {
- xmlWriter.writeStartElement(localName);
- }
- }
-
- private void writeAttribute(String prefix, String namespace, String attName,
- String attValue, XMLStreamWriter xmlWriter)
- throws XMLStreamException {
- if (xmlWriter.getPrefix(namespace) == null) {
- xmlWriter.writeNamespace(prefix, namespace);
- xmlWriter.setPrefix(prefix, namespace);
-
- }
- xmlWriter.writeAttribute(namespace, attName, attValue);
- }
-
- private void writeAttribute(String namespace, String attName,
- String attValue, XMLStreamWriter xmlWriter) throws XMLStreamException {
- if ((namespace == null) || namespace.equals("")) {
- xmlWriter.writeAttribute(attName, attValue);
- } else {
- registerPrefix(xmlWriter, namespace);
- xmlWriter.writeAttribute(namespace, attName, attValue);
- }
- }
-
- private void writeQNameAttribute(String namespace, String attName,
- QName qname, XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
-
- String attributeNamespace = qname.getNamespaceURI();
- String attributePrefix = xmlWriter.getPrefix(attributeNamespace);
- if (attributePrefix == null) {
- attributePrefix = registerPrefix(xmlWriter, attributeNamespace);
- }
- java.lang.String attributeValue;
- if (attributePrefix.trim().length() > 0) {
- attributeValue = attributePrefix + ":" + qname.getLocalPart();
- } else {
- attributeValue = qname.getLocalPart();
- }
-
- if ((namespace != null) && namespace.equals("")) {
- xmlWriter.writeAttribute(attName, attributeValue);
- } else {
- if (namespace != null) {
- registerPrefix(xmlWriter, namespace);
- }
- xmlWriter.writeAttribute(namespace, attName, attributeValue);
- }
- }
-
- private void writeQName(QName qname,
- XMLStreamWriter xmlWriter) throws javax.xml.stream.XMLStreamException {
- String namespaceURI = qname.getNamespaceURI();
- if (namespaceURI != null) {
- String prefix = xmlWriter.getPrefix(namespaceURI);
- if (prefix == null) {
- prefix = generatePrefix(namespaceURI);
- xmlWriter.writeNamespace(prefix, namespaceURI);
- xmlWriter.setPrefix(prefix, namespaceURI);
- }
-
- if (prefix.trim().length() > 0) {
- xmlWriter.writeCharacters(prefix + ":" + ConverterUtil.convertToString(qname));
- } else {
- // i.e this is the default namespace
- xmlWriter.writeCharacters(ConverterUtil.convertToString(qname));
- }
-
- } else {
- xmlWriter.writeCharacters(ConverterUtil.convertToString(qname));
- }
- }
-
- private void writeQNames(QName[] qnames,
- XMLStreamWriter xmlWriter) throws XMLStreamException {
-
- if (qnames != null) {
- // we have to store this data until last moment since it is not possible to write any
- // namespace data after writing the charactor data
- StringBuffer stringToWrite = new StringBuffer();
- String namespaceURI = null;
- String prefix = null;
-
- for (int i = 0; i < qnames.length; i++) {
- if (i > 0) {
- stringToWrite.append(" ");
- }
- namespaceURI = qnames[i].getNamespaceURI();
- if (namespaceURI != null) {
- prefix = xmlWriter.getPrefix(namespaceURI);
- if ((prefix == null) || (prefix.length() == 0)) {
- prefix = generatePrefix(namespaceURI);
- xmlWriter.writeNamespace(prefix, namespaceURI);
- xmlWriter.setPrefix(prefix, namespaceURI);
- }
-
- if (prefix.trim().length() > 0) {
- stringToWrite.append(prefix).append(":").append(ConverterUtil.convertToString(qnames[i]));
- } else {
- stringToWrite.append(ConverterUtil.convertToString(qnames[i]));
- }
- } else {
- stringToWrite.append(ConverterUtil.convertToString(qnames[i]));
- }
- }
- xmlWriter.writeCharacters(stringToWrite.toString());
- }
-
- }
-
-
- private String registerPrefix(XMLStreamWriter xmlWriter, String namespace) throws XMLStreamException {
- String prefix = xmlWriter.getPrefix(namespace);
-
- if (prefix == null) {
- prefix = generatePrefix(namespace);
- while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix) != null) {
- prefix = BeanUtil.getUniquePrefix();
- }
- xmlWriter.writeNamespace(prefix, namespace);
- xmlWriter.setPrefix(prefix, namespace);
- }
- return prefix;
- }
-
-}