01: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
02: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
03: //=== and United Nations Environment Programme (UNEP)
04: //===
05: //=== This program is free software; you can redistribute it and/or modify
06: //=== it under the terms of the GNU General Public License as published by
07: //=== the Free Software Foundation; either version 2 of the License, or (at
08: //=== your option) any later version.
09: //===
10: //=== This program is distributed in the hope that it will be useful, but
11: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
12: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: //=== General Public License for more details.
14: //===
15: //=== You should have received a copy of the GNU General Public License
16: //=== along with this program; if not, write to the Free Software
17: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18: //===
19: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
20: //=== Rome - Italy. email: geonetwork@osgeo.org
21: //==============================================================================
22:
23: package org.fao.geonet.apps.trash;
24:
25: import jeeves.constants.ConfigFile;
26: import jeeves.utils.*;
27: import jeeves.resources.dbms.*;
28:
29: import org.jdom.*;
30:
31: import java.util.*;
32:
33: public class Util {
34: public static DbmsPool getDbmsPool(String configFile)
35: throws Exception {
36: Element configRoot = Xml.loadFile(configFile);
37: Element resourcesRoot = configRoot
38: .getChild(ConfigFile.Child.RESOURCES);
39: List resList = resourcesRoot
40: .getChildren(ConfigFile.Resources.Child.RESOURCE);
41:
42: for (int i = 0; i < resList.size(); i++) {
43: Element res = (Element) resList.get(i);
44: String name = res
45: .getChildText(ConfigFile.Resource.Child.NAME);
46:
47: if (name.equals("main-db")) {
48: Element config = res
49: .getChild(ConfigFile.Resource.Child.CONFIG);
50: DbmsPool pool = new DbmsPool();
51: pool.init(name, config);
52: return pool;
53: }
54: }
55: throw new Exception("resource 'main-db' not found");
56: }
57:
58: public static Element getServices(String configFile, String pack)
59: throws Exception {
60: Element configRoot = Xml.loadFile(configFile);
61: List services = configRoot
62: .getChildren(ConfigFile.Child.SERVICES);
63: for (int i = 0; i < services.size(); i++) {
64: Element ss = (Element) services.get(i);
65: String p = ss
66: .getAttributeValue(ConfigFile.Services.Attr.PACKAGE);
67: if (p != null && p.equals(pack))
68: return ss;
69: }
70: return null;
71: }
72: }
|