org.apache.sling.commons.osgi
Class OsgiUtil

java.lang.Object
  extended by org.apache.sling.commons.osgi.OsgiUtil

public class OsgiUtil
extends java.lang.Object

The OsgiUtil is a utility class providing some usefull utility methods.


Constructor Summary
OsgiUtil()
           
 
Method Summary
static org.osgi.service.event.Event createEvent(org.osgi.framework.Bundle sourceBundle, org.osgi.framework.ServiceReference sourceService, java.lang.String eventName, java.util.Map<java.lang.String,java.lang.Object> props)
           
static double getProperty(java.lang.Object propValue, double defaultValue)
          Deprecated. since 2.0.4, use toDouble(Object, double) instead
static boolean toBoolean(java.lang.Object propValue, boolean defaultValue)
          Returns the boolean value of the named service reference property or the defaultValue if no such service reference property exist.
static double toDouble(java.lang.Object propValue, double defaultValue)
          Returns the named service reference property as a double or the defaultValue if no such reference property exists or if the property is not an Double and cannot be converted to an Double from the property's string value.
static int toInteger(java.lang.Object propValue, int defaultValue)
          Returns the named service reference property as an integer or the defaultValue if no such reference property exists or if the property is not an Integer and cannot be converted to an Integer from the property's string value.
static long toLong(java.lang.Object propValue, long defaultValue)
          Returns the named service reference property as a long or the defaultValue if no such reference property exists or if the property is not an Integer and cannot be converted to a Long from the property's string value.
static java.lang.Object toObject(java.lang.Object propValue)
          Returns the named service reference property as a single value.
static java.lang.String toString(java.lang.Object propValue, java.lang.String defaultValue)
          Returns the named service reference property as a string or the defaultValue if no such reference property exists.
static java.lang.String[] toStringArray(java.lang.Object propValue)
          Returns the named service reference property as an array of Strings.
static java.lang.String[] toStringArray(java.lang.Object propValue, java.lang.String[] defaultArray)
          Returns the named service reference property as an array of Strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OsgiUtil

public OsgiUtil()
Method Detail

toBoolean

public static boolean toBoolean(java.lang.Object propValue,
                                boolean defaultValue)
Returns the boolean value of the named service reference property or the defaultValue if no such service reference property exist. If the service property is not a Boolean it is converted by calling Boolean.valueOf on the string value of the property.


toString

public static java.lang.String toString(java.lang.Object propValue,
                                        java.lang.String defaultValue)
Returns the named service reference property as a string or the defaultValue if no such reference property exists.


toLong

public static long toLong(java.lang.Object propValue,
                          long defaultValue)
Returns the named service reference property as a long or the defaultValue if no such reference property exists or if the property is not an Integer and cannot be converted to a Long from the property's string value.


toInteger

public static int toInteger(java.lang.Object propValue,
                            int defaultValue)
Returns the named service reference property as an integer or the defaultValue if no such reference property exists or if the property is not an Integer and cannot be converted to an Integer from the property's string value.


getProperty

@Deprecated
public static double getProperty(java.lang.Object propValue,
                                            double defaultValue)
Deprecated. since 2.0.4, use toDouble(Object, double) instead

Returns the named service reference property as a double or the defaultValue if no such reference property exists or if the property is not an Double and cannot be converted to an Double from the property's string value.


toDouble

public static double toDouble(java.lang.Object propValue,
                              double defaultValue)
Returns the named service reference property as a double or the defaultValue if no such reference property exists or if the property is not an Double and cannot be converted to an Double from the property's string value.

Since:
2.0.4

toObject

public static java.lang.Object toObject(java.lang.Object propValue)
Returns the named service reference property as a single value. If the property is neither an array nor a java.util.Collection the property is returned unmodified. If the property is a non-empty array, the first array element is returned. If the property is a non-empty java.util.Collection, the first collection element is returned. Otherwise null is returned.


toStringArray

public static java.lang.String[] toStringArray(java.lang.Object propValue)
Returns the named service reference property as an array of Strings. If the property is a scalar value its string value is returned as a single element array. If the property is an array, the elements are converted to String objects and returned as an array. If the property is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the property does not exist) null is returned.


toStringArray

public static java.lang.String[] toStringArray(java.lang.Object propValue,
                                               java.lang.String[] defaultArray)
Returns the named service reference property as an array of Strings. If the property is a scalar value its string value is returned as a single element array. If the property is an array, the elements are converted to String objects and returned as an array. If the property is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the property does not exist) a provided default value is returned.

Since:
2.0.4

createEvent

public static org.osgi.service.event.Event createEvent(org.osgi.framework.Bundle sourceBundle,
                                                       org.osgi.framework.ServiceReference sourceService,
                                                       java.lang.String eventName,
                                                       java.util.Map<java.lang.String,java.lang.Object> props)


Copyright © 2007-2009. All Rights Reserved.