1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.uruma.rcp.util; |
17 | |
|
18 | |
import org.eclipse.core.runtime.Platform; |
19 | |
import org.eclipse.ui.internal.util.BundleUtility; |
20 | |
import org.osgi.framework.Bundle; |
21 | |
import org.osgi.framework.BundleException; |
22 | |
import org.seasar.uruma.core.UrumaConstants; |
23 | |
import org.seasar.uruma.core.UrumaMessageCodes; |
24 | |
import org.seasar.uruma.exception.BundleRuntimeException; |
25 | |
import org.seasar.uruma.log.UrumaLogger; |
26 | |
import org.seasar.uruma.util.AssertionUtil; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class BundleUtil implements UrumaConstants { |
34 | |
|
35 | 0 | private static final UrumaLogger logger = UrumaLogger |
36 | |
.getLogger(BundleUtil.class); |
37 | |
|
38 | |
private static final String UNINSTALLED = "UNINSTALLED"; |
39 | |
|
40 | |
private static final String INSTALLED = "INSTALLED"; |
41 | |
|
42 | |
private static final String RESOLVED = "RESOLVED"; |
43 | |
|
44 | |
private static final String STARTING = "STARTING"; |
45 | |
|
46 | |
private static final String STOPPING = "STOPPING"; |
47 | |
|
48 | |
private static final String ACTIVE = "ACTIVE"; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public static Bundle getBundle(final String symbolicName) { |
58 | 0 | AssertionUtil.assertNotEmpty("SymbolicName", symbolicName); |
59 | 0 | Bundle bundle = Platform.getBundle(symbolicName); |
60 | 0 | return bundle; |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public static void start(final String symbolicName) { |
70 | 0 | AssertionUtil.assertNotEmpty("SymbolicName", symbolicName); |
71 | 0 | Bundle targetBundle = getBundle(symbolicName); |
72 | 0 | AssertionUtil.assertNotNull("Bundle", targetBundle); |
73 | 0 | if (!BundleUtility.isActive(targetBundle)) { |
74 | |
try { |
75 | 0 | logger.log(UrumaMessageCodes.BUNDLE_START, symbolicName); |
76 | 0 | targetBundle.start(); |
77 | 0 | } catch (BundleException e) { |
78 | 0 | throw new BundleRuntimeException( |
79 | |
UrumaMessageCodes.EXCEPTION_OCCURED_WITH_REASON, e); |
80 | 0 | } |
81 | |
} else { |
82 | 0 | logger.log(UrumaMessageCodes.BUNDLE_STARTED, symbolicName); |
83 | |
} |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public static void stop(final String symbolicName) { |
92 | 0 | AssertionUtil.assertNotEmpty("SymbolicName", symbolicName); |
93 | 0 | Bundle targetBundle = getBundle(symbolicName); |
94 | 0 | AssertionUtil.assertNotNull("Bundle", targetBundle); |
95 | 0 | if (BundleUtility.isActive(targetBundle)) { |
96 | |
try { |
97 | 0 | logger.log(UrumaMessageCodes.BUNDLE_STOP, symbolicName); |
98 | 0 | targetBundle.stop(); |
99 | 0 | } catch (BundleException e) { |
100 | 0 | throw new BundleRuntimeException( |
101 | |
UrumaMessageCodes.EXCEPTION_OCCURED_WITH_REASON, e); |
102 | 0 | } |
103 | |
} |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public static void update(final String symbolicName) { |
113 | 0 | AssertionUtil.assertNotEmpty("SymbolicName", symbolicName); |
114 | 0 | Bundle targetBundle = getBundle(symbolicName); |
115 | 0 | AssertionUtil.assertNotNull("Bundle", targetBundle); |
116 | |
try { |
117 | 0 | logger.log(UrumaMessageCodes.BUNDLE_UPDATE, symbolicName); |
118 | 0 | targetBundle.update(); |
119 | 0 | } catch (BundleException e) { |
120 | 0 | throw new BundleRuntimeException( |
121 | |
UrumaMessageCodes.EXCEPTION_OCCURED_WITH_REASON, e); |
122 | 0 | } |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public static String getBundleState(final Bundle bundle) { |
134 | 0 | if (bundle == null) { |
135 | 0 | return NULL_STRING; |
136 | |
} |
137 | |
|
138 | 0 | switch (bundle.getState()) { |
139 | |
case Bundle.ACTIVE: |
140 | 0 | return ACTIVE; |
141 | |
case Bundle.INSTALLED: |
142 | 0 | return INSTALLED; |
143 | |
case Bundle.RESOLVED: |
144 | 0 | return RESOLVED; |
145 | |
case Bundle.STARTING: |
146 | 0 | return STARTING; |
147 | |
case Bundle.STOPPING: |
148 | 0 | return STOPPING; |
149 | |
case Bundle.UNINSTALLED: |
150 | 0 | return UNINSTALLED; |
151 | |
default: |
152 | 0 | return NULL_STRING; |
153 | |
} |
154 | |
|
155 | |
} |
156 | |
} |