1
/*
2
 * $Id$
3
 *
4
 * Copyright (C) 2003-2009 JNode.org
5
 *
6
 * This library is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful, but 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
14
 * License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this library; If not, write to the Free Software Foundation, Inc., 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
 */
20
 
21
package org.jnode.vm;
22
23
import gnu.java.lang.VMClassHelper;
24
25
/**
26
 * Utility class to share some Vm features.
27
 * For now, it's especially used to know how native methods are implemented in JNode.
28
 *
29
 * @author Fabien DUMINY (fduminy at jnode.org)
30
 */
31
public class VmUtils {
32
    private static final String NATIVE_CLASSNAME_PREFIX = "Native";
33
34
    public static boolean couldImplementNativeMethods(String className) {
35
        String clsName = VMClassHelper.getClassNamePortion(className);
36
        return clsName.startsWith(NATIVE_CLASSNAME_PREFIX);
37
    }
38
39
    public static String getNativeClassName(String className) {
40
        final String pkg = VMClassHelper.getPackagePortion(className);
41
        final String nativeClassName = pkg + ((pkg.length() > 0) ? "." : "")
42
            + NATIVE_CLASSNAME_PREFIX + VMClassHelper.getClassNamePortion(className);
43
        return nativeClassName;
44
    }
45
46
    public static boolean allowNatives(String className, String architectureName) {
47
        boolean allowNatives = false;
48
        allowNatives |= className.equals("org.jnode.vm.Unsafe");
49
        /*
50
        allowNatives |= className.equals("org.jnode.vm." + architectureName + ".Unsafe"
51
                + architectureName.toUpperCase());
52
          */
53
        allowNatives |= className.indexOf("org.jnode.vm.") > -1 && className.indexOf(".Unsafe") > -1;
54
        return allowNatives;
55
    }
56
}