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/02/01 11:36:10 UTC
svn commit: r374036 [5/15] - in /webservices/commons/trunk/axiom:
src/org/apache/ws/ src/org/apache/ws/commons/
src/org/apache/ws/commons/attachments/
src/org/apache/ws/commons/attachments/utils/ src/org/apache/ws/commons/om/
src/org/apache/ws/commons/...
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/exception/XMLComparisonException.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.exception;
+
+public class XMLComparisonException extends Exception {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+
+ private static final long serialVersionUID = -7918497983548520994L;
+
+ public XMLComparisonException(String message) {
+ super(message);
+ }
+
+ public XMLComparisonException(Throwable cause) {
+ super(cause);
+ }
+
+ public XMLComparisonException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMLinkedListImplFactory.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,266 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.factory;
+
+import org.apache.ws.commons.om.OMAttribute;
+import org.apache.ws.commons.om.OMComment;
+import org.apache.ws.commons.om.OMContainer;
+import org.apache.ws.commons.om.OMDocType;
+import org.apache.ws.commons.om.OMDocument;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMFactory;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMProcessingInstruction;
+import org.apache.ws.commons.om.OMText;
+import org.apache.ws.commons.om.OMXMLParserWrapper;
+import org.apache.ws.commons.om.impl.llom.OMAttributeImpl;
+import org.apache.ws.commons.om.impl.llom.OMCommentImpl;
+import org.apache.ws.commons.om.impl.llom.OMDocTypeImpl;
+import org.apache.ws.commons.om.impl.llom.OMDocumentImpl;
+import org.apache.ws.commons.om.impl.llom.OMElementImpl;
+import org.apache.ws.commons.om.impl.llom.OMNamespaceImpl;
+import org.apache.ws.commons.om.impl.llom.OMProcessingInstructionImpl;
+import org.apache.ws.commons.om.impl.llom.OMTextImpl;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class OMLinkedListImplFactory
+ */
+public class OMLinkedListImplFactory implements OMFactory {
+
+ private static final String uriAndPrefixSeparator = ";";
+ /**
+ * This is a map of namespaces with the namespace URI as the key and
+ * Namespace object itself as the value.
+ */
+ protected Map namespaceTable = new HashMap(5);
+
+ /**
+ * Method createOMElement.
+ *
+ * @param localName
+ * @param ns
+ * @return Returns OMElement.
+ */
+ public OMElement createOMElement(String localName, OMNamespace ns) {
+ return new OMElementImpl(localName, ns);
+ }
+
+ public OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent) {
+ return new OMElementImpl(localName, ns, parent);
+ }
+
+ /**
+ * Method createOMElement.
+ *
+ * @param localName
+ * @param ns
+ * @param parent
+ * @param builder
+ * @return Returns OMElement.
+ */
+ public OMElement createOMElement(String localName, OMNamespace ns,
+ OMContainer parent,
+ OMXMLParserWrapper builder) {
+ return new OMElementImpl(localName, ns, parent,
+ builder);
+ }
+
+ /**
+ * Method createOMElement.
+ *
+ * @param localName
+ * @param namespaceURI
+ * @param namespacePrefix
+ * @return Returns OMElement.
+ */
+ public OMElement createOMElement(String localName, String namespaceURI,
+ String namespacePrefix) {
+ return this.createOMElement(localName,
+ this.createOMNamespace(namespaceURI,
+ namespacePrefix));
+ }
+
+ /**
+ * Method createOMElement.
+ *
+ * @param qname
+ * @param parent
+ * @return Returns OMElement.
+ * @throws OMException
+ */
+ public OMElement createOMElement(QName qname, OMContainer parent)
+ throws OMException {
+ return new OMElementImpl(qname, parent);
+ }
+
+ /**
+ * Method createOMNamespace.
+ *
+ * @param uri
+ * @param prefix
+ * @return Returns OMNamespace.
+ */
+ public OMNamespace createOMNamespace(String uri, String prefix) {
+ String key = uri + uriAndPrefixSeparator + prefix;
+ OMNamespace existingNamespaceObject = (OMNamespace) namespaceTable.get(key);
+ if (existingNamespaceObject == null) {
+ existingNamespaceObject = new OMNamespaceImpl(uri, prefix);
+ namespaceTable.put(key, existingNamespaceObject);
+ }
+ return existingNamespaceObject;
+ }
+
+ /**
+ * Method createText.
+ *
+ * @param parent
+ * @param text
+ * @return Returns OMText.
+ */
+ public OMText createText(OMElement parent, String text) {
+ return new OMTextImpl(parent, text);
+ }
+
+ public OMText createText(OMElement parent, String text, int type) {
+ return new OMTextImpl(parent, text, type);
+ }
+
+ /**
+ * Method createText.
+ *
+ * @param s
+ * @return Returns OMText.
+ */
+ public OMText createText(String s) {
+ return new OMTextImpl(s);
+ }
+
+ public OMText createText(String s, int type) {
+ return new OMTextImpl(s, type);
+ }
+
+ /**
+ * Creates text.
+ *
+ * @param s
+ * @param mimeType
+ * @param optimize
+ * @return Returns OMText.
+ */
+ public OMText createText(String s, String mimeType, boolean optimize) {
+ return new OMTextImpl(s, mimeType, optimize);
+ }
+
+ /**
+ * Creates text.
+ *
+ * @param dataHandler
+ * @param optimize
+ * @return Returns OMText.
+ */
+ public OMText createText(Object dataHandler, boolean optimize) {
+ return new OMTextImpl(dataHandler, optimize);
+ }
+
+ public OMText createText(String contentID, OMElement parent,
+ OMXMLParserWrapper builder) {
+ return new OMTextImpl(contentID, parent, builder);
+ }
+
+ /**
+ * Creates text.
+ *
+ * @param parent
+ * @param s
+ * @param mimeType
+ * @param optimize
+ * @return Returns OMText.
+ */
+ public OMText createText(OMElement parent,
+ String s,
+ String mimeType,
+ boolean optimize) {
+ return new OMTextImpl(parent, s, mimeType, optimize);
+ }
+
+ /**
+ * Creates attribute.
+ *
+ * @param localName
+ * @param ns
+ * @param value
+ * @return Returns OMAttribute.
+ */
+ public OMAttribute createOMAttribute(String localName,
+ OMNamespace ns,
+ String value) {
+ return new OMAttributeImpl(localName, ns, value);
+ }
+
+ /**
+ * Creates DocType/DTD.
+ *
+ * @param parent
+ * @param content
+ * @return Returns doctype.
+ */
+ public OMDocType createOMDocType(OMContainer parent, String content) {
+ return new OMDocTypeImpl(parent, content);
+ }
+
+ /**
+ * Creates a PI.
+ *
+ * @param parent
+ * @param piTarget
+ * @param piData
+ * @return Returns OMProcessingInstruction.
+ */
+ public OMProcessingInstruction createOMProcessingInstruction(OMContainer parent, String piTarget, String piData) {
+ return new OMProcessingInstructionImpl(parent, piTarget, piData);
+ }
+
+ /**
+ * Creates a comment.
+ *
+ * @param parent
+ * @param content
+ * @return Returns OMComment.
+ */
+ public OMComment createOMComment(OMContainer parent, String content) {
+ return new OMCommentImpl(parent, content);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.commons.om.OMFactory#createOMDocument()
+ */
+ public OMDocument createOMDocument() {
+ return new OMDocumentImpl();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.commons.om.OMFactory#createOMDocument(org.apache.ws.commons.om.OMXMLParserWrapper)
+ */
+ public OMDocument createOMDocument(OMXMLParserWrapper builder) {
+ return new OMDocumentImpl(builder);
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/factory/OMXMLBuilderFactory.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.factory;
+
+import org.apache.ws.commons.om.OMFactory;
+import org.apache.ws.commons.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.ws.commons.soap.SOAPFactory;
+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Class OMXMLBuilderFactory
+ */
+public class OMXMLBuilderFactory {
+ /**
+ * Field PARSER_XPP
+ */
+ public static final String PARSER_XPP = "XPP";
+
+ /**
+ * Field PARSER_STAX
+ */
+ public static final String PARSER_STAX = "StAX";
+
+ /**
+ * Field MODEL_SOAP_SPECIFIC
+ */
+ public static final String MODEL_SOAP_SPECIFIC = "SOAP_SPECIFIC";
+
+ /**
+ * Field MODEL_OM
+ */
+ public static final String MODEL_OM = "OM_ONLY";
+
+ /**
+ * Method createStAXSOAPModelBuilder.
+ *
+ * @param soapFactory
+ * @param parser
+ * @return Returns StAXSOAPModelBuilder.
+ */
+ public static StAXSOAPModelBuilder createStAXSOAPModelBuilder(
+ SOAPFactory soapFactory, XMLStreamReader parser) {
+ return new StAXSOAPModelBuilder(parser, soapFactory, null);
+ }
+
+ /**
+ * Method createStAXOMBuilder.
+ *
+ * @param ombuilderFactory
+ * @param parser
+ * @return Returns StAXOMBuilder.
+ */
+ public static StAXOMBuilder createStAXOMBuilder(OMFactory ombuilderFactory,
+ XMLStreamReader parser) {
+ return new StAXOMBuilder(ombuilderFactory, parser);
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/mtom/MTOMStAXSOAPModelBuilder.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.mtom;
+
+import org.apache.ws.commons.attachments.MIMEHelper;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.OMText;
+import org.apache.ws.commons.om.impl.MTOMConstants;
+import org.apache.ws.commons.om.impl.OMNodeEx;
+import org.apache.ws.commons.soap.SOAPFactory;
+import org.apache.ws.commons.soap.impl.llom.builder.StAXSOAPModelBuilder;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+public class MTOMStAXSOAPModelBuilder extends StAXSOAPModelBuilder implements MTOMConstants {
+
+ /**
+ * <code>mimeHelper</code> handles deferred parsing of incoming MIME
+ * Messages.
+ */
+ MIMEHelper mimeHelper;
+
+ int partIndex = 0;
+
+ public MTOMStAXSOAPModelBuilder(XMLStreamReader parser,
+ SOAPFactory factory,
+ MIMEHelper mimeHelper, String soapVersion) {
+ super(parser, factory, soapVersion);
+ this.mimeHelper = mimeHelper;
+ }
+
+ /**
+ * @param reader
+ * @param mimeHelper
+ */
+ public MTOMStAXSOAPModelBuilder(XMLStreamReader reader,
+ MIMEHelper mimeHelper, String soapVersion) {
+ super(reader, soapVersion);
+ this.mimeHelper = mimeHelper;
+ }
+
+ protected OMNode createOMElement() throws OMException {
+
+ elementLevel++;
+ String elementName = parser.getLocalName();
+
+ String namespaceURI = parser.getNamespaceURI();
+
+ // create an OMBlob if the element is an <xop:Include>
+
+ if (XOP_INCLUDE.equalsIgnoreCase(elementName)
+ && XOP_NAMESPACE_URI
+ .equalsIgnoreCase(namespaceURI)) {
+ // do we need to check prfix as well. Meaning, should it be "XOP" ?
+
+
+ OMText node;
+ String contentID = null;
+ String contentIDName = null;
+ if (lastNode == null) {
+ // Decide whether to ckeck the level >3 or not
+ throw new OMException(
+ "XOP:Include element is not supported here");
+ }
+ if (parser.getAttributeCount() > 0) {
+ contentID = parser.getAttributeValue(0);
+ contentID = contentID.trim();
+ contentIDName = parser.getAttributeLocalName(0);
+ if (contentIDName.equalsIgnoreCase("href")
+ & contentID.substring(0, 3).equalsIgnoreCase("cid")) {
+ contentID = contentID.substring(4);
+ String charsetEncoding = getDocument().getCharsetEncoding();
+ String charEnc = charsetEncoding == null || "".equals(charsetEncoding) ? "UTF-8" : charsetEncoding;
+ try {
+ contentID = URLDecoder.decode(contentID, charEnc);
+ } catch (UnsupportedEncodingException e) {
+ throw new OMException("Unsupported Character Encoding Found", e);
+ }
+ } else if (!(contentIDName.equalsIgnoreCase("href")
+ & (!contentID.equals("")))) {
+ throw new OMException(
+ "contentID not Found in XOP:Include element");
+ }
+ } else {
+ throw new OMException(
+ "Href attribute not found in XOP:Include element");
+ }
+
+ // This cannot happen. XOP:Include is always the only child of an parent element
+ // cause it is same as having some text
+ try {
+ OMElement e = (OMElement) lastNode;
+ //node = new OMTextImpl(contentID, (OMElement) lastNode, this);
+ node = this.omfactory.createText(contentID, (OMElement) lastNode, this);
+ e.setFirstChild(node);
+ } catch (ClassCastException e) {
+ throw new OMException(
+ "Last Node & Parent of an OMText should be an Element" +
+ e);
+ }
+
+ return node;
+
+ } else {
+ OMElement node;
+ if (lastNode == null) {
+ node = constructNode(null, elementName, true);
+ setSOAPEnvelope(node);
+ } else if (lastNode.isComplete()) {
+ node =
+ constructNode((OMElement) lastNode.getParent(),
+ elementName,
+ false);
+ ((OMNodeEx)lastNode).setNextOMSibling(node);
+ ((OMNodeEx)node).setPreviousOMSibling(lastNode);
+ } else {
+ OMElement e = (OMElement) lastNode;
+ node = constructNode((OMElement) lastNode, elementName, false);
+ e.setFirstChild(node);
+ }
+
+ // fill in the attributes
+ processAttributes(node);
+ //TODO Exception when trying to log . check this
+ // log.info("Build the OMElelment {" + node.getLocalName() + '}'
+ // + node.getLocalName() + "By the StaxSOAPModelBuilder");
+ return node;
+ }
+ }
+
+ public DataHandler getDataHandler(String blobContentID) throws OMException {
+ return mimeHelper.getDataHandler(blobContentID);
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamWriterToContentHandlerConverter.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.serialize;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class StreamWriterToContentHandlerConverter
+ */
+public class StreamWriterToContentHandlerConverter implements ContentHandler {
+ /**
+ * Field log
+ */
+ private Log log = LogFactory.getLog(getClass());
+
+ /**
+ * Field writer
+ */
+ private XMLStreamWriter writer;
+
+ /**
+ * Constructor StreamWriterToContentHandlerConverter.
+ *
+ * @param omOutput
+ */
+ public StreamWriterToContentHandlerConverter(org.apache.ws.commons.om.impl.OMOutputImpl omOutput) {
+ this.writer = omOutput.getXmlStreamWriter();
+ }
+
+ /**
+ * Method endDocument.
+ *
+ * @throws SAXException
+ */
+ public void endDocument() throws SAXException {
+
+ // do nothing
+ }
+
+ /**
+ * Method startDocument.
+ *
+ * @throws SAXException
+ */
+ public void startDocument() throws SAXException {
+
+ //
+ }
+
+ /**
+ * Method characters.
+ *
+ * @param ch
+ * @param start
+ * @param length
+ * @throws SAXException
+ */
+ public void characters(char ch[], int start, int length)
+ throws SAXException {
+ try {
+ writer.writeCharacters(ch, start, length);
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ /**
+ * Method ignorableWhitespace.
+ *
+ * @param ch
+ * @param start
+ * @param length
+ * @throws SAXException
+ */
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException {
+
+ // throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method endPrefixMapping.
+ *
+ * @param prefix
+ * @throws SAXException
+ */
+ public void endPrefixMapping(String prefix) throws SAXException {
+
+ // throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method skippedEntity.
+ *
+ * @param name
+ * @throws SAXException
+ */
+ public void skippedEntity(String name) throws SAXException {
+
+ // throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method setDocumentLocator.
+ *
+ * @param locator
+ */
+ public void setDocumentLocator(Locator locator) {
+
+ // throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method processingInstruction.
+ *
+ * @param target
+ * @param data
+ * @throws SAXException
+ */
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+
+ // throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Method startPrefixMapping.
+ *
+ * @param prefix
+ * @param uri
+ * @throws SAXException
+ */
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ try {
+ writer.writeNamespace(prefix, uri);
+ writer.setPrefix(prefix, uri);
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ /**
+ * Method endElement.
+ *
+ * @param namespaceURI
+ * @param localName
+ * @param qName
+ * @throws SAXException
+ */
+ public void endElement(String namespaceURI,
+ String localName,
+ String qName)
+ throws SAXException {
+ try {
+ writer.writeEndElement();
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ /**
+ * Method getPrefix.
+ *
+ * @param qName
+ * @return Returns String.
+ */
+ private String getPrefix(String qName) {
+ if (qName != null) {
+ return qName.substring(0, qName.indexOf(":"));
+ }
+ return null;
+ }
+
+ /**
+ * Method startElement.
+ *
+ * @param namespaceURI
+ * @param localName
+ * @param qName
+ * @param atts
+ * @throws SAXException
+ */
+ public void startElement(String namespaceURI,
+ String localName,
+ String qName,
+ Attributes atts)
+ throws SAXException {
+ try {
+ log.info("writing element {" + namespaceURI + '}' + localName
+ + " directly to stream ");
+ String prefix = getPrefix(qName);
+
+ // it is only the prefix we want to learn from the QName! so we can get rid of the
+ // spliting QName
+ if (prefix == null) {
+ writer.writeStartElement(namespaceURI, localName);
+ } else {
+ writer.writeStartElement(prefix, localName, namespaceURI);
+ }
+ if (atts != null) {
+ int attCount = atts.getLength();
+ for (int i = 0; i < attCount; i++) {
+ writer.writeAttribute(atts.getURI(i), localName,
+ atts.getValue(i));
+ }
+ }
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/serialize/StreamingOMSerializer.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,248 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.serialize;
+
+import org.apache.ws.commons.om.OMSerializer;
+import org.apache.ws.commons.om.impl.OMOutputImpl;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * Class StreamingOMSerializer
+ */
+public class StreamingOMSerializer implements XMLStreamConstants, OMSerializer {
+
+ /*
+ * The behavior of the serializer is such that it returns when it encounters the
+ * starting element for the second time. The depth variable tracks the depth of the
+ * serilizer and tells it when to return.
+ * Note that it is assumed that this serialization starts on an Element.
+ */
+
+ /**
+ * Field depth
+ */
+ private int depth = 0;
+
+ /**
+ * Method serialize.
+ *
+ * @param node
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void serialize(XMLStreamReader node, XMLStreamWriter writer)
+ throws XMLStreamException {
+ serializeNode(node, new OMOutputImpl(writer));
+ }
+
+ /**
+ * Method serialize.
+ *
+ * @param obj
+ * @param omOutput
+ * @throws XMLStreamException
+ */
+ public void serialize(XMLStreamReader obj, OMOutputImpl omOutput)
+ throws XMLStreamException {
+ XMLStreamReader node = obj;
+ serializeNode(node, omOutput);
+ }
+
+ /**
+ * Method serializeNode.
+ *
+ * @param reader
+ * @param omOutput
+ * @throws XMLStreamException
+ */
+ protected void serializeNode(XMLStreamReader reader, OMOutputImpl omOutput)
+ throws XMLStreamException {
+ //TODO We get the StAXWriter at this point and uses it hereafter assuming that this is the only entry point to this class.
+ // If there can be other classes calling methodes of this we might need to change methode signatures to OMOutputer
+ XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+ while (reader.hasNext()) {
+ int event = reader.next();
+ if (event == START_ELEMENT) {
+ serializeElement(reader, writer);
+ depth++;
+ } else if (event == ATTRIBUTE) {
+ serializeAttributes(reader, writer);
+ } else if (event == CHARACTERS) {
+ serializeText(reader, writer);
+ } else if (event == COMMENT) {
+ serializeComment(reader, writer);
+ } else if (event == CDATA) {
+ serializeCData(reader, writer);
+ } else if (event == END_ELEMENT) {
+ serializeEndElement(writer);
+ depth--;
+ } else if (event == END_DOCUMENT) {
+ try {
+ serializeEndElement(writer);
+ } catch (Exception e) {
+ //TODO: log exceptions
+ }
+ }
+ if (depth == 0) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeElement(XMLStreamReader reader,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ String prefix = reader.getPrefix();
+ String nameSpaceName = reader.getNamespaceURI();
+ if (nameSpaceName != null) {
+ String writer_prefix = writer.getPrefix(nameSpaceName);
+ if (writer_prefix != null) {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, reader.getLocalName(),
+ nameSpaceName);
+ writer.writeNamespace(prefix, nameSpaceName);
+ writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ writer.writeStartElement(nameSpaceName,
+ reader.getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ writer.setDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
+
+ // add attributes
+ serializeAttributes(reader, writer);
+
+ // add the namespaces
+ int count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ namespacePrefix = reader.getNamespacePrefix(i);
+ if(namespacePrefix != null && namespacePrefix.length()==0)
+ continue;
+
+ serializeNamespace(namespacePrefix,
+ reader.getNamespaceURI(i), writer);
+ }
+ }
+
+ /**
+ * Method serializeEndElement.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeEndElement(XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeText(XMLStreamReader reader,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeCharacters(reader.getText());
+ }
+
+ /**
+ * Method serializeCData.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeCData(XMLStreamReader reader,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeCData(reader.getText());
+ }
+
+ /**
+ * Method serializeComment.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeComment(XMLStreamReader reader,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeComment(reader.getText());
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeAttributes(XMLStreamReader reader,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ int count = reader.getAttributeCount();
+ String prefix = null;
+ String namespaceName = null;
+ for (int i = 0; i < count; i++) {
+ prefix = reader.getAttributePrefix(i);
+ namespaceName = reader.getAttributeNamespace(i);
+ if ((prefix != null) && !namespaceName.equals("")) {
+ writer.writeAttribute(prefix, namespaceName,
+ reader.getAttributeLocalName(i),
+ reader.getAttributeValue(i));
+ } else {
+ writer.writeAttribute(reader.getAttributeLocalName(i),
+ reader.getAttributeValue(i));
+ }
+ }
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param prefix
+ * @param URI
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void serializeNamespace(String prefix,
+ String URI,
+ XMLStreamWriter writer)
+ throws XMLStreamException {
+ String prefix1 = writer.getPrefix(URI);
+ if (prefix1 == null) {
+ writer.writeNamespace(prefix, URI);
+ writer.setPrefix(prefix, URI);
+ }
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildElementIterator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.traverse;
+
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+
+import java.util.Iterator;
+
+public class OMChildElementIterator implements Iterator {
+
+ /**
+ * Field currentChild
+ */
+ protected OMNode currentChild;
+
+ /**
+ * Field lastChild
+ */
+ protected OMNode lastChild;
+
+ /**
+ * Field nextCalled
+ */
+ protected boolean nextCalled = false;
+
+ /**
+ * Field removeCalled
+ */
+ protected boolean removeCalled = false;
+
+ /**
+ * Constructor OMChildrenIterator.
+ *
+ * @param currentChild
+ */
+ public OMChildElementIterator(OMElement currentChild) {
+ this.currentChild = currentChild;
+ }
+
+ /**
+ * Removes the last element returned by the iterator (optional operation)
+ * from the underlying collection. This method can be called only once per
+ * call to <tt>next</tt>. The behavior of an iterator is unspecified if
+ * the underlying collection is modified while the iteration is in
+ * progress in any way other than by calling this method.
+ *
+ * @throws UnsupportedOperationException if the <tt>remove</tt>
+ * operation is not supported by this Iterator.
+ * @throws IllegalStateException if the <tt>next</tt> method has not
+ * yet been called, or the <tt>remove</tt> method has already
+ * been called after the last call to the <tt>next</tt>
+ * method.
+ */
+ public void remove() {
+ if (!nextCalled) {
+ throw new IllegalStateException(
+ "next method has not yet being called");
+ }
+ if (removeCalled) {
+ throw new IllegalStateException("remove has already being called");
+ }
+ removeCalled = true;
+
+ // since this acts on the last child there is no need to mess with the current child
+ if (lastChild == null) {
+ throw new OMException("cannot remove a child at this stage!");
+ }
+ lastChild.detach();
+ }
+
+ /**
+ * Returns <tt>true</tt> if the iteration has more elements. (In other
+ * words, returns <tt>true</tt> if <tt>next</tt> would return an element
+ * rather than throwing an exception.)
+ *
+ * @return Returns <tt>true</tt> if the iterator has more elements.
+ */
+ public boolean hasNext() {
+ return (currentChild != null);
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ *
+ * @return Returns the next element in the iteration.
+ * @throws java.util.NoSuchElementException
+ * iteration has no more elements.
+ */
+ public Object next() {
+ nextCalled = true;
+ removeCalled = false;
+
+ if (hasNext()) {
+ lastChild = currentChild;
+ do{
+ currentChild = currentChild.getNextOMSibling();
+ }while(currentChild!=null && currentChild.getType()!=OMNode.ELEMENT_NODE);
+
+
+ return lastChild;
+ }
+ return null;
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenIterator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.traverse;
+
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.om.OMNode;
+
+import java.util.Iterator;
+
+/**
+ * Class OMChildrenIterator
+ */
+public class OMChildrenIterator implements Iterator {
+ /**
+ * Field currentChild
+ */
+ protected OMNode currentChild;
+
+ /**
+ * Field lastChild
+ */
+ protected OMNode lastChild;
+
+ /**
+ * Field nextCalled
+ */
+ protected boolean nextCalled = false;
+
+ /**
+ * Field removeCalled
+ */
+ protected boolean removeCalled = false;
+
+ /**
+ * Constructor OMChildrenIterator.
+ *
+ * @param currentChild
+ */
+ public OMChildrenIterator(OMNode currentChild) {
+ this.currentChild = currentChild;
+ }
+
+ /**
+ * Removes the last element returned by the iterator (optional operation)
+ * from the underlying collection. This method must be called only once per
+ * call to <tt>next</tt>. The behavior of an iterator is unspecified if
+ * the underlying collection is modified while the iteration is in
+ * progress in any way other than by calling this method.
+ *
+ * @throws UnsupportedOperationException if the <tt>remove</tt>
+ * operation is not supported by this Iterator.
+ * @throws IllegalStateException if the <tt>next</tt> method has not
+ * yet been called, or the <tt>remove</tt> method has already
+ * been called after the last call to the <tt>next</tt>
+ * method.
+ */
+ public void remove() {
+ if (!nextCalled) {
+ throw new IllegalStateException(
+ "next method has not yet being called");
+ }
+ if (removeCalled) {
+ throw new IllegalStateException("remove has already being called");
+ }
+ removeCalled = true;
+
+ // since this acts on the last child there is no need to mess with the current child
+ if (lastChild == null) {
+ throw new OMException("cannot remove a child at this stage!");
+ }
+ lastChild.detach();
+ }
+
+ /**
+ * Returns <tt>true</tt> if the iteration has more elements. (In other
+ * words, returns <tt>true</tt> if <tt>next</tt> would return an element
+ * rather than throwing an exception.)
+ *
+ * @return Returns <tt>true</tt> if the iterator has more elements.
+ */
+ public boolean hasNext() {
+ return (currentChild != null);
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ *
+ * @return Returns the next element in the iteration.
+ * @throws java.util.NoSuchElementException
+ * iteration has no more elements.
+ */
+ public Object next() {
+ nextCalled = true;
+ removeCalled = false;
+ if (hasNext()) {
+ lastChild = currentChild;
+ currentChild = currentChild.getNextOMSibling();
+ return lastChild;
+ }
+ return null;
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenQNameIterator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.traverse;
+
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class OMChildrenQNameIterator
+ */
+public class OMChildrenQNameIterator extends OMChildrenIterator {
+ /**
+ * Field givenQName
+ */
+ private QName givenQName;
+
+ /**
+ * Field needToMoveForward
+ */
+ private boolean needToMoveForward = true;
+
+ /**
+ * Field isMatchingNodeFound
+ */
+ private boolean isMatchingNodeFound = false;
+
+ /**
+ * Constructor OMChildrenQNameIterator.
+ *
+ * @param currentChild
+ * @param givenQName
+ */
+ public OMChildrenQNameIterator(OMNode currentChild, QName givenQName) {
+ super(currentChild);
+ this.givenQName = givenQName;
+ }
+
+ /**
+ * Returns <tt>true</tt> if the iteration has more elements. (In other
+ * words, returns <tt>true</tt> if <tt>next</tt> would return an element
+ * rather than throwing an exception.)
+ *
+ * @return Returns <tt>true</tt> if the iterator has more elements.
+ */
+ public boolean hasNext() {
+ while (needToMoveForward) {
+ if (currentChild != null) {
+
+ // check the current node for the criteria
+ if ((currentChild instanceof OMElement)
+ && (isQNamesMatch(
+ ((OMElement) currentChild).getQName(),
+ this.givenQName))) {
+ isMatchingNodeFound = true;
+ needToMoveForward = false;
+ } else {
+
+ // get the next named node
+ currentChild = currentChild.getNextOMSibling();
+ isMatchingNodeFound = needToMoveForward = !(currentChild
+ == null);
+ }
+ } else {
+ needToMoveForward = false;
+ }
+ }
+ return isMatchingNodeFound;
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ *
+ * @return Returns the next element in the iteration.
+ * @throws java.util.NoSuchElementException
+ * iteration has no more elements.
+ */
+ public Object next() {
+
+ // reset the flags
+ needToMoveForward = true;
+ isMatchingNodeFound = false;
+ nextCalled = true;
+ removeCalled = false;
+ lastChild = currentChild;
+ currentChild = currentChild.getNextOMSibling();
+ return lastChild;
+ }
+
+ /**
+ * Cannot use the overridden equals method of QName, as one might want to get
+ * some element just by giving the localname, even though a matching element
+ * has a namespace uri as well.
+ * This is not supported in the equals method of the QName.
+ *
+ * @param elementQName
+ * @param qNameToBeMatched
+ * @return Returns boolean.
+ */
+ private boolean isQNamesMatch(QName elementQName, QName qNameToBeMatched) {
+
+ // if no QName was given, that means user is asking for all
+ if (qNameToBeMatched == null) {
+ return true;
+ }
+
+ // if the given localname is null, whatever value this.qname has, its a match. But can one give a QName without a localName ??
+ boolean localNameMatch =
+ (qNameToBeMatched.getLocalPart() == null)
+ || (qNameToBeMatched.getLocalPart() == "")
+ ||
+ ((elementQName != null)
+ &&
+ elementQName.getLocalPart().equalsIgnoreCase(
+ qNameToBeMatched.getLocalPart()));
+ boolean namespaceURIMatch =
+ (qNameToBeMatched.getNamespaceURI() == null)
+ || (qNameToBeMatched.getNamespaceURI() == "")
+ ||
+ ((elementQName != null)
+ &&
+ elementQName.getNamespaceURI().equalsIgnoreCase(
+ qNameToBeMatched.getNamespaceURI()));
+ return localNameMatch && namespaceURIMatch;
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/traverse/OMChildrenWithSpecificAttributeIterator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.traverse;
+
+import org.apache.ws.commons.om.OMAttribute;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNode;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class OMChildrenWithSpecificAttributeIterator
+ */
+public class OMChildrenWithSpecificAttributeIterator
+ extends OMChildrenIterator {
+ /**
+ * Field attributeName
+ */
+ private QName attributeName;
+
+ /**
+ * Field attributeValue
+ */
+ private String attributeValue;
+
+ /**
+ * Field detach
+ */
+ private boolean detach;
+
+ /**
+ * Constructor OMChildrenWithSpecificAttributeIterator.
+ *
+ * @param currentChild
+ * @param attributeName
+ * @param attributeValue
+ * @param detach
+ */
+ public OMChildrenWithSpecificAttributeIterator(OMNode currentChild,
+ QName attributeName,
+ String attributeValue,
+ boolean detach) {
+ super(currentChild);
+ this.attributeName = attributeName;
+ this.attributeValue = attributeValue;
+ this.detach = detach;
+ }
+
+ /**
+ * Method hasNext.
+ *
+ * @return Returns boolean.
+ */
+ public boolean hasNext() {
+
+ // First check whether we have a child, using the super class
+ if (currentChild == null) {
+ return false;
+ }
+ boolean isMatchingNodeFound = false;
+ boolean needToMoveForward = true;
+
+ // now we have a child to check. If its an OMElement and matches the criteria, then we are done
+ while (needToMoveForward) {
+
+ // check the current node for the criteria
+ if (currentChild instanceof OMElement) {
+ OMAttribute attr =
+ ((OMElement) currentChild).getAttribute(
+ attributeName);
+ if ((attr != null)
+ && attr.getAttributeValue().equalsIgnoreCase(attributeValue)) {
+ isMatchingNodeFound = true;
+ needToMoveForward = false;
+ } else {
+ currentChild = currentChild.getNextOMSibling();
+ needToMoveForward = !(currentChild == null);
+ }
+ } else {
+
+ // get the next named node
+ currentChild = currentChild.getNextOMSibling();
+ needToMoveForward = !(currentChild == null);
+ }
+ }
+ return isMatchingNodeFound;
+ }
+
+ /**
+ * Method next.
+ *
+ * @return Returns Object.
+ */
+ public Object next() {
+ nextCalled = true;
+ removeCalled = false;
+ lastChild = currentChild;
+ currentChild = currentChild.getNextOMSibling();
+ if ((lastChild != null) && detach && lastChild.getParent() != null) {
+ lastChild.detach();
+ }
+ return lastChild;
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/EmptyIterator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.util;
+
+import java.util.Iterator;
+
+public class EmptyIterator implements Iterator {
+ public void remove() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ throw new UnsupportedOperationException();
+ }
+}
+
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/impl/llom/util/XMLComparator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,222 @@
+/*
+ * 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.
+ */
+
+package org.apache.ws.commons.om.impl.llom.util;
+
+import org.apache.ws.commons.om.OMAttribute;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMNode;
+import org.apache.ws.commons.om.impl.llom.exception.XMLComparisonException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+public class XMLComparator {
+ /**
+ * Eran Chinthaka (chinthaka@apache.org)
+ */
+ private Log log = LogFactory.getLog(getClass());
+
+ private Vector ignorableNamespaceList = new Vector();
+
+ public void addIgnorableNamespace(String nsURI){
+ ignorableNamespaceList.add(nsURI);
+ }
+
+ public void clearIgnorableNamespaces(){
+ ignorableNamespaceList.clear();
+ }
+
+
+ public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+
+ //ignore if the elements belong to any of the ignorable namespaces list
+ if (isIgnorable(elementOne) ||
+ isIgnorable(elementTwo)){
+ return true;
+ }
+
+ if (elementOne == null && elementTwo == null) {
+ log.info("Both Elements are null.");
+ return true;
+ }
+ if (elementOne == null && elementTwo != null) {
+ throw new XMLComparisonException(
+ "Element One is null and Element Two is not null");
+ }
+ if (elementOne != null && elementTwo == null) {
+ throw new XMLComparisonException(
+ "Element Two is null and Element One is not null");
+ }
+
+ log.info(
+ "Now Checking " + elementOne.getLocalName() + " and " +
+ elementTwo.getLocalName() +
+ "=============================");
+
+ log.info("Comparing Element Names .......");
+ compare("Elements names are not equal. ",
+ elementOne.getLocalName(),
+ elementTwo.getLocalName());
+
+ log.info("Comparing Namespaces .........");
+ compare("Element namespaces are not equal",
+ elementOne.getNamespace(),
+ elementTwo.getNamespace());
+
+ log.info("Comparing attributes .....");
+ compareAllAttributes(elementOne, elementTwo);
+
+ log.info("Comparing texts .....");
+
+ /*
+ * Trimming the value of the XMLElement is not correct
+ * since this compare method cannot be used to compare
+ * element contents with trailing and leading whitespaces
+ * BUT for the practicalltiy of tests and to get the current
+ * tests working we have to trim() the contents
+ */
+ compare("Elements texts are not equal ",
+ elementOne.getText().trim(),
+ elementTwo.getText().trim());
+
+ log.info("Comparing Children ......");
+ compareAllChildren(elementOne, elementTwo);
+
+
+ return true;
+ }
+
+ private void compareAllAttributes(OMElement elementOne,
+ OMElement elementTwo) throws XMLComparisonException {
+ compareAttibutes(elementOne, elementTwo);
+ compareAttibutes(elementTwo, elementOne);
+ }
+
+ private void compareAllChildren(OMElement elementOne,
+ OMElement elementTwo) throws XMLComparisonException {
+ compareChildren(elementOne, elementTwo);
+ compareChildren(elementTwo, elementOne);
+ }
+
+
+ private boolean isIgnorable(OMElement elt){
+ if (elt!=null){
+ OMNamespace namespace = elt.getNamespace();
+ if (namespace!=null){
+ return ignorableNamespaceList.contains(namespace.getName());
+ }else{
+ return false;
+ }
+ }else{
+ return false;
+ }
+ }
+
+
+ private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ //ignore if the elements belong to any of the ignorable namespaces list
+ if (isIgnorable(elementOne) ||
+ isIgnorable(elementTwo)){
+ return ;
+ }
+ Iterator elementOneChildren = elementOne.getChildren();
+ while (elementOneChildren.hasNext()) {
+ OMNode omNode = (OMNode) elementOneChildren.next();
+ if (omNode instanceof OMElement) {
+ OMElement elementOneChild = (OMElement) omNode;
+ OMElement elementTwoChild = null;
+ //Do the comparison only if the element is not ignorable
+ if (!isIgnorable(elementOneChild)){
+ elementTwoChild = elementTwo.getFirstChildWithName(
+ elementOneChild.getQName());
+ //Do the comparison only if the element is not ignorable
+ if (!isIgnorable(elementTwoChild)){
+ if (elementTwoChild == null) {
+ throw new XMLComparisonException(
+ " There is no " + elementOneChild.getLocalName() +
+ " element under " +
+ elementTwo.getLocalName());
+ }
+ }
+ }
+ compare(elementOneChild, elementTwoChild);
+ }
+ }
+ }
+
+
+ private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ int elementOneAtribCount = 0;
+ int elementTwoAtribCount = 0;
+ Iterator attributes = elementOne.getAllAttributes();
+ while (attributes.hasNext()) {
+ OMAttribute omAttribute = (OMAttribute) attributes.next();
+ OMAttribute attr = elementTwo.getAttribute(
+ omAttribute.getQName());
+ if (attr == null) {
+ throw new XMLComparisonException(
+ "Attributes are not the same in two elements. Attribute " +
+ omAttribute.getLocalName() +
+ " != ");
+ }
+ elementOneAtribCount++;
+ }
+
+ Iterator elementTwoIter = elementTwo.getAllAttributes();
+ while (elementTwoIter.hasNext()) {
+ elementTwoIter.next();
+ elementTwoAtribCount++;
+
+ }
+
+ if (elementOneAtribCount != elementTwoAtribCount) {
+ throw new XMLComparisonException(
+ "Attributes are not the same in two elements.");
+ }
+ }
+
+ private void compare(String failureNotice, String one, String two) throws XMLComparisonException {
+ if (!one.equals(two)) {
+ throw new XMLComparisonException(
+ failureNotice + one + " != " + two);
+ }
+ }
+
+ private void compare(String failureNotice,
+ OMNamespace one,
+ OMNamespace two) throws XMLComparisonException {
+ if (one == null && two == null) {
+ return;
+ } else if (one != null && two == null) {
+ throw new XMLComparisonException(
+ "First Namespace is NOT null. But the second is null");
+ } else if (one == null && two != null) {
+ throw new XMLComparisonException(
+ "First Namespace is null. But the second is NOT null");
+ }
+
+ if (!one.getName().equals(two.getName())) {
+ throw new XMLComparisonException(
+ failureNotice + one + " != " + two);
+ }
+
+ // Do we need to compare prefixes as well
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/Base64.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/Base64.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/Base64.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/Base64.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,295 @@
+package org.apache.ws.commons.om.util;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.Writer;
+
+/*
+ * Copyright 2001-2004 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 Base64 {
+ private static final char[] S_BASE64CHAR = {'A', 'B', 'C', 'D', 'E', 'F',
+ 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
+ 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
+ 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', '+', '/'};
+
+ private static final char S_BASE64PAD = '=';
+
+ private static final byte[] S_DECODETABLE = new byte[128];
+
+ static {
+ for (int i = 0; i < S_DECODETABLE.length; i++)
+ S_DECODETABLE[i] = Byte.MAX_VALUE; // 127
+ for (int i = 0; i < S_BASE64CHAR.length; i++)
+ // 0 to 63
+ S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i;
+ }
+
+ private static int decode0(char[] ibuf, byte[] obuf, int wp) {
+ int outlen = 3;
+ if (ibuf[3] == S_BASE64PAD)
+ outlen = 2;
+ if (ibuf[2] == S_BASE64PAD)
+ outlen = 1;
+ int b0 = S_DECODETABLE[ibuf[0]];
+ int b1 = S_DECODETABLE[ibuf[1]];
+ int b2 = S_DECODETABLE[ibuf[2]];
+ int b3 = S_DECODETABLE[ibuf[3]];
+ switch (outlen) {
+ case 1:
+ obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ return 1;
+ case 2:
+ obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+ return 2;
+ case 3:
+ obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+ obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f);
+ return 3;
+ default:
+ throw new RuntimeException("internalError00");
+ }
+ }
+
+ /**
+ *
+ */
+ public static byte[] decode(char[] data, int off, int len) {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[len / 4 * 3 + 3];
+ int obufcount = 0;
+ for (int i = off; i < off + len; i++) {
+ char ch = data[i];
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length
+ && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ obufcount += decode0(ibuf, obuf, obufcount);
+ }
+ }
+ }
+ if (obufcount == obuf.length)
+ return obuf;
+ byte[] ret = new byte[obufcount];
+ System.arraycopy(obuf, 0, ret, 0, obufcount);
+ return ret;
+ }
+
+ /**
+ *
+ */
+ public static byte[] decode(String data) {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[data.length() / 4 * 3 + 3];
+ int obufcount = 0;
+ for (int i = 0; i < data.length(); i++) {
+ char ch = data.charAt(i);
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length
+ && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ obufcount += decode0(ibuf, obuf, obufcount);
+ }
+ }
+ }
+ if (obufcount == obuf.length)
+ return obuf;
+ byte[] ret = new byte[obufcount];
+ System.arraycopy(obuf, 0, ret, 0, obufcount);
+ return ret;
+ }
+
+ /**
+ *
+ */
+ public static void decode(char[] data, int off, int len,
+ OutputStream ostream) throws IOException {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[3];
+ for (int i = off; i < off + len; i++) {
+ char ch = data[i];
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length
+ && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ int obufcount = decode0(ibuf, obuf, 0);
+ ostream.write(obuf, 0, obufcount);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static void decode(String data, OutputStream ostream)
+ throws IOException {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[3];
+ for (int i = 0; i < data.length(); i++) {
+ char ch = data.charAt(i);
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length
+ && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ int obufcount = decode0(ibuf, obuf, 0);
+ ostream.write(obuf, 0, obufcount);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns base64 representation of specified byte array.
+ */
+ public static String encode(byte[] data) {
+ return encode(data, 0, data.length);
+ }
+
+ /**
+ * Returns base64 representation of specified byte array.
+ */
+ public static String encode(byte[] data, int off, int len) {
+ if (len <= 0)
+ return "";
+ char[] out = new char[len / 3 * 4 + 4];
+ int rindex = off;
+ int windex = 0;
+ int rest = len - off;
+ while (rest >= 3) {
+ int i = ((data[rindex] & 0xff) << 16)
+ + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[windex++] = S_BASE64CHAR[i >> 18];
+ out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[windex++] = S_BASE64CHAR[i & 0x3f];
+ rindex += 3;
+ rest -= 3;
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[windex++] = S_BASE64CHAR[i >> 2];
+ out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f];
+ out[windex++] = S_BASE64PAD;
+ out[windex++] = S_BASE64PAD;
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[windex++] = S_BASE64CHAR[i >> 10];
+ out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f];
+ out[windex++] = S_BASE64PAD;
+ }
+ return new String(out, 0, windex);
+ }
+
+ /**
+ * Outputs base64 representation of the specified byte array to a byte
+ * stream.
+ */
+ public static void encode(byte[] data, int off, int len,
+ OutputStream ostream) throws IOException {
+ if (len <= 0)
+ return;
+ byte[] out = new byte[4];
+ int rindex = off;
+ int rest = len - off;
+ while (rest >= 3) {
+ int i = ((data[rindex] & 0xff) << 16)
+ + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[0] = (byte) S_BASE64CHAR[i >> 18];
+ out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[3] = (byte) S_BASE64CHAR[i & 0x3f];
+ ostream.write(out, 0, 4);
+ rindex += 3;
+ rest -= 3;
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[0] = (byte) S_BASE64CHAR[i >> 2];
+ out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f];
+ out[2] = (byte) S_BASE64PAD;
+ out[3] = (byte) S_BASE64PAD;
+ ostream.write(out, 0, 4);
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[0] = (byte) S_BASE64CHAR[i >> 10];
+ out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f];
+ out[3] = (byte) S_BASE64PAD;
+ ostream.write(out, 0, 4);
+ }
+ }
+
+ /**
+ * Outputs base64 representation of the specified byte array to a character
+ * stream.
+ */
+ public static void encode(byte[] data, int off, int len, Writer writer)
+ throws IOException {
+ if (len <= 0)
+ return;
+ char[] out = new char[4];
+ int rindex = off;
+ int rest = len - off;
+ int output = 0;
+ while (rest >= 3) {
+ int i = ((data[rindex] & 0xff) << 16)
+ + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[0] = S_BASE64CHAR[i >> 18];
+ out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[3] = S_BASE64CHAR[i & 0x3f];
+ writer.write(out, 0, 4);
+ rindex += 3;
+ rest -= 3;
+ output += 4;
+ if (output % 76 == 0)
+ writer.write("\n");
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[0] = S_BASE64CHAR[i >> 2];
+ out[1] = S_BASE64CHAR[(i << 4) & 0x3f];
+ out[2] = S_BASE64PAD;
+ out[3] = S_BASE64PAD;
+ writer.write(out, 0, 4);
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[0] = S_BASE64CHAR[i >> 10];
+ out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[2] = S_BASE64CHAR[(i << 2) & 0x3f];
+ out[3] = S_BASE64PAD;
+ writer.write(out, 0, 4);
+ }
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/ElementHelper.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/ElementHelper.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/ElementHelper.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/ElementHelper.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 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.
+ */
+package org.apache.ws.commons.om.util;
+
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.om.OMNode;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Helper class to provide extra utility stuff against elements.
+ * The code is designed to work with any element implementation.
+ */
+
+public class ElementHelper {
+
+ private OMElement element;
+
+ /**
+ * Constructs and binds to an element.
+ * @param element element to work with
+ */
+ public ElementHelper(OMElement element) {
+ this.element = element;
+ }
+
+ /**
+ * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
+ *
+ * @param qname qname to resolve
+ * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
+ * @return Returns null for any failure to extract a qname.
+ */
+ public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
+ int colon = qname.indexOf(':');
+ if (colon < 0) {
+ if (defaultToParentNameSpace) {
+ //get the parent ns and use it for the child
+ OMNamespace namespace = element.getNamespace();
+ return new QName(namespace.getName(), qname, namespace.getPrefix());
+ } else {
+ //else things without no prefix are local.
+ return new QName(qname);
+ }
+ }
+ String prefix = qname.substring(0, colon);
+ String local = qname.substring(colon + 1);
+ if (local.length() == 0) {
+ //empy local, exit accordingly
+ return null;
+ }
+
+ OMNamespace namespace = element.findNamespaceURI(prefix);
+ if (namespace == null) {
+ return null;
+ }
+ return new QName(namespace.getName(), local, prefix);
+ }
+
+ /**
+ * Turns a prefix:local qname string into a proper QName, evaluating it in the OMElement context.
+ * Unprefixed qnames resolve to the local namespace.
+ *
+ * @param qname prefixed qname string to resolve
+ * @return Returns null for any failure to extract a qname.
+ */
+ public QName resolveQName(String qname) {
+ return resolveQName(qname, true);
+ }
+
+ public static void setNewElement(OMElement parent,
+ OMElement myElement,
+ OMElement newElement) {
+ if (myElement != null) {
+ myElement.discard();
+ }
+ parent.addChild(newElement);
+ myElement = newElement;
+ }
+
+ public static OMElement getChildWithName(OMElement parent,
+ String childName) {
+ Iterator childrenIter = parent.getChildren();
+ while (childrenIter.hasNext()) {
+ OMNode node = (OMNode) childrenIter.next();
+ if (node.getType() == OMNode.ELEMENT_NODE &&
+ childName.equals(((OMElement) node).getLocalName())) {
+ return (OMElement) node;
+ }
+ }
+ return null;
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/UUIDGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/UUIDGenerator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/UUIDGenerator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/UUIDGenerator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,104 @@
+package org.apache.ws.commons.om.util;
+
+/*
+ * Copyright 2001-2004 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.
+ *
+ */
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Date;
+import java.util.Random;
+
+public class UUIDGenerator {
+ /**
+ * This class will give UUIDs for axis2.
+ */
+
+ private static String baseUUID = null;
+ private static long incrementingValue = 0;
+
+
+ private static Random myRand = null;
+
+ /**
+ * MD5 a random string with localhost/date etc will return 128 bits
+ * construct a string of 18 characters from those bits.
+ *
+ * @return string
+ */
+ public static String getUUID() {
+ if (baseUUID == null) {
+ baseUUID = getInitialUUID();
+ }
+ if (++incrementingValue >= Long.MAX_VALUE) {
+ incrementingValue = 0;
+ }
+ return "urn:uuid:" + baseUUID + new Date().getTime() + incrementingValue;
+ }
+
+ protected static String getInitialUUID() {
+ if (myRand == null) {
+ myRand = new Random();
+ }
+ long rand = myRand.nextLong();
+ String sid;
+ try {
+ sid = InetAddress.getLocalHost().toString();
+ } catch (UnknownHostException e) {
+ sid = Thread.currentThread().getName();
+ }
+ StringBuffer sb = new StringBuffer();
+ sb.append(sid);
+ sb.append(":");
+ sb.append(Long.toString(rand));
+ MessageDigest md5 = null;
+ try {
+ md5 = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ //System.out.println("Error: " + e);
+ //todo heve to be properly handle
+ }
+ md5.update(sb.toString().getBytes());
+ byte[] array = md5.digest();
+ StringBuffer sb2 = new StringBuffer();
+ for (int j = 0; j < array.length; ++j) {
+ int b = array[j] & 0xFF;
+ sb2.append(Integer.toHexString(b));
+ }
+ int begin = myRand.nextInt();
+ if (begin < 0) begin = begin * -1;
+ begin = begin % 8;
+ return sb2.toString().substring(begin, begin + 18).toUpperCase();
+ }
+
+ public static void main(String[] args) {
+ long startTime = new Date().getTime();
+ for (int i = 0; i < 100000; i++) {
+ UUIDGenerator.getInitialUUID();
+ }
+ long endTime = new Date().getTime();
+ System.out.println("getInitialUUID Difference = " + (endTime - startTime));
+
+ startTime = new Date().getTime();
+ for (int i = 0; i < 100000; i++) {
+ UUIDGenerator.getUUID();
+ }
+ endTime = new Date().getTime();
+ System.out.println("getUUID Difference = " + (endTime - startTime));
+ }
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/XPathEvaluator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/XPathEvaluator.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/XPathEvaluator.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/util/XPathEvaluator.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,21 @@
+package org.apache.ws.commons.om.util;
+
+import org.apache.ws.commons.om.xpath.AXIOMXPath;
+import org.jaxen.SimpleNamespaceContext;
+
+import java.util.List;
+
+public class XPathEvaluator {
+
+ public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception{
+ AXIOMXPath xpath = new AXIOMXPath(xpathExpression);
+ if (nsURI!=null){
+ SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
+ nsContext.addNamespace(null,nsURI);
+ xpath.setNamespaceContext(nsContext);
+ }
+ return xpath.selectNodes(element);
+ }
+
+
+}
Added: webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java?rev=374036&view=auto
==============================================================================
--- webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java (added)
+++ webservices/commons/trunk/axiom/src/org/apache/ws/commons/om/xpath/AXIOMXPath.java Wed Feb 1 02:33:37 2006
@@ -0,0 +1,20 @@
+package org.apache.ws.commons.om.xpath;
+
+import org.jaxen.BaseXPath;
+import org.jaxen.JaxenException;
+
+public class AXIOMXPath extends BaseXPath {
+
+ private static final long serialVersionUID = -5839161412925154639L;
+
+ /**
+ * Construct given an XPath expression string.
+ *
+ * @param xpathExpr the XPath expression.
+ * @throws org.jaxen.JaxenException if there is a syntax error while
+ * parsing the expression
+ */
+ public AXIOMXPath(String xpathExpr) throws JaxenException {
+ super(xpathExpr, new DocumentNavigator());
+ }
+}