001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: /*
022: * JSmoothModelBean.java
023: *
024: * Created on 7 août 2003, 18:32
025: */
026:
027: package net.charabia.jsmoothgen.application;
028:
029: import java.util.*;
030: import java.beans.*;
031: import java.io.*;
032:
033: public class JSmoothModelBean {
034: private String m_skeletonName;
035: private String m_executableName;
036: private String m_currentDirectory;
037:
038: private String m_iconLocation;
039: private boolean m_embedJar = false;
040: private String m_jarLocation;
041: private String m_mainClassName;
042: private String m_arguments;
043: private String[] m_classPath;
044: private String m_minimumVersion = "";
045: private String m_maximumVersion = "";
046: private String[] m_jvmSearch = null;
047:
048: public int m_maxHeap = -1;
049: public int m_initialHeap = -1;
050:
051: private String m_noJvmMessage;
052: private String m_noJvmURL;
053:
054: private String m_bundledJVM = null;
055:
056: private JavaPropertyPair[] m_javaprops = new JavaPropertyPair[0];
057: private JSmoothModelBean.Property[] m_skelproperties;
058:
059: static public class Property {
060: public String Key;
061: public String Value;
062:
063: public void setKey(String key) {
064: this .Key = key;
065: }
066:
067: public String getKey() {
068: return this .Key;
069: }
070:
071: public void setValue(String val) {
072: this .Value = val;
073: }
074:
075: public String getValue() {
076: return this .Value;
077: }
078:
079: public String toString() {
080: return getKey() + "==" + getValue();
081: }
082: }
083:
084: transient Vector m_listeners = new Vector();
085:
086: public static interface Listener {
087: public void dataChanged();
088: }
089:
090: transient Vector m_skeletonChangedListener = new Vector();
091:
092: public static interface SkeletonChangedListener {
093: public void skeletonChanged();
094: }
095:
096: /** Creates a new instance of JSmoothModelBean */
097: public JSmoothModelBean() {
098: }
099:
100: public void addListener(JSmoothModelBean.Listener l) {
101: m_listeners.add(l);
102: }
103:
104: public void removeListener(JSmoothModelBean.Listener l) {
105: m_listeners.remove(l);
106: }
107:
108: public void addSkeletonChangedListener(
109: JSmoothModelBean.SkeletonChangedListener l) {
110: m_skeletonChangedListener.add(l);
111: }
112:
113: public void removeSkeletonChangedListener(
114: JSmoothModelBean.SkeletonChangedListener l) {
115: m_skeletonChangedListener.remove(l);
116: }
117:
118: private void fireChanged() {
119: for (Iterator i = m_listeners.iterator(); i.hasNext();) {
120: JSmoothModelBean.Listener l = (JSmoothModelBean.Listener) i
121: .next();
122: l.dataChanged();
123: }
124: }
125:
126: private void fireSkeletonChanged() {
127: for (Iterator i = m_skeletonChangedListener.iterator(); i
128: .hasNext();) {
129: JSmoothModelBean.SkeletonChangedListener l = (JSmoothModelBean.SkeletonChangedListener) i
130: .next();
131: l.skeletonChanged();
132: }
133: }
134:
135: public void setSkeletonName(String name) {
136: if (name != m_skeletonName) {
137: m_skeletonName = name;
138: fireSkeletonChanged();
139: fireChanged();
140: }
141: }
142:
143: public String getSkeletonName() {
144: return m_skeletonName;
145: }
146:
147: public void setExecutableName(String name) {
148: if (name != m_executableName) {
149: m_executableName = name;
150: fireChanged();
151: }
152: }
153:
154: public void setCurrentDirectory(String curdir) {
155: if (curdir != m_currentDirectory) {
156: m_currentDirectory = curdir;
157: fireChanged();
158: }
159: }
160:
161: public String getCurrentDirectory() {
162: return m_currentDirectory;
163: }
164:
165: public String getExecutableName() {
166: return m_executableName;
167: }
168:
169: public void setIconLocation(String name) {
170: if (name != m_iconLocation) {
171: m_iconLocation = name;
172: fireChanged();
173: }
174: }
175:
176: public String getIconLocation() {
177: return m_iconLocation;
178: }
179:
180: public boolean getEmbeddedJar() {
181: return m_embedJar;
182: }
183:
184: public void setEmbeddedJar(boolean b) {
185: m_embedJar = b;
186: fireChanged();
187: }
188:
189: public void setJarLocation(String name) {
190: if (name != m_jarLocation) {
191: m_jarLocation = name;
192: fireChanged();
193: }
194: }
195:
196: public String getJarLocation() {
197: return m_jarLocation;
198: }
199:
200: public void setMainClassName(String name) {
201: if (name != m_mainClassName) {
202: m_mainClassName = name;
203: fireChanged();
204: }
205: }
206:
207: public String getMainClassName() {
208: return m_mainClassName;
209: }
210:
211: public void setArguments(String args) {
212: m_arguments = args;
213: fireChanged();
214: }
215:
216: public String getArguments() {
217: return m_arguments;
218: }
219:
220: public void setClassPath(String[] cp) {
221: m_classPath = cp;
222: fireChanged();
223: }
224:
225: public String[] getClassPath() {
226: return m_classPath;
227: }
228:
229: public void setMaximumVersion(String version) {
230: m_maximumVersion = version;
231: fireChanged();
232: }
233:
234: public String getMaximumVersion() {
235: return m_maximumVersion;
236: }
237:
238: public void setMinimumVersion(String version) {
239: m_minimumVersion = version;
240: fireChanged();
241: }
242:
243: public String getMinimumVersion() {
244: return m_minimumVersion;
245: }
246:
247: public void setJVMSearchPath(String[] path) {
248: m_jvmSearch = path;
249: fireChanged();
250: }
251:
252: public String[] getJVMSearchPath() {
253: return m_jvmSearch;
254: }
255:
256: public void setSkeletonProperties(JSmoothModelBean.Property[] props) {
257: // for (int i=0; i<props.length; i++)
258: // System.out.println("SET PROPERTY: " + props[i].getIdName() + "=" + props[i].getValue());
259:
260: m_skelproperties = props;
261: fireChanged();
262: }
263:
264: public JSmoothModelBean.Property[] getSkeletonProperties() {
265: return m_skelproperties;
266: }
267:
268: public void setNoJvmMessage(String msg) {
269: m_noJvmMessage = msg;
270: fireChanged();
271: }
272:
273: public String getNoJvmMessage() {
274: return m_noJvmMessage;
275: }
276:
277: public void setNoJvmURL(String url) {
278: m_noJvmURL = url;
279: fireChanged();
280: }
281:
282: public String getNoJvmURL() {
283: return m_noJvmURL;
284: }
285:
286: public String getBundledJVMPath() {
287: return m_bundledJVM;
288: }
289:
290: public void setBundledJVMPath(String path) {
291: m_bundledJVM = path;
292: fireChanged();
293: }
294:
295: public void setJavaProperties(JavaPropertyPair[] pairs) {
296: m_javaprops = pairs;
297: }
298:
299: public JavaPropertyPair[] getJavaProperties() {
300: return m_javaprops;
301: }
302:
303: public void setMaximumMemoryHeap(int size) {
304: m_maxHeap = size;
305: }
306:
307: public int getMaximumMemoryHeap() {
308: return m_maxHeap;
309: }
310:
311: public void setInitialMemoryHeap(int size) {
312: m_initialHeap = size;
313: }
314:
315: public int getInitialMemoryHeap() {
316: return m_initialHeap;
317: }
318:
319: public String[] normalizePaths(java.io.File filebase) {
320: return normalizePaths(filebase, true);
321: }
322:
323: public String[] normalizePaths(java.io.File filebase,
324: boolean toRelativePath) {
325: // System.out.println("Normalize Path " + filebase + " / " + toRelativePath);
326: Vector result = new Vector();
327:
328: m_iconLocation = checkRelativePath(filebase, m_iconLocation,
329: result, "Icon location", toRelativePath);
330: m_jarLocation = checkRelativePath(filebase, m_jarLocation,
331: result, "Jar location", toRelativePath);
332: m_bundledJVM = checkRelativePath(filebase, m_bundledJVM,
333: result, "Bundle JVM location", toRelativePath);
334: m_executableName = checkRelativePath(filebase,
335: m_executableName, result, "Executable location",
336: toRelativePath);
337:
338: if (m_executableName != null) {
339: File exebase = new File(m_executableName);
340: if (exebase.isAbsolute() == false)
341: exebase = new File(filebase, exebase.toString())
342: .getParentFile();
343:
344: // System.out.println("EXE FILEBASE: " + exebase.toString());
345: if ((m_currentDirectory != null)
346: && (m_currentDirectory.indexOf("${") >= 0))
347: m_currentDirectory = checkRelativePath(exebase,
348: m_currentDirectory, result,
349: "Current directory", toRelativePath);
350: }
351:
352: if (m_classPath != null) {
353: for (int i = 0; i < m_classPath.length; i++) {
354: m_classPath[i] = checkRelativePath(filebase,
355: m_classPath[i], result, "Classpath entry (" + i
356: + ")", toRelativePath);
357: }
358: }
359:
360: if (result.size() == 0)
361: return null;
362:
363: String[] res = new String[result.size()];
364: result.toArray(res);
365:
366: return res;
367: }
368:
369: private String checkRelativePath(java.io.File root, String value,
370: java.util.Vector errors, String name, boolean toRelativePath) {
371: if (value == null)
372: return value;
373:
374: if (toRelativePath) {
375: File nf = JSmoothModelPersistency
376: .makePathRelativeIfPossible(root, new File(value));
377: if (nf.isAbsolute()) {
378: errors.add(name);
379: }
380: return nf.toString();
381: } else {
382: File nf = new File(value);
383: if (nf.isAbsolute() == false) {
384: nf = new File(root, value);
385: nf = nf.getAbsoluteFile();
386:
387: try {
388: nf = nf.getCanonicalFile();
389: nf = nf.getAbsoluteFile();
390: } catch (IOException iox) {
391: // do nothing
392: }
393: }
394: return nf.toString();
395: }
396: }
397: }
|