Nuxeo Enterprise Platform 5.4

org.nuxeo.runtime.api
Class Framework

java.lang.Object
  extended by org.nuxeo.runtime.api.Framework

public final class Framework
extends java.lang.Object

This class is the main entry point to a Nuxeo runtime application.

It offers an easy way to create new sessions, to access system services and other resources.

There are two type of services:

Author:
Bogdan Stefanescu

Method Summary
static void addListener(RuntimeServiceListener listener)
          Registers a listener to be notified about runtime events.
static java.lang.String expandVars(java.lang.String expression)
          Expands any variable found in the given expression with the value of the corresponding framework property.
static
<T> T
getLocalService(java.lang.Class<T> serviceClass)
          Gets a nuxeo-runtime local service.
static java.util.Properties getProperties()
          Gets all the framework properties.
static java.lang.String getProperty(java.lang.String key)
          Gets the given property value if any, otherwise null.
static java.lang.String getProperty(java.lang.String key, java.lang.String defValue)
          Gets the given property value if any, otherwise returns the given default value.
static SharedResourceLoader getResourceLoader()
           
static RuntimeService getRuntime()
          Gets the runtime service instance.
static
<T> T
getService(java.lang.Class<T> serviceClass)
          Gets a service given its class.
static
<T> T
getService(java.lang.Class<T> serviceClass, java.lang.String name)
          Gets a service given its class and an identifier.
static void handleDevError(java.lang.Throwable t)
          This method stops the application if development mode is enabled (i.e. org.nuxeo.dev system property is set) and one of the following errors occurs during startup: Component XML parse error.
static void initialize(RuntimeService runtimeService)
           
static boolean isDevModeSet()
           
static boolean isInitialized()
          Tests whether or not the runtime was initialized.
static boolean isTestModeSet()
           
static javax.security.auth.login.LoginContext login()
          Login in the system as the system user (a pseudo-user having all privileges).
static javax.security.auth.login.LoginContext login(javax.security.auth.callback.CallbackHandler cbHandler)
          Login in the system using the given callback handler for login info resolution.
static javax.security.auth.login.LoginContext login(java.lang.String username, java.lang.Object password)
          Login in the system as the given user using the given password.
static javax.security.auth.login.LoginContext loginAs(java.lang.String username)
          Login in the system as the system user (a pseudo-user having all privileges).
static java.lang.Object lookup(java.lang.String key)
          Lookup a registered object given its key.
static void main(java.lang.String[] args)
           
static void reloadResourceLoader()
           
static void removeListener(RuntimeServiceListener listener)
          Removes the given listener.
static void sendEvent(RuntimeServiceEvent event)
           
static void shutdown()
           
static void trackFile(java.io.File file, java.lang.Object marker)
          Deletes the given file when the marker object is collected by GC.
static void trackFile(java.io.File file, java.lang.Object marker, FileDeleteStrategy fileDeleteStrategy)
          Deletes the given file when the marker object is collected by GC.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initialize

public static void initialize(RuntimeService runtimeService)
                       throws java.lang.Exception
Throws:
java.lang.Exception

reloadResourceLoader

public static void reloadResourceLoader()
                                 throws java.lang.Exception
Throws:
java.lang.Exception

shutdown

public static void shutdown()
                     throws java.lang.Exception
Throws:
java.lang.Exception

isInitialized

public static boolean isInitialized()
Tests whether or not the runtime was initialized.

Returns:
true if the runtime was initialized, false otherwise

getResourceLoader

public static SharedResourceLoader getResourceLoader()

getRuntime

public static RuntimeService getRuntime()
Gets the runtime service instance.

Returns:
the runtime service instance

getService

public static <T> T getService(java.lang.Class<T> serviceClass)
                    throws java.lang.Exception
Gets a service given its class.

Throws:
java.lang.Exception

getService

public static <T> T getService(java.lang.Class<T> serviceClass,
                               java.lang.String name)
                    throws java.lang.Exception
