1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 // Debug.java - Print debug messages 6 7 /* 8 * Copyright 2001-2004 The Apache Software Foundation or its licensors, 9 * as applicable. 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); 12 * you may not use this file except in compliance with the License. 13 * You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 */ 23 24 package com.sun.org.apache.xml.internal.resolver.helpers; 25 26 /** 27 * Static debugging/messaging class for Catalogs. 28 * 29 * <p>This class defines a set of static methods that can be called 30 * to produce debugging messages. Messages have an associated "debug 31 * level" and messages below the current setting are not displayed.</p> 32 * 33 * @author Norman Walsh 34 * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a> 35 * 36 */ 37 public class Debug { 38 /** The internal debug level. */ 39 protected int debug = 0; 40 41 /** Constructor */ 42 public Debug() { 43 // nop 44 } 45 46 /** Set the debug level for future messages. */ 47 public void setDebug(int newDebug) { 48 debug = newDebug; 49 } 50 51 /** Get the current debug level. */ 52 public int getDebug() { 53 return debug; 54 } 55 56 /** 57 * Print debug message (if the debug level is high enough). 58 * 59 * <p>Prints "the message"</p> 60 * 61 * @param level The debug level of this message. This message 62 * will only be 63 * displayed if the current debug level is at least equal to this 64 * value. 65 * @param message The text of the message. 66 */ 67 public void message(int level, String message) { 68 if (debug >= level) { 69 System.out.println(message); 70 } 71 } 72 73 /** 74 * Print debug message (if the debug level is high enough). 75 * 76 * <p>Prints "the message: spec"</p> 77 * 78 * @param level The debug level of this message. This message 79 * will only be 80 * displayed if the current debug level is at least equal to this 81 * value. 82 * @param message The text of the message. 83 * @param spec An argument to the message. 84 */ 85 public void message(int level, String message, String spec) { 86 if (debug >= level) { 87 System.out.println(message + ": " + spec); 88 } 89 } 90 91 /** 92 * Print debug message (if the debug level is high enough). 93 * 94 * <p>Prints "the message: spec1" and "spec2" indented on the next line.</p> 95 * 96 * @param level The debug level of this message. This message 97 * will only be 98 * displayed if the current debug level is at least equal to this 99 * value. 100 * @param message The text of the message. 101 * @param spec1 An argument to the message. 102 * @param spec2 Another argument to the message. 103 */ 104 public void message(int level, String message, 105 String spec1, String spec2) { 106 if (debug >= level) { 107 System.out.println(message + ": " + spec1); 108 System.out.println("\t" + spec2); 109 } 110 } 111 }