KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > dom > SecuritySupport


1 /*
2  * Copyright 2002-2004 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  * $Id: SecuritySupport.java,v 1.2 2004/02/23 10:29:36 aruny Exp $
18  */

19
20 package org.apache.xalan.xsltc.dom;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.FileNotFoundException JavaDoc;
25 import java.io.InputStream JavaDoc;
26
27 import java.util.Properties JavaDoc;
28
29 /**
30  * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
31  * It is package private and therefore is not exposed as part of the Xalan-Java
32  * API.
33  *
34  * Base class with security related methods that work on JDK 1.1.
35  */

36 class SecuritySupport {
37
38     /*
39      * Make this of type Object so that the verifier won't try to
40      * prove its type, thus possibly trying to load the SecuritySupport12
41      * class.
42      */

43     private static final Object JavaDoc securitySupport;
44
45     static {
46     SecuritySupport ss = null;
47     try {
48         Class JavaDoc c = Class.forName("java.security.AccessController");
49         // if that worked, we're on 1.2.
50
/*
51         // don't reference the class explicitly so it doesn't
52         // get dragged in accidentally.
53         c = Class.forName("javax.mail.SecuritySupport12");
54         Constructor cons = c.getConstructor(new Class[] { });
55         ss = (SecuritySupport)cons.newInstance(new Object[] { });
56         */

57         /*
58          * Unfortunately, we can't load the class using reflection
59          * because the class is package private. And the class has
60          * to be package private so the APIs aren't exposed to other
61          * code that could use them to circumvent security. Thus,
62          * we accept the risk that the direct reference might fail
63          * on some JDK 1.1 JVMs, even though we would never execute
64          * this code in such a case. Sigh...
65          */

66         ss = new SecuritySupport12();
67     } catch (Exception JavaDoc ex) {
68         // ignore it
69
} finally {
70         if (ss == null)
71         ss = new SecuritySupport();
72         securitySupport = ss;
73     }
74     }
75
76     /**
77      * Return an appropriate instance of this class, depending on whether
78      * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
79      */

80     static SecuritySupport getInstance() {
81     return (SecuritySupport)securitySupport;
82     }
83
84     ClassLoader JavaDoc getContextClassLoader() {
85     return null;
86     }
87
88     ClassLoader JavaDoc getSystemClassLoader() {
89         return null;
90     }
91
92     ClassLoader JavaDoc getParentClassLoader(ClassLoader JavaDoc cl) {
93         return null;
94     }
95
96     String JavaDoc getSystemProperty(String JavaDoc propName) {
97         return System.getProperty(propName);
98     }
99
100     FileInputStream JavaDoc getFileInputStream(File JavaDoc file)
101         throws FileNotFoundException JavaDoc
102     {
103         return new FileInputStream JavaDoc(file);
104     }
105
106     InputStream JavaDoc getResourceAsStream(ClassLoader JavaDoc cl, String JavaDoc name) {
107         InputStream JavaDoc ris;
108         if (cl == null) {
109             ris = ClassLoader.getSystemResourceAsStream(name);
110         } else {
111             ris = cl.getResourceAsStream(name);
112         }
113         return ris;
114     }
115     
116     boolean getFileExists(File JavaDoc f) {
117         return f.exists();
118     }
119     
120     long getLastModified(File JavaDoc f) {
121         return f.lastModified();
122     }
123 }
124
Popular Tags