Author: davidb
Date: Fri Apr 24 14:53:27 2009
New Revision: 768323
URL: http://svn.apache.org/viewvc?rev=768323&view=rev
Log:
Brought back the SPIActivator that I removed in r765974.
Found out that it was needed after all, although its hard to test automatically
since the system tests don't need it (probably because the Spring-DM system
test framework does some of this already).
Added:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
(with props)
Modified:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
Modified:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java?rev=768323&r1=768322&r2=768323&view=diff
==============================================================================
---
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
(original)
+++
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/AggregatedActivator.java
Fri Apr 24 14:53:27 2009
@@ -102,18 +102,28 @@
}
void startEmbeddedActivators(BundleContext ctx) throws Exception {
- for (String s : getActivators()) {
- try {
- Class<?> clazz = getClass().getClassLoader().loadClass(s);
- Object o = clazz.newInstance();
- if (o instanceof BundleActivator) {
- BundleActivator ba = (BundleActivator) o;
- activators.add(ba);
- ba.start(ctx);
+ ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
+ try {
+
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ for (String s : getActivators()) {
+ try {
+ Class<?> clazz = getClass().getClassLoader().loadClass(s);
+ Object o = clazz.newInstance();
+ if (o instanceof BundleActivator) {
+ BundleActivator ba = (BundleActivator) o;
+ activators.add(ba);
+ ba.start(ctx);
+ }
+ } catch (Throwable th) {
+ th.printStackTrace();
}
- } catch (Throwable th) {
- th.printStackTrace();
}
+
+ SPIActivator sba = new SPIActivator();
+ sba.start(ctx);
+ activators.add(sba);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@@ -123,10 +133,10 @@
}
}
- Collection<String> getActivators() throws IOException {
+ static Collection<String> getActivators() throws IOException {
List<String> bundleActivators = new ArrayList<String>();
- URL url = getClass().getResource(ACTIVATOR_RESOURCE);
+ URL url = AggregatedActivator.class.getResource(ACTIVATOR_RESOURCE);
if (url == null) {
return Collections.emptyList();
}
Added:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java?rev=768323&view=auto
==============================================================================
---
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
(added)
+++
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
Fri Apr 24 14:53:27 2009
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.dosgi.singlebundle;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.servicemix.specs.locator.OsgiLocator;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+import org.springframework.core.io.Resource;
+import org.springframework.osgi.io.OsgiBundleResourcePatternResolver;
+
+public class SPIActivator implements BundleActivator,
SynchronousBundleListener {
+ private ConcurrentMap<Long, Map<String, Callable<Class>>> factories = new
ConcurrentHashMap<Long, Map<String, Callable<Class>>>();
+
+ public synchronized void start(BundleContext bundleContext) throws
Exception {
+ register(bundleContext.getBundle());
+ }
+
+ public synchronized void stop(BundleContext bundleContext) throws
Exception {
+ while (!factories.isEmpty()) {
+ unregister(factories.keySet().iterator().next());
+ }
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if (event.getType() == BundleEvent.RESOLVED) {
+ register(event.getBundle());
+ } else if (event.getType() == BundleEvent.UNRESOLVED) {
+ unregister(event.getBundle().getBundleId());
+ }
+ }
+
+ protected void register(final Bundle bundle) {
+ Map<String, Callable<Class>> map = factories.get(bundle.getBundleId());
+
+ Vector<URL> v = new Vector<URL>();
+ try {
+ Resource[] resources = new
OsgiBundleResourcePatternResolver(bundle).getResources("classpath*:META-INF/services/*");
+ for (Resource r : resources) {
+ v.add(r.getURL());
+ }
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+
+ Enumeration<URL> e = v.elements();
+ if (e != null) {
+ while (e.hasMoreElements()) {
+ final URL u = (URL) e.nextElement();
+ final String url = u.toString();
+ if (url.endsWith("/")) {
+ continue;
+ }
+ final String factoryId = url.substring(url.lastIndexOf("/") +
1);
+ if (map == null) {
+ map = new HashMap<String, Callable<Class>>();
+ factories.put(bundle.getBundleId(), map);
+ }
+ map.put(factoryId, new Callable<Class>() {
+ public Class call() throws Exception {
+ BufferedReader br = new BufferedReader(new
InputStreamReader(u.openStream(), "UTF-8"));
+ String factoryClassName = br.readLine();
+ br.close();
+ return bundle.loadClass(factoryClassName);
+ }
+ });
+ }
+ }
+ if (map != null) {
+ for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+ OsgiLocator.register(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ protected void unregister(long bundleId) {
+ Map<String, Callable<Class>> map = factories.remove(bundleId);
+ if (map != null) {
+ for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+ OsgiLocator.unregister(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+}
Propchange:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/dosgi/trunk/distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/SPIActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date