org.apache.sling.launchpad.base.impl
Class Sling

java.lang.Object
  extended by org.apache.sling.launchpad.base.impl.Sling
All Implemented Interfaces:
org.osgi.framework.BundleActivator
Direct Known Subclasses:
SlingBridge

public class Sling
extends Object
implements org.osgi.framework.BundleActivator

The Sling serves as the starting point for Sling.

Launch Configuration

The Apache Felix framework requires configuration parameters to be specified for startup. This servlet builds the list of parameters from three locations:

  1. The sling.properties file is read from the servlet class path. This properties file contains default settings.
  2. Extensions of this servlet may provide additional properties to be loaded overwriting the loadPropertiesOverride(Map) method.
  3. Finally, web application init parameters are added to the properties and may overwrite existing properties of the same name(s).

After loading all properties, variable substitution takes place on the property values. A variable is indicated as ${<prop-name>} where <prop-name> is the name of a system or configuration property (configuration properties override system properties). Variables may be nested and are resolved from inner-most to outer-most. For example, the property value ${outer-${inner}} is resolved by first resolving ${inner} and then resolving the property whose name is the catenation of outer- and the result of resolving ${inner}.


Field Summary
static String CONFIG_PROPERTIES
          The name of the default launcher properties file to setup the environment for the Felix framework (value is "sling.properties").
static String JCR_REPO_CONFIG_FILE_URL
          The name of the configuration property defining the URL of an existing repository config file (repository.xml).
static String JCR_REPO_HOME
          The name of the configuration property defining the JCR home directory (value is "sling.repository.home").
protected  org.apache.felix.framework.Logger logger
          The simple logger to log messages during startup and shutdown to
static String OSGI_FRAMEWORK_BUNDLES
          The name of the configuration property defining a properties file defining a list of bundles, which are installed into the framework when it has been launched (value is "org.apache.osgi.bundles").
static String PROP_SYSTEM_PACKAGES
           
static String SLING_HOME_URL
          The name of the configuration property defining the Sling home directory as an URL (value is "sling.home.url").
static String SLING_IGNORE_SYSTEM_PROPERTIES
          The property to be set to ignore the system properties when building the Felix framework properties (value is "sling.ignoreSystemProperties").
 
Constructor Summary
Sling(Notifiable notifiable, org.apache.felix.framework.Logger logger, LaunchpadContentProvider resourceProvider, Map<String,String> propOverwrite)
          Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.
 
Method Summary
 void destroy()
          Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.
protected  void doStartBundle()
          Executes additional startup tasks and is called by the start(BundleContext) method.
protected  void doStopBundle()
          Executes additional shutdown tasks and is called by the stop(BundleContext) method.
protected  org.osgi.framework.BundleContext getBundleContext()
          Returns the BundleContext of the system bundle of the OSGi framework launched by this servlet.
protected  void loadPropertiesOverride(Map<String,String> properties)
          Loads additional properties into the properties object.
 void start(org.osgi.framework.BundleContext bundleContext)
          Called when the OSGi framework is being started.
 void stop(org.osgi.framework.BundleContext bundleContext)
          Called when the OSGi framework is being shut down.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLING_HOME_URL

public static final String SLING_HOME_URL
The name of the configuration property defining the Sling home directory as an URL (value is "sling.home.url").

The value of this property is assigned the value of new File(${sling.home}).toURI().toString() before resolving the property variables.

See Also:
SharedConstants.SLING_HOME, Constant Field Values

JCR_REPO_HOME

public static final String JCR_REPO_HOME
The name of the configuration property defining the JCR home directory (value is "sling.repository.home").

The value of this property could be set as a system property, init-param in web.xml or property in sling.properties.

Default value to #SLING_HOME/repository_name

See Also:
Constant Field Values

JCR_REPO_CONFIG_FILE_URL

public static final String JCR_REPO_CONFIG_FILE_URL
The name of the configuration property defining the URL of an existing repository config file (repository.xml).

The value of this property could be set as a system property, init-param in web.xml or property in sling.properties.

Default value to #SLING_HOME/repository_name/repository.xml

See Also:
Constant Field Values

OSGI_FRAMEWORK_BUNDLES

