01: /*
02: * ToolDefinition.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.util;
13:
14: import java.io.File;
15: import java.io.IOException;
16: import java.util.List;
17:
18: /**
19: * @author support@sql-workbench.net
20: */
21: public class ToolDefinition {
22: private String appPath;
23: private String name;
24:
25: public ToolDefinition() {
26: }
27:
28: public ToolDefinition(String exe, String name) {
29: setApplicationPath(exe);
30: setName(name);
31: }
32:
33: public String getName() {
34: return name;
35: }
36:
37: public void setName(String appName) {
38: this .name = appName;
39: }
40:
41: public String getApplicationPath() {
42: return appPath;
43: }
44:
45: public void setApplicationPath(String path) {
46: this .appPath = path;
47: }
48:
49: public String toString() {
50: return getName();
51: }
52:
53: public void runApplication(String arg) throws IOException {
54: List<String> appDef = tokenizePath();
55: String[] cmd = new String[appDef.size() + 1];
56: for (int i = 0; i < appDef.size(); i++) {
57: cmd[i] = appDef.get(i);
58: }
59: cmd[appDef.size()] = arg;
60: Runtime.getRuntime().exec(cmd, null);
61: }
62:
63: public boolean executableExists() {
64: List<String> appDef = tokenizePath();
65: String prgPath = appDef.get(0);
66: File f = new File(prgPath);
67: return f.exists();
68: }
69:
70: private List<String> tokenizePath() {
71: WbStringTokenizer tok = new WbStringTokenizer(this .appPath,
72: " ", true, "\"", true);
73: return tok.getAllTokens();
74: }
75:
76: public boolean equals(Object other) {
77: if (this .name == null)
78: return false;
79: if (other instanceof ToolDefinition) {
80: ToolDefinition t = (ToolDefinition) other;
81: return this .name.equals(t.getName());
82: } else if (other instanceof String) {
83: return this .name.equals((String) other);
84: }
85: return false;
86: }
87: }
|