RE: file open help
Adrian Cho <[email protected]> Sun, 20 Apr 2003 11:31:00 +0100
| Newsgroups | gmane.comp.java.mvc.devel |
|---|---|
| Message-ID | <[email protected]> |
Not sure whether I understand the problem.
Here is a quick shot (into the dark though)
If question is about forward or backward slash, then
System.get("file.separator") should help.
On the other hand, if question is about calling different object or even
constructor to open a file, then one may try "factory pattern"
You have one common java interface that has a signature / method to open a
file.
argument can be a relative path or canonical path.
The factory is responsible to give you an object, implementing the
aforementioned interface for reading the file. The code in dao would
hopefully be cleaner. The mess is moved under the factory instead.
Say when the application covers more than strut and console app, it is only
the factory that needs to be enhanced. To elaborate this further, one may
even introduce abstract factory.
Hope it helps.
If one does not like the simple term "factory", there are similar terms used
in the literature: business delegate / service locator.
but the essence is not to pollute the core dao with if-else code. The code
that calls the "factory" or filehelper object can be located in your baseDAO
for better re-use.
>===== Original Message From [email protected] =====
>I can't think of a nice solution to open file. I wonder if somone else
>might be able to think of something of the top.
>
>I have beans using db layers. I want to use them in both struts and a
>console app (no container).
>
>To get console to work I open config like this:
>File f = new File ("properties\\sql-map-config.xml");
> _sqlMap = XmlSqlMapBuilder.buildSqlMap(f);
>
>
>To get struts to work I open config file like this:
>Reader reader = Resources.getResourceAsReader(
>"properties/sql-map-config.xml");
>
>_sqlMap = XmlSqlMapBuilder.buildSqlMap(reader);
>
>
>Of course I would like to be able to get to it from console app and
>struts/web app without some if/than thing. I looked at DB layer resource
>file.
>
>Suggestion?
>
>It's late and... I can't think. But what ever I think of will be in my
>best practices.
>
>tia,
>
>.V
>
>_______________________________________________
>MVC-Programmers mailing list
>[email protected]
>http://www.basebeans.net:8080/mailman/listinfo/mvc-programmers