001: //==============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.gast.gui.panels.config.dbms;
025:
026: import java.util.StringTokenizer;
027: import javax.swing.JLabel;
028: import javax.swing.JTextField;
029: import org.dlib.gui.FlexLayout;
030: import org.fao.gast.lib.Lib;
031:
032: //==============================================================================
033:
034: public class OraclePanel extends DbmsPanel {
035: //---------------------------------------------------------------------------
036: //---
037: //--- Constructor
038: //---
039: //---------------------------------------------------------------------------
040:
041: public OraclePanel() {
042: FlexLayout fl = new FlexLayout(3, 5);
043: fl.setColProp(1, FlexLayout.EXPAND);
044: setLayout(fl);
045:
046: add("0,0", new JLabel("Server"));
047: add("0,1", new JLabel("Port"));
048: add("0,2", new JLabel("SID"));
049: add("0,3", new JLabel("Username"));
050: add("0,4", new JLabel("Password"));
051:
052: add("1,0", txtServer);
053: add("1,1", txtPort);
054: add("1,2", txtSid);
055: add("1,3", txtUser);
056: add("1,4", txtPass);
057:
058: add("2,0", new JLabel("<html><font color='red'>(REQ)</font>"));
059: add("2,1", new JLabel("<html><font color='red'>(REQ)</font>"));
060: add("2,2", new JLabel("<html><font color='red'>(REQ)</font>"));
061:
062: txtPort.setText("1521");
063: txtPort.setToolTipText("The default port is 1521");
064: }
065:
066: //---------------------------------------------------------------------------
067: //---
068: //--- DbmsPanel methods
069: //---
070: //---------------------------------------------------------------------------
071:
072: public String getLabel() {
073: return "Oracle";
074: }
075:
076: //---------------------------------------------------------------------------
077:
078: public boolean matches(String url) {
079: return url.startsWith("jdbc:oracle:");
080: }
081:
082: //---------------------------------------------------------------------------
083: //--- jdbc:oracle:thin:@<host>:<1521>:<database>
084:
085: public void retrieve() {
086: String url = Lib.config.getDbmsURL();
087:
088: //--- cut prefix +'@'
089: url = url.substring(PREFIX.length() + 1);
090:
091: StringTokenizer st = new StringTokenizer(url, ":");
092:
093: String server = st.nextToken();
094: String port = st.hasMoreTokens() ? st.nextToken() : "1521";
095: String sid = st.hasMoreTokens() ? st.nextToken() : "????";
096:
097: txtServer.setText(server);
098: txtPort.setText(port);
099: txtSid.setText(sid);
100: txtUser.setText(Lib.config.getDbmsUser());
101: txtPass.setText(Lib.config.getDbmsPassword());
102: }
103:
104: //---------------------------------------------------------------------------
105:
106: public void save() throws Exception {
107: String server = txtServer.getText();
108: String port = txtPort.getText();
109: String sid = txtSid.getText();
110:
111: if (server.equals(""))
112: throw new Exception("The server cannot be empty");
113:
114: if (!Lib.type.isInteger(port))
115: throw new Exception("The port must be an integer");
116:
117: if (sid.equals(""))
118: throw new Exception("The sid cannot be empty");
119:
120: String url = PREFIX + "@" + server + ":" + port + ":" + sid;
121:
122: Lib.config.setDbmsDriver("oracle.jdbc.driver.OracleDriver");
123: Lib.config.setDbmsURL(url);
124: Lib.config.setDbmsUser(txtUser.getText());
125: Lib.config.setDbmsPassword(txtPass.getText());
126: Lib.config.removeActivator();
127: Lib.config.save();
128: }
129:
130: //---------------------------------------------------------------------------
131: //---
132: //--- Variables
133: //---
134: //---------------------------------------------------------------------------
135:
136: private JTextField txtServer = new JTextField(15);
137: private JTextField txtPort = new JTextField(6);
138: private JTextField txtSid = new JTextField(12);
139: private JTextField txtUser = new JTextField(12);
140: private JTextField txtPass = new JTextField(12);
141:
142: //---------------------------------------------------------------------------
143:
144: private static final String PREFIX = "jdbc:oracle:thin:";
145: }
146:
147: //==============================================================================
|