01: /*
02: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: package com.sun.midp.main;
26:
27: import java.io.File;
28:
29: /**
30: * Initialize the CDC environment for MIDlet execution.
31: */
32: public class CDCInit {
33: /**
34: * Performs CDC API initialization.
35: *
36: * @param midpHome root directory of the MIDP working files
37: * @param nativeLib name of the native shared library, only applies to
38: * non-rommized build
39: */
40: public static void init(String midpHome, String nativeLib) {
41: try {
42: if (nativeLib != null) {
43: System.loadLibrary(nativeLib);
44: }
45: } catch (UnsatisfiedLinkError err) {
46: /*
47: * Since there is currenly no to determine if the build rommized
48: * the MIDP native methods or not, it is customary to pass in a
49: * default library name even if there is no library to load,
50: * which will cause this exception, so the exception has to be
51: * ignored here. If this is a non-rommized build and library is
52: * not found, the first native method call below will throw an
53: * error.
54: */
55: }
56:
57: /*
58: * In case the normal system properites configration did not set
59: * the profile set it here.
60: */
61: String profile = System.getProperty("microedition.profiles");
62: if (profile == null) {
63: System.setProperty("microedition.profiles", "MIDP-2.1");
64: }
65:
66: initMidpNativeStates(midpHome);
67: }
68:
69: /** Performs CDC API initialization. */
70: public static void init() {
71: /*
72: * Path to MIDP working directory.
73: * Default is the property "sun.midp.home.path",
74: * the fallback is user.dir.
75: */
76: String userdir = System.getProperty("user.dir", ".");
77: userdir += File.separator + "midp" + File.separator + "midp_fb";
78: String home = System.getProperty("sun.midp.home.path", userdir);
79: String lib = System
80: .getProperty("sun.midp.library.name", "midp");
81:
82: init(home, lib);
83: }
84:
85: /**
86: * Performs native subsystem initialization.
87: * @param home path to the MIDP working directory.
88: */
89: static native void initMidpNativeStates(String home);
90: }
|