Class BundleUtils
- java.lang.Object
-
- org.apache.xbean.osgi.bundle.util.BundleUtils
-
public class BundleUtils extends java.lang.Object
- Version:
- $Rev: 1347954 $ $Date: 2012-06-08 11:08:40 +0200 (Fri, 08 Jun 2012) $
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FILE_SCHEMA
static java.lang.String
REFERENCE_FILE_SCHEMA
static java.lang.String
REFERENCE_SCHEME
-
Constructor Summary
Constructors Constructor Description BundleUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
canStart(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be started a.static boolean
canStop(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be stopped a.static boolean
canUninstall(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be un-installed a.static org.osgi.framework.Bundle
getBundle(java.lang.ClassLoader classLoader, boolean unwrap)
Returns bundle (if any) associated with the classloader.static org.osgi.framework.Bundle
getContextBundle(boolean unwrap)
Returns bundle (if any) associated with current thread's context classloader.static java.net.URL
getEntry(org.osgi.framework.Bundle bundle, java.lang.String name)
1, If the bundle was installed with reference directory mode return the file URL directly.static java.util.Enumeration<java.lang.String>
getEntryPaths(org.osgi.framework.Bundle bundle, java.lang.String name)
Works likeBundle.getEntryPaths(String)
but also returns paths in attached fragment bundles.static java.net.URL
getNestedEntry(org.osgi.framework.Bundle bundle, java.lang.String jarEntryName, java.lang.String subEntryName)
static java.util.LinkedHashSet<org.osgi.framework.Bundle>
getWiredBundles(org.osgi.framework.Bundle bundle)
static java.util.LinkedHashSet<org.osgi.framework.Bundle>
getWiredBundles(org.osgi.service.packageadmin.PackageAdmin packageAdmin, org.osgi.framework.Bundle bundle)
static boolean
isFragment(org.osgi.framework.Bundle bundle)
static boolean
isResolved(org.osgi.framework.Bundle bundle)
Based on the constant field values, if it is bigger than the RESOLVED status value, the bundle has been resolved by the frameworkstatic void
resolve(org.osgi.framework.Bundle bundle)
resolve method will try to load the Object.class, the behavior triggers a resolved request to the OSGI framework.static java.io.File
toFile(java.lang.String url)
Translate the reference:file:// style URL to the underlying file instancestatic java.io.File
toFile(java.net.URL url)
static java.io.File
toFile(org.osgi.framework.Bundle bundle)
static java.lang.String
toReferenceFileLocation(java.io.File file)
static org.osgi.framework.Bundle
unwrapBundle(org.osgi.framework.Bundle bundle)
If the given bundle is aDelegatingBundle
this function will return the main application bundle backing theDelegatingBundle
.
-
-
-
Field Detail
-
REFERENCE_SCHEME
public static final java.lang.String REFERENCE_SCHEME
- See Also:
- Constant Field Values
-
FILE_SCHEMA
public static final java.lang.String FILE_SCHEMA
- See Also:
- Constant Field Values
-
REFERENCE_FILE_SCHEMA
public static final java.lang.String REFERENCE_FILE_SCHEMA
- See Also:
- Constant Field Values
-
-
Method Detail
-
isResolved
public static boolean isResolved(org.osgi.framework.Bundle bundle)
Based on the constant field values, if it is bigger than the RESOLVED status value, the bundle has been resolved by the framework- Parameters:
bundle
-- Returns:
- true if the bundle is resolved, or false if not.
-
resolve
public static void resolve(org.osgi.framework.Bundle bundle)
resolve method will try to load the Object.class, the behavior triggers a resolved request to the OSGI framework.- Parameters:
bundle
-
-
canStart
public static boolean canStart(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be started a. Not in the UNINSTALLED status. b. Not in the STARTING status. c. Not a fragment bundle.- Parameters:
bundle
-- Returns:
-
canStop
public static boolean canStop(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be stopped a. Not in the UNINSTALLED status. b. Not in the STOPPING status. c. Not a fragment bundle.- Parameters:
bundle
-- Returns:
-
canUninstall
public static boolean canUninstall(org.osgi.framework.Bundle bundle)
If the bundle fulfills the conditions below, it could be un-installed a. Not in the UNINSTALLED status.- Parameters:
bundle
-- Returns:
-
isFragment
public static boolean isFragment(org.osgi.framework.Bundle bundle)
-
getContextBundle
public static org.osgi.framework.Bundle getContextBundle(boolean unwrap)
Returns bundle (if any) associated with current thread's context classloader. Invoking this method is equivalent to getBundle(Thread.currentThread().getContextClassLoader(), unwrap)
-
getBundle
public static org.osgi.framework.Bundle getBundle(java.lang.ClassLoader classLoader, boolean unwrap)
Returns bundle (if any) associated with the classloader.- Parameters:
classLoader
-unwrap
- if true and if the bundle associated with the context classloader is aDelegatingBundle
, this function will return the main application bundle backing theDelegatingBundle
. Otherwise, the bundle associated with the context classloader is returned as is. SeeBundleClassLoader.getBundle(boolean)
for more information.- Returns:
- The bundle associated with the classloader. Might be null.
-
unwrapBundle
public static org.osgi.framework.Bundle unwrapBundle(org.osgi.framework.Bundle bundle)
If the given bundle is aDelegatingBundle
this function will return the main application bundle backing theDelegatingBundle
. Otherwise, the bundle passed in is returned as is.
-
getEntryPaths
public static java.util.Enumeration<java.lang.String> getEntryPaths(org.osgi.framework.Bundle bundle, java.lang.String name)
Works likeBundle.getEntryPaths(String)
but also returns paths in attached fragment bundles.- Parameters:
bundle
-name
-- Returns:
-
getEntry
public static java.net.URL getEntry(org.osgi.framework.Bundle bundle, java.lang.String name) throws java.net.MalformedURLException
1, If the bundle was installed with reference directory mode return the file URL directly. 2, For traditional package bundle, Works likeBundle.getEntry(String)
In addition to the searching abaove, it also checks attached fragment bundles for the given entry.- Parameters:
bundle
-name
-- Returns:
- Throws:
java.net.MalformedURLException
-
getNestedEntry
public static java.net.URL getNestedEntry(org.osgi.framework.Bundle bundle, java.lang.String jarEntryName, java.lang.String subEntryName) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
toFile
public static java.io.File toFile(org.osgi.framework.Bundle bundle)
-
toFile
public static java.io.File toFile(java.net.URL url)
-
toFile
public static java.io.File toFile(java.lang.String url)
Translate the reference:file:// style URL to the underlying file instance- Parameters:
url
-- Returns:
-
toReferenceFileLocation
public static java.lang.String toReferenceFileLocation(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
getWiredBundles
public static java.util.LinkedHashSet<org.osgi.framework.Bundle> getWiredBundles(org.osgi.framework.Bundle bundle)
-
getWiredBundles
public static java.util.LinkedHashSet<org.osgi.framework.Bundle> getWiredBundles(org.osgi.service.packageadmin.PackageAdmin packageAdmin, org.osgi.framework.Bundle bundle)
-
-