Gets a service given its class and an identifier.

Throws:
java.lang.Exception

getLocalService

public static <T> T getLocalService(java.lang.Class<T> serviceClass)
Gets a nuxeo-runtime local service.


lookup

public static java.lang.Object lookup(java.lang.String key)
Lookup a registered object given its key.


login

public static javax.security.auth.login.LoginContext login()
                                                    throws javax.security.auth.login.LoginException
Login in the system as the system user (a pseudo-user having all privileges).

Returns:
the login session if successful. Never returns null.
Throws:
javax.security.auth.login.LoginException - on login failure

loginAs

public static javax.security.auth.login.LoginContext loginAs(java.lang.String username)
                                                      throws javax.security.auth.login.LoginException
Login in the system as the system user (a pseudo-user having all privileges). The given username will be used to identify the user id that called this method.

Parameters:
username - the originating user id
Returns:
the login session if successful. Never returns null.
Throws:
javax.security.auth.login.LoginException - on login failure

login

public static javax.security.auth.login.LoginContext login(java.lang.String username,
                                                           java.lang.Object password)
                                                    throws javax.security.auth.login.LoginException
Login in the system as the given user using the given password.

Parameters:
username - the username to login
password - the password
Returns:
a login session if login was successful. Never returns null.
Throws:
javax.security.auth.login.LoginException - if login failed

login

public static javax.security.auth.login.LoginContext login(javax.security.auth.callback.CallbackHandler cbHandler)
                                                    throws javax.security.auth.login.LoginException
Login in the system using the given callback handler for login info resolution.

Parameters:
cbHandler - used to fetch the login info
Returns:
the login context
Throws:
javax.security.auth.login.LoginException

sendEvent

public static void sendEvent(RuntimeServiceEvent event)

addListener

public static void addListener(RuntimeServiceListener listener)
Registers a listener to be notified about runtime events.

If the listener is already registered, do nothing.

Parameters:
listener - the listener to register

removeListener

public static void removeListener(RuntimeServiceListener listener)
Removes the given listener.

If the listener is not registered, do nothing.

Parameters:
listener - the listener to remove

getProperty

public static java.lang.String getProperty(java.lang.String key)
Gets the given property value if any, otherwise null.

The framework properties will be searched first then if any matching property is found the system properties are searched too.

Parameters:
key - the property key
Returns:
the property value if any or null otherwise

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           java.lang.String defValue)
Gets the given property value if any, otherwise returns the given default value.

The framework properties will be searched first then if any matching property is found the system properties are searched too.

Parameters:
key - the property key
defValue - the default value to use
Returns:
the property value if any otherwise the default value

getProperties

public static java.util.Properties getProperties()
Gets all the framework properties. The system properties are not included in the returned map.

Returns:
the framework properties map. Never returns null.

expandVars

public static java.lang.String expandVars(java.lang.String expression)
Expands any variable found in the given expression with the value of the corresponding framework property.

The variable format is ${property_key}.

System properties are also expanded.


isDevModeSet

public static boolean isDevModeSet()

isTestModeSet

public static boolean isTestModeSet()

handleDevError

public static void handleDevError(java.lang.Throwable t)
This method stops the application if development mode is enabled (i.e. org.nuxeo.dev system property is set) and one of the following errors occurs during startup:

Parameters:
t - the exception or null if none

trackFile

public static void trackFile(java.io.File file,
                             java.lang.Object marker)
Deletes the given file when the marker object is collected by GC.

Parameters:
file - The file to delete
marker - the marker Object

trackFile

public static void trackFile(java.io.File file,
                             java.lang.Object marker,
                             FileDeleteStrategy fileDeleteStrategy)
Deletes the given file when the marker object is collected by GC. The fileDeleteStrategy can be used for instance do delete only empty directory or force deletion.

Parameters:
file - The file to delete
marker - the marker Object
fileDeleteStrategy - add a custom delete strategy

main

public static void main(java.lang.String[] args)

Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.