1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.dbforms.devgui;
30
31 import java.io.*;
32
33 import java.util.*;
34
35
36
37 /***
38 * DOCUMENT ME!
39 *
40 * @author Joe Peer Changes: - 2002-03-4: usage of default property and
41 * constant string values via new Interface Propertynames (dikr)
42 *
43 */
44 public class ProjectData implements Serializable, PropertyNames {
45 private static Properties defaultProps;
46
47
48
49 static {
50 defaultProps = new Properties();
51
52 defaultProps.setProperty(INCLUDE_SCHEMANAME, FALSESTRING);
53
54 defaultProps.setProperty(INCLUDE_CATALOGNAME, FALSESTRING);
55
56 defaultProps.setProperty(AUTOCOMMIT_MODE, TRUESTRING);
57
58 defaultProps.setProperty(CATALOG_SELECTION, ALL);
59
60 defaultProps.setProperty(SCHEMA_SELECTION, ALL);
61
62 defaultProps.setProperty(TABLE_SELECTION, ALL);
63
64 defaultProps.setProperty(EXAMINE_TABLES, TRUESTRING);
65
66 defaultProps.setProperty(EXAMINE_VIEWS, TRUESTRING);
67
68 defaultProps.setProperty(EXAMINE_SYSTABS, FALSESTRING);
69
70 defaultProps.setProperty(WRITE_STD_TYPENAMES, FALSESTRING);
71
72 defaultProps.setProperty(FOREIGNKEY_DETECTION, USE_GETIMPORTEDKEYS);
73 }
74
75 private File file;
76 private Properties props;
77 private boolean unsavedChanges = false;
78
79 /***
80 * Creates new Project
81 */
82 public ProjectData() {
83 this.props = new Properties(defaultProps);
84
85 String dbFormsHomeStr = System.getProperty("DBFORMS_HOME");
86
87 if (dbFormsHomeStr != null) {
88 setProperty(STYLESHEET_DIR,
89 dbFormsHomeStr
90 + System.getProperties().getProperty("file.separator")
91 + "xsl-stylesheets");
92 }
93
94 unsavedChanges = false;
95 }
96
97
98 /***
99 * Constructor for the ProjectData object
100 *
101 * @param props Description of the Parameter
102 */
103 public ProjectData(Properties props) {
104 this.props = props;
105
106 unsavedChanges = false;
107
108
109 String dbFormsHomeStr = props.getProperty(STYLESHEET_DIR);
110
111 if ("".equals(dbFormsHomeStr)) {
112 dbFormsHomeStr = System.getProperty("DBFORMS_HOME");
113
114 if (dbFormsHomeStr != null) {
115 setProperty(STYLESHEET_DIR,
116 dbFormsHomeStr
117 + System.getProperties().getProperty("file.separator")
118 + "xsl-stylesheets");
119
120 unsavedChanges = true;
121 }
122 }
123 }
124
125 /***
126 * Sets the file attribute of the ProjectData object
127 *
128 * @param file The new file value
129 */
130 public void setFile(File file) {
131 this.file = file;
132 }
133
134
135 /***
136 * Gets the file attribute of the ProjectData object
137 *
138 * @return The file value
139 */
140 public File getFile() {
141 return file;
142 }
143
144
145 /***
146 * Sets the property attribute of the ProjectData object
147 *
148 * @param key The new property value
149 * @param value The new property value
150 */
151 public void setProperty(String key,
152 String value) {
153 String oldValue = getProperty(key);
154
155 if (!oldValue.equals(value)) {
156 props.setProperty(key, value);
157
158 this.unsavedChanges = true;
159
160 System.out.println("unsaved state look like this:" + this.toString());
161 }
162 }
163
164
165 /***
166 * Gets the property attribute of the ProjectData object
167 *
168 * @param prop Description of the Parameter
169 *
170 * @return The property value
171 */
172 public String getProperty(String prop) {
173 return props.getProperty(prop, "");
174
175
176 }
177
178
179 /***
180 * Gets the unsaved attribute of the ProjectData object
181 *
182 * @return The unsaved value
183 */
184 public boolean isUnsaved() {
185 return unsavedChanges;
186 }
187
188
189 /***
190 * Description of the Method
191 *
192 * @param f Description of the Parameter
193 *
194 * @return Description of the Return Value
195 *
196 * @exception IOException Description of the Exception
197 */
198 public static ProjectData loadFromDisc(File f) throws IOException {
199 Properties l_props = new Properties(defaultProps);
200
201 l_props.load(new FileInputStream(f));
202
203 ProjectData pd = new ProjectData(l_props);
204
205 pd.setFile(f);
206
207 return pd;
208 }
209
210
211 /***
212 * Description of the Method
213 *
214 * @param f Description of the Parameter
215 *
216 * @exception IOException Description of the Exception
217 */
218 public void storeToDisc(File f) throws IOException {
219 this.props.store(new FileOutputStream(f), "DbForms DevGUI Property File");
220
221 this.file = f;
222
223 this.unsavedChanges = false;
224 }
225
226
227 /***
228 * Description of the Method
229 *
230 * @return Description of the Return Value
231 */
232 public String toString() {
233 StringBuffer buf = new StringBuffer();
234
235 Enumeration e = props.propertyNames();
236
237 boolean first = true;
238
239 while (e.hasMoreElements()) {
240 if (first) {
241 first = false;
242 } else {
243 buf.append(", ");
244 }
245
246 String aPropsName = (String) e.nextElement();
247
248 buf.append(aPropsName);
249
250 buf.append("=");
251
252 buf.append(this.getProperty(aPropsName));
253 }
254
255 return buf.toString();
256 }
257 }