001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
011: * Microsystems, Inc. All Rights Reserved.
012:
013: If you wish your version of this file to be governed by only the CDDL
014: or only the GPL Version 2, indicate your decision by adding
015: "[Contributor] elects to include this software in this distribution
016: under the [CDDL or GPL Version 2] license." If you do not indicate a
017: single choice of license, a recipient has the option to distribute
018: your version of this file under either the CDDL, the GPL Version 2 or
019: to extend the choice of license to its licensees as provided above.
020: However, if you add GPL Version 2 code and therefore, elected the GPL
021: Version 2 license, then the option applies only if the new code is
022: made subject to such option by the copyright holder.
023:
024: If you wish your version of this file to be governed by only the CDDL
025: or only the GPL Version 2, indicate your decision by adding
026: "[Contributor] elects to include this software in this distribution
027: under the [CDDL or GPL Version 2] license." If you do not indicate a
028: single choice of license, a recipient has the option to distribute
029: your version of this file under either the CDDL, the GPL Version 2 or
030: to extend the choice of license to its licensees as provided above.
031: However, if you add GPL Version 2 code and therefore, elected the GPL
032: Version 2 license, then the option applies only if the new code is
033: made subject to such option by the copyright holder.
034: */
035: package org.netbeans.modules.mashup.db.ui;
036:
037: import java.io.File;
038: import java.io.FileInputStream;
039: import java.io.FileNotFoundException;
040: import java.io.FileOutputStream;
041: import java.io.IOException;
042: import java.util.Properties;
043:
044: import net.java.hulp.i18n.Logger;
045: import org.netbeans.modules.etl.logger.Localizer;
046: import org.netbeans.modules.etl.logger.LogUtil;
047: import org.openide.nodes.BeanNode;
048: import org.openide.util.NbBundle;
049:
050: /**
051: *
052: * @author karthikeyan s
053: */
054: public class AxionDBConfiguration {
055:
056: private static final AxionDBConfiguration DEFAULT = new AxionDBConfiguration();
057: public static final String PROP_DB_LOC = "DBLocation";
058: public static final String PROP_DRIVER_LOC = "DriverLocation";
059: public static final String PROP_LOC = "location";
060: public static final String PROP_DRV_LOC = "driver";
061: private static transient final Logger mLogger = LogUtil
062: .getLogger(FlatfileResulSetPanel.class.getName());
063: private static transient final Localizer mLoc = Localizer.get();
064:
065: public static AxionDBConfiguration getDefault() {
066: return DEFAULT;
067: }
068:
069: public String displayName() {
070: String nbBundle4 = mLoc.t("PRSR001: MashupDB Configuration");
071: return Localizer.parse(nbBundle4);
072: }
073:
074: protected final String putProperty(String key, String value,
075: boolean notify) {
076: System.setProperty(key, value);
077: return System.getProperty(key);
078: }
079:
080: protected final String getProperty(String key) {
081: return System.getProperty(key);
082: }
083:
084: public String getDriver() {
085: File conf = getConfigFile();
086: if (conf != null) {
087: Properties prop = new Properties();
088: FileInputStream in = null;
089: try {
090: in = new FileInputStream(conf);
091: prop.load(in);
092: } catch (FileNotFoundException ex) {
093: //ignore
094: } catch (IOException ioEx) {
095: //ignore
096: }
097: String drv = prop.getProperty(PROP_DRIVER_LOC);
098: if (drv != null) {
099: return drv;
100: }
101: } else {
102: // Check for mashup driver under soa cluster.
103: String nbHomeDir = System.getProperty("netbeans.home")
104: + File.separator + ".." + File.separator + "soa2"
105: + File.separator + "modules" + File.separator
106: + "ext" + File.separator + "etl" + File.separator
107: + "axiondb.jar";
108: File driver = new File(nbHomeDir);
109: if (!driver.exists()) {
110:
111: // check for mashup driver under extra cluster.
112: nbHomeDir = System.getProperty("netbeans.home")
113: + File.separator + ".." + File.separator
114: + "extra" + File.separator + "modules"
115: + File.separator + "ext" + File.separator
116: + "etl" + File.separator + "axiondb.jar";
117: driver = new File(nbHomeDir);
118: if (!driver.exists()) {
119: nbHomeDir = "";
120: }
121: return nbHomeDir;
122: }
123: }
124: return "";
125: }
126:
127: public void setDriver(String driver) {
128: driver = driver.trim();
129: File conf = getConfigFile();
130: try {
131: FileInputStream in = new FileInputStream(conf);
132: Properties oldProp = new Properties();
133: oldProp.load(in);
134: String dbLoc = oldProp.getProperty(PROP_DB_LOC);
135: in.close();
136: FileOutputStream out = new FileOutputStream(conf);
137: Properties prop = new Properties();
138: prop.setProperty(PROP_DRIVER_LOC, driver);
139: prop.setProperty(PROP_DB_LOC, dbLoc);
140: String nbBundle3 = mLoc
141: .t("PRSR001: MashupDB Configurations");
142: prop.store(out, Localizer.parse(nbBundle3));
143: out.close();
144: } catch (FileNotFoundException ex) {
145: //ignore
146: } catch (IOException ex) {
147: //ignore
148: }
149: }
150:
151: /**
152: * Returns the AXION location or an empty string if the AXION location
153: * is not set. Never returns null.
154: * @return dbLocation
155: */
156: public String getLocation() {
157: File conf = getConfigFile();
158: if (conf != null) {
159: Properties prop = new Properties();
160: FileInputStream in = null;
161: try {
162: in = new FileInputStream(conf);
163: prop.load(in);
164: } catch (FileNotFoundException ex) {
165: //ignore
166: } catch (IOException ioEx) {
167: //ignore
168: }
169: return prop.getProperty(PROP_DB_LOC);
170: }
171: return System.getProperty("netbeans.user") + File.separator
172: + "MashupDatabases" + File.separator;
173: }
174:
175: /**
176: * Sets the AXION location.
177: *
178: * @param location the AXION location. A null value is valid and
179: * will be returned by getLocation() as an empty
180: * string (meaning "not set"). An empty string is valid
181: * and has the meaning "set to the default location".
182: */
183: public void setLocation(String location) {
184: location = location.trim();
185: if (!location.endsWith(File.separator)) {
186: location = location + File.separator;
187: }
188: File conf = getConfigFile();
189: try {
190: FileInputStream in = new FileInputStream(conf);
191: Properties oldProp = new Properties();
192: oldProp.load(in);
193: String drv = oldProp.getProperty(PROP_DRIVER_LOC);
194: in.close();
195: FileOutputStream out = new FileOutputStream(conf);
196: Properties prop = new Properties();
197: prop.setProperty(PROP_DB_LOC, location);
198: prop.setProperty(PROP_DRIVER_LOC, drv);
199: String nbBundle3 = mLoc
200: .t("PRSR001: MashupDB Configurations");
201: prop.store(out, Localizer.parse(nbBundle3));
202: out.close();
203: File db = new File(location);
204: if (!db.exists()) {
205: db.mkdir();
206: }
207: } catch (FileNotFoundException ex) {
208: //ignore
209: } catch (IOException ex) {
210: //ignore
211: }
212: }
213:
214: public static File getConfigFile() {
215: String nbUsrDir = System.getProperty("netbeans.user");
216:
217: // Check for mashup driver under soa cluster.
218: String nbHomeDir = System.getProperty("netbeans.home")
219: + File.separator + ".." + File.separator + "soa1"
220: + File.separator + "modules" + File.separator + "ext"
221: + File.separator + "etl" + File.separator
222: + "axiondb.jar";
223: File driver = new File(nbHomeDir);
224: if (!driver.exists()) {
225:
226: // check for mashup driver under extra cluster.
227: nbHomeDir = System.getProperty("netbeans.home")
228: + File.separator + ".." + File.separator + "extra"
229: + File.separator + "modules" + File.separator
230: + "ext" + File.separator + "etl" + File.separator
231: + "axiondb.jar";
232: driver = new File(nbHomeDir);
233: if (!driver.exists()) {
234: nbHomeDir = "";
235: } else {
236: nbHomeDir = driver.getAbsolutePath();
237: }
238: }
239: String DEFAULT_DB_LOCATION = System
240: .getProperty("netbeans.user")
241: + File.separator + "MashupDatabases" + File.separator;
242: nbUsrDir = nbUsrDir + File.separator + "config"
243: + File.separator + "Databases" + File.separator
244: + "MashupDB";
245: File conf = new File(nbUsrDir);
246: if (!conf.exists()) {
247: conf.mkdir();
248: }
249: nbUsrDir = nbUsrDir + File.separator
250: + "MashupDBConfig.properties";
251: conf = new File(nbUsrDir);
252: if (!conf.exists()) {
253: try {
254: conf.createNewFile();
255: Properties prop = new Properties();
256: prop.setProperty(PROP_DB_LOC, DEFAULT_DB_LOCATION);
257: prop.setProperty(PROP_DRIVER_LOC, nbHomeDir);
258: FileOutputStream out = null;
259: try {
260: out = new FileOutputStream(conf);
261: String nbBundle2 = mLoc
262: .t("PRSR001: Mashup Database Location");
263: prop.store(out, Localizer.parse(nbBundle2));
264: out.close();
265: } catch (FileNotFoundException ex) {
266: //ignore
267: } catch (IOException ioEx) {
268: //igonre
269: }
270: } catch (IOException ex) {
271: conf = null;
272: }
273: }
274: return conf;
275: }
276:
277: protected static BeanNode createViewNode()
278: throws java.beans.IntrospectionException {
279: BeanNode nd = new BeanNode(AxionDBConfiguration.getDefault());
280: String nbBundle1 = mLoc.t("PRSR001: Mashup Database");
281: nd.setName(Localizer.parse(nbBundle1));
282: return nd;
283: }
284: }
|