You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by sam ” <sk...@gmail.com> on 2012/06/12 22:07:00 UTC
BundleContext or ComponentContext from @Component?
Hey,
I am using maven-scr-plugin to create a Component.
@Component
public class MyComponent {
//@Reference
private ComponentContext context;
private BundleContenxt bundleContext;
}
How can I initialize MyComponent.context ?
In project's pom.xml, I can specify Bundle-Activator:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>
my.Activator
</Bundle-Activator>
....
In my.Activator, I have
@Override
public void start(BundleContext context) throws Exception {
//would like to get reference of MyComponent so that I can pass
context to it.
}
Re: BundleContext or ComponentContext from @Component?
Posted by sam ” <sk...@gmail.com>.
Nice, that works.
Thanks.
On Tue, Jun 12, 2012 at 4:23 PM, Felix Meschberger <fm...@adobe.com>wrote:
> Hi,
>
> Am 12.06.2012 um 16:07 schrieb sam ”:
>
> > Hey,
> >
> > I am using maven-scr-plugin to create a Component.
> > @Component
> > public class MyComponent {
> > //@Reference
> > private ComponentContext context;
> > private BundleContenxt bundleContext;
> > }
> >
> > How can I initialize MyComponent.context ?
>
> You implement a method like this:
>
> @Activate
> private void activate(ComponentContext context) {
> this.context = context;
> }
>
> The activate method is called by the DS runtime when the component is
> activated. And there you get the ComponentContext.
>
> The ComponentContext is not a service and can thus not be provided as a
> service @Reference
>
> >
> > In project's pom.xml, I can specify Bundle-Activator:
> > <plugin>
> > <groupId>org.apache.felix</groupId>
> > <artifactId>maven-bundle-plugin</artifactId>
> > <version>2.3.6</version>
> > <extensions>true</extensions>
> > <configuration>
> > <instructions>
> > <Bundle-Activator>
> > my.Activator
> > </Bundle-Activator>
> > ....
> >
> > In my.Activator, I have
> > @Override
> > public void start(BundleContext context) throws Exception {
> > //would like to get reference of MyComponent so that I can pass
> > context to it.
> > }
>
> This does not work since your bundle activator does not have direct access
> to the component and no access at all to any ComponentContext.
>
> Regards
> Felix
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
Re: BundleContext or ComponentContext from @Component?
Posted by Felix Meschberger <fm...@adobe.com>.
Hi,
Am 12.06.2012 um 16:07 schrieb sam ”:
> Hey,
>
> I am using maven-scr-plugin to create a Component.
> @Component
> public class MyComponent {
> //@Reference
> private ComponentContext context;
> private BundleContenxt bundleContext;
> }
>
> How can I initialize MyComponent.context ?
You implement a method like this:
@Activate
private void activate(ComponentContext context) {
this.context = context;
}
The activate method is called by the DS runtime when the component is activated. And there you get the ComponentContext.
The ComponentContext is not a service and can thus not be provided as a service @Reference
>
> In project's pom.xml, I can specify Bundle-Activator:
> <plugin>
> <groupId>org.apache.felix</groupId>
> <artifactId>maven-bundle-plugin</artifactId>
> <version>2.3.6</version>
> <extensions>true</extensions>
> <configuration>
> <instructions>
> <Bundle-Activator>
> my.Activator
> </Bundle-Activator>
> ....
>
> In my.Activator, I have
> @Override
> public void start(BundleContext context) throws Exception {
> //would like to get reference of MyComponent so that I can pass
> context to it.
> }
This does not work since your bundle activator does not have direct access to the component and no access at all to any ComponentContext.
Regards
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org