Package com.apple.misc

Source Code of com.apple.misc.StandardClassLoader

/*     */ package com.apple.misc;
/*     */
/*     */ import com.apple.util.PathResourceLocator;
/*     */ import com.apple.util.ResourceLocator;
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.io.Serializable;
/*     */ import java.net.URL;
/*     */ import java.util.Hashtable;
/*     */ import java.util.Properties;
/*     */
/*     */ public class StandardClassLoader extends ClassLoader
/*     */   implements Serializable
/*     */ {
/*  35 */   private static int _debuglvl = 0;
/*     */
/*  46 */   protected static boolean _lisf = true;
/*     */
/* 114 */   protected Hashtable _hash = new Hashtable();
/*     */
/* 122 */   protected ResourceLocator _locator = null;
/*     */
/*     */   static void setLookInSystemFirst(boolean paramBoolean)
/*     */   {
/* 100 */     if (_debuglvl >= 1) {
/* 101 */       System.err.println("StandardClassLoader: debug: " + (paramBoolean ? "" : "don't ") + "look in system first");
/*     */     }
/* 103 */     _lisf = paramBoolean;
/*     */   }
/*     */
/*     */   public StandardClassLoader()
/*     */   {
/* 134 */     setResourceLocator(new PathResourceLocator());
/*     */   }
/*     */
/*     */   public StandardClassLoader(ResourceLocator paramResourceLocator)
/*     */   {
/* 145 */     setResourceLocator(paramResourceLocator);
/*     */   }
/*     */
/*     */   public void setResourceLocator(ResourceLocator paramResourceLocator)
/*     */   {
/* 155 */     this._locator = paramResourceLocator;
/*     */   }
/*     */
/*     */   public ResourceLocator getResourceLocator()
/*     */   {
/* 164 */     return this._locator;
/*     */   }
/*     */
/*     */   public URL getResource(String paramString)
/*     */   {
/* 176 */     URL localURL = null;
/*     */
/* 182 */     if (_lisf) {
/* 183 */       localURL = getSystemResource(paramString);
/* 184 */       if (localURL != null) {
/* 185 */         return localURL;
/*     */       }
/*     */     }
/*     */
/* 189 */     localURL = this._locator.getResource(paramString);
/* 190 */     if (localURL != null) {
/* 191 */       return localURL;
/*     */     }
/*     */
/* 194 */     if (!_lisf) {
/* 195 */       localURL = getSystemResource(paramString);
/*     */     }
/*     */
/* 198 */     return localURL;
/*     */   }
/*     */
/*     */   public InputStream getResourceAsStream(String paramString)
/*     */   {
/* 217 */     InputStream localInputStream = null;
/*     */
/* 223 */     if (_lisf) {
/* 224 */       localInputStream = getSystemResourceAsStream(paramString);
/* 225 */       if (localInputStream != null) {
/* 226 */         return localInputStream;
/*     */       }
/*     */     }
/*     */
/* 230 */     localInputStream = this._locator.getResourceAsStream(paramString);
/* 231 */     if (localInputStream != null) {
/* 232 */       return localInputStream;
/*     */     }
/*     */
/* 235 */     if (!_lisf) {
/* 236 */       localInputStream = getSystemResourceAsStream(paramString);
/*     */     }
/*     */
/* 239 */     return localInputStream;
/*     */   }
/*     */
/*     */   private byte[] getClassImplementation(String paramString)
/*     */   {
/* 251 */     String str = paramString.replace('.', '/') + ".class";
/*     */
/* 253 */     InputStream localInputStream = getResourceAsStream(str);
/*     */
/* 255 */     if (_debuglvl >= 1) {
/* 256 */       System.err.println(this + ": debug: getClassImplementation(" + paramString + "), looking for " + str + ", got stream " + localInputStream);
/*     */     }
/*     */
/* 259 */     byte[] arrayOfByte = getClassImplementation(localInputStream);
/*     */
/* 261 */     if (localInputStream != null) try {
/* 262 */         localInputStream.close();
/*     */       }
/*     */       catch (IOException localIOException)
/*     */       {
/*     */       } return arrayOfByte;
/*     */   }
/*     */
/*     */   protected byte[] getClassImplementation(InputStream paramInputStream)
/*     */   {
/* 278 */     if (paramInputStream != null) {
/* 279 */       if (_debuglvl >= 1) {
/* 280 */         System.err.println(this + ": debug: getClassImplementation(" + paramInputStream + ")");
/*     */       }
/*     */
/* 283 */       int i = 0;
/* 284 */       Object localObject = new byte[1024];
/*     */       try
/*     */       {
/*     */         int j;
/* 289 */         i = j = paramInputStream.read((byte[])localObject);
/*     */
/* 297 */         byte[] arrayOfByte2 = new byte[4096];
/*     */
/* 299 */         while ((j = paramInputStream.read(arrayOfByte2)) > 0) {
/* 300 */           if (i + j > localObject.length) {
/* 301 */             byte[] arrayOfByte3 = new byte[i + j];
/*     */
/* 303 */             System.arraycopy(localObject, 0, arrayOfByte3, 0, i);
/* 304 */             localObject = arrayOfByte3;
/*     */           }
/*     */
/* 307 */           System.arraycopy(arrayOfByte2, 0, localObject, i, j);
/*     */
/* 309 */           i += j;
/*     */         }
/*     */       } catch (IOException localIOException) {
/* 312 */         if (_debuglvl >= 1) {
/* 313 */           System.err.println(this + ": debug: class implementation cannot be read: " + localIOException);
/* 314 */           localIOException.printStackTrace(System.err);
/*     */         }
/*     */
/* 317 */         localObject = null;
/*     */       }
/*     */
/* 320 */       if (localObject != null) {
/* 321 */         if (i < localObject.length) {
/* 322 */           byte[] arrayOfByte1 = new byte[i];
/* 323 */           System.arraycopy(localObject, 0, arrayOfByte1, 0, i);
/*     */
/* 325 */           localObject = arrayOfByte1;
/*     */         }
/*     */
/* 328 */         if (_debuglvl >= 1) {
/* 329 */           System.err.println(this + ": debug: class implementation is " + localObject.length + " byte" + (localObject.length != 1 ? "s" : "") + " long");
/*     */         }
/*     */       }
/*     */
/* 333 */       return localObject;
/*     */     }
/*     */
/* 336 */     return null;
/*     */   }
/*     */
/*     */   public Class loadClass(String paramString)
/*     */     throws ClassNotFoundException
/*     */   {
/* 347 */     return loadClass(paramString, true);
/*     */   }
/*     */
/*     */   public synchronized Class loadClass(String paramString, boolean paramBoolean)
/*     */     throws ClassNotFoundException
/*     */   {
/* 367 */     Class localClass1 = null;
/* 368 */     byte[] arrayOfByte = null;
/*     */
/* 374 */     paramString = paramString.replace('/', '.');
/*     */
/* 376 */     if (_debuglvl >= 1) {
/* 377 */       System.err.println(this + ": debug: request to load " + paramString + " and " + (paramBoolean ? "" : "not ") + "resolve it");
/*     */     }
/*     */
/* 383 */     checkSecurity(paramString, false);
/*     */
/* 388 */     localClass1 = findLoadedClass(paramString);
/* 389 */     if (localClass1 != null) {
/* 390 */       if (_debuglvl >= 2) {
/* 391 */         System.err.println(this + ": debug: found class " + paramString + " in loaded classes");
/*     */       }
/* 393 */       return localClass1;
/*     */     }
/*     */
/* 399 */     if (_lisf) {
/*     */       try {
/* 401 */         Class localClass2 = findSystemClass(paramString);
/* 402 */         if (_debuglvl >= 1) {
/* 403 */           System.err.println(this + ": debug: found class " + paramString + " in system classes");
/*     */         }
/* 405 */         return localClass2;
/*     */       }
/*     */       catch (ClassNotFoundException localClassNotFoundException1)
/*     */       {
/*     */       }
/*     */
/*     */     }
/*     */
/* 415 */     checkSecurity(paramString, true);
/*     */
/* 419 */     arrayOfByte = getClassImplementation(paramString);
/*     */
/* 421 */     if ((arrayOfByte == null) || (arrayOfByte.length == 0))
/*     */     {
/* 427 */       if (!_lisf)
/*     */         try {
/* 429 */           Class localClass3 = findSystemClass(paramString);
/* 430 */           if (_debuglvl >= 2) {
/* 431 */             System.err.println(this + ": debug: found class " + paramString + " in system classes");
/*     */           }
/* 433 */           return localClass3;
/*     */         }
/*     */         catch (ClassNotFoundException localClassNotFoundException2)
/*     */         {
/*     */         }
/* 438 */       if (_debuglvl >= 2) {
/* 439 */         System.err.println(this + ": debug: cannot find class " + paramString + ", raising");
/*     */       }
/*     */
/* 442 */       throw new ClassNotFoundException(paramString);
/*     */     }
/*     */
/* 447 */     localClass1 = defineClass(paramString, arrayOfByte, 0, arrayOfByte.length);
/* 448 */     if (localClass1 == null) {
/* 449 */       throw new ClassFormatError(paramString);
/*     */     }
/*     */
/* 455 */     String str = paramString.replace('.', '/') + ".class";
/*     */
/* 457 */     if (_debuglvl >= 3)
/* 458 */       System.err.println(this + ": debug: entering class " + getResource(str) + " (" + localClass1 + ") for name " + paramString + " into classes cache");
/*     */     try
/*     */     {
/* 461 */       this._hash.put(getResource(str).toString(), localClass1);
/*     */     } catch (Exception localException) {
/* 463 */       if (_debuglvl >= 1) {
/* 464 */         System.err.println(this + ": couldn't enter class " + getResource(str) + " (" + localClass1 + ") for name " + paramString + " into classes cache");
/*     */       }
/*     */
/*     */     }
/*     */
/* 471 */     if (paramBoolean) {
/* 472 */       if (_debuglvl >= 3) {
/* 473 */         System.err.println(this + ": debug: resolving " + localClass1);
/*     */       }
/* 475 */       resolveClass(localClass1);
/*     */     }
/*     */
/* 480 */     return localClass1;
/*     */   }
/*     */
/*     */   protected void checkSecurity(String paramString, boolean paramBoolean)
/*     */   {
/* 501 */     SecurityManager localSecurityManager = System.getSecurityManager();
/*     */
/* 503 */     if (localSecurityManager != null) {
/* 504 */       int i = paramString.lastIndexOf('.');
/* 505 */       if (i >= 0)
/* 506 */         if (paramBoolean)
/* 507 */           localSecurityManager.checkPackageDefinition(paramString.substring(0, i));
/*     */         else
/* 509 */           localSecurityManager.checkPackageAccess(paramString.substring(0, i));
/*     */     }
/*     */   }
/*     */
/*     */   static
/*     */   {
/*     */     try
/*     */     {
/*  50 */       Properties localProperties = new Properties();
/*     */       try
/*     */       {
/*  53 */         localProperties.load(new FileInputStream(new File(System.getProperty("java.home"), "lib" + File.separator + "javastuff.properties")));
/*     */       } catch (IOException localIOException1) {
/*     */       }
/*     */       try {
/*  57 */         localProperties.load(new FileInputStream(new File(System.getProperty("user.home"), "lib" + File.separator + "javastuff.properties")));
/*     */       }
/*     */       catch (IOException localIOException2) {
/*     */       }
/*     */       try {
/*  62 */         String str1 = localProperties.getProperty("logfile", "");
/*     */
/*  64 */         if (!str1.equals("")) {
/*  65 */           str1 = str1.replace('/', File.separatorChar);
/*     */
/*  67 */           File localFile1 = new File(str1);
/*     */
/*  69 */           if (!localFile1.isAbsolute()) {
/*  70 */             localFile1 = new File(System.getProperty("user.home"), localFile1.toString());
/*     */           }
/*     */
/*  73 */           File localFile2 = new File(localFile1.getParent());
/*  74 */           if (!localFile2.exists()) {
/*  75 */             localFile2.mkdirs();
/*     */           }
/*     */
/*  78 */           FileOutputStream localFileOutputStream = new FileOutputStream(localFile1);
/*     */
/*  80 */           System.setErr(new PrintStream(localFileOutputStream));
/*     */         }
/*     */       } catch (Exception localException2) {
/*     */       }
/*     */       try {
/*  85 */         String str2 = localProperties.getProperty("standardclassloader.debug", "0");
/*  86 */         _debuglvl = Integer.valueOf(str2).intValue();
/*     */       }
/*     */       catch (Exception localException3) {
/*     */       }
/*     */       try {
/*  91 */         String str3 = localProperties.getProperty("standardclassloader.lisf", "true");
/*  92 */         _lisf = Boolean.valueOf(str3).booleanValue();
/*     */       }
/*     */       catch (Exception localException4)
/*     */       {
/*     */       }
/*     */     }
/*     */     catch (Exception localException1)
/*     */     {
/*     */     }
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\
* Qualified Name:     com.apple.misc.StandardClassLoader
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.apple.misc.StandardClassLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.