org.apache.felix.framework.util
Class Util

java.lang.Object
  extended by org.apache.felix.framework.util.Util

public class Util
extends java.lang.Object


Constructor Summary
Util()
           
 
Method Summary
static java.lang.String base64Encode(java.lang.String s)
           
static java.lang.String encode(byte[] in, int len)
          Encode a raw byte array to a Base64 String.
static void encode(java.io.InputStream in, java.io.OutputStream out, int len)
           
static long getBundleIdFromModuleId(java.lang.String id)
          Converts a module identifier to a bundle identifier.
static java.lang.String getClassName(java.lang.String className)
           
static java.lang.String getClassPackage(java.lang.String className)
           
static int getModuleRevisionFromModuleId(java.lang.String id)
          Converts a module identifier to a bundle identifier.
static java.lang.String getResourcePackage(java.lang.String resource)
           
static ICapability getSatisfyingCapability(IModule m, IRequirement req)
           
static IWire getWire(IModule m, java.lang.String name)
           
static boolean isServiceAssignable(org.osgi.framework.Bundle requester, org.osgi.framework.ServiceReference ref)
          This method determines if the requesting bundle is able to cast the specified service reference based on class visibility rules of the underlying modules.
static java.lang.Class loadClassUsingClass(java.lang.Class clazz, java.lang.String name)
           This is a simple utility class that attempts to load the named class using the class loader of the supplied class or the class loader of one of its super classes or their implemented interfaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

getBundleIdFromModuleId

public static long getBundleIdFromModuleId(java.lang.String id)
Converts a module identifier to a bundle identifier. Module IDs are typically <bundle-id>.<revision>; this method returns only the portion corresponding to the bundle ID.


getModuleRevisionFromModuleId

public static int getModuleRevisionFromModuleId(java.lang.String id)
Converts a module identifier to a bundle identifier. Module IDs are typically <bundle-id>.<revision>; this method returns only the portion corresponding to the revision.


getClassName

public static java.lang.String getClassName(java.lang.String className)

getClassPackage

public static java.lang.String getClassPackage(java.lang.String className)

getResourcePackage

public static java.lang.String getResourcePackage(java.lang.String resource)

loadClassUsingClass

public static java.lang.Class loadClassUsingClass(java.lang.Class clazz,
                                                  java.lang.String name)

This is a simple utility class that attempts to load the named class using the class loader of the supplied class or the class loader of one of its super classes or their implemented interfaces. This is necessary during service registration to test whether a given service object implements its declared service interfaces.

To perform this test, the framework must try to load the classes associated with the declared service interfaces, so it must choose a class loader. The class loader of the registering bundle cannot be used, since this disallows third parties to register service on behalf of another bundle. Consequently, the class loader of the service object must be used. However, this is also not sufficient since the class loader of the service object may not have direct access to the class in question.

The service object's class loader may not have direct access to its service interface if it extends a super class from another bundle which implements the service interface from an imported bundle or if it implements an extension of the service interface from another bundle which imports the base interface from another bundle. In these cases, the service object's class loader only has access to the super class's class or the extended service interface, respectively, but not to the actual service interface.

Thus, it is necessary to not only try to load the service interface class from the service object's class loader, but from the class loaders of any interfaces it implements and the class loaders of all super classes.

Parameters:
svcObj - the class that is the root of the search.
name - the name of the class to load.
Returns:
the loaded class or null if it could not be loaded.

isServiceAssignable

public static boolean isServiceAssignable(org.osgi.framework.Bundle requester,
                                          org.osgi.framework.ServiceReference ref)
This method determines if the requesting bundle is able to cast the specified service reference based on class visibility rules of the underlying modules.

Parameters:
requester - The bundle requesting the service.
ref - The service in question.
Returns:
true if the requesting bundle is able to case the service object to a known type.

getSatisfyingCapability

public static ICapability getSatisfyingCapability(IModule m,
                                                  IRequirement req)

getWire

public static IWire getWire(IModule m,
                            java.lang.String name)

base64Encode

public static java.lang.String base64Encode(java.lang.String s)
                                     throws java.io.IOException
Throws:
java.io.IOException

encode

public static java.lang.String encode(byte[] in,
                                      int len)
                               throws java.io.IOException
Encode a raw byte array to a Base64 String.

Parameters:
in - Byte array to encode.
len - Length of Base64 lines. 0 means no line breaks.
Throws:
java.io.IOException

encode

public static void encode(java.io.InputStream in,
                          java.io.OutputStream out,
                          int len)
                   throws java.io.IOException
Throws:
java.io.IOException