Save This Page
Home » org.apache.sling.commons.osgi-2.0.6-source-release » org.apache.sling.commons.osgi » [javadoc | source]
org.apache.sling.commons.osgi
public class: OsgiUtil [javadoc | source]
java.lang.Object
   org.apache.sling.commons.osgi.OsgiUtil
The OsgiUtil is a utility class providing some usefull utility methods.
Method from org.apache.sling.commons.osgi.OsgiUtil Summary:
createEvent,   getComparableForServiceRanking,   getProperty,   toBoolean,   toDouble,   toInteger,   toLong,   toObject,   toString,   toStringArray,   toStringArray
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.sling.commons.osgi.OsgiUtil Detail:
 public static Event createEvent(Bundle sourceBundle,
    ServiceReference sourceService,
    String topic,
    Map<String, Object> props) 
    Create an osgi event with the given topic and properties. If a bundle parameter is provided the symbolic name is added as a property. If a service parameter is provided, information about the service is added to the properties.
 public static Comparable<Object> getComparableForServiceRanking(Map<String, Object> props) 
    Create a comparable object out of the service properties. With the result it is possible to compare service properties based on the service ranking of a service. Therefore this object acts like ServiceReference#compareTo(Object) .
 public static double getProperty(Object propValue,
    double defaultValue) 
Deprecated! since - 2.0.4, use #toDouble(Object, double) instead

    Returns the parameter as a double or the defaultValue if the parameter is null or if the parameter is not a Double and cannot be converted to a Double from the parameter's string value.
 public static boolean toBoolean(Object propValue,
    boolean defaultValue) 
    Returns the boolean value of the parameter or the defaultValue if the parameter is null. If the parameter is not a Boolean it is converted by calling Boolean.valueOf on the string value of the object.
 public static double toDouble(Object propValue,
    double defaultValue) 
    Returns the parameter as a double or the defaultValue if the parameter is null or if the parameter is not a Double and cannot be converted to a Double from the parameter's string value.
 public static int toInteger(Object propValue,
    int defaultValue) 
    Returns the parameter as an integer or the defaultValue if the parameter is null or if the parameter is not an Integer and cannot be converted to an Integer from the parameter's string value.
 public static long toLong(Object propValue,
    long defaultValue) 
    Returns the parameter as a long or the defaultValue if the parameter is null or if the parameter is not a Long and cannot be converted to a Long from the parameter's string value.
 public static Object toObject(Object propValue) 
    Returns the parameter as a single value. If the parameter is neither an array nor a java.util.Collection the parameter is returned unmodified. If the parameter 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.
 public static String toString(Object propValue,
    String defaultValue) 
    Returns the parameter as a string or the defaultValue if the parameter is null.
 public static String[] toStringArray(Object propValue) 
    Returns the parameter as an array of Strings. If the parameter is a scalar value its string value is returned as a single element array. If the parameter is an array, the elements are converted to String objects and returned as an array. If the parameter is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the parameter is null) null is returned.
 public static String[] toStringArray(Object propValue,
    String[] defaultArray) 
    Returns the parameter as an array of Strings. If the parameter is a scalar value its string value is returned as a single element array. If the parameter is an array, the elements are converted to String objects and returned as an array. If the parameter is a collection, the collection elements are converted to String objects and returned as an array. Otherwise (if the property is null) a provided default value is returned.