KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > datatype > SecuritySupport


1 /*
2  * @(#)SecuritySupport.java 1.3 05/01/04
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.xml.datatype;
9
10 import java.security.*;
11 import java.net.*;
12 import java.io.*;
13 import java.util.*;
14
15 /**
16  * This class is duplicated for each JAXP subpackage so keep it in sync.
17  * It is package private and therefore is not exposed as part of the JAXP
18  * API.
19  *
20  * Security related methods that only work on J2SE 1.2 and newer.
21  */

22 class SecuritySupport {
23
24     
25     ClassLoader JavaDoc getContextClassLoader() {
26     return (ClassLoader JavaDoc)
27         AccessController.doPrivileged(new PrivilegedAction() {
28         public Object JavaDoc run() {
29         ClassLoader JavaDoc cl = null;
30         try {
31             cl = Thread.currentThread().getContextClassLoader();
32         } catch (SecurityException JavaDoc ex) { }
33         return cl;
34         }
35     });
36     }
37
38     String JavaDoc getSystemProperty(final String JavaDoc propName) {
39     return (String JavaDoc)
40             AccessController.doPrivileged(new PrivilegedAction() {
41                 public Object JavaDoc run() {
42                     return System.getProperty(propName);
43                 }
44             });
45     }
46
47     FileInputStream getFileInputStream(final File file)
48         throws FileNotFoundException
49     {
50     try {
51             return (FileInputStream)
52                 AccessController.doPrivileged(new PrivilegedExceptionAction() {
53                     public Object JavaDoc run() throws FileNotFoundException {
54                         return new FileInputStream(file);
55                     }
56                 });
57     } catch (PrivilegedActionException e) {
58         throw (FileNotFoundException)e.getException();
59     }
60     }
61
62     InputStream getResourceAsStream(final ClassLoader JavaDoc cl,
63                                            final String JavaDoc name)
64     {
65         return (InputStream)
66             AccessController.doPrivileged(new PrivilegedAction() {
67                 public Object JavaDoc run() {
68                     InputStream ris;
69                     if (cl == null) {
70                         ris = ClassLoader.getSystemResourceAsStream(name);
71                     } else {
72                         ris = cl.getResourceAsStream(name);
73                     }
74                     return ris;
75                 }
76             });
77     }
78
79     boolean doesFileExist(final File f) {
80     return ((Boolean JavaDoc)
81             AccessController.doPrivileged(new PrivilegedAction() {
82                 public Object JavaDoc run() {
83                     return new Boolean JavaDoc(f.exists());
84                 }
85             })).booleanValue();
86     }
87
88 }
89
Popular Tags