~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/java/lang/LangHelper.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2007-2011 Jeroen Frijters
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
 
 
25
package java.lang;
 
26
 
 
27
import ikvm.runtime.AssemblyClassLoader;
 
28
import java.io.IOException;
 
29
import java.net.MalformedURLException;
 
30
import java.net.URL;
 
31
import java.security.AccessController;
 
32
import java.util.Enumeration;
 
33
import java.util.Map;
 
34
import sun.nio.ch.Interruptible;
 
35
import sun.reflect.annotation.AnnotationType;
 
36
import sun.security.action.GetPropertyAction;
 
37
 
 
38
@ikvm.lang.Internal
 
39
public class LangHelper
 
40
{
 
41
    private static boolean addedSystemPackages;
 
42
 
 
43
    private static void addSystemPackage(Map pkgMap)
 
44
    {
 
45
        // NOTE caller must have acquired lock on pkgMap
 
46
        if (!addedSystemPackages)
 
47
        {
 
48
            addedSystemPackages = true;
 
49
            String[] pkgs = AssemblyClassLoader.GetPackages(getBootstrapAssembly());
 
50
            for (int i = 0; i < pkgs.length; i++)
 
51
            {
 
52
                pkgMap.put(pkgs[i],
 
53
                    new Package(pkgs[i],
 
54
                    VMSystemProperties.SPEC_TITLE,                 // specTitle
 
55
                    VMSystemProperties.SPEC_VERSION,               // specVersion
 
56
                    VMSystemProperties.SPEC_VENDOR,                // specVendor
 
57
                    "IKVM.NET OpenJDK",                            // implTitle
 
58
                    PropertyConstants.openjdk_version,             // implVersion
 
59
                    "Oracle Corporation & others",                 // implVendor
 
60
                    null,                                          // sealBase
 
61
                    null));                                        // class loader
 
62
            }
 
63
        }
 
64
    }
 
65
 
 
66
    /* this method gets called by Package.getSystemPackage() via a redefined method in map.xml */
 
67
    static Package getSystemPackage(Map pkgs, String name)
 
68
    {
 
69
        synchronized (pkgs)
 
70
        {
 
71
            addSystemPackage(pkgs);
 
72
            return (Package)pkgs.get(name);
 
73
        }
 
74
    }
 
75
 
 
76
    /* this method gets called by Package.getSystemPackages() via a redefined method in map.xml */
 
77
    static Package[] getSystemPackages(Map pkgs)
 
78
    {
 
79
        synchronized (pkgs)
 
80
        {
 
81
            addSystemPackage(pkgs);
 
82
            return (Package[])pkgs.values().toArray(new Package[pkgs.size()]);
 
83
 
 
84
        }
 
85
    }
 
86
 
 
87
    private static cli.System.Reflection.Assembly getBootstrapAssembly()
 
88
    {
 
89
        return ikvm.runtime.Util.getInstanceTypeFromClass(Object.class).get_Assembly();
 
90
    }
 
91
 
 
92
    static URL getBootstrapResource(String name)
 
93
    {
 
94
        return AssemblyClassLoader.getResource(null, getBootstrapAssembly(), name);
 
95
    }
 
96
 
 
97
    static Enumeration getBootstrapResources(String name) throws IOException
 
98
    {
 
99
        return AssemblyClassLoader.getResources(null, getBootstrapAssembly(), name);
 
100
    }
 
101
    
 
102
    public static sun.misc.JavaLangAccess getJavaLangAccess()
 
103
    {
 
104
        return new sun.misc.JavaLangAccess() {
 
105
            public sun.reflect.ConstantPool getConstantPool(Class klass) {
 
106
                return null;
 
107
            }
 
108
            public void setAnnotationType(Class klass, AnnotationType type) {
 
109
                klass.setAnnotationType(type);
 
110
            }
 
111
            public AnnotationType getAnnotationType(Class klass) {
 
112
                return klass.getAnnotationType();
 
113
            }
 
114
            public <E extends Enum<E>>
 
115
                    E[] getEnumConstantsShared(Class<E> klass) {
 
116
                return klass.getEnumConstantsShared();
 
117
            }
 
118
            public void blockedOn(Thread t, Interruptible b) {
 
119
                t.blockedOn(b);
 
120
            }
 
121
            public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
 
122
                Shutdown.add(slot, registerShutdownInProgress, hook);
 
123
            }
 
124
            public int getStackTraceDepth(Throwable t) {
 
125
                return t.getStackTraceDepth();
 
126
            }
 
127
            public StackTraceElement getStackTraceElement(Throwable t, int i) {
 
128
                return t.getStackTraceElement(i);
 
129
            }
 
130
            public int getStringHash32(String string) {
 
131
                return StringHelper.hash32(string);
 
132
            }
 
133
        };
 
134
    }
 
135
}