aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Service Locator Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Service Locator Pattern" Watch "Service Locator Pattern" New topic
Author

Service Locator Pattern

Sherryl Philip
Greenhorn

Joined: Jul 02, 2004
Posts: 20
Hi,
I'm completely to the Service Locator Pattern. I'm aware of the need.
Now, I need to know what is the String to be passed to call the method getDataSource(String datasourceName) of the Service Locator class.

Please do help me.

Thanks.

Regards,
Sherryl
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Typically you'd pass in the JNDI name, but you could enhance the Service Locator to have an internal mapping from a constant public name like "MyDataSource" to the actual JNDI name used to look up the data source. This mapping could be stored in a configuration file so clients would not need to be changed when changing the JNDI name.
[ January 28, 2005: Message edited by: David Harkness ]
Sherryl Philip
Greenhorn

Joined: Jul 02, 2004
Posts: 20
Hi,

Could please tell me the "MyDataSource" mapping should be specified in which configuration file. Is the struts-congif.xml file , as i use the Struts framework?
Or is it the oracle-ds.xml file, as I use Oracle as my database?

Thanks again.

regards,
Sherryl
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Definitely not struts. If the oracle-ds.xml file is the configuration for your J2EE container (application server like WebLogic, WebSphere, JBoss, etc), then yes. Are you using OC4J (I think that's the name of Oracle's app server)?
Sherryl Philip
Greenhorn

Joined: Jul 02, 2004
Posts: 20
Hi,
My applocation server is JBoss.
How does the code go and see that it has to read the datasource from oracle-ds.xml file in the client? I've given tried as what you have adviced me to do. And it does work out.

This is the code of the method of ServiceLocator class:


And finally I call the method in the client like this :


When the client tries to call the method - I get the folllowing error


javax.naming.NameNotFoundException: OracleDS not bound
at servicelocator.ServiceLocator.getDataSource(ServiceLocator.java:249)
at servicelocator.ServiceLocatorTester.main(ServiceLocatorTester.java:38)


Looking forward for the solution.

thanks & rgds,
Sherryl
[ January 31, 2005: Message edited by: Sherryl Philip ]
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi Sherryl Philip,

Please follow the steps to avoid the error:

1. First make sure that OracleDS - DataSource is created in the JBOSS. I have n't used the JBOSS, but in weblogic you have the provision to view the jndi tree. If the DataSource is created properly then that entry must be present in the JNDI Tree. (Checking the DataSource in the app server level).

2. You need to set the initial context URL and Initial Context factory properties in the Initial Context if the appserver is different from your development box.

Hashtable ht = new Hashtable();
ht.put("INITIAL_CONTEXT_FACTORY", ....);
ht.put("PROVIDER_URL", ....);
Context ctx = new InitialContext(ht);

Please check the JBOSS manual for the above to get clear idea.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Service Locator Pattern