All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.api.xml.parsers.Util Maven / Gradle / Ivy

The newest version!
/*
 * 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.
 */
package org.netbeans.api.xml.parsers;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.util.NbBundle;

/**
 *
 * @author Libor Kramolis
 */
class Util  {

    /** Default and only one instance of this class. */
    public static final Util THIS = new Util();

    /** Nobody can create instance of it, just me. */
    private Util () {
    }

    /** Instance package ErrorManager. */
    private static final Logger LOG = Logger.getLogger(Util.class.getName());
    /** Default debug severity used with ErrorManager. */
    private static final Level DEBUG_SEVERITY = Level.INFO;

    //
    // String localizing purposes
    //


    /** 
     * Get localized string from package bundle.
     * @param key Key identifing localized value.
     * @return localized value.
     */
    public final String getString (String key) {
        if (key == null) throw new NullPointerException();
	return NbBundle.getMessage (this.getClass(), key);
    }
    
    /** 
     * Get localized string from package bundle.
     * @param key Key identifing localized value (MessageFormat).
     * @param param An argument {0} used for message parametrization.
     * @return localized value.
     */
    public final String getString (String key, Object param) {
        if (key == null) throw new NullPointerException();        
	return NbBundle.getMessage (this.getClass(), key, param);
    }
    
    /**
     * Get localized string from package bundle.
     * @param key Key identifing localized value (MessageFormat).
     * @param param1 An argument {0} used for message parametrization.
     * @param param2 An argument {1} used for message parametrization.
     * @return Localized value.
     */
    public final String getString (String key, Object param1, Object param2) {
        if (key == null) throw new NullPointerException();        
	return NbBundle.getMessage (this.getClass(), key, param1, param2);
    }
    
    /** 
     * Get localized character from package bundle. Usually used on mnemonic.
     * @param key Key identifing localized value.
     * @return localized value.
     */
    public final char getChar (String key) {
        if (key == null) throw new NullPointerException();        
	return NbBundle.getMessage (this.getClass(), key).charAt (0);
    }
    
    
    //
    // Debugging purposes
    //
    
    /**
     * Check whether running at loggable level.
     * @return true if debug (...) will log something.
     */
    public final boolean isLoggable () {
        return isLoggable (DEBUG_SEVERITY);
    }

    /**
     * Check whether running at loggable level.
     * @param level the log level
     * @return true if debug (...) will log something.
     */
    public final boolean isLoggable (Level level) {
        return LOG.isLoggable (level);
    }

    /**
     * Log a message if package log level passes.
     * @param message Message to log down. null is allowed
     *        but is not logged.
     */
    public final void debug (String message) {
        debug(DEBUG_SEVERITY, message);
    }

    /**
     * Log a message if package log level passes.
     * @param level the log level
     * @param message Message to log down. null is allowed
     *        but is not logged.
     */
    public final void debug (Level level, String message) {
        if (message == null) return;
        LOG.log (level, message);
    }

    /**
     * Always log a exception.
     * @param ex Exception to log down. null is allowed
     *           but is not logged.
     */
    public final void debug (Throwable ex) {
        if (ex == null) return;
        LOG.log (DEBUG_SEVERITY, null, ex);
    }

    /**
     * Always log an annotated exception.
     * @param message Message used for exception annotation or null.
     * @param ex Exception to log down. null is allowed
     *        but is not logged.
     */
    public final void debug (String message, Throwable ex) {
        if (ex == null) return;
        LOG.log (DEBUG_SEVERITY, message, ex);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy