001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.j2me.main;
026:
027: import java.util.Properties;
028: import java.util.Hashtable;
029:
030: /**
031: * Intermediate class for getting internal properties
032: */
033: public class Configuration {
034:
035: /** List of all internal properties. */
036: private static Properties props = new Properties();
037:
038: /** Static native initialization. */
039: static {
040: initialize();
041: }
042:
043: /** Don't let anyone instantiate this class. */
044: private Configuration() {
045: }
046:
047: /**
048: * Returns internal property value by key.
049: *
050: * @param key property key.
051: * @return property value.
052: */
053: public static String getProperty(String key) {
054: return props.getProperty(key);
055: }
056:
057: /**
058: * Sets internal property value by key.
059: *
060: * @param key property key.
061: * @param value property value.
062: */
063: public static void setProperty(String key, String value) {
064: props.setProperty(key, value);
065: }
066:
067: /**
068: * Gets the implementation property indicated by the specified key or
069: * returns the specified default value as an int.
070: *
071: * @param key the name of the implementation property.
072: * @param def the default value for the property if not
073: * specified in the configuration files or command
074: * line over rides.
075: *
076: * @return the int value of the implementation property,
077: * or <code>def</code> if there is no property with that key or
078: * the config value is not an int.
079: *
080: * @exception NullPointerException if <code>key</code> is
081: * <code>null</code>.
082: * @exception IllegalArgumentException if <code>key</code> is empty.
083: */
084: public static int getIntProperty(String key, int def) {
085: String prop = getProperty(key);
086: if (prop == null) {
087: return def;
088: }
089:
090: try {
091: int temp = Integer.parseInt(prop);
092: return temp;
093: } catch (NumberFormatException nfe) {
094: // keep the default
095: }
096:
097: return def;
098: }
099:
100: /**
101: * Performs native initialization necessary for this class.
102: */
103: private static native void initialize();
104: }
|