Code Search for Developers
 
 
  

SystemConfigVarManager.java from BIRT at Krugle


Show SystemConfigVarManager.java syntax highlighted

/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.core.config;

/**
 * Implements a default config variable manager using System support
 */
public class SystemConfigVarManager {

	/**
	 * Constructor 
	 */
	public SystemConfigVarManager() {
	}

	/**
	 * @param key the configuration variable name
	 * @return The value for the configuration variable. null if it is not set.
	 */
	public String getConfigVar(String key) {
		return System.getProperty(key);
	}
	
	/**
	 * @param key the configuration variable name
	 * @param defaultValue returns this value is the configuration variable is not set 
	 * @return The value for the configuration variable. In case the config var is not set, 
	 * or there is an exception, defaultValue is returned.
	 */
	public String getConfigVar(String key, String defaultValue) {
	    String ret = null;
	    
	    try{
	        ret = getConfigVar(key);
	    } catch (Exception e)
	    {
	        return defaultValue;
	    }
	    
		if (ret == null)
		    return defaultValue;
	    return ret;
	}	
	
	/**
	 * @param key the configuration variable name
	 * @return true if set to true (case insensitive), false in any other cases
	 */
	public boolean getConfigBoolean(String key) {
	    // We do not use Boolean.getProperty() so that this method is more generic and can get config
	    // var from other sources, i.e., a configuration file
	    String booleanValue;
	    
	    try{
	        booleanValue = getConfigVar(key);
	    } catch (Exception e)
	    {
	        return false;
	    }
	    
	    if (booleanValue == null || booleanValue.compareToIgnoreCase("true") != 0)
	        return false;
		return true;
	}

	/**
	 * @param key the configuration variable name
	 * @return the value for the configuration variable. returns null if the config var is
	 * not set or not set to an integer or any other exception happens. 
	 */
	public Integer getConfigInteger(String key) {
	    try
	    {
		    // We do not use Integer.getProperty so that this method is more generic and can get config
		    // var from other sources, i.e., a configuration file
		    String intString = getConfigVar(key);
		    
		    if ( intString != null )
		        return Integer.valueOf(intString);
	        return null;
	    } catch (Exception e)
	    {
	        return null;
	    }
	}
	
	/**
	 * @param key the configuration variable name
	 * @param defaultValue returns this value is the configuration variable is not set 
	 * @return the value for the configuration variable. In case the config var is not set, 
	 * or not set to a number, or there is an exception, defaultValue is returned.
	 */
	public int getConfigInteger(String key, int defaultValue) {
	    try
	    {
		    // We do not use Integer.getProperty so that this method is more generic and can get config
		    // var from other sources, i.e., a configuration file
		    String intString = getConfigVar(key);
		    
		    if ( intString == null )
		        return defaultValue; 
		    return Integer.valueOf(intString).intValue();
	    } catch (Exception e)
	    {
	        return defaultValue;
	    }
	}
}




See more files for this project here

BIRT

BIRT is an open source, Eclipse-based reporting system that integrates with your application to produce compelling reports for both web and PDF.

Project homepage: http://www.eclipse.org/birt/phoenix/
Programming language(s): Java,XML
License: gpl2

  FileConfigVarManager.java
  IConfigVarManager.java
  SystemConfigVarManager.java
  package.html