Class Util
- java.lang.Object
-
- org.apache.felix.framework.util.Util
-
public class Util extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringbase64Encode(java.lang.String s)static booleancheckImplementsWithName(java.lang.Class<?> clazz, java.lang.String name)static java.lang.Stringencode(byte[] in, int len)Encode a raw byte array to a Base64 String.static voidencode(java.io.InputStream in, java.io.OutputStream out, int len)static longgetBundleIdFromRevisionId(java.lang.String id)Converts a revision identifier to a bundle identifier.static java.lang.StringgetClassName(java.lang.String className)static java.lang.StringgetClassPackage(java.lang.String className)static java.util.List<BundleRequirement>getDynamicRequirements(java.util.List<BundleRequirement> reqs)static java.util.List<BundleRevision>getFragments(BundleWiring wiring)static java.lang.StringgetFrameworkUUIDFromURL(java.lang.String host)static intgetModuleRevisionFromModuleId(java.lang.String id)Converts a module identifier to a bundle identifier.static java.util.Map<java.lang.String,java.lang.Object>getMultiReleaseAwareManifestHeaders(java.lang.String version, BundleArchiveRevision revision)static BundleCapabilitygetPackageCapability(BundleRevision br, java.lang.String name)static java.util.Map<java.lang.String,java.lang.String>getPropertiesWithPrefix(java.util.Properties props, java.lang.String prefix)static java.lang.StringgetPropertyWithSubs(java.util.Properties props, java.lang.String name)static java.lang.StringgetResourcePackage(java.lang.String resource)static java.lang.StringgetRevisionIdFromURL(java.lang.String host)static BundleWiregetWire(BundleRevision br, java.lang.String name)static java.util.Map<java.lang.String,java.util.Set<java.lang.String>>initializeJPMS(java.util.Properties properties)static voidinitializeJPMSEE(java.lang.String javaVersion, java.util.Properties properties, Logger logger)static booleanisFragment(BundleRevision revision)Checks if the provided module definition declares a fragment host.static booleanisFragment(Resource resource)static booleanisServiceAssignable(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 booleanisSingleton(BundleRevision revision)Returns true if the specified bundle revision is a singleton (i.e., directive singleton:=true in Bundle-SymbolicName).static java.lang.ClassloadClassUsingClass(java.lang.Class clazz, java.lang.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 java.util.PropertiesloadDefaultProperties(Logger logger)static <T> java.util.List<T>newImmutableList(java.util.List<T> list)static <K,V>
java.util.Map<K,V>newImmutableMap(java.util.Map<K,V> map)static <K,V>
VputIfAbsentAndReturn(java.util.concurrent.ConcurrentHashMap<K,V> map, K key, V value)static java.lang.StringrandomUUID(boolean secure)Generates a variant 2, version 4 (randomly generated number) UUID as per RFC 4122.static java.lang.StringsubstVars(java.lang.String val, java.lang.String currentKey, java.util.Map cycleMap, java.util.Properties configProps)This method performs property variable substitution on the specified value.static java.util.PropertiestoProperties(java.util.Map map)
-
-
-
Method Detail
-
loadDefaultProperties
public static java.util.Properties loadDefaultProperties(Logger logger)
-
initializeJPMSEE
public static void initializeJPMSEE(java.lang.String javaVersion, java.util.Properties properties, Logger logger)
-
initializeJPMS
public static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> initializeJPMS(java.util.Properties properties)
-
getPropertyWithSubs
public static java.lang.String getPropertyWithSubs(java.util.Properties props, java.lang.String name)
-
getPropertiesWithPrefix
public static java.util.Map<java.lang.String,java.lang.String> getPropertiesWithPrefix(java.util.Properties props, java.lang.String prefix)
-
toProperties
public static java.util.Properties toProperties(java.util.Map map)
-
getBundleIdFromRevisionId
public static long getBundleIdFromRevisionId(java.lang.String id)
Converts a revision identifier to a bundle identifier. Revision 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, 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.
- Parameters:
clazz- 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.
-
checkImplementsWithName
public static boolean checkImplementsWithName(java.lang.Class<?> clazz, java.lang.String name)
-
isServiceAssignable
public 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.- 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.
-
getDynamicRequirements
public static java.util.List<BundleRequirement> getDynamicRequirements(java.util.List<BundleRequirement> reqs)
-
getWire
public static BundleWire getWire(BundleRevision br, java.lang.String name)
-
getPackageCapability
public static BundleCapability getPackageCapability(BundleRevision br, 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.IOExceptionEncode 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
-
substVars
public static java.lang.String substVars(java.lang.String val, java.lang.String currentKey, java.util.Map cycleMap, java.util.Properties configProps) throws java.lang.IllegalArgumentExceptionThis 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.
- Parameters:
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.- Returns:
- The value of the specified string after system property substitution.
- Throws:
java.lang.IllegalArgumentException- If there was a syntax error in the property placeholder syntax or a recursive variable reference.
-
isSingleton
public static boolean isSingleton(BundleRevision revision)
Returns true if the specified bundle revision is a singleton (i.e., directive singleton:=true in Bundle-SymbolicName).- Parameters:
revision- the revision to check for singleton status.- Returns:
- true if the revision is a singleton, false otherwise.
-
isFragment
public static boolean isFragment(BundleRevision revision)
Checks if the provided module definition declares a fragment host.- Parameters:
revision- the module to check- Returns:
trueif the module declares a fragment host,falseotherwise.
-
isFragment
public static boolean isFragment(Resource resource)
-
getFragments
public static java.util.List<BundleRevision> getFragments(BundleWiring wiring)
-
randomUUID
public static java.lang.String randomUUID(boolean secure)
Generates a variant 2, version 4 (randomly generated number) UUID as per RFC 4122.
- Returns:
- an UUID instance.
-
putIfAbsentAndReturn
public static <K,V> V putIfAbsentAndReturn(java.util.concurrent.ConcurrentHashMap<K,V> map, K key, V value)
-
getFrameworkUUIDFromURL
public static java.lang.String getFrameworkUUIDFromURL(java.lang.String host)
-
getRevisionIdFromURL
public static java.lang.String getRevisionIdFromURL(java.lang.String host)
-
getMultiReleaseAwareManifestHeaders
public static java.util.Map<java.lang.String,java.lang.Object> getMultiReleaseAwareManifestHeaders(java.lang.String version, BundleArchiveRevision revision) throws java.lang.Exception- Throws:
java.lang.Exception
-
newImmutableList
public static <T> java.util.List<T> newImmutableList(java.util.List<T> list)
-
newImmutableMap
public static <K,V> java.util.Map<K,V> newImmutableMap(java.util.Map<K,V> map)
-
-