001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 */ 017package org.apache.commons.scxml2.env; 018 019import java.io.Serializable; 020 021import javax.xml.stream.Location; 022import javax.xml.stream.XMLReporter; 023import javax.xml.stream.XMLStreamException; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027 028/** 029 * Custom {@link XMLReporter} that logs the StAX parsing warnings in the 030 * SCXML document. 031 * 032 * @since 1.0 033 */ 034public class SimpleXMLReporter implements XMLReporter, Serializable { 035 036 /** Serial version UID. */ 037 private static final long serialVersionUID = 1L; 038 039 /** Log. */ 040 private Log log = LogFactory.getLog(getClass()); 041 042 /** 043 * Constructor. 044 */ 045 public SimpleXMLReporter() { 046 super(); 047 } 048 049 /** 050 * @see XMLReporter#report(String, String, Object, Location) 051 */ 052 public void report(final String message, final String errorType, final Object relatedInformation, 053 final Location location) 054 throws XMLStreamException { 055 if (log.isWarnEnabled()) { 056 log.warn("[" + errorType + "] " + message + " (" + relatedInformation + ") at " + location); 057 } 058 059 } 060 061}