|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.rt.support; |
|
19 |
|
20 import com.nokia.mj.impl.rt.JvmPort; |
|
21 |
|
22 /** |
|
23 * Provides JVM utilities for Java API implementations to use. Some of these |
|
24 * utilities hide differences between CLDC and CDC configurations and some |
|
25 * provide completely non-standard access to JVM features and to process memory. |
|
26 *<p> |
|
27 * Example how to load a system library |
|
28 * <pre> |
|
29 * package com.nokia.mj.impl.mypackage; |
|
30 * |
|
31 * import com.nokia.mj.impl.rt.support; |
|
32 * public void myClass() |
|
33 * { |
|
34 * public void myMethod() |
|
35 * { |
|
36 * //loads the system library. |
|
37 * Jvm.loadSystemLibrary("my_system_library"); |
|
38 * |
|
39 * //my implementation... |
|
40 * } |
|
41 * } |
|
42 *</pre> |
|
43 * @author Nokia Corporation |
|
44 * @version 1.0 |
|
45 */ |
|
46 |
|
47 public class Jvm |
|
48 { |
|
49 /** |
|
50 * Loads the system library specified by the libName argument. |
|
51 * <p> |
|
52 * This method uses <code>System.loadLibrary</code> in CDC based |
|
53 * configuration while in CLDC a proprieatary API is used. |
|
54 * @param libName The name of the library. |
|
55 */ |
|
56 public static void loadSystemLibrary(String libName) |
|
57 { |
|
58 JvmPort.getInstance().loadSystemLibrary(libName); |
|
59 } |
|
60 |
|
61 /** |
|
62 * JAVADOCS ARE UNDER CONSTRUCTION!! |
|
63 * <p> |
|
64 * Returns the Class object associated with the class or interface with the |
|
65 * given string name. |
|
66 * @param name A fully qualified name of the desired class. |
|
67 * @return class object representing the desired class . |
|
68 */ |
|
69 public static Class loadApplicationClass(String name) |
|
70 throws ClassNotFoundException |
|
71 { |
|
72 return JvmPort.getInstance().loadApplicationClass(name); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Marks the given thread as either a daemon thread or a user thread |
|
77 * This can only be done before the Thread starts running. |
|
78 * @param thread The thread to be modified. |
|
79 * @param daemon If true, marks the given thread as a daemon thread. |
|
80 * @throws IllegalThreadStateException if the Thread has already been |
|
81 * started. |
|
82 * @throws SecurityException if the caller is not in the boot class path. |
|
83 */ |
|
84 public static void setThreadAsDaemon(Thread thread, boolean daemon) |
|
85 throws IllegalThreadStateException, SecurityException |
|
86 { |
|
87 JvmPort.getInstance().setThreadAsDaemon(thread, daemon); |
|
88 } |
|
89 |
|
90 /** |
|
91 * JAVADOCS ARE UNDER CONSTRUCTION!! |
|
92 * <p> |
|
93 * Gets a NativeMemoryBlock. NativeMemoryBlock provids a way |
|
94 * read the whole content of resource in jar file into native memory |
|
95 * buffer. The content is not copien into Java side - only pointer |
|
96 * and size of the data is usable in the Java side. |
|
97 * |
|
98 * @param jarPath If jarPath is null then the resource is searched from |
|
99 * the classpath - like in normal class.getResourceAsStream. If it is |
|
100 * provided then it can be any Jar file availble in the file system. |
|
101 * @param resName Name of the desired resource |
|
102 * |
|
103 * @return MemoryInputStream object as InputStream if resource is found, |
|
104 * otherwise null. |
|
105 */ |
|
106 public static NativeMemoryBlock getResourceAsNativeMemory(String jarPath, |
|
107 String resName) |
|
108 { |
|
109 return JvmPort.getInstance().getResourceAsNativeMemory(jarPath, resName); |
|
110 } |
|
111 } |