org.eclipse.osgi.framework.util
Class SecureAction

java.lang.Object
  extended by org.eclipse.osgi.framework.util.SecureAction

public class SecureAction
extends java.lang.Object

Utility class to execute common privileged code.

Since:
3.1

Method Summary
static java.security.PrivilegedAction createSecureAction()
          Creates a privileged action that can be used to construct a SecureAction object.
 java.lang.Thread createThread(java.lang.Runnable target, java.lang.String name)
          Creates a new Thread from a Runnable.
 boolean exists(java.io.File file)
          Returns true if a file exists, otherwise false is returned.
 java.lang.Class forName(java.lang.String name)
          Returns a Class.
 java.io.FileInputStream getFileInputStream(java.io.File file)
          Creates a FileInputStream from a File.
 java.io.FileOutputStream getFileOutputStream(java.io.File file, boolean append)
          Creates a FileInputStream from a File.
 java.util.Properties getProperties()
          Returns the system properties.
 java.lang.String getProperty(java.lang.String property)
          Returns a system property.
 java.lang.String getProperty(java.lang.String property, java.lang.String def)
          Returns a system property.
 java.lang.Object getService(ServiceReference reference, BundleContext context)
          Gets a service object.
 java.net.URL getURL(java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.net.URLStreamHandler handler)
          Gets a URL.
 java.util.zip.ZipFile getZipFile(java.io.File file)
          Returns a ZipFile.
 boolean isDirectory(java.io.File file)
          Returns true if a file is a directory, otherwise false is returned.
 long lastModified(java.io.File file)
          Returns a file's last modified stamp.
 long length(java.io.File file)
          Returns the length of a file.
 java.lang.String[] list(java.io.File file)
          Returns a file's list.
 java.lang.Class loadSystemClass(java.lang.String name)
          Returns a Class.
 void open(ServiceTracker tracker)
          Opens a ServiceTracker.
 void start(Bundle bundle)
          Starts a bundle
 void start(Bundle bundle, int options)
          Starts a bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createSecureAction

public static java.security.PrivilegedAction createSecureAction()
Creates a privileged action that can be used to construct a SecureAction object. The recommended way to construct a SecureAction object is the following:

 SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction());
 

Returns:
a privileged action object that can be used to construct a SecureAction object.

getProperty

public java.lang.String getProperty(java.lang.String property)
Returns a system property. Same as calling System.getProperty(String).

Parameters:
property - the property key.
Returns:
the value of the property or null if it does not exist.

getProperty

public java.lang.String getProperty(java.lang.String property,
                                    java.lang.String def)
Returns a system property. Same as calling System.getProperty(String,String).

Parameters:
property - the property key.
def - the default value if the property key does not exist.
Returns:
the value of the property or the def value if the property does not exist.

getProperties

public java.util.Properties getProperties()
Returns the system properties. Same as calling System.getProperties().

Returns:
the system properties.

getFileInputStream

public java.io.FileInputStream getFileInputStream(java.io.File file)
                                           throws java.io.FileNotFoundException
Creates a FileInputStream from a File. Same as calling new FileInputStream(File).

Parameters:
file - the File to craete a FileInputStream from.
Returns:
The FileInputStream.
Throws:
java.io.FileNotFoundException - if the File does not exist.

getFileOutputStream

public java.io.FileOutputStream getFileOutputStream(java.io.File file,
                                                    boolean append)
                                             throws java.io.FileNotFoundException
Creates a FileInputStream from a File. Same as calling new FileOutputStream(File,boolean).

Parameters:
file - the File to create a FileOutputStream from.
append - indicates if the OutputStream should append content.
Returns:
The FileOutputStream.
Throws:
java.io.FileNotFoundException - if the File does not exist.

length

public long length(java.io.File file)
Returns the length of a file. Same as calling file.length().

Parameters:
file - a file object
Returns:
the length of a file.

exists

public boolean exists(java.io.File file)
Returns true if a file exists, otherwise false is returned. Same as calling file.exists().

Parameters:
file - a file object
Returns:
true if a file exists, otherwise false

isDirectory

public boolean isDirectory(java.io.File file)
Returns true if a file is a directory, otherwise false is returned. Same as calling file.isDirectory().

Parameters:
file - a file object
Returns:
true if a file is a directory, otherwise false

lastModified

public long lastModified(java.io.File file)
Returns a file's last modified stamp. Same as calling file.lastModified().

Parameters:
file - a file object
Returns:
a file's last modified stamp.

list

public java.lang.String[] list(java.io.File file)
Returns a file's list. Same as calling file.list().

Parameters:
file - a file object
Returns:
a file's list.

getZipFile

public java.util.zip.ZipFile getZipFile(java.io.File file)
                                 throws java.io.IOException
Returns a ZipFile. Same as calling new ZipFile(file)

Parameters:
file - the file to get a ZipFile for
Returns:
a ZipFile
Throws:
java.io.IOException - if an error occured

getURL

public java.net.URL getURL(java.lang.String protocol,
                           java.lang.String host,
                           int port,
                           java.lang.String file,
                           java.net.URLStreamHandler handler)
                    throws java.net.MalformedURLException
Gets a URL. Same a calling URL.URL(java.lang.String, java.lang.String, int, java.lang.String, java.net.URLStreamHandler)

Parameters:
protocol - the protocol
host - the host
port - the port
file - the file
handler - the URLStreamHandler
Returns:
a URL
Throws:
java.net.MalformedURLException

createThread

public java.lang.Thread createThread(java.lang.Runnable target,
                                     java.lang.String name)
Creates a new Thread from a Runnable. Same as calling new Thread(target,name).

Parameters:
target - the Runnable to create the Thread from.
name - The name of the Thread.
Returns:
The new Thread

getService

public java.lang.Object getService(ServiceReference reference,
                                   BundleContext context)
Gets a service object. Same as calling context.getService(reference)

Parameters:
reference - the ServiceReference
context - the BundleContext
Returns:
a service object

forName

public java.lang.Class forName(java.lang.String name)
                        throws java.lang.ClassNotFoundException
Returns a Class. Same as calling Class.forName(name)

Parameters:
name - the name of the class.
Returns:
a Class
Throws:
java.lang.ClassNotFoundException

loadSystemClass

public java.lang.Class loadSystemClass(java.lang.String name)
                                throws java.lang.ClassNotFoundException
Returns a Class. Tries to load a class from the System ClassLoader or if that doesn't exist tries the boot ClassLoader

Parameters:
name - the name of the class.
Returns:
a Class
Throws:
java.lang.ClassNotFoundException

open

public void open(ServiceTracker tracker)
Opens a ServiceTracker. Same as calling tracker.open()

Parameters:
tracker - the ServiceTracker to open.

start

public void start(Bundle bundle,
                  int options)
           throws BundleException
Starts a bundle.

Parameters:
bundle - the bundle to start
options - the start options
Throws:
BundleException

start

public void start(Bundle bundle)
           throws BundleException
Starts a bundle

Parameters:
bundle -
Throws:
BundleException