⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtconfig.java

📁 Open DMT GPS server source code
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        return (rtp != null)? rtp.getDouble(key, dft) : dft;    }    public static double getDouble(String key[], double dft)    {        if (key != null) {            for (int i = 0; i < key.length; i++) {                RTProperties rtp = getPropertiesForKey(key[i]);                if (rtp != null) { return rtp.getDouble(key[i], dft); }            }        }        return dft;    }    public static void setDouble(String key, double value)    {        RTProperties cfgProps = getConfigFileProperties();        cfgProps.setDouble(key, value);    }    // ------------------------------------------------------------------------    public static float getFloat(String key)    {        return RTConfig.getFloat(key, 0.0F);    }    public static float getFloat(String key, float dft)    {        RTProperties rtp = getPropertiesForKey(key);        return (rtp != null)? rtp.getFloat(key, dft) : dft;    }    public static float getFloat(String key[], float dft)    {        if (key != null) {            for (int i = 0; i < key.length; i++) {                RTProperties rtp = getPropertiesForKey(key[i]);                if (rtp != null) { return rtp.getFloat(key[i], dft); }            }        }        return dft;    }    public static void setFloat(String key, float value)    {        RTProperties cfgProps = getConfigFileProperties();        cfgProps.setFloat(key, value);    }    // ------------------------------------------------------------------------    public static long getLong(String key)    {        return RTConfig.getLong(key, 0L);    }    public static long getLong(String key, long dft)    {        RTProperties rtp = getPropertiesForKey(key);        return (rtp != null)? rtp.getLong(key, dft) : dft;    }    public static long getLong(String key[], long dft)    {        if (key != null) {            for (int i = 0; i < key.length; i++) {                RTProperties rtp = getPropertiesForKey(key[i]);                if (rtp != null) { return rtp.getLong(key[i], dft); }            }        }        return dft;    }    public static void setLong(String key, long value)    {        RTProperties cfgProps = getConfigFileProperties();        cfgProps.setLong(key, value);    }    // ------------------------------------------------------------------------    public static int getInt(String key)    {        return RTConfig.getInt(key, 0);    }    public static int getInt(String key, int dft)    {        RTProperties rtp = getPropertiesForKey(key);        return (rtp != null)? rtp.getInt(key, dft) : dft;    }    public static int getInt(String key[], int dft)    {        if (key != null) {            for (int i = 0; i < key.length; i++) {                RTProperties rtp = getPropertiesForKey(key[i]);                if (rtp != null) { return rtp.getInt(key[i], dft); }            }        }        return dft;    }    public static void setInt(String key, int value)    {        RTProperties cfgProps = getConfigFileProperties();        cfgProps.setInt(key, value);    }    // ------------------------------------------------------------------------    public static boolean getBoolean(String key)    {        return getBoolean(key, hasProperty(key));    }    public static boolean getBoolean(String key, boolean dft)    {        RTProperties rtp = getPropertiesForKey(key);        if (rtp == null) {            return dft; // no key, return default        } else {            String s = rtp.getString(key, "");            if ((s != null) && s.equals("")) {                return rtp.getBoolean(key, true); // key with no argument            } else {                return rtp.getBoolean(key, dft);  // key with argument, use dft if not parsable.            }        }        //return (rtp != null)? rtp.getBoolean(key, dft) : dft;    }    public static boolean getBoolean(String key[], boolean dft)    {        if (key != null) {            for (int i = 0; i < key.length; i++) {                RTProperties rtp = getPropertiesForKey(key[i]);                if (rtp != null) { return rtp.getBoolean(key[i], dft); }            }        }        return dft;    }    public static void setBoolean(String key, boolean value)    {        RTProperties cfgProps = getConfigFileProperties();        cfgProps.setBoolean(key, value);    }    // ------------------------------------------------------------------------    public static void setAdminMode(boolean admin)    {        RTConfig.setBoolean(RTKey.ADMIN_MODE, admin);    }    public static boolean isAdminMode()    {        return RTConfig.getBoolean(RTKey.ADMIN_MODE);    }    // ------------------------------------------------------------------------    public static void setDebugMode(boolean debug)    {        RTConfig.setBoolean(RTKey.DEBUG_MODE, debug);    }    //private static int _debug_recursion = 0;    public static boolean isDebugMode()    {        //if (_debug_recursion > 0) { Thread.dumpStack(); System.exit(0); }        //try { _debug_recursion++;        return !isInitialized() || getBoolean(RTKey.DEBUG_MODE);        //} finally { _debug_recursion--; }    }    // ------------------------------------------------------------------------    public static void setTestMode(boolean test)    {        setBoolean(RTKey.TEST_MODE, test);    }    public static boolean isTestMode()    {        return getBoolean(RTKey.TEST_MODE);    }    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    private static Boolean isRunningAsWebApp = null;    public static void setWebApp(boolean webapp)    {        setBoolean(RTKey.IS_WEBAPP, webapp);        isRunningAsWebApp = null; // <== to bypass Boolean check    }    public static boolean isWebApp()    {        /* already know where we are running? */        if (isRunningAsWebApp != null) {            return isRunningAsWebApp.booleanValue();        }        /* "isWebApp" explicitly defined? */        if (hasProperty(RTKey.IS_WEBAPP, false)) {            return getBoolean(RTKey.IS_WEBAPP);        }        /* check invocation stack */        isRunningAsWebApp = new Boolean(_isWebApp_2());        return isRunningAsWebApp.booleanValue();    }    private static String WebAppClassNames[] = {        "javax.servlet.http.HttpServlet", // as long as the servlet didn't override 'service'        "org.apache.catalina.core.ApplicationFilterChain"    };    protected static boolean _isWebApp_1()    {        // We should also check the invocation stack        // A typical stack-trace segment for a servlet is as follows:        //   ...        //   at com.example.war.DataMessage.doPost(DataMessage.java:46)        //   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)        //   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)        //   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)        //   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)        //   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)        //   ...        // Possible search Strings would be:        //  - "javax.servlet.http.HttpServlet" (assuming 'service' was not overridden)        //  - "org.apache.catalina.core.ApplicationFilterChain" (only valid for Tomcat)        Throwable t = new Throwable();        t.fillInStackTrace();        //t.printStackTrace();        StackTraceElement stackFrame[] = t.getStackTrace();        for (int i = 0; i < stackFrame.length; i++) {            String cn = stackFrame[i].getClassName();            for (int w = 0; w < WebAppClassNames.length; w++) {                if (cn.equalsIgnoreCase(WebAppClassNames[w])) {                    return true;                }            }        }        return false;    }    protected static boolean _isWebApp_2()    {        return (getServletClass() != null);    }    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    private static Class Main_class = null;    public static Class getMainClass()    {        if (Main_class == null) {            Class lastClz = null;            for (int sf = 2; ; sf++) {                Class clz = OSTools.getCallerClass(sf);                if (clz == null) { break; }                lastClz = clz;            }            Main_class = lastClz;        }        return Main_class;    }    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    private static String SERVLET_CLASS = "javax.servlet.Servlet"; // GenericServlet    private static boolean Servlet_init = false;    private static Class<?> Servlet_class = null;    public static Class<?> getServletClass()    {        /* init for Servlet class */        if (!Servlet_init) {            try {                Servlet_class = Class.forName(SERVLET_CLASS);            } catch (Throwable t) {                // class not found?                //Print.logWarn("Not a servlet - running as application?");            }            Servlet_init = true;        }        /* find Servlet in invocation stack */        if (Servlet_class != null) {            for (int sf = 2; ; sf++) {                Class<?> clz = OSTools.getCallerClass(sf);                if (clz == null) { break; }                if (Servlet_class.isAssignableFrom(clz)) {                    return clz;                }            }        }        /* not found */        return null;    }    // ------------------------------------------------------------------------    // ------------------------------------------------------------------------    public static void main(String argv[])    {        Print.logInfo("Before RTConfig was initialized ...");        RTConfig.setCommandLineArgs(argv);        Print.logInfo("String test = " + RTConfig.getString("test","???"));        Print.logInfo("Double test = " + RTConfig.getDouble("test",0.0));        Print.logInfo("Long   test = " + RTConfig.getLong("test",0L));        //Print.logFatal("DebugMode [false] = " + RTConfig.getBoolean(RTKey.DEBUG_MODE,false));        //Print.logError("DebugMode [false] = " + RTConfig.getBoolean(RTKey.DEBUG_MODE,false));        //Print.logWarn ("DebugMode [true ] = " + RTConfig.getBoolean(RTKey.DEBUG_MODE,true));        //Print.logInfo ("DebugMode [undef] = " + RTConfig.getBoolean(RTKey.DEBUG_MODE));        //Print.logDebug("DebugMode [undef] = " + RTConfig.getBoolean(RTKey.DEBUG_MODE));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -