Sorry, I overlooked this small detail ;-)
Like Knut mentioned, a possible solution is a JndiServiceFactory.
You can also use object providers (http://jakarta.apache.org/hivemind/hivemind/ObjectProviders.html).


1. Implement a new object provider
2. Register and use the new provider in your hivemind descriptor.

The jndi: prefix tells hivemind to use the new provider for
retrieving an instance.

Bye
Achim


<module id="test" version="1.0.0">

<service-point id="JndiObjectProvider" interface="org.apache.hivemind.service.ObjectProvider">
<invoke-factory>
<construct class="test.JndiObjectProvider">
<set-object property="nameService" value="hivemind.lib.NameService"/>
</construct>
</invoke-factory>
</service-point>


<contribution configuration-id="hivemind.ObjectProviders">
<provider prefix="jndi" service-id="JndiObjectProvider"/>
</contribution>

<service-point id="Consumer" interface="java.lang.Runnable">
<invoke-factory>
<construct class="test.Consumer">
<set-object property="dataSource" value="jndi:java:/comp/env/jdbc/TestDB"/>
</construct>
</invoke-factory>
</service-point>

</module>



package test;

import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.lib.NameLookup;
import org.apache.hivemind.service.ObjectProvider;

public class JndiObjectProvider implements ObjectProvider
{
        private NameLookup _nameLookup;

        public JndiObjectProvider()
        {
                super();
        }

        public Object provideObject(Module contributingModule, Class 
propertyType,
                String locator, Location location)
        {
                return _nameLookup.lookup(locator, Object.class);
        }

        
        public NameLookup getNameLookup()
        {
                return _nameLookup;
        }

        public void setNameLookup(NameLookup Lookup)
        {
                _nameLookup = Lookup;
        }
}



Hugo Palma wrote:
You didn't get the datasource from the jndi tree. I think it has to be through the NameLookup service.

Do you know how to do this ?

Thanks.

Hugo

Achim Huegen wrote:

Ok, let's start with the DataSource declaration from the wiki:

  <service-point id="DefaultDataSource" nterface="javax.sql.DataSource">
        <invoke-factory service-id="hivemind.BuilderFactory">
            <construct class="org.apache.commons.dbcp.BasicDataSource">
               ....
            </construct>
        </invoke-factory>
  </service-point>

To inject this datasource in a service Consumer :

<service-point id="Consumer" interface="...">
  <invoke-factory>
   <construct class="impl.TaskExecutor">
     <set-service service-id="DefaultDataSource" property="dataSource"/>
   </construct>
  </invoke-factory>
</service-point>

Hivemind will call the setter setDefaultDataSource(javax.sql.DataSource) and hand over a reference to the DefaultDataSource.

I hope this helps

Achim



Hugo Palma wrote:

Forgot to say one thing.
I know how to get the data source in java code, after i've declared the NameLookup service in my module. What i want is to get the datasource and inject it as a property of another service. All this in the module descriptor.


Thanks.

Hugo

Hugo Palma wrote:

Hi, i'm having some trouble in grasping all the concepts behind hivemind so i'd like to ask for some help in what i think should be a pretty easy thing to do.
What i want is just to get a data source from the app server jndi tree. I've found an example of getting a data source in the wiki(http://wiki.apache.org/jakarta-hivemind/DatasourceService) and i know i have to use the hivemind.lib.NameLookup service, but i just haven't been able to figure out how. An example of how to do this would be great.



Thanks.

Hugo

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to