KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > xinclude > SecuritySupport


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The name "Apache Software Foundation" must not be used to endorse or
28  * promote products derived from this software without prior written
29  * permission. For written permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  * nor may "Apache" appear in their name, without prior written
33  * permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation and was
51  * originally based on software copyright (c) 1999-2002, Sun Microsystems,
52  * Inc., http://www.sun.com. For more information on the Apache Software
53  * Foundation, please see <http://www.apache.org/>.
54  */

55
56 package com.sun.org.apache.xerces.internal.xinclude;
57
58 import java.io.*;
59
60 /**
61  * This class is duplicated for each JAXP subpackage so keep it in sync.
62  * It is package private and therefore is not exposed as part of the JAXP
63  * API.
64  *
65  * Base class with security related methods that work on JDK 1.1.
66  */

67 class SecuritySupport {
68
69     /*
70      * Make this of type Object so that the verifier won't try to
71      * prove its type, thus possibly trying to load the SecuritySupport12
72      * class.
73      */

74     private static final Object JavaDoc securitySupport;
75
76     static {
77     SecuritySupport ss = null;
78     try {
79         Class JavaDoc c = Class.forName("java.security.AccessController");
80         // if that worked, we're on 1.2.
81
/*
82         // don't reference the class explicitly so it doesn't
83         // get dragged in accidentally.
84         c = Class.forName("javax.mail.SecuritySupport12");
85         Constructor cons = c.getConstructor(new Class[] { });
86         ss = (SecuritySupport)cons.newInstance(new Object[] { });
87         */

88         /*
89          * Unfortunately, we can't load the class using reflection
90          * because the class is package private. And the class has
91          * to be package private so the APIs aren't exposed to other
92          * code that could use them to circumvent security. Thus,
93          * we accept the risk that the direct reference might fail
94          * on some JDK 1.1 JVMs, even though we would never execute
95          * this code in such a case. Sigh...
96          */

97         ss = new SecuritySupport12();
98     } catch (Exception JavaDoc ex) {
99         // ignore it
100
} finally {
101         if (ss == null)
102         ss = new SecuritySupport();
103         securitySupport = ss;
104     }
105     }
106
107     /**
108      * Return an appropriate instance of this class, depending on whether
109      * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
110      */

111     static SecuritySupport getInstance() {
112     return (SecuritySupport)securitySupport;
113     }
114
115     ClassLoader JavaDoc getContextClassLoader() {
116     return null;
117     }
118
119     ClassLoader JavaDoc getSystemClassLoader() {
120         return null;
121     }
122
123     ClassLoader JavaDoc getParentClassLoader(ClassLoader JavaDoc cl) {
124         return null;
125     }
126
127     String JavaDoc getSystemProperty(String JavaDoc propName) {
128         return System.getProperty(propName);
129     }
130
131     FileInputStream getFileInputStream(File file)
132         throws FileNotFoundException
133     {
134         return new FileInputStream(file);
135     }
136
137     InputStream getResourceAsStream(ClassLoader JavaDoc cl, String JavaDoc name) {
138         InputStream ris;
139         if (cl == null) {
140             ris = ClassLoader.getSystemResourceAsStream(name);
141         } else {
142             ris = cl.getResourceAsStream(name);
143         }
144         return ris;
145     }
146
147     boolean getFileExists(File f) {
148         return f.exists();
149     }
150
151     long getLastModified(File f) {
152         return f.lastModified();
153     }
154 }
155
Popular Tags