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.XMLStreamReader;
025 import javax.xml.stream.util.StreamReaderDelegate;
026
027 /**
028 * @version $Revision: 1.2 $
029 */
030 public class LoggingXMLStreamReader extends StreamReaderDelegate {
031 private Log log;
032
033 public LoggingXMLStreamReader(XMLStreamReader xmlStreamReader) {
034 this(xmlStreamReader, LogFactory.getLog(LoggingXMLStreamReader.class));
035 }
036
037 public LoggingXMLStreamReader(XMLStreamReader xmlStreamReader, Log log) {
038 super(xmlStreamReader);
039 this.log = log;
040 }
041
042 public boolean hasNext() throws XMLStreamException {
043 boolean answer = super.hasNext();
044 log.info("hasNext() returns: " + answer);
045 return answer;
046 }
047
048 public int next() throws XMLStreamException {
049 int answer = super.next();
050 if (log.isDebugEnabled()) {
051 switch (answer) {
052 case START_ELEMENT:
053 log.debug("START_ELEMENT: " + getName());
054 break;
055 case END_ELEMENT:
056 log.debug("END_ELEMENT: " + getName());
057 break;
058 case START_DOCUMENT:
059 log.debug("START_DOCUMENT");
060 break;
061 case END_DOCUMENT:
062 log.debug("END_DOCUMENT");
063 break;
064 case CHARACTERS:
065 log.debug("CHARACTERS: " + getText());
066 break;
067 default:
068 log.debug("event type: " + answer);
069 }
070 }
071 return answer;
072 }
073 }