niagara-ax/modules/cfr_output/com/tridium/sys/module/ModuleClassLoader.java
2026-03-17 13:31:18 -07:00

400 lines
15 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package com.tridium.sys.module;
import com.tridium.asm.Buffer;
import com.tridium.sys.module.ModuleExtClassLoader;
import com.tridium.sys.module.NModule;
import com.tridium.util.jar.JarEntry;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.security.AllPermission;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.SecureClassLoader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import javax.baja.spy.Spy;
import javax.baja.spy.SpyWriter;
/*
* Illegal identifiers - consider using --renameillegalidents true
*/
public class ModuleClassLoader
extends SecureClassLoader {
private static final DecimalFormat DF = new DecimalFormat("###,###,###");
static final boolean legacyExtClassLoader = Boolean.getBoolean("niagara.classLoader.ext");
static final boolean parallelCapableClassLoader = Boolean.getBoolean("niagara.classLoader.parallelCapable");
static final Object NOT_FOUND;
private static final Map spyMap;
public final NModule module;
private Hashtable cache;
private Buffer buffer;
protected CodeSource codeSource;
private Permissions permissions;
private Hashtable extClassLoadersByResourcePath;
static /* synthetic */ Class class$java$lang$String;
static /* synthetic */ Class class$java$lang$ClassLoader;
public Class loadClass(String string, boolean bl) throws ClassNotFoundException {
Class clazz = this.nload(string, bl);
if (clazz == null) {
String string2 = string;
if (this.module != null) {
string2 = this.module.name + ':' + string;
}
throw new ClassNotFoundException(string2);
}
return clazz;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
public Class nload(String string, boolean bl) {
Object object = ModuleClassLoader.getLoadClassLock(this, string);
Object object2 = object;
synchronized (object2) {
Object v = this.cache.get(string);
if (v == NOT_FOUND) {
return null;
}
Class clazz = (Class)v;
if (clazz == null) {
clazz = this.nfind(string, bl);
if (clazz == null) {
this.cache.put(string, NOT_FOUND);
return null;
}
this.cache.put(string, clazz);
}
if (bl) {
this.resolveClass(clazz);
}
return clazz;
}
}
static final Object getLoadClassLock(ClassLoader classLoader, String string) {
Object object = classLoader;
try {
Method method;
Class clazz = class$java$lang$ClassLoader;
if (clazz == null) {
clazz = class$java$lang$ClassLoader = ModuleClassLoader.class("[Ljava.lang.ClassLoader;", false);
}
Class[] classArray = new Class[1];
Class clazz2 = class$java$lang$String;
if (clazz2 == null) {
clazz2 = classArray[0] = (class$java$lang$String = ModuleClassLoader.class("[Ljava.lang.String;", false));
}
if ((method = clazz.getDeclaredMethod("getClassLoadingLock", classArray)) != null) {
object = method.invoke((Object)classLoader, string);
}
}
catch (Throwable throwable) {}
return object;
}
Class defineExtClass(String string, byte[] byArray, int n, int n2, CodeSource codeSource) {
return this.defineClass(string, byArray, 0, byArray.length, codeSource);
}
protected Class nfind(String string, boolean bl) {
block18: {
block17: {
if (string.startsWith("auto.")) {
ModuleClassLoader.addClassToSpy(this.module.name, string, this.buffer.count);
return this.defineClass(string, this.buffer.bytes, 0, this.buffer.count, this.codeSource);
}
try {
return this.getParent().loadClass(string);
}
catch (ClassNotFoundException classNotFoundException) {
String string2 = string.replace('.', '/') + ".class";
ArrayList arrayList = (ArrayList)this.extClassLoadersByResourcePath.get(string2);
if (arrayList != null) {
return ((ModuleExtClassLoader)arrayList.get(0)).nfind(string, bl, false);
}
if (this.module.isSynthetic()) break block17;
JarEntry jarEntry = this.module.jarFile.getJarEntry(string2);
if (jarEntry != null) {
byte[] byArray = null;
try {
int n = (int)jarEntry.getSize();
InputStream inputStream = jarEntry.getInputStream();
byArray = new byte[n];
int n2 = 0;
while (n2 < n) {
int n3 = inputStream.read(byArray, n2, n - n2);
if (n3 < 0) {
throw new IOException("Unexpected EOF");
}
n2 += n3;
}
inputStream.close();
ModuleClassLoader.addClassToSpy(this.module.name, string, byArray.length);
return this.defineClass(string, byArray, 0, byArray.length, this.codeSource);
}
catch (IOException iOException) {
iOException.printStackTrace();
return null;
}
}
break block18;
}
}
if (this.module.getTypeClassName(string.substring(string.lastIndexOf(46) + 2)) != null) {
ModuleClassLoader.addClassToSpy(this.module.name, string, this.buffer.count);
Class<?> clazz = this.defineClass(string, this.buffer.bytes, 0, this.buffer.count, this.codeSource);
try {
Class.forName(clazz.getName(), true, clazz.getClassLoader());
}
catch (ClassNotFoundException classNotFoundException) {}
return clazz;
}
}
if (this.module.depends != null) {
Class clazz;
NModule nModule;
int n = string.lastIndexOf(46);
String string3 = n == -1 ? "" : string.substring(0, n);
int n4 = 0;
while (n4 < this.module.depends.length) {
nModule = this.module.depends[n4].resolution;
if (!nModule.isSystemJar && nModule.containsPackage(string3) && (clazz = nModule.classLoader.nload(string, bl)) != null) {
return clazz;
}
++n4;
}
n4 = 0;
while (n4 < this.module.depends.length) {
nModule = this.module.depends[n4].resolution;
if (!nModule.isSystemJar && (clazz = nModule.classLoader.nload(string, bl)) != null) {
return clazz;
}
++n4;
}
}
return null;
}
public URL getResource(String string) {
URL uRL = this.getResourceImpl(string);
if (uRL != null) {
return uRL;
}
return ModuleClassLoader.getSystemResource(string);
}
private final URL getResourceImpl(String string) {
ArrayList arrayList = (ArrayList)this.extClassLoadersByResourcePath.get(string);
if (arrayList != null) {
return ((ModuleExtClassLoader)arrayList.get(0)).getResourceImpl(string);
}
JarEntry jarEntry = this.module.jarFile.getJarEntry(string);
if (jarEntry != null) {
return jarEntry.getURL();
}
if (this.module.depends != null) {
int n = 0;
while (n < this.module.depends.length) {
URL uRL;
NModule nModule = this.module.depends[n].resolution;
if (!nModule.isSystemJar && (uRL = nModule.classLoader.getResourceImpl(string)) != null) {
return uRL;
}
++n;
}
}
return null;
}
public InputStream getResourceAsStream(String string) {
try {
URL uRL = this.getResource(string);
if (uRL != null) {
URLConnection uRLConnection = uRL.openConnection();
uRLConnection.connect();
return uRLConnection.getInputStream();
}
}
catch (IOException iOException) {
iOException.printStackTrace();
}
return null;
}
protected Enumeration findResources(String string) throws IOException {
ArrayList arrayList = (ArrayList)this.extClassLoadersByResourcePath.get(string);
Vector<URL> vector = new Vector<URL>();
if (arrayList != null) {
Iterator iterator = arrayList.iterator();
while (iterator.hasNext()) {
vector.add(((ModuleExtClassLoader)iterator.next()).getResourceImpl(string));
}
return vector.elements();
}
URL uRL = this.getResourceImpl(string);
if (uRL != null) {
vector.add(uRL);
}
return vector.elements();
}
public PermissionCollection getPermissions(CodeSource codeSource) {
return this.permissions;
}
Class loadAutoClass(String string, Buffer buffer) throws ClassNotFoundException {
this.buffer = buffer;
Class<?> clazz = this.loadClass(string);
this.buffer = null;
return clazz;
}
protected static void addClassToSpy(String string, String string2, int n) {
int[] nArray = (int[])spyMap.get(string);
if (nArray == null) {
nArray = new int[2];
spyMap.put(string, nArray);
}
nArray[0] = nArray[0] + 1;
nArray[1] = nArray[1] + n;
}
public String toString() {
return this.getClass().getName() + " for " + this.module + " [" + Integer.toString(System.identityHashCode(this), 36) + ']';
}
public static void registerAsParallelCapableFix() {
try {
Method method;
Class clazz = class$java$lang$ClassLoader;
if (clazz == null) {
clazz = class$java$lang$ClassLoader = ModuleClassLoader.class("[Ljava.lang.ClassLoader;", false);
}
if ((method = clazz.getDeclaredMethod("registerAsParallelCapable", null)) != null) {
method.setAccessible(true);
Object object = method.invoke(null, null);
}
}
catch (Throwable throwable) {}
}
static /* synthetic */ Class class(String string, boolean bl) {
try {
Class<?> clazz = Class.forName(string);
if (!bl) {
clazz = clazz.getComponentType();
}
return clazz;
}
catch (ClassNotFoundException classNotFoundException) {
throw new NoClassDefFoundError(classNotFoundException.getMessage());
}
}
private final /* synthetic */ void this() {
this.cache = new Hashtable();
this.extClassLoadersByResourcePath = new Hashtable();
}
ModuleClassLoader(NModule nModule) {
super(nModule.getClass().getClassLoader());
this.this();
this.module = nModule;
URL uRL = null;
if (nModule.jarFile != null) {
uRL = nModule.jarFile.getFileURL();
}
this.codeSource = new CodeSource(uRL, null);
this.permissions = new Permissions();
this.permissions.add(new AllPermission());
if (nModule.extJars != null) {
int n = 0;
while (n < nModule.extJars.length) {
ModuleExtClassLoader moduleExtClassLoader = new ModuleExtClassLoader(this, nModule.extJars[n], this.codeSource);
Iterator iterator = nModule.extJars[n].resourcePaths.iterator();
while (iterator.hasNext()) {
String string = (String)iterator.next();
ArrayList<ModuleExtClassLoader> arrayList = (ArrayList<ModuleExtClassLoader>)this.extClassLoadersByResourcePath.get(string);
if (arrayList == null) {
arrayList = new ArrayList<ModuleExtClassLoader>();
this.extClassLoadersByResourcePath.put(string, arrayList);
}
arrayList.add(moduleExtClassLoader);
}
++n;
}
}
}
static {
if (parallelCapableClassLoader) {
ModuleClassLoader.registerAsParallelCapableFix();
}
NOT_FOUND = new Object();
spyMap = new HashMap();
}
public static class LoaderSpy
extends Spy {
private final void row(SpyWriter spyWriter, String string, int n, int n2) {
spyWriter.w("<tr>");
spyWriter.w("<td align='left' nowrap='true'>").w(string).w("</td>");
spyWriter.w("<td align='right' nowrap='true'>").w(DF.format(n)).w("</td>");
spyWriter.w("<td align='right' nowrap='true'>").w(DF.format(n2)).w("</td>");
spyWriter.w("</tr>\n");
}
private final void summary(SpyWriter spyWriter, String string, int n) {
spyWriter.w("<tr>");
spyWriter.w("<td align='left' nowrap='true'>").w(string).w("</td>");
spyWriter.w("<td align='right' nowrap='true'>").w(DF.format(n)).w("</td>");
spyWriter.w("</tr>\n");
}
public void write(SpyWriter spyWriter) throws Exception {
int n = 0;
int n2 = 0;
spyWriter.startTable(true);
spyWriter.w("<tr>");
spyWriter.thTitle("Class Loader");
spyWriter.thTitle("Classes");
spyWriter.thTitle("Bytes Loaded");
spyWriter.w("</tr>");
Iterator iterator = spyMap.keySet().iterator();
while (iterator.hasNext()) {
String string = (String)iterator.next();
int[] nArray = (int[])spyMap.get(string);
this.row(spyWriter, string, nArray[0], nArray[1]);
n += nArray[0];
n2 += nArray[1];
}
spyWriter.endTable();
spyWriter.w("<p/>");
spyWriter.startTable(true);
spyWriter.trTitle("Summary", 2);
this.summary(spyWriter, "Total Classes", n);
this.summary(spyWriter, "Total Bytes Loaded", n2);
spyWriter.endTable();
}
}
}