Home » xml-commons-external-1.4.01-src » javax » xml » datatype » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   // $Id: SecuritySupport.java 446598 2006-09-15 12:55:40Z jeremias $
   19   
   20   package javax.xml.datatype;
   21   
   22   import java.io.File;
   23   import java.io.FileInputStream;
   24   import java.io.FileNotFoundException;
   25   import java.io.InputStream;
   26   import java.security.AccessController;
   27   import java.security.PrivilegedAction;
   28   import java.security.PrivilegedActionException;
   29   import java.security.PrivilegedExceptionAction;
   30   
   31   /**
   32    * This class is duplicated for each JAXP subpackage so keep it in sync.
   33    * It is package private and therefore is not exposed as part of the JAXP
   34    * API.
   35    *
   36    * Security related methods that only work on J2SE 1.2 and newer.
   37    */
   38   final class SecuritySupport  {
   39       
   40       private SecuritySupport() {}
   41       
   42       static ClassLoader getContextClassLoader() {
   43   	return (ClassLoader)
   44   		AccessController.doPrivileged(new PrivilegedAction() {
   45   	    public Object run() {
   46   		ClassLoader cl = null;
   47   		try {
   48   		    cl = Thread.currentThread().getContextClassLoader();
   49   		} catch (SecurityException ex) { }
   50   		return cl;
   51   	    }
   52   	});
   53       }
   54   
   55       static String getSystemProperty(final String propName) {
   56   	return (String)
   57               AccessController.doPrivileged(new PrivilegedAction() {
   58                   public Object run() {
   59                       return System.getProperty(propName);
   60                   }
   61               });
   62       }
   63   
   64       static FileInputStream getFileInputStream(final File file)
   65           throws FileNotFoundException
   66       {
   67   	try {
   68               return (FileInputStream)
   69                   AccessController.doPrivileged(new PrivilegedExceptionAction() {
   70                       public Object run() throws FileNotFoundException {
   71                           return new FileInputStream(file);
   72                       }
   73                   });
   74   	} catch (PrivilegedActionException e) {
   75   	    throw (FileNotFoundException)e.getException();
   76   	}
   77       }
   78   
   79       static InputStream getResourceAsStream(final ClassLoader cl,
   80                                              final String name)
   81       {
   82           return (InputStream)
   83               AccessController.doPrivileged(new PrivilegedAction() {
   84                   public Object run() {
   85                       InputStream ris;
   86                       if (cl == null) {
   87                           ris = ClassLoader.getSystemResourceAsStream(name);
   88                       } else {
   89                           ris = cl.getResourceAsStream(name);
   90                       }
   91                       return ris;
   92                   }
   93               });
   94       }
   95   
   96       static boolean doesFileExist(final File f) {
   97       return ((Boolean)
   98               AccessController.doPrivileged(new PrivilegedAction() {
   99                   public Object run() {
  100                       return f.exists() ? Boolean.TRUE : Boolean.FALSE;
  101                   }
  102               })).booleanValue();
  103       }
  104   
  105   }

Home » xml-commons-external-1.4.01-src » javax » xml » datatype » [javadoc | source]