SeamFramework.orgCommunity Documentation
Weld-OSGi allows bean bundles to directly interact with the OSGi service registry by getting a
ServiceRegistry
bean:
@Inject ServiceRegistry registry;
This bean is injectable everywhere into a bean bundle.
It allows to:
Register a service implementation
Obtain a service provider as a Service<T>
Obtain all existing registrations
Obtain a specific set of registrations
Weld-OSGi allows to obtain, by injection into bean bundles, some of the useful objects of the OSGi environment:
The current bundle
@Inject Bundle bundle;
The current bundle context
@Inject BundleContext bundleContext;
The current bundle headers
@Inject @BundleHeaders Map<String,String>metadata;
A specific current bundle header
@Inject @BundleHeader("Bundle-SymbolicName") String symbolicName;
A specific current bundle resource file
@Inject @BundleDataFile("test.txt") File file;
It is possible to precise an external bundle by bundle symbolic name and version(optional)
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") bundle; @Inject @BundleName("com.sample.gui") bundle;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") BundleContext bundleContext;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleHeaders Map<String,String>metadata;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleHeader("Bundle-SymbolicName") String symbolicName;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleDataFile("test.txt") File file;
If
a BundleVersion
annotation is provided without a BundleName
annotation Weld-OSGi
detects the problem and treats it as an error.
Weld-OSGi allows to obtain, by injection into bean bundles, Registration<T>
of a specific
type. A registration object represent all the bindings between a service contract class and its OSGi
ServiceRegistration
.
@Inject Registration<MyService> registrations;
It is possible to filter the obtained bindings by specifying OSGi LDAP properties and filter.
@Inject @AnyQualifier Registration<MyService> qualifiedRegistrations; @Inject @Filter("(&(lang=EN)(country=US))") Registration<MyService> qualifiedRegistrations;
A Registration<T>
allows to:
Iterate over the contained bindings
Select a subset of the bindings using OSGi LDAP properties and filter
Obtain a service provider, as a Service<T>
for the current bindings
Unregister all the services for the current bindings