|
Lines 15-42
Link Here
|
| 15 |
|
15 |
|
| 16 |
package org.eclipse.gemini.blueprint.extender.internal.activator; |
16 |
package org.eclipse.gemini.blueprint.extender.internal.activator; |
| 17 |
|
17 |
|
| 18 |
import java.util.Map; |
|
|
| 19 |
import java.util.WeakHashMap; |
| 20 |
|
| 21 |
import org.apache.commons.logging.Log; |
18 |
import org.apache.commons.logging.Log; |
| 22 |
import org.apache.commons.logging.LogFactory; |
19 |
import org.apache.commons.logging.LogFactory; |
| 23 |
import org.osgi.framework.Bundle; |
20 |
import org.eclipse.gemini.blueprint.extender.OsgiApplicationContextCreator; |
| 24 |
import org.osgi.framework.BundleActivator; |
21 |
import org.eclipse.gemini.blueprint.extender.internal.activator.listeners.BaseListener; |
| 25 |
import org.osgi.framework.BundleContext; |
|
|
| 26 |
import org.osgi.framework.BundleEvent; |
| 27 |
import org.osgi.framework.SynchronousBundleListener; |
| 28 |
import org.osgi.framework.Version; |
| 29 |
import org.springframework.beans.BeanUtils; |
| 30 |
import org.springframework.beans.CachedIntrospectionResults; |
| 31 |
import org.eclipse.gemini.blueprint.context.event.OsgiBundleApplicationContextEventMulticaster; |
| 32 |
import org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration; |
22 |
import org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration; |
| 33 |
import org.eclipse.gemini.blueprint.extender.internal.support.NamespaceManager; |
23 |
import org.eclipse.gemini.blueprint.extender.support.DefaultOsgiApplicationContextCreator; |
| 34 |
import org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils; |
24 |
import org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils; |
| 35 |
import org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean; |
|
|
| 36 |
import org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceCollectionProxyFactoryBean; |
| 37 |
import org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceProxyFactoryBean; |
| 38 |
import org.eclipse.gemini.blueprint.util.OsgiBundleUtils; |
25 |
import org.eclipse.gemini.blueprint.util.OsgiBundleUtils; |
| 39 |
import org.eclipse.gemini.blueprint.util.OsgiStringUtils; |
26 |
import org.eclipse.gemini.blueprint.util.OsgiStringUtils; |
|
|
27 |
import org.osgi.framework.*; |
| 40 |
|
28 |
|
| 41 |
/** |
29 |
/** |
| 42 |
* Osgi Extender that bootstraps 'Spring powered bundles'. |
30 |
* Osgi Extender that bootstraps 'Spring powered bundles'. |
|
Lines 80-202
import org.eclipse.gemini.blueprint.util.OsgiStringUtils;
Link Here
|
| 80 |
*/ |
68 |
*/ |
| 81 |
public class ContextLoaderListener implements BundleActivator { |
69 |
public class ContextLoaderListener implements BundleActivator { |
| 82 |
|
70 |
|
| 83 |
/** |
71 |
/** |
| 84 |
* Common base class for {@link ContextLoaderListener} listeners. |
|
|
| 85 |
* |
| 86 |
* @author Costin Leau |
| 87 |
*/ |
| 88 |
private abstract class BaseListener implements SynchronousBundleListener { |
| 89 |
|
| 90 |
static final int LAZY_ACTIVATION_EVENT_TYPE = 0x00000200; |
| 91 |
|
| 92 |
protected final Log log = LogFactory.getLog(getClass()); |
| 93 |
|
| 94 |
/** |
| 95 |
* common cache used for tracking down bundles started lazily so they don't get processed twice (once when |
| 96 |
* started lazy, once when started fully) |
| 97 |
*/ |
| 98 |
protected Map<Bundle, Object> lazyBundleCache = new WeakHashMap<Bundle, Object>(); |
| 99 |
/** dummy value for the bundle cache */ |
| 100 |
private final Object VALUE = new Object(); |
| 101 |
|
| 102 |
// caches the bundle |
| 103 |
protected void push(Bundle bundle) { |
| 104 |
synchronized (lazyBundleCache) { |
| 105 |
lazyBundleCache.put(bundle, VALUE); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
// checks the presence of the bundle as well as removing it |
| 110 |
protected boolean pop(Bundle bundle) { |
| 111 |
synchronized (lazyBundleCache) { |
| 112 |
return (lazyBundleCache.remove(bundle) != null); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* A bundle has been started, stopped, resolved, or unresolved. This method is a synchronous callback, do not do |
| 118 |
* any long-running work in this thread. |
| 119 |
* |
| 120 |
* @see org.osgi.framework.SynchronousBundleListener#bundleChanged |
| 121 |
*/ |
| 122 |
public void bundleChanged(BundleEvent event) { |
| 123 |
|
| 124 |
boolean trace = log.isTraceEnabled(); |
| 125 |
|
| 126 |
// check if the listener is still alive |
| 127 |
if (isClosed) { |
| 128 |
if (trace) |
| 129 |
log.trace("Listener is closed; events are being ignored"); |
| 130 |
return; |
| 131 |
} |
| 132 |
if (trace) { |
| 133 |
log.trace("Processing bundle event [" + OsgiStringUtils.nullSafeToString(event) + "] for bundle [" |
| 134 |
+ OsgiStringUtils.nullSafeSymbolicName(event.getBundle()) + "]"); |
| 135 |
} |
| 136 |
try { |
| 137 |
handleEvent(event); |
| 138 |
} catch (Exception ex) { |
| 139 |
/* log exceptions before swallowing */ |
| 140 |
log.warn("Got exception while handling event " + event, ex); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
protected abstract void handleEvent(BundleEvent event); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Bundle listener used for detecting namespace handler/resolvers. Exists as a separate listener so that it can be |
| 149 |
* registered early to avoid race conditions with bundles in INSTALLING state but still to avoid premature context |
| 150 |
* creation before the Spring {@link ContextLoaderListener} is not fully initialized. |
| 151 |
* |
| 152 |
* @author Costin Leau |
| 153 |
*/ |
| 154 |
private class NamespaceBundleLister extends BaseListener { |
| 155 |
|
| 156 |
private final boolean resolved; |
| 157 |
|
| 158 |
NamespaceBundleLister(boolean resolvedBundles) { |
| 159 |
this.resolved = resolvedBundles; |
| 160 |
} |
| 161 |
|
| 162 |
protected void handleEvent(BundleEvent event) { |
| 163 |
Bundle bundle = event.getBundle(); |
| 164 |
|
| 165 |
switch (event.getType()) { |
| 166 |
|
| 167 |
case BundleEvent.RESOLVED: |
| 168 |
if (resolved) { |
| 169 |
maybeAddNamespaceHandlerFor(bundle, false); |
| 170 |
} |
| 171 |
break; |
| 172 |
|
| 173 |
case LAZY_ACTIVATION_EVENT_TYPE: { |
| 174 |
if (!resolved) { |
| 175 |
push(bundle); |
| 176 |
maybeAddNamespaceHandlerFor(bundle, true); |
| 177 |
} |
| 178 |
break; |
| 179 |
} |
| 180 |
case BundleEvent.STARTED: { |
| 181 |
if (!resolved) { |
| 182 |
if (!pop(bundle)) { |
| 183 |
maybeAddNamespaceHandlerFor(bundle, false); |
| 184 |
} |
| 185 |
} |
| 186 |
break; |
| 187 |
} |
| 188 |
case BundleEvent.STOPPED: { |
| 189 |
pop(bundle); |
| 190 |
maybeRemoveNameSpaceHandlerFor(bundle); |
| 191 |
break; |
| 192 |
} |
| 193 |
default: |
| 194 |
break; |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Bundle listener used for context creation/destruction. |
72 |
* Bundle listener used for context creation/destruction. |
| 201 |
*/ |
73 |
*/ |
| 202 |
private class ContextBundleListener extends BaseListener { |
74 |
private class ContextBundleListener extends BaseListener { |
|
Lines 205-218
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 205 |
|
77 |
|
| 206 |
Bundle bundle = event.getBundle(); |
78 |
Bundle bundle = event.getBundle(); |
| 207 |
|
79 |
|
| 208 |
// ignore current bundle for context creation |
80 |
// ignore current bundle for context creation |
| 209 |
if (bundle.getBundleId() == bundleId) { |
81 |
if (bundle.getBundleId() == bundleId) { |
| 210 |
return; |
82 |
return; |
| 211 |
} |
83 |
} |
| 212 |
|
84 |
|
| 213 |
switch (event.getType()) { |
85 |
switch (event.getType()) { |
| 214 |
case LAZY_ACTIVATION_EVENT_TYPE: { |
86 |
case LAZY_ACTIVATION_EVENT_TYPE: { |
| 215 |
// activate bundle |
87 |
// activate bundle |
| 216 |
try { |
88 |
try { |
| 217 |
bundle.loadClass("org.osgi.service.blueprint.container.BlueprintContainer"); |
89 |
bundle.loadClass("org.osgi.service.blueprint.container.BlueprintContainer"); |
| 218 |
} catch (Exception ex) { |
90 |
} catch (Exception ex) { |
|
Lines 228-235
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 228 |
if (log.isDebugEnabled()) { |
100 |
if (log.isDebugEnabled()) { |
| 229 |
log.debug("System bundle stopping"); |
101 |
log.debug("System bundle stopping"); |
| 230 |
} |
102 |
} |
| 231 |
// System bundle is shutting down; Special handling for |
103 |
// System bundle is shutting down; Special handling for |
| 232 |
// framework shutdown |
104 |
// framework shutdown |
| 233 |
shutdown(); |
105 |
shutdown(); |
| 234 |
} else { |
106 |
} else { |
| 235 |
lifecycleManager.maybeCloseApplicationContextFor(bundle); |
107 |
lifecycleManager.maybeCloseApplicationContextFor(bundle); |
|
Lines 244-266
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 244 |
|
116 |
|
| 245 |
protected final Log log = LogFactory.getLog(getClass()); |
117 |
protected final Log log = LogFactory.getLog(getClass()); |
| 246 |
|
118 |
|
| 247 |
/** extender bundle id */ |
119 |
private ExtenderConfiguration extenderConfiguration; |
| 248 |
private long bundleId; |
120 |
private VersionMatcher versionMatcher; |
| 249 |
|
121 |
private Version extenderVersion; |
| 250 |
/** extender configuration */ |
|
|
| 251 |
private ExtenderConfiguration extenderConfiguration; |
| 252 |
|
122 |
|
| 253 |
/** Spring namespace/resolver manager */ |
123 |
/** extender bundle id */ |
| 254 |
private NamespaceManager nsManager; |
124 |
private long bundleId; |
| 255 |
|
125 |
|
| 256 |
/** The bundle's context */ |
126 |
/** The bundle's context */ |
| 257 |
private BundleContext bundleContext; |
127 |
private BundleContext bundleContext; |
| 258 |
|
128 |
|
| 259 |
/** Bundle listener interested in context creation */ |
129 |
/** Bundle listener interested in context creation */ |
| 260 |
private SynchronousBundleListener contextListener; |
130 |
private BaseListener contextListener; |
| 261 |
|
|
|
| 262 |
/** Bundle listener interested in namespace resolvers/parsers discovery */ |
| 263 |
private SynchronousBundleListener nsListener; |
| 264 |
|
131 |
|
| 265 |
/** |
132 |
/** |
| 266 |
* Monitor used for dealing with the bundle activator and synchronous bundle threads |
133 |
* Monitor used for dealing with the bundle activator and synchronous bundle threads |
|
Lines 272-331
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 272 |
*/ |
139 |
*/ |
| 273 |
private volatile boolean isClosed = false; |
140 |
private volatile boolean isClosed = false; |
| 274 |
|
141 |
|
| 275 |
/** This extender version */ |
|
|
| 276 |
private Version extenderVersion; |
| 277 |
|
| 278 |
private volatile OsgiBundleApplicationContextEventMulticaster multicaster; |
| 279 |
|
| 280 |
private volatile LifecycleManager lifecycleManager; |
142 |
private volatile LifecycleManager lifecycleManager; |
| 281 |
private volatile VersionMatcher versionMatcher; |
|
|
| 282 |
private volatile OsgiContextProcessor processor; |
143 |
private volatile OsgiContextProcessor processor; |
| 283 |
private volatile ListListenerAdapter osgiListeners; |
|
|
| 284 |
|
144 |
|
| 285 |
/** |
145 |
public ContextLoaderListener(ExtenderConfiguration extenderConfiguration) { |
|
|
146 |
this.extenderConfiguration = extenderConfiguration; |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 286 |
* <p/> Called by OSGi when this bundle is started. Finds all previously resolved bundles and adds namespace |
150 |
* <p/> Called by OSGi when this bundle is started. Finds all previously resolved bundles and adds namespace |
| 287 |
* handlers for them if necessary. </p> <p/> Creates application contexts for bundles started before the extender |
151 |
* handlers for them if necessary. </p> <p/> Creates application contexts for bundles started before the extender |
| 288 |
* was started. </p> <p/> Registers a namespace/entity resolving service for use by web app contexts. </p> |
152 |
* was started. </p> <p/> Registers a namespace/entity resolving service for use by web app contexts. </p> |
| 289 |
* |
153 |
* |
| 290 |
* @see org.osgi.framework.BundleActivator#start |
154 |
* @see org.osgi.framework.BundleActivator#start |
| 291 |
*/ |
155 |
*/ |
| 292 |
public void start(BundleContext context) throws Exception { |
156 |
public void start(BundleContext extenderBundleContext) throws Exception { |
| 293 |
|
157 |
|
| 294 |
this.bundleContext = context; |
158 |
this.bundleContext = extenderBundleContext; |
| 295 |
this.bundleId = context.getBundle().getBundleId(); |
159 |
this.bundleId = extenderBundleContext.getBundle().getBundleId(); |
| 296 |
|
160 |
this.extenderVersion = OsgiBundleUtils.getBundleVersion(extenderBundleContext.getBundle()); |
| 297 |
this.extenderVersion = OsgiBundleUtils.getBundleVersion(context.getBundle()); |
161 |
this.versionMatcher = new DefaultVersionMatcher(getManagedBundleExtenderVersionHeader(), extenderVersion); |
| 298 |
log.info("Starting [" + bundleContext.getBundle().getSymbolicName() + "] bundle v.[" + extenderVersion + "]"); |
162 |
this.processor = createContextProcessor(); |
| 299 |
versionMatcher = new DefaultVersionMatcher(getManagedBundleExtenderVersionHeader(), extenderVersion); |
163 |
|
| 300 |
processor = createContextProcessor(); |
164 |
// initialize the configuration once namespace handlers have been detected |
| 301 |
|
165 |
this.lifecycleManager = |
| 302 |
// init cache (to prevent ad-hoc Java Bean discovery on lazy bundles) |
166 |
new LifecycleManager( |
| 303 |
initJavaBeansCache(); |
167 |
this.extenderConfiguration, |
| 304 |
|
168 |
getVersionMatcher(), |
| 305 |
// Step 1 : discover existing namespaces (in case there are fragments with custom XML definitions) |
169 |
createContextConfigFactory(), |
| 306 |
nsManager = new NamespaceManager(context); |
170 |
getOsgiApplicationContextCreator(), |
| 307 |
initNamespaceHandlers(bundleContext); |
171 |
this.processor, |
| 308 |
|
172 |
getTypeCompatibilityChecker(), |
| 309 |
// Step 2: initialize the extender configuration |
173 |
bundleContext); |
| 310 |
extenderConfiguration = initExtenderConfiguration(bundleContext); |
174 |
|
| 311 |
|
175 |
// Step 3: discover the bundles that are started |
| 312 |
// init the OSGi event dispatch/listening system |
176 |
// and require context creation |
| 313 |
initListenerService(); |
|
|
| 314 |
|
| 315 |
// initialize the configuration once namespace handlers have been detected |
| 316 |
lifecycleManager = |
| 317 |
new LifecycleManager(extenderConfiguration, versionMatcher, createContextConfigFactory(), |
| 318 |
this.processor, getTypeCompatibilityChecker(), bundleContext); |
| 319 |
|
| 320 |
// Step 3: discover the bundles that are started |
| 321 |
// and require context creation |
| 322 |
initStartedBundles(bundleContext); |
177 |
initStartedBundles(bundleContext); |
| 323 |
} |
178 |
} |
| 324 |
|
179 |
|
| 325 |
protected ExtenderConfiguration initExtenderConfiguration(BundleContext bundleContext) { |
|
|
| 326 |
return new ExtenderConfiguration(bundleContext, log); |
| 327 |
} |
| 328 |
|
| 329 |
protected OsgiContextProcessor createContextProcessor() { |
180 |
protected OsgiContextProcessor createContextProcessor() { |
| 330 |
return new NoOpOsgiContextProcessor(); |
181 |
return new NoOpOsgiContextProcessor(); |
| 331 |
} |
182 |
} |
|
Lines 334-379
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 334 |
return null; |
185 |
return null; |
| 335 |
} |
186 |
} |
| 336 |
|
187 |
|
| 337 |
protected String getManagedBundleExtenderVersionHeader() { |
|
|
| 338 |
return ConfigUtils.EXTENDER_VERSION; |
| 339 |
} |
| 340 |
|
| 341 |
protected void initNamespaceHandlers(BundleContext context) { |
| 342 |
nsManager = new NamespaceManager(context); |
| 343 |
|
| 344 |
// register listener first to make sure any bundles in INSTALLED state |
| 345 |
// are not lost |
| 346 |
|
| 347 |
// if the property is defined and true, consider bundles in STARTED/LAZY-INIT state, otherwise use RESOLVED |
| 348 |
boolean nsResolved = !Boolean.getBoolean("org.eclipse.gemini.blueprint.ns.bundles.started"); |
| 349 |
nsListener = new NamespaceBundleLister(nsResolved); |
| 350 |
context.addBundleListener(nsListener); |
| 351 |
|
| 352 |
Bundle[] previousBundles = context.getBundles(); |
| 353 |
|
| 354 |
for (Bundle bundle : previousBundles) { |
| 355 |
// special handling for uber bundle being restarted |
| 356 |
if ((nsResolved && OsgiBundleUtils.isBundleResolved(bundle)) || (!nsResolved && OsgiBundleUtils.isBundleActive(bundle)) || bundleId == bundle.getBundleId()) { |
| 357 |
maybeAddNamespaceHandlerFor(bundle, false); |
| 358 |
} else if (OsgiBundleUtils.isBundleLazyActivated(bundle)) { |
| 359 |
maybeAddNamespaceHandlerFor(bundle, true); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
// discovery finished, publish the resolvers/parsers in the OSGi space |
| 364 |
nsManager.afterPropertiesSet(); |
| 365 |
} |
| 366 |
|
| 367 |
protected void initStartedBundles(BundleContext bundleContext) { |
188 |
protected void initStartedBundles(BundleContext bundleContext) { |
| 368 |
// register the context creation listener |
189 |
// register the context creation listener |
| 369 |
contextListener = new ContextBundleListener(); |
190 |
contextListener = new ContextBundleListener(); |
| 370 |
// listen to any changes in bundles |
191 |
// listen to any changes in bundles |
| 371 |
bundleContext.addBundleListener(contextListener); |
192 |
bundleContext.addBundleListener(contextListener); |
| 372 |
// get the bundles again to get an updated view |
193 |
// get the bundles again to get an updated view |
| 373 |
Bundle[] previousBundles = bundleContext.getBundles(); |
194 |
Bundle[] previousBundles = bundleContext.getBundles(); |
| 374 |
|
195 |
|
| 375 |
// Instantiate all previously resolved bundles which are Spring |
196 |
// Instantiate all previously resolved bundles which are Spring |
| 376 |
// powered |
197 |
// powered |
| 377 |
for (int i = 0; i < previousBundles.length; i++) { |
198 |
for (int i = 0; i < previousBundles.length; i++) { |
| 378 |
if (OsgiBundleUtils.isBundleActive(previousBundles[i])) { |
199 |
if (OsgiBundleUtils.isBundleActive(previousBundles[i])) { |
| 379 |
try { |
200 |
try { |
|
Lines 403-507
public class ContextLoaderListener implements BundleActivator {
Link Here
|
| 403 |
*/ |
224 |
*/ |
| 404 |
protected void shutdown() { |
225 |
protected void shutdown() { |
| 405 |
synchronized (monitor) { |
226 |
synchronized (monitor) { |
| 406 |
// if already closed, bail out |
227 |
// if already closed, bail out |
| 407 |
if (isClosed) |
228 |
if (isClosed) |
| 408 |
return; |
229 |
return; |
| 409 |
else |
230 |
else |
| 410 |
isClosed = true; |
231 |
isClosed = true; |
| 411 |
} |
232 |
} |
| 412 |
log.info("Stopping [" + bundleContext.getBundle().getSymbolicName() + "] bundle v.[" + extenderVersion + "]"); |
|
|
| 413 |
|
233 |
|
| 414 |
destroyJavaBeansCache(); |
234 |
this.contextListener.close(); |
| 415 |
|
235 |
|
| 416 |
// remove the bundle listeners (we are closing down) |
236 |
// remove the bundle listeners (we are closing down) |
| 417 |
if (contextListener != null) { |
237 |
if (contextListener != null) { |
| 418 |
bundleContext.removeBundleListener(contextListener); |
238 |
bundleContext.removeBundleListener(contextListener); |
| 419 |
contextListener = null; |
239 |
contextListener = null; |
| 420 |
} |
240 |
} |
| 421 |
|
241 |
|
| 422 |
if (nsListener != null) { |
242 |
// close managed bundles |
| 423 |
bundleContext.removeBundleListener(nsListener); |
|
|
| 424 |
nsListener = null; |
| 425 |
} |
| 426 |
|
| 427 |
// close managed bundles |
| 428 |
lifecycleManager.destroy(); |
243 |
lifecycleManager.destroy(); |
| 429 |
// clear the namespace registry |
|
|
| 430 |
nsManager.destroy(); |
| 431 |
|
| 432 |
// release multicaster |
| 433 |
if (multicaster != null) { |
| 434 |
multicaster.removeAllListeners(); |
| 435 |
multicaster = null; |
| 436 |
} |
| 437 |
// release listeners |
| 438 |
osgiListeners.destroy(); |
| 439 |
osgiListeners = null; |
| 440 |
|
| 441 |
extenderConfiguration.destroy(); |
| 442 |
} |
| 443 |
|
| 444 |
private void initJavaBeansCache() { |
| 445 |
Class<?>[] classes = |
| 446 |
new Class<?>[] { OsgiServiceFactoryBean.class, OsgiServiceProxyFactoryBean.class, |
| 447 |
OsgiServiceCollectionProxyFactoryBean.class }; |
| 448 |
|
| 449 |
CachedIntrospectionResults.acceptClassLoader(OsgiStringUtils.class.getClassLoader()); |
| 450 |
|
| 451 |
for (Class<?> clazz : classes) { |
| 452 |
BeanUtils.getPropertyDescriptors(clazz); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
private void destroyJavaBeansCache() { |
| 457 |
CachedIntrospectionResults.clearClassLoader(OsgiStringUtils.class.getClassLoader()); |
| 458 |
} |
| 459 |
|
| 460 |
protected void maybeAddNamespaceHandlerFor(Bundle bundle, boolean isLazy) { |
| 461 |
if (handlerBundleMatchesExtenderVersion(bundle)) |
| 462 |
nsManager.maybeAddNamespaceHandlerFor(bundle, isLazy); |
| 463 |
} |
| 464 |
|
| 465 |
protected void maybeRemoveNameSpaceHandlerFor(Bundle bundle) { |
| 466 |
if (handlerBundleMatchesExtenderVersion(bundle)) |
| 467 |
nsManager.maybeRemoveNameSpaceHandlerFor(bundle); |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Utility method that does extender range versioning and approapriate |
| 472 |
* |
| 473 |
* logging. |
| 474 |
* |
| 475 |
* @param bundle |
| 476 |
*/ |
| 477 |
private boolean handlerBundleMatchesExtenderVersion(Bundle bundle) { |
| 478 |
if (!versionMatcher.matchVersion(bundle)) { |
| 479 |
if (log.isDebugEnabled()) |
| 480 |
log.debug("Ignoring handler bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) |
| 481 |
+ "] due to mismatch in expected extender version"); |
| 482 |
return false; |
| 483 |
} |
| 484 |
return true; |
| 485 |
} |
244 |
} |
| 486 |
|
245 |
|
| 487 |
protected ApplicationContextConfigurationFactory createContextConfigFactory() { |
246 |
protected ApplicationContextConfigurationFactory createContextConfigFactory() { |
| 488 |
return new DefaultApplicationContextConfigurationFactory(); |
247 |
return new DefaultApplicationContextConfigurationFactory(); |
| 489 |
} |
248 |
} |
| 490 |
|
249 |
|
| 491 |
protected void initListenerService() { |
250 |
public VersionMatcher getVersionMatcher() { |
| 492 |
multicaster = extenderConfiguration.getEventMulticaster(); |
251 |
return versionMatcher; |
| 493 |
|
252 |
} |
| 494 |
addApplicationListener(multicaster); |
253 |
|
| 495 |
multicaster.addApplicationListener(extenderConfiguration.getContextEventListener()); |
254 |
protected String getManagedBundleExtenderVersionHeader() { |
| 496 |
|
255 |
return ConfigUtils.EXTENDER_VERSION; |
| 497 |
if (log.isDebugEnabled()) |
256 |
} |
| 498 |
log.debug("Initialization of OSGi listeners service completed..."); |
257 |
|
| 499 |
} |
258 |
protected OsgiApplicationContextCreator getOsgiApplicationContextCreator() { |
| 500 |
|
259 |
OsgiApplicationContextCreator creator = this.extenderConfiguration.getContextCreator(); |
| 501 |
protected void addApplicationListener(OsgiBundleApplicationContextEventMulticaster multicaster) { |
260 |
if (creator == null) { |
| 502 |
osgiListeners = new ListListenerAdapter(bundleContext); |
261 |
creator = createDefaultOsgiApplicationContextCreator(); |
| 503 |
osgiListeners.afterPropertiesSet(); |
262 |
} |
| 504 |
// register the listener that does the dispatching |
263 |
return creator; |
| 505 |
multicaster.addApplicationListener(osgiListeners); |
264 |
} |
| 506 |
} |
265 |
|
|
|
266 |
protected OsgiApplicationContextCreator createDefaultOsgiApplicationContextCreator() { |
| 267 |
return new DefaultOsgiApplicationContextCreator(); |
| 268 |
} |
| 507 |
} |
269 |
} |