cm:managed-properties lookup within bundle

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

cm:managed-properties lookup within bundle

Niten Aggarwal

Hi All,

 

Is there any way to access container managed bean inside java class of same bundle directly without giving it as a reference to service? The java class is not a managed bean neither service.

How to access below Foo class inside a class which is not blueprint managed.

 

        <bean id="component-managed" class="org.apache.aries.blueprint.sample.Foo">

               <cm:managed-properties persistent-id="blueprint-sample-managed.component"

                       update-strategy="component-managed" update-method="update" />

        </bean>

 

 

 

 



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: cm:managed-properties lookup within bundle

Brad Johnson
Can you clarify the question a bit? It appears there are two aspects to it and I'm not quite sure what you are after.

The properties are normally defined  outside of the scope of the bean and are available to all beans using the ${{myproperties}} style of reference.  

Is there a particular reason you wouldn't want to just inject the Foo bean into the other bean?  If it isn't declared in the blueprint file then it has to be instantiated by something else. What is instantiating the bean that you want to have access to the Foo bean? It seems like you are trying to make the Foo bean some sort of static registry that other beans can access properties from but I'm not really sure and I've never tried doing it that way as I've never found a need.  Perhaps there is one though. Dunno.

It appears that what you seem to want is to inject all properties into your Foo bean?  I've never tried it but suppose it can be done but the question is, why?  

Perhaps clarify what it is you are trying to accomplish and less on the mechanics of how you are attempting to do with it with the implementation you show.


Brad



On Thu, Oct 20, 2016 at 9:19 AM, Niten Aggarwal <[hidden email]> wrote:

Hi All,

 

Is there any way to access container managed bean inside java class of same bundle directly without giving it as a reference to service? The java class is not a managed bean neither service.

How to access below Foo class inside a class which is not blueprint managed.

 

        <bean id="component-managed" class="org.apache.aries.blueprint.sample.Foo">

               <cm:managed-properties persistent-id="blueprint-sample-managed.component"

                       update-strategy="component-managed" update-method="update" />

        </bean>

 

 

 

 



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

RE: cm:managed-properties lookup within bundle

Niten Aggarwal
I am just trying to understand that any container managed bean can be accessed via referenced service or it can be injected into another bean as property. This part I am clear of which is as per blueprint definition .

My use case is let's say I have some java class which is not container managed. Is it possible to refer container managed bean directly into this class which is in same bundle and defined in blueprint? I want to access some of those container managed properties in this java class. I can also define this java class as bean instance into blueprint as well and inject other bean as property but don't want that.

Just trying to understand that only beans can be referred to each other which are container managed not outside that scope.
________________________________________
From: Brad Johnson [[hidden email]]
Sent: Saturday, October 22, 2016 3:06 PM
To: [hidden email]
Subject: Re: cm:managed-properties lookup within bundle

Can you clarify the question a bit? It appears there are two aspects to it and I'm not quite sure what you are after.

The properties are normally defined  outside of the scope of the bean and are available to all beans using the ${{myproperties}} style of reference.

Is there a particular reason you wouldn't want to just inject the Foo bean into the other bean?  If it isn't declared in the blueprint file then it has to be instantiated by something else. What is instantiating the bean that you want to have access to the Foo bean? It seems like you are trying to make the Foo bean some sort of static registry that other beans can access properties from but I'm not really sure and I've never tried doing it that way as I've never found a need.  Perhaps there is one though. Dunno.

It appears that what you seem to want is to inject all properties into your Foo bean?  I've never tried it but suppose it can be done but the question is, why?

Perhaps clarify what it is you are trying to accomplish and less on the mechanics of how you are attempting to do with it with the implementation you show.


Brad



On Thu, Oct 20, 2016 at 9:19 AM, Niten Aggarwal <[hidden email]<mailto:[hidden email]>> wrote:
Hi All,

Is there any way to access container managed bean inside java class of same bundle directly without giving it as a reference to service? The java class is not a managed bean neither service.
How to access below Foo class inside a class which is not blueprint managed.

        <bean id="component-managed" class="org.apache.aries.blueprint.sample.Foo">
               <cm:managed-properties persistent-id="blueprint-sample-managed.component"
                       update-strategy="component-managed" update-method="update" />
        </bean>






::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.
----------------------------------------------------------------------------------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: cm:managed-properties lookup within bundle

Brad Johnson
That would be a highly unusual use case.  If it isn't container managed then it will be instantiated by one of your blueprint managed  bean classes which will have access to the properties. You obviously could pass the properties to a class via a static and then use it as something like a properties server for your bundle but, again, that is a highly unusual use case.  If you are just learning blueprint and OSGi I'd look at more mainstream use cases.  

I'd focus more on using properties and services/references and then on properly constructing your bundles with Maven ensuring that classes you mean to keep internal to the bundle and unavailable to the world are not listed in the manifest as exported. Check to see that the classes and services you want to export are.  Learn how to test the bundle and its contents.  Those are far more important than learning how to solve an edge case problem.

Are you using this with Camel or stand alone?

Brad

On Sat, Oct 22, 2016 at 8:56 PM, Niten Aggarwal <[hidden email]> wrote:
I am just trying to understand that any container managed bean can be accessed via referenced service or it can be injected into another bean as property. This part I am clear of which is as per blueprint definition .

My use case is let's say I have some java class which is not container managed. Is it possible to refer container managed bean directly into this class which is in same bundle and defined in blueprint? I want to access some of those container managed properties in this java class. I can also define this java class as bean instance into blueprint as well and inject other bean as property but don't want that.

Just trying to understand that only beans can be referred to each other which are container managed not outside that scope.
________________________________________
From: Brad Johnson [[hidden email]]
Sent: Saturday, October 22, 2016 3:06 PM
To: [hidden email]
Subject: Re: cm:managed-properties lookup within bundle

Can you clarify the question a bit? It appears there are two aspects to it and I'm not quite sure what you are after.

The properties are normally defined  outside of the scope of the bean and are available to all beans using the ${{myproperties}} style of reference.

Is there a particular reason you wouldn't want to just inject the Foo bean into the other bean?  If it isn't declared in the blueprint file then it has to be instantiated by something else. What is instantiating the bean that you want to have access to the Foo bean? It seems like you are trying to make the Foo bean some sort of static registry that other beans can access properties from but I'm not really sure and I've never tried doing it that way as I've never found a need.  Perhaps there is one though. Dunno.

It appears that what you seem to want is to inject all properties into your Foo bean?  I've never tried it but suppose it can be done but the question is, why?

Perhaps clarify what it is you are trying to accomplish and less on the mechanics of how you are attempting to do with it with the implementation you show.


Brad



On Thu, Oct 20, 2016 at 9:19 AM, Niten Aggarwal <[hidden email]<mailto:[hidden email]>> wrote:
Hi All,

Is there any way to access container managed bean inside java class of same bundle directly without giving it as a reference to service? The java class is not a managed bean neither service.
How to access below Foo class inside a class which is not blueprint managed.

        <bean id="component-managed" class="org.apache.aries.blueprint.sample.Foo">
               <cm:managed-properties persistent-id="blueprint-sample-managed.component"
                       update-strategy="component-managed" update-method="update" />
        </bean>






::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and other defects.
----------------------------------------------------------------------------------------------------------------------------------------------------