IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Proxy.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2007-2013 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*/
24using System;
25
26using IKVM.Runtime;
27
29{
30
31 static class Proxy
32 {
33
34 public static object defineClass0(global::java.lang.ClassLoader classLoader, string name, byte[] b, int off, int len)
35 {
36 return IKVM.Java.Externs.java.lang.ClassLoader.defineClass1(classLoader, name, b, off, len, null, null);
37 }
38
39 public static global::java.lang.Class getPrecompiledProxy(global::java.lang.ClassLoader classLoader, string proxyName, global::java.lang.Class[] interfaces)
40 {
41#if FIRST_PASS
42 throw new NotImplementedException();
43#else
44 RuntimeAssemblyClassLoader acl = JVM.Context.ClassLoaderFactory.GetClassLoaderWrapper(classLoader) as RuntimeAssemblyClassLoader;
45 if (acl == null)
46 {
47 return null;
48 }
49 RuntimeJavaType[] wrappers = new RuntimeJavaType[interfaces.Length];
50 for (int i = 0; i < wrappers.Length; i++)
51 {
52 wrappers[i] = RuntimeJavaType.FromClass(interfaces[i]);
53 }
54 // TODO support multi assembly class loaders
55 Type type = acl.MainAssembly.GetType(TypeNameUtil.GetProxyName(wrappers));
56 if (type == null)
57 {
58 return null;
59 }
60 RuntimeJavaType tw = JVM.Context.ManagedByteCodeJavaTypeFactory.newInstance(proxyName, type);
61 RuntimeJavaType tw2 = acl.RegisterInitiatingLoader(tw);
62 if (tw != tw2)
63 {
64 return null;
65 }
66 // we need to explicitly register the type, because the type isn't visible by normal means
67 JVM.Context.ClassLoaderFactory.SetWrapperForType(type, tw);
68 RuntimeJavaType[] wrappers2 = tw.Interfaces;
69 if (wrappers.Length != wrappers.Length)
70 {
71 return null;
72 }
73 for (int i = 0; i < wrappers.Length; i++)
74 {
75 if (wrappers[i] != wrappers2[i])
76 {
77 return null;
78 }
79 }
80 return tw.ClassObject;
81#endif
82 }
83
84 }
85
86}
IKVM.Reflection.Type Type
static global::java.lang.Class defineClass1(global::java.lang.ClassLoader self, string name, byte[] b, int off, int len, global::java.security.ProtectionDomain pd, string source)
Implements the native method 'defineClass1'.
static global::java.lang.Class getPrecompiledProxy(global::java.lang.ClassLoader classLoader, string proxyName, global::java.lang.Class[] interfaces)
Definition Proxy.cs:39
static object defineClass0(global::java.lang.ClassLoader classLoader, string name, byte[] b, int off, int len)
Definition Proxy.cs:34
Main state of the running JVM.
RuntimeManagedByteCodeJavaTypeFactory ManagedByteCodeJavaTypeFactory
Gets the RuntimeManagedJavaTypeFactory associated with this instance of the runtime.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
RuntimeManagedByteCodeJavaType newInstance(string name, Type type)
Creates a new instance of the appropriate runtime type.