/* * 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. */ /* * $Id$ */ /* * * LoggingHandler.java * */ package org.apache.qetest; /** * Base class defining common functionality of logging handlers. *

Common functionality used for testing when implementing * various Handlers and Listeners. Provides common ways to set * Loggers and levels, reset, and set expected errors or the * like. Likely used to implement testing wrapper classes for * things like javax.xml.transform.ErrorListener and * org.xml.sax.ErrorHandler

*

The best description for this class can be seen in an * example; see trax.LoggingErrorHandler.java for one.

* @author shane_curcuru@lotus.com * @version $Id$ */ public class LoggingHandler { /** * Set a default handler for us to wrapper. * Often you may want to keep the default handler for some * operation while you're logging. For subclasses that support * this call, they will log every operation, and then simply * call-through to this default handler. * * Subclasses should implement this and verify that the default * is of an appropriate type to use. * * @param default Object of the correct type to pass-through to; * throws IllegalArgumentException if null or incorrect type */ public void setDefaultHandler(Object defaultHandler) { throw new java.lang.IllegalArgumentException("LoggingHandler.setDefaultHandler() is unimplemented!"); } /** * Accessor method for our default handler; here returns null. * * @return default (Object) our default handler; null if unset */ public Object getDefaultHandler() { return null; } /** * Get a list of counters of all items we've logged. * LoggingHandlers each will have various kinds or types of * things they handle (errors, warnings, messages, URIs, etc.). * They should keep a running tally of how many of each kind of * item they've 'handled'. * * @return array of int counters for each item we log; * subclasses should define constants for what each slot is */ public int[] getCounters() { return NOTHING_HANDLED_CTR; } /** * Get a string representation of last item we logged. * For every item that we handle, subclasses should store a * String representation and return it here if asked. Normally * this will only be a copy of the very last item we logged - * not necessarily what users might want, but the simplest to * implement everywhere. * * @return String of the last item handled */ public String getLast() { return NOTHING_HANDLED; } /** * Reset any items or counters we've handled. * Resets any data about what we've handled or logged so far, * like getLast() and getCounters() data, as well as any * expected items from setExpected(). Does not change our * Logger or loggingLevel. */ public void reset() { /* no-op */; } /** * Ask us to report checkPass/Fail for certain events we handle. * Since we may have to handle many events between when a test * will be able to call us, testers can set this to have us * automatically call checkPass when we see an item that matches, * or to call checkFail when we get an unexpected item. * Generally, we only call check* methods when: *