Class OsgiUtil

java.lang.Object
org.opencastproject.util.OsgiUtil

public final class OsgiUtil extends Object
Contains general purpose OSGi utility functions.
  • Method Details

    • getContextProperty

      public static String getContextProperty(org.osgi.service.component.ComponentContext cc, String key)
      Get a mandatory, non-blank value from the bundle context.
      Throws:
      RuntimeException - key does not exist or its value is blank
    • getOptContextProperty

      public static Option<String> getOptContextProperty(org.osgi.service.component.ComponentContext cc, String key)
      Get an optional, non-blank value from the bundle context.
      Throws:
      RuntimeException - key does not exist or its value is blank
    • getComponentContextProperty

      public static String getComponentContextProperty(org.osgi.service.component.ComponentContext cc, String key)
      Get a mandatory, non-blank value from the component context.
      Throws:
      RuntimeException - key does not exist or its value is blank
    • getComponentContextProperty

      public static String getComponentContextProperty(org.osgi.service.component.ComponentContext cc, String key, String defaultValue)
      Get a mandatory, non-blank value from the component context. In case the propertie is not defined (null), the default value will be returned.
    • getCfg

      public static String getCfg(Dictionary d, String key) throws org.osgi.service.cm.ConfigurationException
      Get a mandatory, non-blank value from a dictionary.
      Throws:
      org.osgi.service.cm.ConfigurationException - key does not exist or its value is blank
    • getOptCfg

      public static Option<String> getOptCfg(Dictionary d, String key)
      Get a value from a dictionary. Return none if the key does either not exist or the value is blank.
    • getOptCfgAsInt

      public static Option<Integer> getOptCfgAsInt(Dictionary d, String key)
      Get a value from a dictionary. Return none if the key does either not exist or the value is blank.
    • filterByPrefix

      public static Map<String,String> filterByPrefix(Dictionary d, String prefix)
      Filter a dictionary by key prefix. For example the following map {w.p.key1: "value1", w.p.key2: "value2", x: "1"} filtered by filterByPrefix(d, "w.p.") returns {key1: "value1", key2: "value"}.
    • getOptCfgAsBoolean

      public static Option<Boolean> getOptCfgAsBoolean(Dictionary d, String key)
      Get an optional boolean from a dictionary.
    • getCfgAsInt

      public static int getCfgAsInt(Dictionary d, String key) throws org.osgi.service.cm.ConfigurationException
      Get a mandatory integer from a dictionary.
      Throws:
      org.osgi.service.cm.ConfigurationException - key does not exist or is not an integer
    • registerServlet

      public static org.osgi.framework.ServiceRegistration<?> registerServlet(org.osgi.framework.BundleContext bundleContext, Object service, String alias)