Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.runtime.api
Class Framework

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

public final class Framework
extends 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 String expandVars(String expression)
          Expands any variable found in the given expression with the value of the corresponding framework property.
static
<T> T
getLocalService(Class<T> serviceClass)
          Gets a nuxeo-runtime local service.
static Properties getProperties()
          Gets all the framework properties.
static String getProperty(String key)
          Gets the given property value if any, otherwise null.
static String getProperty(String key, 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(Class<T> serviceClass)
          Gets a service given its class.
static
<T> T
getService(Class<T> serviceClass, String name)
          Gets a service given its class and an identifier.
static void handleDevError(Throwable t)
          This method stops the application if development mode is enabled (i.e.
static void initialize(RuntimeService runtimeService)
           
static boolean isDevModeSet()
           
static boolean isInitialized()
          Tests whether or not the runtime was initialized.
static boolean isOSGiServiceSupported()
           
static boolean isTestModeSet()
           
static LoginContext login()
          Login in the system as the system user (a pseudo-user having all privileges).
static LoginContext login(CallbackHandler cbHandler)
          Login in the system using the given callback handler for login info resolution.
static LoginContext login(String username, Object password)
          Login in the system as the given user using the given password.
static LoginContext loginAs(String username)
          Login in the system as the system user (a pseudo-user having all privileges).
static LoginContext loginAsUser(String username)
          Login in the system as the given user without checking the password.
static Object lookup(String key)
          Lookup a registered object given its key.
static void main(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(File file, Object marker)
          Deletes the given file when the marker object is collected by GC.
static void trackFile(File file, 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 Exception
Throws:
Exception

reloadResourceLoader

public static void reloadResourceLoader()
                                 throws Exception
Throws:
Exception

shutdown

public static void shutdown()
                     throws Exception
Throws:
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(Class<T> serviceClass)
                    throws Exception
Gets a service given its class.

Throws:
Exception

getService

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

Throws:
Exception

getLocalService

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


lookup

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


login

public static LoginContext login()
                          throws 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:
LoginException - on login failure

loginAs

public static LoginContext loginAs(String username)
                            throws 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:
LoginException - on login failure

loginAsUser

public static LoginContext loginAsUser(String username)
                                throws LoginException
Login in the system as the given user without checking the password.

Parameters:
username - the user name to login as.
Returns:
the login context
Throws:
LoginException - if any error occurs
Since:
5.4.2

login

public static LoginContext login(String username,
                                 Object password)
                          throws 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:
LoginException - if login failed

login

public static LoginContext login(CallbackHandler cbHandler)
                          throws 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:
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 String getProperty(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 String getProperty(String key,
                                 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 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 String expandVars(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.


isOSGiServiceSupported

public static boolean isOSGiServiceSupported()

isDevModeSet

public static boolean isDevModeSet()

isTestModeSet

public static boolean isTestModeSet()

handleDevError

public static void handleDevError(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(File file,
                             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(File file,
                             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(String[] args)

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.