IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RuntimeGenericClassLoader.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2015 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;
25using System.Text;
26
27namespace IKVM.Runtime
28{
29
31 {
32
33 readonly RuntimeClassLoader[] delegates;
34
41 internal RuntimeGenericClassLoader(RuntimeContext context, RuntimeClassLoader[] delegates, object javaClassLoader) :
42 base(context, CodeGenOptions.None, javaClassLoader)
43 {
44 this.delegates = delegates;
45 }
46
47 internal bool Matches(RuntimeClassLoader[] key)
48 {
49 if (key.Length == delegates.Length)
50 {
51 for (int i = 0; i < key.Length; i++)
52 if (key[i] != delegates[i])
53 return false;
54
55 return true;
56 }
57
58 return false;
59 }
60
61 protected override RuntimeJavaType FindLoadedClassLazy(string name)
62 {
63 var tw1 = FindOrLoadGenericClass(name, LoadMode.Find);
64 if (tw1 != null)
65 return tw1;
66
67 foreach (var loader in delegates)
68 {
69 var tw = loader.FindLoadedClass(name);
70 if (tw != null && tw.ClassLoader == loader)
71 return tw;
72 }
73
74 return null;
75 }
76
77 internal string GetName()
78 {
79 var sb = new ValueStringBuilder();
80 sb.Append('[');
81
82 foreach (var loader in delegates)
83 {
84 sb.Append('[');
85
86 if (loader is RuntimeGenericClassLoader gcl)
87 sb.Append(gcl.GetName());
88 else
89 sb.Append(((RuntimeAssemblyClassLoader)loader).MainAssembly.FullName);
90
91 sb.Append(']');
92 }
93
94 sb.Append(']');
95
96 return sb.ToString();
97 }
98
99#if IMPORTER == false && EXPORTER == false
100
101 internal java.util.Enumeration GetResources(string name)
102 {
103#if FIRST_PASS
104 throw new NotImplementedException();
105#else
106 var v = new java.util.Vector();
107 foreach (var url in Context.ClassLoaderFactory.GetBootstrapClassLoader().GetResources(name))
108 v.add(url);
109
110 if (name.EndsWith(".class", StringComparison.Ordinal) && name.IndexOf('.') == name.Length - 6)
111 {
112 var tw = FindLoadedClass(name.Substring(0, name.Length - 6).Replace('/', '.'));
113 if (tw != null && !tw.IsArray && !tw.IsDynamic)
114 {
115 var loader = tw.ClassLoader;
116 if (loader is RuntimeGenericClassLoader)
117 v.add(new java.net.URL("ikvmres", "gen", Context.ClassLoaderFactory.GetGenericClassLoaderId(loader), "/" + name));
118 else if (loader is RuntimeAssemblyClassLoader acl)
119 foreach (java.net.URL url in acl.FindResources(name))
120 v.add(url);
121 }
122 }
123
124 return v.elements();
125#endif
126 }
127
128 internal java.net.URL FindResource(string name)
129 {
130#if FIRST_PASS
131 throw new NotImplementedException();
132#else
133 if (name.EndsWith(".class", StringComparison.Ordinal) && name.IndexOf('.') == name.Length - 6)
134 {
135 var tw = FindLoadedClass(name.Substring(0, name.Length - 6).Replace('/', '.'));
136 if (tw != null && tw.ClassLoader == this && !tw.IsArray && !tw.IsDynamic)
137 return new java.net.URL("ikvmres", "gen", Context.ClassLoaderFactory.GetGenericClassLoaderId(this), "/" + name);
138 }
139
140 return null;
141#endif
142 }
143
144#endif
145
146 }
147
148}
Runtime support for a class loader.
RuntimeContext Context
Gets a reference to the RuntimeContext that this RuntimeClassLoader is hosted within.
java.lang.ClassLoader javaClassLoader
Maintains services relevant to an instane of the IKVM runtime.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
override RuntimeJavaType FindLoadedClassLazy(string name)