KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xml > sax > helpers > SecuritySupport


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.xml.sax.helpers;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileNotFoundException JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 /**
25  * This class is duplicated for each JAXP subpackage so keep it in sync.
26  * It is package private and therefore is not exposed as part of the JAXP
27  * API.
28  *
29  * Base class with security related methods that work on JDK 1.1.
30  */

31 class SecuritySupport {
32
33     /*
34      * Make this of type Object so that the verifier won't try to
35      * prove its type, thus possibly trying to load the SecuritySupport12
36      * class.
37      */

38     private static final Object JavaDoc securitySupport;
39
40     static {
41     SecuritySupport JavaDoc ss = null;
42     try {
43         Class JavaDoc c = Class.forName("java.security.AccessController");
44         // if that worked, we're on 1.2.
45
/*
46          * Unfortunately, we can't load the class using reflection
47          * because the class is package private. And the class has
48          * to be package private so the APIs aren't exposed to other
49          * code that could use them to circumvent security. Thus,
50          * we accept the risk that the direct reference might fail
51          * on some JDK 1.1 JVMs, even though we would never execute
52          * this code in such a case. Sigh...
53          */

54         ss = new SecuritySupport12 JavaDoc();
55     } catch (Exception JavaDoc ex) {
56         // ignore it
57
} finally {
58         if (ss == null)
59         ss = new SecuritySupport JavaDoc();
60         securitySupport = ss;
61     }
62     }
63
64     /**
65      * Return an appropriate instance of this class, depending on whether
66      * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
67      */

68     public static SecuritySupport JavaDoc getInstance() {
69     return (SecuritySupport JavaDoc)securitySupport;
70     }
71
72     public ClassLoader JavaDoc getContextClassLoader() {
73     return null;
74     }
75
76     public String JavaDoc getSystemProperty(String JavaDoc propName) {
77         return System.getProperty(propName);
78     }
79
80     public FileInputStream JavaDoc getFileInputStream(File JavaDoc file)
81         throws FileNotFoundException JavaDoc
82     {
83         return new FileInputStream JavaDoc(file);
84     }
85
86     public InputStream JavaDoc getResourceAsStream(ClassLoader JavaDoc cl, String JavaDoc name) {
87         InputStream JavaDoc ris;
88         if (cl == null) {
89             ris = ClassLoader.getSystemResourceAsStream(name);
90         } else {
91             ris = cl.getResourceAsStream(name);
92         }
93         return ris;
94     }
95 }
96
Popular Tags