org.eclipse.osgi.framework.util
Class SecureAction

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

public class SecureAction
extends Object

Utility class to execute common privileged code.

Since:
3.1

Method Summary
static PrivilegedAction<SecureAction> createSecureAction()
          Creates a privileged action that can be used to construct a SecureAction object.
 Thread createThread(Runnable target, String name, ClassLoader contextLoader)
          Creates a new Thread from a Runnable.
 boolean exists(File file)
          Returns true if a file exists, otherwise false is returned.
 Class<?> forName(String name)
          Returns a Class.
 String getCanonicalPath(File file)
          Returns the canonical path of a file.
 FileInputStream getFileInputStream(File file)
          Creates a FileInputStream from a File.
 FileOutputStream getFileOutputStream(File file, boolean append)
          Creates a FileInputStream from a File.
 Properties getProperties()
          Returns the system properties.
 String getProperty(String property)
          Returns a system property.
 String getProperty(String property, String def)
          Returns a system property.
<S> S
getService(ServiceReference<S> reference, BundleContext context)
          Gets a service object.
 URL getURL(String protocol, String host, int port, String file, URLStreamHandler handler)
          Gets a URL.
 ZipFile getZipFile(File file)
          Returns a ZipFile.
 boolean isDirectory(File file)
          Returns true if a file is a directory, otherwise false is returned.
 long lastModified(File file)
          Returns a file's last modified stamp.
 long length(File file)
          Returns the length of a file.
 String[] list(File file)
          Returns a file's list.
 Class<?> loadSystemClass(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 PrivilegedAction<SecureAction> 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 String getProperty(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 String getProperty(String property,
                          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 Properties getProperties()
Returns the system properties. Same as calling System.getProperties().

Returns:
the system properties.

getFileInputStream

public FileInputStream getFileInputStream(File file)
                                   throws 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:
FileNotFoundException - if the File does not exist.

getFileOutputStream

public FileOutputStream getFileOutputStream(File file,
                                            boolean append)
                                     throws 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:
FileNotFoundException - if the File does not exist.

length

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

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

getCanonicalPath

public String getCanonicalPath(File file)
                        throws IOException
Returns the canonical path of a file. Same as calling file.getCanonicalPath().

Parameters:
file - a file object
Returns:
the canonical path of a file.
Throws:
IOException - on error

exists

public boolean exists(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(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(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 String[] list(File file)
Returns a file's list. Same as calling file.list().

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

getZipFile

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

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

getURL

public URL getURL(String protocol,
                  String host,
                  int port,
                  String file,
                  URLStreamHandler handler)
           throws 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:
MalformedURLException

createThread

public Thread createThread(Runnable target,
                           String name,
                           ClassLoader contextLoader)
Creates a new Thread from a Runnable. Same as calling new Thread(target,name).setContextClassLoader(contextLoader).

Parameters:
target - the Runnable to create the Thread from.
name - The name of the Thread.
contextLoader - the context class loader for the thread
Returns:
The new Thread

getService

public <S> S getService(ServiceReference<S> 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 Class<?> forName(String name)
                 throws ClassNotFoundException
Returns a Class. Same as calling Class.forName(name)

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

loadSystemClass

public Class<?> loadSystemClass(String name)
                         throws 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:
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


Copyright © 2007–2014 The Apache Software Foundation. All rights reserved.