|
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 |
|
19 package com.ibm.oti.nokiaextcldc; |
|
20 |
|
21 import java.util.Hashtable; |
|
22 |
|
23 import com.ibm.oti.util.SystemPropertiesHook; |
|
24 import com.ibm.oti.vm.VM; |
|
25 |
|
26 import com.nokia.mj.impl.rt.SystemPropertyHashtable; |
|
27 import com.nokia.mj.impl.rt.support.Finalizer; |
|
28 import com.nokia.mj.impl.rt.JvmPort; |
|
29 |
|
30 /** |
|
31 * A class that implements a system property extension mechanism provided |
|
32 * by J9 for CLDC. The idea is that the VM provides the original system |
|
33 * properties in a Hashtable object as an argument in extendSystemProperties |
|
34 * method. In the method a new Hashtable based instance of object is returned |
|
35 * containing original properties. The object is from class that extendeds |
|
36 * the Hashtable where the get() method is overwritten in order to handle |
|
37 * dynamic properties. |
|
38 * |
|
39 * @author Nokia Corporation |
|
40 * @version 1.0 |
|
41 */ |
|
42 public class SystemPropertyExtension implements SystemPropertiesHook |
|
43 { |
|
44 |
|
45 public Hashtable extendSystemProperties(Hashtable originalProperties) |
|
46 { |
|
47 // Vital to make finalizer implementation reliable. If this is not done |
|
48 // the first class registering for finalization never receves |
|
49 // finalization serverces - i.e. none of the instances of that |
|
50 // particular class will ever be finalized. |
|
51 VM.enableFinalization(Finalizer.class); |
|
52 |
|
53 // Create a new object extending java.util.Hashtable and fill with the |
|
54 // original properties. |
|
55 SystemPropertyHashtable newProperties = |
|
56 new SystemPropertyHashtable(originalProperties); |
|
57 |
|
58 // Store the hashtable to be able to add properties during runtime. |
|
59 JvmPort.setPropertiesContainer(newProperties); |
|
60 |
|
61 // Override existing line.separator |
|
62 newProperties.put("line.separator", "\n"); |
|
63 |
|
64 return newProperties; |
|
65 } |
|
66 } |