public static final String OSGI_FRAMEWORK_BUNDLES
The name of the configuration property defining a properties file defining a list of bundles, which are installed into the framework when it has been launched (value is "org.apache.osgi.bundles").

This configuration property is generally set in the web application configuration and may be referenced in all property files (default, user supplied and web application parameters) used to build the framework configuration.

See Also:
Constant Field Values

SLING_IGNORE_SYSTEM_PROPERTIES

public static final String SLING_IGNORE_SYSTEM_PROPERTIES
The property to be set to ignore the system properties when building the Felix framework properties (value is "sling.ignoreSystemProperties"). If this is property is set to true (case does not matter), the system properties will not be used by loadConfigProperties(Map).

See Also:
Constant Field Values

CONFIG_PROPERTIES

public static final String CONFIG_PROPERTIES
The name of the default launcher properties file to setup the environment for the Felix framework (value is "sling.properties").

Extensions of this class may overwrite some or all properties in this file through Web Application parameters or other properties files.

See Also:
Constant Field Values

PROP_SYSTEM_PACKAGES

public static final String PROP_SYSTEM_PACKAGES
See Also:
Constant Field Values

logger

protected final org.apache.felix.framework.Logger logger
The simple logger to log messages during startup and shutdown to

Constructor Detail

Sling

public Sling(Notifiable notifiable,
             org.apache.felix.framework.Logger logger,
             LaunchpadContentProvider resourceProvider,
             Map<String,String> propOverwrite)
      throws org.osgi.framework.BundleException
Initializes this servlet by loading the framework configuration properties, starting the OSGi framework (Apache Felix) and exposing the system bundle context and the Felix instance as servlet context attributes.

Throws:
org.osgi.framework.BundleException - if the framework cannot be initialized.
Method Detail

destroy

public final void destroy()
Destroys this servlet by shutting down the OSGi framework and hence the delegatee servlet if one is set at all.


start

public final void start(org.osgi.framework.BundleContext bundleContext)
                 throws Exception
Called when the OSGi framework is being started. This implementation registers as a service listener for the javax.servlet.Servlet class and calls the doStartBundle() method for implementations to execute more startup tasks. Additionally the context URL protocol handler is registered.

Specified by:
start in interface org.osgi.framework.BundleActivator
Parameters:
bundleContext - The BundleContext of the system bundle of the OSGi framework.
Throws:
Exception - May be thrown if the doStartBundle() throws.

stop

public final void stop(org.osgi.framework.BundleContext bundleContext)
Called when the OSGi framework is being shut down. This implementation first calls the doStopBundle() method method before unregistering as a service listener and ungetting an servlet delegatee if one has been acquired.

Specified by:
stop in interface org.osgi.framework.BundleActivator
Parameters:
bundleContext - The BundleContext of the system bundle of the OSGi framework.

loadPropertiesOverride

protected void loadPropertiesOverride(Map<String,String> properties)
Loads additional properties into the properties object.

This implementation does nothing and may be overwritten by extensions requiring additional properties to be set.

This method is called when the servlet is initialized to prepare the configuration for Felix. Implementations may add properties from implementation specific sources. Properties added here overwrite properties loaded from the default properties file and may be overwritten by parameters set in the web application.

The properties object has not undergone variable substition and properties added by this method may also contain values refererring to other properties.

The properties added in this method will not be persisted in the sling.properties file in the sling.home directory.

Parameters:
properties - The Properties object to which custom properties may be added.

getBundleContext

protected final org.osgi.framework.BundleContext getBundleContext()
Returns the BundleContext of the system bundle of the OSGi framework launched by this servlet. This method only returns a non-null object after the system bundle of the framework has been started and before it is being stopped.


doStartBundle

protected void doStartBundle()
                      throws Exception
Executes additional startup tasks and is called by the start(BundleContext) method.

This implementation does nothing and may be overwritten by extensions requiring additional startup tasks.

Throws:
Exception - May be thrown in case of problems.

doStopBundle

protected void doStopBundle()
Executes additional shutdown tasks and is called by the stop(BundleContext) method.

This implementation does nothing and may be overwritten by extensions requiring additional shutdown tasks.

When overwriting this method, it must be made sure, that no exception may be thrown, otherwise unexpected behaviour may result.



Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.