Hi,

This scenario is supported out of the box.

Let's imagine a simple component A:
@Component(name="comp-a")
@Provides
class Component1
{
  @Validate
  public void init() {
      System.out.println("Ping from " + getClass());
  }

  public boolean doSomething() {
      System.out.println("I'm doing something cool");
      return true;
  }
}

Let's also imagine a simple component B (in the same bundle):
@Component(name="comp-b")
class Component2
{
   @Requires
   private Component1 cmp;


  @Validate
  public void init() {
      System.out.println("Ping from " + getClass());
      System.out.println(cmp.doSomething());
  }
}

And now, the metadata.xml declaring the instances: 
<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="org.apache.felix.ipojo 
http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd";
xmlns="org.apache.felix.ipojo" xmlns:c="org.apache.felix.ipojo.composite">

    <instance component="comp-a" />
    <instance component="comp-b" />

</ipojo>

If you deploy this bundle, you will see:
Ping from class ipojo.test.org.apache.felix.ipojo.instance.injection.Component1
Ping from class ipojo.test.org.apache.felix.ipojo.instance.injection.Component2
I'm doing something cool
true

So, nothing else should be required. Could you give me more details about your 
case as well as the stack trace.

Regards,

Clement

On 04.10.2011, at 09:57, Benoît Thiébault wrote:

> Hi everyone,
> 
> I'm using iPOJO in my application and I would like to inject a service
> instance in another class of the same bundle.
> 
> Something like this:
> <iPOJO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>       xmlns="org.apache.felix.ipojo"
>       xsi:schemaLocation="org.apache.felix.ipojo
> http://felix.apache.org/ipojo/schemas/CURRENT/core.xsd";>
>       <component classname="org.test.ServiceImpl"
>               name="ServiceImpl" public="true" immediate="true">
>               <callback transition="invalidate" method="terminate" />
>               <provides />
>       </component>
>       <instance component="ServiceImpl" />
>       <component classname="org.test.User"
>               name="User" public="true">
>               <requires field="serviceInstance"/>
>       </component>
>       <instance component="User" />
> </iPOJO>
> 
> Is is supported by iPOJO? Is there a special way to do it?
> 
> I tried it and have a null pointer exception on the instance...
> 
> Kind regards
> 
> Ben
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 

Reply via email to