felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alejandro.E...@miranda.com
Subject iPOJO instances
Date Thu, 03 Apr 2014 17:59:53 GMT
I am having some problems understanding the concept of component 
instanciation. I read 
and I get the analogy to classes and objects but I still have some 
concrete problems and some conceptual problems that I hope someone can 

 I thought I needed to create instances via iPOJO (@Instantiate or 
factories) only for service providers since they never use new because the 
impl is always hidden. However, I have some consumers @Component that I 
instanciate myself (say in a main() method where I call new on them 
directly). I made them @Component because they need to have things 
injected. I was assuming that the ipojo bytecode manipulation would make 
it so that when the objects were constructed, they would have their 
dependencies injected (I'm using mostly method injection with @Bind) but 
it seems that is not the case. Can someone clarify this for me please. Now 
it seems to me that for iPOJO to do any injection at all I need to always 
use one of the iPOJO instantiation techniques. The problem I have is that 
then the constructors I made in the consumer classes are not called

This is a simplified example to illustrate my confusion

public class MyFoo {
        private List<External> externals; //injected
        private Bar bar; //passed via constructor

        public MyFoo(Bar otherBar) {
                bar = otherBar;
                externals = new ArrayList();
        public addExternal(External service) {

So, as can be seen here, I need to have all the providers of interface 
External, but I also need a Bar object that I pass when I construct the 
object using new MyFoo(someBar)

My problem is that if I need to pass a Bar to the constructor then I need 
to use new; but If i use new, iPojo never invokes my injection method. On 
the other hand, if I use iPOJOs instantiation (say I add @Instantiate) 
then the injection does happen but it throws a NPE because the list has 
not been created yet + bar will not be set. I know I can create the list 
inside the injection method, but my question is more conceptual. 

1) How are you supposed to accomplish this (making sure that the 
constructor is invoked)? 
2) How can iPOJO be calling addExternal (which means the object has been 
created) without calling my one and only constructor that creates the 
object? this is very counter-intuitive in standard java
3) Are you just not supposed to use constructors when using iPOJO 
components maybe?

Thanks for any help

Alejandro Endo | Software Designer/Concepteur de logiciels 

Privileged and/or Confidential information may be contained in this
message. If you are not the addressee of this message, you may not
copy, use or deliver this message to anyone. In such event, you
should destroy the message and kindly notify the sender by reply
e-mail. It is understood that opinions or conclusions that do not
relate to the official business of the company are neither given
nor endorsed by the company.
Thank You.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message