javacommons/utils/tsrc/rtsupport/javasrc/com/nokia/mj/impl/rt/testvm/JvmPortTest.java
changeset 80 d6dafc5d983f
parent 78 71ad690e91f5
child 87 1627c337e51e
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
     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.j9;
       
    19 
       
    20 import com.nokia.mj.impl.rt.JvmPort;
       
    21 import com.nokia.mj.impl.rt.support.ThreadEventListener;
       
    22 import com.nokia.mj.impl.rt.support.NativeMemoryBlock;
       
    23 import java.io.*;
       
    24 import java.util.Properties;
       
    25 import java.util.Enumeration;
       
    26 import com.nokia.mj.impl.rt.DynamicSystemPropertiesSun;
       
    27 
       
    28 /**
       
    29  *
       
    30  * @author Nokia Corporation
       
    31  * @version 1.0
       
    32  */
       
    33 
       
    34 public final class JvmPortTest extends JvmPort
       
    35 {
       
    36     static
       
    37     {
       
    38         //The code below reads all the odc files from the location
       
    39         //where the API jsr files are. It also enables the System
       
    40         //property extension mechanism for Sun's J2SE vm.
       
    41         try
       
    42         {
       
    43             String odcLocation = System.getProperty("java.ext.dirs");
       
    44             // This filter only returns directories
       
    45             File odcDir = new File(odcLocation);
       
    46             FileFilter filter = new FileFilter()
       
    47             {
       
    48                 public boolean accept(File f)
       
    49                 {
       
    50                     if (f.getName().endsWith(".odc"))
       
    51                     {
       
    52                         return true;
       
    53                     }
       
    54                     return false;
       
    55                 }
       
    56             };
       
    57 
       
    58             File[] files = odcDir.listFiles(filter);
       
    59             DynamicSystemPropertiesSun props = new DynamicSystemPropertiesSun();
       
    60 
       
    61             Properties origProps = System.getProperties();
       
    62             Enumeration keys = origProps.keys();
       
    63             while (keys.hasMoreElements())
       
    64             {
       
    65                 Object key = keys.nextElement();
       
    66                 props.put(key, origProps.get(key));
       
    67             }
       
    68 
       
    69             for (int i=0; i<files.length; i++)
       
    70             {
       
    71                 BufferedReader input =
       
    72                     new BufferedReader(new FileReader(files[i]));
       
    73                 try
       
    74                 {
       
    75                     String line = null;
       
    76                     while ((line = input.readLine()) != null)
       
    77                     {
       
    78                         if (line.startsWith("-D"))
       
    79                         {
       
    80                             String name = null;
       
    81                             String value = null;
       
    82                             int pos = line.indexOf("=");
       
    83                             if (pos == -1)
       
    84                             {
       
    85                                 name = line.substring(2);
       
    86                                 value = "";
       
    87                             }
       
    88                             else
       
    89                             {
       
    90                                 name = line.substring(2,pos);
       
    91                                 value = line.substring(pos+1);
       
    92                             }
       
    93                             props.put(name, value);
       
    94                         }
       
    95                     }
       
    96                 }
       
    97                 finally
       
    98                 {
       
    99                     input.close();
       
   100                 }
       
   101             }
       
   102             System.setProperties(props);
       
   103         }
       
   104         catch (Throwable t)
       
   105         {
       
   106             System.err.println("JvmPortJ2se: Exception: "+t);
       
   107         }
       
   108     }
       
   109     /**
       
   110      * @see com.nokia.mj.impl.runtimesupport.JvmPort#loadSystemLibrary.
       
   111      */
       
   112     public final void loadSystemLibrary(String libName)
       
   113     {
       
   114         System.out.println("TestVm: loadSystemLibrary");
       
   115     }
       
   116 
       
   117     /**
       
   118      * @see com.nokia.mj.impl.runtimesupport.JvmPort#loadApplicationClass.
       
   119      */
       
   120     public final Class loadApplicationClass(String name) throws ClassNotFoundException
       
   121     {
       
   122         System.out.println("TestVm: loadApplicationClass: "+name);
       
   123         return null;
       
   124     }
       
   125 
       
   126     /**
       
   127      * @see com.nokia.mj.impl.runtimesupport.JvmPort#setThreadAsDaemon.
       
   128      */
       
   129     public final void setThreadAsDaemon(Thread thread, boolean daemon)
       
   130     throws IllegalThreadStateException, SecurityException
       
   131     {
       
   132         System.out.println("TestVm: loadApplicationClass");
       
   133     }
       
   134 
       
   135     /**
       
   136      * @see com.nokia.mj.impl.runtimesupport.JvmPort#runFinalization.
       
   137      */
       
   138     public final void runFinalization()
       
   139     {
       
   140         System.out.println("TestVm: runFinalization");
       
   141     }
       
   142 
       
   143     /**
       
   144      * @see com.nokia.mj.impl.runtimesupport.JvmPort#enableFinalization.
       
   145      */
       
   146     public final void enableFinalization(Class clazz)
       
   147     {
       
   148         System.out.println("TestVm: enableFinalization");
       
   149     }
       
   150 
       
   151     /**
       
   152      * @see com.nokia.mj.impl.runtimesupport.JvmPort#runYoungGenerationGc.
       
   153      */
       
   154     public final boolean runYoungGenerationGc()
       
   155     {
       
   156         System.out.println("TestVm: runYoungGenerationGc");
       
   157         return false;
       
   158     }
       
   159 
       
   160     /**
       
   161      * @see com.nokia.mj.impl.runtimesupport.JvmPort#getResourceAsNativeMemory.
       
   162      */
       
   163     public final NativeMemoryBlock getResourceAsNativeMemory(String jarPath, String resName)
       
   164     {
       
   165         System.out.println("TestVm: getResourceAsNativeMemory");
       
   166         return null;
       
   167     }
       
   168 
       
   169     /**
       
   170      * @see com.nokia.mj.impl.runtimesupport.JvmPort#disableRuntimeExit.
       
   171      */
       
   172     public final void disableRuntimeExit()
       
   173     {
       
   174         System.out.println("TestVm: disableRuntimeExit");
       
   175     }
       
   176 
       
   177     /**
       
   178      * @see com.nokia.mj.impl.runtimesupport.JvmPort#enableRuntimeExit.
       
   179      */
       
   180     public final void enableRuntimeExit()
       
   181     {
       
   182         System.out.println("TestVm: enableRuntimeExit");
       
   183     }
       
   184 
       
   185     /**
       
   186      * @see com.nokia.mj.impl.runtimesupport.JvmPort#exitVm.
       
   187      */
       
   188     public final void exitVm(int status)
       
   189     {
       
   190         System.out.println("TestVm: exitVm "+status);
       
   191     }
       
   192 
       
   193     /**
       
   194      * @see com.nokia.mj.impl.runtimesupport.JvmPort#setThreadEventListener.
       
   195      */
       
   196     public final void setThreadEventListener(ThreadEventListener listener)
       
   197     {
       
   198         System.out.println("TestVm: setThreadEventListener");
       
   199     }
       
   200 
       
   201     /**
       
   202      * @see com.nokia.mj.impl.runtimesupport.JvmPort#addRestrictedPackagePrefixes.
       
   203      */
       
   204     public final void addRestrictedPackagePrefixes(String[] packageNames)
       
   205     throws SecurityException
       
   206     {
       
   207         System.out.println("TestVm: addRestrictedPackagePrefixes");
       
   208     }
       
   209 
       
   210     /**
       
   211      * @see com.nokia.mj.impl.runtimesupport.JvmPort#addProtectedPackagePrefixes.
       
   212      */
       
   213     public final void addProtectedPackagePrefixes(String[] packageNames)
       
   214     throws SecurityException
       
   215     {
       
   216         System.out.println("TestVm: addProtectedPackagePrefixes");
       
   217     }
       
   218 }