001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    package org.codehaus.activesoap.util;
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    
023    import javax.xml.stream.XMLStreamException;
024    import javax.xml.stream.XMLStreamWriter;
025    
026    /**
027     * An implementation of {@link XMLStreamWriter} which will log
028     * calls to start/end element which can be very useful for debugging StAX related issues.
029     *
030     * @version $Revision: 1.2 $
031     */
032    public class LoggingXMLStreamWriter extends DelegateXMLStreamWriter {
033        private transient Log log;
034    
035        public LoggingXMLStreamWriter(XMLStreamWriter delegate) {
036            this(delegate, LogFactory.getLog(LoggingXMLStreamWriter.class));
037        }
038    
039        public LoggingXMLStreamWriter(XMLStreamWriter delegate, Log log) {
040            super(delegate);
041            this.log = log;
042        }
043    
044        public void writeStartDocument() throws XMLStreamException {
045            log.debug("writeStartDocument()");
046            super.writeStartDocument();
047        }
048    
049        public void writeStartDocument(String s) throws XMLStreamException {
050            log.debug("writeStartDocument(" + s + ")");
051            super.writeStartDocument(s);
052        }
053    
054        public void writeStartDocument(String s, String s1) throws XMLStreamException {
055            log.debug("writeStartDocument(" + s + ", " + s1 + ")");
056            super.writeStartDocument(s, s1);
057        }
058    
059        public void writeStartElement(String s) throws XMLStreamException {
060            log.debug("writeStartElement(" + s + ")");
061            super.writeStartElement(s);
062        }
063    
064        public void writeStartElement(String s, String s1) throws XMLStreamException {
065            log.debug("writeStartElement(" + s + ", " + s1 + ")");
066            super.writeStartElement(s, s1);
067        }
068    
069        public void writeStartElement(String s, String s1, String s2) throws XMLStreamException {
070            log.debug("writeStartElement(" + s + ", " + s1 + ", " + s2 + ")");
071            super.writeStartElement(s, s1, s2);
072        }
073    
074        public void writeEndElement() throws XMLStreamException {
075            log.debug("writeEndElement()");
076            super.writeEndElement();
077        }
078    
079        public void writeEndDocument() throws XMLStreamException {
080            log.debug("writeEndDocument()");
081            super.writeEndDocument();
082        }
083    }