public class Util extends Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static String |
base64Encode(String s) |
static String |
encode(byte[] in,
int len)
Encode a raw byte array to a Base64 String.
|
static void |
encode(InputStream in,
OutputStream out,
int len) |
static long |
getBundleIdFromRevisionId(String id)
Converts a revision identifier to a bundle identifier.
|
static List<BundleCapability> |
getCapabilityByNamespace(BundleRevision br,
String namespace)
Returns all the capabilities from a module that has a specified namespace.
|
static String |
getClassName(String className) |
static String |
getClassPackage(String className) |
static Map<String,String> |
getDefaultPropertiesWithPrefix(Logger logger,
String prefix) |
static Map<String,String> |
getDefaultPropertiesWithPrefix(Properties props,
String prefix) |
static String |
getDefaultProperty(Logger logger,
String name) |
static List<BundleRequirement> |
getDynamicRequirements(List<BundleRequirement> reqs) |
static List<BundleRevision> |
getFragments(BundleWiring wiring) |
static int |
getModuleRevisionFromModuleId(String id)
Converts a module identifier to a bundle identifier.
|
static BundleCapability |
getPackageCapability(BundleRevision br,
String name) |
static String |
getPropertyWithSubs(Properties props,
String name) |
static String |
getResourcePackage(String resource) |
static BundleWire |
getWire(BundleRevision br,
String name) |
static boolean |
isFragment(BundleRevision revision)
Checks if the provided module definition declares a fragment host.
|
static boolean |
isFragment(Resource resource) |
static boolean |
isServiceAssignable(Bundle requester,
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 boolean |
isSingleton(BundleRevision revision)
Returns true if the specified bundle revision is a singleton
(i.e., directive singleton:=true in Bundle-SymbolicName).
|
static Class |
loadClassUsingClass(Class clazz,
String name,
SecureAction action)
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.
|
static Properties |
loadDefaultProperties(Logger logger) |
static String |
randomUUID()
Generates a variant 2, version 4 (randomly generated number) UUID as per
RFC 4122.
|
static String |
substVars(String val,
String currentKey,
Map cycleMap,
Properties configProps)
This method performs property variable substitution on the
specified value.
|
public static Properties loadDefaultProperties(Logger logger)
public static String getPropertyWithSubs(Properties props, String name)
public static Map<String,String> getDefaultPropertiesWithPrefix(Logger logger, String prefix)
public static Map<String,String> getDefaultPropertiesWithPrefix(Properties props, String prefix)
public static long getBundleIdFromRevisionId(String id)
public static int getModuleRevisionFromModuleId(String id)
public static Class loadClassUsingClass(Class clazz, String name, SecureAction action)
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.
svcObj
- the class that is the root of the search.name
- the name of the class to load.public static boolean isServiceAssignable(Bundle requester, ServiceReference ref)
requester
- The bundle requesting the service.ref
- The service in question.public static List<BundleCapability> getCapabilityByNamespace(BundleRevision br, String namespace)
br
- module providing capabilitiesnamespace
- capability namespacepublic static List<BundleRequirement> getDynamicRequirements(List<BundleRequirement> reqs)
public static BundleWire getWire(BundleRevision br, String name)
public static BundleCapability getPackageCapability(BundleRevision br, String name)
public static String base64Encode(String s) throws IOException
IOException
public static String encode(byte[] in, int len) throws IOException
in
- Byte array to encode.len
- Length of Base64 lines. 0 means no line breaks.IOException
public static void encode(InputStream in, OutputStream out, int len) throws IOException
IOException
public static String substVars(String val, String currentKey, Map cycleMap, Properties configProps) throws IllegalArgumentException
This method performs property variable substitution on the specified value. If the specified value contains the syntax ${<prop-name>}, where <prop-name> refers to either a configuration property or a system property, then the corresponding property value is substituted for the variable placeholder. Multiple variable placeholders may exist in the specified value as well as nested variable placeholders, which are substituted from inner most to outer most. Configuration properties override system properties.
val
- The string on which to perform property substitution.currentKey
- The key of the property being evaluated used to
detect cycles.cycleMap
- Map of variable references used to detect nested cycles.configProps
- Set of configuration properties.IllegalArgumentException
- If there was a syntax error in the
property placeholder syntax or a recursive variable reference.public static boolean isSingleton(BundleRevision revision)
revision
- the revision to check for singleton status.public static boolean isFragment(BundleRevision revision)
module
- the module to checktrue
if the module declares a fragment host, false
otherwise.public static boolean isFragment(Resource resource)
public static List<BundleRevision> getFragments(BundleWiring wiring)
Copyright © 2006–2016 The Apache Software Foundation. All rights reserved.