You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Massimo Lusetti <ml...@gmail.com> on 2005/12/04 10:47:57 UTC

Working with classes

How should DI from hivemind work when dealing with classes and not
interfaces for service point?

I've to work with classes so refactoring is not an option.

I got a FruitBowl class which has this constructors:
   public FruitBowl()
    {
    }

    public FruitBowl(Fruit fruit[])
    {
        for (int i = 0; i < fruit.length; i++) {
            bowl.put(fruit[i].getClass(), fruit[i]);
        }
    }

    public FruitBowl(Apple apple, Banana banana)
    {
        bowl.put(apple.getClass(), apple);
        bowl.put(banana.getClass(), banana);
    }

And this getters/setters methods:
   public boolean hasApple()
    {
        return bowl.get(Apple.class) != null;
    }

    public boolean hasBanana()
    {
        return bowl.get(Banana.class) != null;
    }

    public Apple getApple()
    {
        return (Apple) bowl.get(Apple.class);
    }

    public void setApple(Apple apple)
    {
        bowl.put(apple.getClass(), apple);
    }

    public Banana getBanana()
    {
        return (Banana) bowl.get(Banana.class);
    }

    public void setBanana(Banana banana)
    {
        bowl.put(banana.getClass(), banana);
    }


Have Apple and Banana classes without a constructor and a hivemodule like this:
<module id="tck" version="1.0.0" package="org.mule.tck.testmodels.fruit">
    <service-point id="Apple" interface="Apple">
     <invoke-factory>
      <construct class="Apple"/>
     </invoke-factory>
    </service-point>
    <service-point id="Banana" interface="Banana">
     <invoke-factory>
      <construct class="Banana"/>
     </invoke-factory>
    </service-point>
    <service-point id="FruitBowl" interface="FruitBowl">
      <invoke-factory>
        <construct class="FruitBowl">
         <service>Apple</service>
         <service>Banana</service>
        </construct>
      </invoke-factory>
    </service-point>
</module>

I've already tried different ways of injecting deps like construct
based with service and object nested element of <construct> without
any luck

As you can see this is a test case to make pass the Mule ESB test
suite to add support for HiveMind container context (to use HiveMind
services within Mule descriptors)
Inside the test it fails when assertTrue(fruitBowl.hasApple()).

The code is there, just need help to pass this test.

Regards
--
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: Working with classes

Posted by Massimo Lusetti <ml...@gmail.com>.
On 12/4/05, Achim Hügen <ac...@gmx.de> wrote:

> I assume that the map access doesn't work because
[..]
> Hope this helps
> Achim

You were right and, yep, this helps me a lot.
Hope to get Mule HiveMind support out soon

--
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: Working with classes

Posted by Massimo Lusetti <ml...@gmail.com>.
On 12/4/05, Achim Hügen <ac...@gmx.de> wrote:

> I assume that the map access doesn't work because
> it uses different keys for storing and retrieval.
> Hivemind doesn't hand in instances of the Apple and Banana
> class in the constructor, but proxies that are descendants of
> the original classes.
> That means, that apple.getClass() is not equivalant to Apple.class.

Well, haven't thought about that, thanks Achim

> Try to verify this by adding a
>
> System.out.println(apple.getClass().getName()) to the constructor.
>
> and solve it by using:
>
> bowl.put(Apple.class, apple);
> bowl.put(Banana.class, banana);

Its not an option to modify that source (even if actually that's more
precise), I've to look elsewhere.

I'll try and report back, thanks again.

--
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: Working with classes

Posted by Achim Hügen <ac...@gmx.de>.
I assume that the map access doesn't work because
it uses different keys for storing and retrieval.
Hivemind doesn't hand in instances of the Apple and Banana
class in the constructor, but proxies that are descendants of
the original classes.
That means, that apple.getClass() is not equivalant to Apple.class.

Try to verify this by adding a

System.out.println(apple.getClass().getName()) to the constructor.

and solve it by using:

bowl.put(Apple.class, apple);
bowl.put(Banana.class, banana);


Hope this helps
Achim


Am Sun, 04 Dec 2005 10:47:57 +0100 schrieb Massimo Lusetti  
<ml...@gmail.com>:

> How should DI from hivemind work when dealing with classes and not
> interfaces for service point?
>
> I've to work with classes so refactoring is not an option.
>
> I got a FruitBowl class which has this constructors:
>    public FruitBowl()
>     {
>     }
>
>     public FruitBowl(Fruit fruit[])
>     {
>         for (int i = 0; i < fruit.length; i++) {
>             bowl.put(fruit[i].getClass(), fruit[i]);
>         }
>     }
>
>     public FruitBowl(Apple apple, Banana banana)
>     {
>         bowl.put(apple.getClass(), apple);
>         bowl.put(banana.getClass(), banana);
>     }
>
> And this getters/setters methods:
>    public boolean hasApple()
>     {
>         return bowl.get(Apple.class) != null;
>     }
>
>     public boolean hasBanana()
>     {
>         return bowl.get(Banana.class) != null;
>     }
>
>     public Apple getApple()
>     {
>         return (Apple) bowl.get(Apple.class);
>     }
>
>     public void setApple(Apple apple)
>     {
>         bowl.put(apple.getClass(), apple);
>     }
>
>     public Banana getBanana()
>     {
>         return (Banana) bowl.get(Banana.class);
>     }
>
>     public void setBanana(Banana banana)
>     {
>         bowl.put(banana.getClass(), banana);
>     }
>
>
> Have Apple and Banana classes without a constructor and a hivemodule  
> like this:
> <module id="tck" version="1.0.0" package="org.mule.tck.testmodels.fruit">
>     <service-point id="Apple" interface="Apple">
>      <invoke-factory>
>       <construct class="Apple"/>
>      </invoke-factory>
>     </service-point>
>     <service-point id="Banana" interface="Banana">
>      <invoke-factory>
>       <construct class="Banana"/>
>      </invoke-factory>
>     </service-point>
>     <service-point id="FruitBowl" interface="FruitBowl">
>       <invoke-factory>
>         <construct class="FruitBowl">
>          <service>Apple</service>
>          <service>Banana</service>
>         </construct>
>       </invoke-factory>
>     </service-point>
> </module>
>
> I've already tried different ways of injecting deps like construct
> based with service and object nested element of <construct> without
> any luck
>
> As you can see this is a test case to make pass the Mule ESB test
> suite to add support for HiveMind container context (to use HiveMind
> services within Mule descriptors)
> Inside the test it fails when assertTrue(fruitBowl.hasApple()).
>
> The code is there, just need help to pass this test.
>
> Regards
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org