KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > util > BundleUtility


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.util;
12
13 import java.net.URL JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.ui.internal.WorkbenchPlugin;
20 import org.osgi.framework.Bundle;
21
22 /**
23  * A set of static methods that provide an nicer interface to common platform
24  * operations related to bundle management.
25  */

26 public class BundleUtility {
27     public static boolean isActive(Bundle bundle) {
28         if (bundle == null) {
29             return false;
30         }
31         return bundle.getState() == Bundle.ACTIVE;
32     }
33
34     public static boolean isActivated(Bundle bundle) {
35         if ((bundle.getState() & Bundle.STARTING) != 0)
36             return WorkbenchPlugin.getDefault().isStarting(bundle);
37         return bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STOPPING)) != 0;
38     }
39
40     // TODO: needs a better name
41
public static boolean isReady(Bundle bundle) {
42         return bundle != null && isReady(bundle.getState());
43     }
44
45     public static boolean isReady(int bundleState) {
46         return (bundleState & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0;
47     }
48
49     public static boolean isActive(String JavaDoc bundleId) {
50         return isActive(Platform.getBundle(bundleId));
51     }
52
53     public static boolean isActivated(String JavaDoc bundleId) {
54         return isActivated(Platform.getBundle(bundleId));
55     }
56
57     public static boolean isReady(String JavaDoc bundleId) {
58         return isReady(Platform.getBundle(bundleId));
59     }
60
61     public static URL JavaDoc find(Bundle bundle, String JavaDoc path) {
62         if (bundle == null) {
63             return null;
64         }
65         return Platform.find(bundle, new Path(path));
66     }
67
68     public static URL JavaDoc find(String JavaDoc bundleId, String JavaDoc path) {
69         return find(Platform.getBundle(bundleId), path);
70     }
71
72     public static void log(String JavaDoc bundleId, Throwable JavaDoc exception) {
73         Bundle bundle = Platform.getBundle(bundleId);
74         if (bundle == null) {
75             return;
76         }
77         IStatus status = new Status(IStatus.ERROR, bundleId, IStatus.ERROR,
78                 exception.getMessage() == null ? "" : exception.getMessage(), //$NON-NLS-1$
79
exception);
80         Platform.getLog(bundle).log(status);
81     }
82 }
83
Popular Tags