You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by ga...@apache.org on 2012/04/02 19:55:45 UTC
svn commit: r1308440 - in /geronimo/xbean/trunk/xbean-bundleutils: ./
src/main/java/org/apache/xbean/osgi/bundle/util/
Author: gawor
Date: Mon Apr 2 17:55:44 2012
New Revision: 1308440
URL: http://svn.apache.org/viewvc?rev=1308440&view=rev
Log:
XBEAN-204: Initial OSGi 4.3 updates
Modified:
geronimo/xbean/trunk/xbean-bundleutils/pom.xml
geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java
geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleContext.java
Modified: geronimo/xbean/trunk/xbean-bundleutils/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/pom.xml?rev=1308440&r1=1308439&r2=1308440&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/pom.xml (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/pom.xml Mon Apr 2 17:55:44 2012
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
- <version>4.2.0</version>
+ <version>4.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -72,6 +72,7 @@
<instructions>
<Import-Package>
org.eclipse.*;resolution:=optional,
+ org.osgi.framework.wiring;resolution:=optional,
*
</Import-Package>
</instructions>
Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java?rev=1308440&r1=1308439&r2=1308440&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java Mon Apr 2 17:55:44 2012
@@ -30,6 +30,9 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
@@ -37,6 +40,17 @@ import org.osgi.service.packageadmin.Pac
* @version $Rev$ $Date$
*/
public class BundleUtils {
+
+ private static final boolean isOSGi43 = isOSGi43();
+
+ private static boolean isOSGi43() {
+ try {
+ Class.forName("org.osgi.framework.wiring.BundleWiring");
+ return true;
+ } catch (Throwable e) {
+ return false;
+ }
+ }
/**
* Based on the constant field values, if it is bigger than the RESOLVED status value, the bundle has been resolved by the framework
@@ -202,6 +216,14 @@ public class BundleUtils {
}
public static LinkedHashSet<Bundle> getWiredBundles(Bundle bundle) {
+ if (isOSGi43) {
+ return getWiredBundles43(bundle);
+ } else {
+ return getWiredBundles42(bundle);
+ }
+ }
+
+ private static LinkedHashSet<Bundle> getWiredBundles42(Bundle bundle) {
ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
try {
@@ -210,7 +232,7 @@ public class BundleUtils {
bundle.getBundleContext().ungetService(reference);
}
}
-
+
public static LinkedHashSet<Bundle> getWiredBundles(PackageAdmin packageAdmin, Bundle bundle) {
BundleDescription description = new BundleDescription(bundle.getHeaders());
// handle static wire via Import-Package
@@ -253,4 +275,24 @@ public class BundleUtils {
}
return null;
}
+
+ // OSGi 4.3 API
+
+ private static LinkedHashSet<Bundle> getWiredBundles43(Bundle bundle) {
+ LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>();
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ if (wiring != null) {
+ List<BundleWire> wires;
+ wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
+ for (BundleWire wire : wires) {
+ wiredBundles.add(wire.getProviderWiring().getBundle());
+ }
+ wires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);
+ for (BundleWire wire : wires) {
+ wiredBundles.add(wire.getProviderWiring().getBundle());
+ }
+ }
+ return wiredBundles;
+ }
+
}
Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java?rev=1308440&r1=1308439&r2=1308440&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundle.java Mon Apr 2 17:55:44 2012
@@ -19,6 +19,7 @@
package org.apache.xbean.osgi.bundle.util;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -288,6 +289,18 @@ public class DelegatingBundle implements
bundle.update(arg0);
}
+ public int compareTo(Bundle other) {
+ return bundle.compareTo(other);
+ }
+
+ public <A> A adapt(Class<A> type) {
+ return bundle.adapt(type);
+ }
+
+ public File getDataFile(String filename) {
+ return bundle.getDataFile(filename);
+ }
+
public String toString() {
return "[DelegatingBundle: " + bundles + "]";
}
Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleContext.java?rev=1308440&r1=1308439&r2=1308440&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleContext.java (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/DelegatingBundleContext.java Mon Apr 2 17:55:44 2012
@@ -21,6 +21,7 @@ package org.apache.xbean.osgi.bundle.uti
import java.io.File;
import java.io.InputStream;
+import java.util.Collection;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
@@ -73,11 +74,6 @@ public class DelegatingBundleContext imp
return bundleContext.createFilter(arg0);
}
- public ServiceReference[] getAllServiceReferences(String arg0, String arg1)
- throws InvalidSyntaxException {
- return bundleContext.getAllServiceReferences(arg0, arg1);
- }
-
public Bundle getBundle(long arg0) {
return bundleContext.getBundle(arg0);
}
@@ -94,19 +90,30 @@ public class DelegatingBundleContext imp
return bundleContext.getProperty(arg0);
}
- public Object getService(ServiceReference arg0) {
- return bundleContext.getService(arg0);
+ public <S> S getService(ServiceReference<S> reference) {
+ return bundleContext.getService(reference);
+ }
+
+ public ServiceReference<?> getServiceReference(String clazz) {
+ return bundleContext.getServiceReference(clazz);
}
- public ServiceReference getServiceReference(String arg0) {
- return bundleContext.getServiceReference(arg0);
+ public ServiceReference<?>[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return bundleContext.getServiceReferences(clazz, filter);
}
- public ServiceReference[] getServiceReferences(String arg0, String arg1)
- throws InvalidSyntaxException {
- return bundleContext.getServiceReferences(arg0, arg1);
+ public <S> ServiceReference<S> getServiceReference(Class<S> clazz) {
+ return bundleContext.getServiceReference(clazz);
}
+ public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> clazz, String filter) throws InvalidSyntaxException {
+ return bundleContext.getServiceReferences(clazz, filter);
+ }
+
+ public ServiceReference<?>[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
+ return bundleContext.getAllServiceReferences(clazz, filter);
+ }
+
public Bundle installBundle(String arg0, InputStream arg1) throws BundleException {
return bundleContext.installBundle(arg0, arg1);
}
@@ -115,12 +122,16 @@ public class DelegatingBundleContext imp
return bundleContext.installBundle(arg0);
}
- public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
- return bundleContext.registerService(arg0, arg1, arg2);
+ public ServiceRegistration<?> registerService(String clazz, Object service, Dictionary<String, ?> properties) {
+ return bundleContext.registerService(clazz, service, properties);
}
- public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
- return bundleContext.registerService(arg0, arg1, arg2);
+ public ServiceRegistration<?> registerService(String[] classes, Object service, Dictionary<String, ?> properties) {
+ return bundleContext.registerService(classes, service, properties);
+ }
+
+ public <S> ServiceRegistration<S> registerService(Class<S> clazz, S service, Dictionary<String, ?> properties) {
+ return bundleContext.registerService(clazz, service, properties);
}
public void removeBundleListener(BundleListener arg0) {
@@ -135,8 +146,12 @@ public class DelegatingBundleContext imp
bundleContext.removeServiceListener(arg0);
}
- public boolean ungetService(ServiceReference arg0) {
- return bundleContext.ungetService(arg0);
+ public boolean ungetService(ServiceReference<?> reference) {
+ return bundleContext.ungetService(reference);
+ }
+
+ public Bundle getBundle(String location) {
+ return bundleContext.getBundle(location);
}
}