1 55 56 package com.sun.org.apache.xml.internal.serialize; 57 58 import java.security.*; 59 import java.io.*; 60 61 68 class SecuritySupport12 extends SecuritySupport { 69 70 ClassLoader getContextClassLoader() { 71 return (ClassLoader ) 72 AccessController.doPrivileged(new PrivilegedAction() { 73 public Object run() { 74 ClassLoader cl = null; 75 try { 76 cl = Thread.currentThread().getContextClassLoader(); 77 } catch (SecurityException ex) { } 78 return cl; 79 } 80 }); 81 } 82 83 ClassLoader getSystemClassLoader() { 84 return (ClassLoader ) 85 AccessController.doPrivileged(new PrivilegedAction() { 86 public Object run() { 87 ClassLoader cl = null; 88 try { 89 cl = ClassLoader.getSystemClassLoader(); 90 } catch (SecurityException ex) {} 91 return cl; 92 } 93 }); 94 } 95 96 ClassLoader getParentClassLoader(final ClassLoader cl) { 97 return (ClassLoader ) 98 AccessController.doPrivileged(new PrivilegedAction() { 99 public Object run() { 100 ClassLoader parent = null; 101 try { 102 parent = cl.getParent(); 103 } catch (SecurityException ex) {} 104 105 return (parent == cl) ? null : parent; 108 } 109 }); 110 } 111 112 String getSystemProperty(final String propName) { 113 return (String ) 114 AccessController.doPrivileged(new PrivilegedAction() { 115 public Object run() { 116 return System.getProperty(propName); 117 } 118 }); 119 } 120 121 FileInputStream getFileInputStream(final File file) 122 throws FileNotFoundException 123 { 124 try { 125 return (FileInputStream) 126 AccessController.doPrivileged(new PrivilegedExceptionAction() { 127 public Object run() throws FileNotFoundException { 128 return new FileInputStream(file); 129 } 130 }); 131 } catch (PrivilegedActionException e) { 132 throw (FileNotFoundException)e.getException(); 133 } 134 } 135 136 InputStream getResourceAsStream(final ClassLoader cl, 137 final String name) 138 { 139 return (InputStream) 140 AccessController.doPrivileged(new PrivilegedAction() { 141 public Object run() { 142 InputStream ris; 143 if (cl == null) { 144 ris = ClassLoader.getSystemResourceAsStream(name); 145 } else { 146 ris = cl.getResourceAsStream(name); 147 } 148 return ris; 149 } 150 }); 151 } 152 153 boolean getFileExists(final File f) { 154 return ((Boolean ) 155 AccessController.doPrivileged(new PrivilegedAction() { 156 public Object run() { 157 return new Boolean (f.exists()); 158 } 159 })).booleanValue(); 160 } 161 162 long getLastModified(final File f) { 163 return ((Long ) 164 AccessController.doPrivileged(new PrivilegedAction() { 165 public Object run() { 166 return new Long (f.lastModified()); 167 } 168 })).longValue(); 169 } 170 171 } 172 | Popular Tags |