01: package com.xoetrope.data;
02:
03: import java.io.Reader;
04: import net.xoetrope.data.XDataSource;
05: import net.xoetrope.xui.XProject;
06: import net.xoetrope.xui.build.BuildProperties;
07: import net.xoetrope.debug.DebugLogger;
08: import net.xoetrope.optional.data.XOptionalDataSource;
09: import net.xoetrope.optional.data.sql.DataConnection;
10: import net.xoetrope.optional.data.sql.DatabaseTableModel;
11: import net.xoetrope.xui.helper.ReflectionHelper;
12:
13: /**
14: * A wrapper for the database access code
15: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
16: * the GNU Public License (GPL), please see license.txt for more details. If
17: * you make commercial use of this software you must purchase a commercial
18: * license from Xoetrope.</p>
19: * $Revision: 1.3 $
20: */
21: public class DatabaseConnector {
22: private XProject currentProject;
23: private Class defaultSourceClass;
24: private XDataSource modelDataSource;
25: private DataConnection connection;
26:
27: public DatabaseConnector(XProject project) {
28: currentProject = project;
29: createDataSource();
30: }
31:
32: public DataConnection getConnection(String connName) {
33: if (connection == null)
34: connection = new DataConnection(currentProject, connName);
35:
36: return connection;
37: }
38:
39: protected void createDataSource() {
40: try {
41: // Check for subclassing of the datasource/model
42: String klass = currentProject
43: .getStartupParam("XDataSourceClass");
44: if (klass != null) {
45: Object[] values = { currentProject };
46: modelDataSource = (XDataSource) ReflectionHelper
47: .constructViaReflection(klass, values);
48: }
49:
50: if (modelDataSource == null)
51: return;
52:
53: try {
54: String fileName = currentProject
55: .getStartupParam("DelayedModelData");
56: if (fileName != null) {
57: try {
58: modelDataSource.read(currentProject
59: .getBufferedReader(fileName, null));
60: return;
61: } catch (Exception ex3) {
62: if (BuildProperties.DEBUG)
63: DebugLogger
64: .logError("Could not access file:"
65: + fileName);
66: }
67: }
68: } catch (Exception ex) {
69: if (BuildProperties.DEBUG)
70: DebugLogger.logError("Exception in setContent");
71: }
72: } catch (Exception ex) {
73: ex.printStackTrace();
74: }
75: }
76: }
|