Source Code Cross Referenced for OracleSpatialWizardPage.java in  » GIS » udig-1.1 » net » refractions » udig » catalog » internal » oracle » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » udig 1.1 » net.refractions.udig.catalog.internal.oracle.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    uDig - User Friendly Desktop Internet GIS client
003:         *    http://udig.refractions.net
004:         *    (C) 2004, Refractions Research Inc.
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package net.refractions.udig.catalog.internal.oracle.ui;
018:
019:        import java.io.Serializable;
020:        import java.lang.reflect.InvocationTargetException;
021:        import java.net.URL;
022:        import java.sql.Connection;
023:        import java.sql.DriverManager;
024:        import java.sql.SQLException;
025:        import java.util.ArrayList;
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Map;
030:
031:        import org.eclipse.core.runtime.IProgressMonitor;
032:        import org.eclipse.jface.operation.IRunnableWithProgress;
033:        import org.eclipse.jface.viewers.ISelection;
034:        import org.eclipse.jface.viewers.IStructuredSelection;
035:        import org.eclipse.jface.viewers.StructuredSelection;
036:        import org.eclipse.swt.SWT;
037:        import org.eclipse.swt.custom.CCombo;
038:        import org.eclipse.swt.events.FocusEvent;
039:        import org.eclipse.swt.events.ModifyEvent;
040:        import org.eclipse.swt.widgets.Composite;
041:        import org.eclipse.swt.widgets.Event;
042:        import org.eclipse.swt.widgets.Group;
043:        import org.eclipse.swt.widgets.Text;
044:        import org.eclipse.ui.PlatformUI;
045:        import org.geotools.data.DataStoreFactorySpi.Param;
046:        import org.geotools.data.oracle.OracleConnectionFactory;
047:        import org.geotools.data.oracle.OracleDataStoreFactory;
048:
049:        import net.refractions.udig.catalog.IResolve;
050:        import net.refractions.udig.catalog.IService;
051:        import net.refractions.udig.catalog.internal.oracle.OracleServiceExtension;
052:        import net.refractions.udig.catalog.oracle.internal.Messages;
053:        import net.refractions.udig.catalog.ui.UDIGConnectionPage;
054:        import net.refractions.udig.catalog.ui.preferences.AbstractProprietaryDatastoreWizardPage;
055:        import net.refractions.udig.catalog.ui.preferences.AbstractProprietaryJarPreferencePage;
056:        import net.refractions.udig.ui.PlatformGIS;
057:
058:        /**
059:         * Enter Oracle connection parameters.
060:         * 
061:         * @author dzwiers
062:         * @since 0.3
063:         */
064:        public class OracleSpatialWizardPage extends
065:                AbstractProprietaryDatastoreWizardPage implements 
066:                UDIGConnectionPage {
067:
068:            public OracleSpatialWizardPage() {
069:                super (Messages.OracleSpatialWizardPage_wizardTitle);
070:            }
071:
072:            @Override
073:            protected AbstractProprietaryJarPreferencePage getPreferencePage() {
074:                return new OracleSpatialPreferences();
075:            }
076:
077:            public String getId() {
078:                return "net.refractions.udig.catalog.ui.oracle"; //$NON-NLS-1$
079:            }
080:
081:            @Override
082:            protected String getRestartMessage() {
083:                return Messages.OracleSpatialWizardPage_restart;
084:            }
085:
086:            @Override
087:            protected String getDriversMessage() {
088:                return Messages.OracleSpatialWizardPage_drivers;
089:            }
090:
091:            @Override
092:            protected void doCreateWizardPage(Composite parent) {
093:
094:                // For Drag 'n Drop as well as for general selections
095:                // look for a url as part of the selction
096:                ISelection tmpSelection = PlatformUI.getWorkbench()
097:                        .getActiveWorkbenchWindow().getActivePage()
098:                        .getSelection();
099:                IStructuredSelection selection = null;
100:                if (tmpSelection == null
101:                        || !(tmpSelection instanceof  IStructuredSelection)) {
102:                    selection = new StructuredSelection();
103:                } else {
104:                    selection = (IStructuredSelection) tmpSelection;
105:                }
106:
107:                String selectedText = null;
108:                for (Iterator itr = selection.iterator(); itr.hasNext();) {
109:                    Object o = itr.next();
110:                    if (o instanceof  URL || o instanceof  String) {
111:                        selectedText = (String) o;
112:                        // jdbc:postgresql://host:port/database
113:                        // jdbc:oracle:thin:@host:port:instance
114:                        if (selectedText.contains("jdbc:oracle:thin:@")) { //$NON-NLS-1$
115:                            break;
116:                        }
117:                        selectedText = null;
118:                    }
119:                }
120:                if (selectedText != null) {
121:                    int startindex = selectedText.indexOf("@"); //$NON-NLS-1$
122:                    int hostEnd = selectedText.indexOf(":", startindex); //$NON-NLS-1$
123:                    int portEnd = selectedText.indexOf(":", hostEnd); //$NON-NLS-1$
124:                    int databaseEnd = selectedText.indexOf(":", portEnd); //$NON-NLS-1$
125:                    String the_host = selectedText.substring(startindex,
126:                            hostEnd);
127:                    ((Text) host).setText(the_host);
128:
129:                    String the_port = selectedText.substring(hostEnd, portEnd);
130:                    if (!the_port.equalsIgnoreCase("")) { //$NON-NLS-1$
131:                        port.setText(the_port);
132:                    }
133:                    String the_database = selectedText.substring(portEnd,
134:                            databaseEnd);
135:                    ((CCombo) database).add(the_database);
136:                }
137:            }
138:
139:            public boolean canProcess(Object object) {
140:                return getOracleURL(object) != null;
141:            }
142:
143:            protected String getOracleURL(Object data) {
144:                String url = null;
145:                if (data instanceof  String) {
146:                    String[] strings = ((String) data).split("\n"); //$NON-NLS-1$
147:                    url = strings[0];
148:                    if (!url.toLowerCase().contains("jdbc:oracle")) { //$NON-NLS-1$
149:                        url = null;
150:                    }
151:                }
152:
153:                return url;
154:            }
155:
156:            /**
157:             * TODO summary sentence for createAdvancedControl ...
158:             * 
159:             */
160:            protected Group createAdvancedControl(Composite arg0) {
161:                port.setText("1521"); //$NON-NLS-1$
162:                return null;
163:            }
164:
165:            /*
166:             * dbtype host port user passwd instance schema namespace
167:             */
168:
169:            private static OracleDataStoreFactory factory = new OracleDataStoreFactory();
170:
171:            protected OracleDataStoreFactory getDataStoreFactorySpi() {
172:                return factory;
173:            }
174:
175:            public Map<String, Serializable> getParams() {
176:                if (!OracleSpatialPreferences.isInstalled())
177:                    return null;
178:
179:                if (getHostText() == null || getPortText() == null
180:                        || getUserText() == null || getDBText() == null
181:                        || getSchema() == null)
182:                    return null;
183:
184:                Map<String, Serializable> params = new HashMap<String, Serializable>();
185:                Param[] dbParams = factory.getParametersInfo();
186:
187:                params.put(dbParams[0].key, "oracle"); //$NON-NLS-1$
188:                params.put(dbParams[1].key, getHostText());
189:
190:                String port1 = getPortText();
191:                params.put(dbParams[2].key, port1);
192:
193:                String user1 = getUserText();
194:                params.put(dbParams[3].key, user1);
195:
196:                String pass1 = getPassText();
197:                params.put(dbParams[4].key, pass1);
198:
199:                String db = getDBText();
200:                params.put(dbParams[5].key, db);
201:
202:                String schema1 = getSchema();
203:                params.put(dbParams[6].key, schema1);
204:
205:                // not sureabout this line
206:                // params.put(dbParams[7].key,"MAPINFO"); //$NON-NLS-1$
207:
208:                return params;
209:            }
210:
211:            /**
212:             *
213:             * @return
214:             */
215:            protected String getPortText() {
216:                return this .port.getText();
217:            }
218:
219:            /**
220:             * TODO summary sentence for getConnection ...
221:             * 
222:             * @see net.refractions.udig.catalog.internal.ui.datastore.DataBaseRegistryWizardPage#getConnection()
223:             * @return
224:             */
225:            protected Connection getConnection() {
226:                try {
227:                    String db1 = ((Text) database).getText();
228:                    db1 = "".equals(db1) ? null : db1; //$NON-NLS-1$
229:                    final String db = db1;
230:                    final String host1 = ((Text) host).getText();
231:                    final String port1 = port.getText();
232:                    final String user1 = user.getText();
233:                    final String pass1 = pass.getText();
234:                    if (db == null) {
235:                        //don't bother
236:                        return null;
237:                    }
238:                    getContainer().run(true, true, new IRunnableWithProgress() {
239:
240:                        public void run(IProgressMonitor monitor)
241:                                throws InvocationTargetException,
242:                                InterruptedException {
243:                            PlatformGIS.runBlockingOperation(
244:                                    new IRunnableWithProgress() {
245:
246:                                        public void run(IProgressMonitor monitor)
247:                                                throws InvocationTargetException,
248:                                                InterruptedException {
249:                                            monitor
250:                                                    .beginTask(
251:                                                            Messages.OracleSpatialWizardPage_connectionTask,
252:                                                            IProgressMonitor.UNKNOWN);
253:                                            if (OracleSpatialWizardPage.this .connection != null)
254:                                                try {
255:                                                    OracleSpatialWizardPage.this .connection
256:                                                            .close();
257:                                                } catch (SQLException e1) {
258:                                                    // it's dead anyhow
259:                                                }
260:
261:                                            OracleConnectionFactory connFac = new OracleConnectionFactory(
262:                                                    host1, port1, db);
263:                                            connFac.setLogin(user1, pass1);
264:                                            DriverManager.setLoginTimeout(3);
265:
266:                                            try {
267:                                                OracleSpatialWizardPage.this .connection = connFac
268:                                                        .getConnectionPool()
269:                                                        .getConnection();
270:                                                if (OracleSpatialWizardPage.this .connection != null) {
271:                                                    OracleSpatialWizardPage.this .database
272:                                                            .getDisplay()
273:                                                            .asyncExec(
274:                                                                    new Runnable() {
275:                                                                        public void run() {
276:                                                                            OracleSpatialWizardPage.this .database
277:                                                                                    .notifyListeners(
278:                                                                                            SWT.FocusIn,
279:                                                                                            new Event());
280:
281:                                                                        }
282:                                                                    });
283:                                                }
284:                                            } catch (SQLException e) {
285:                                                throw new InvocationTargetException(
286:                                                        e,
287:                                                        e.getLocalizedMessage());
288:                                            }
289:                                        }
290:
291:                                    }, monitor);
292:                        }
293:                    });
294:                } catch (InvocationTargetException e2) {
295:                    throw new RuntimeException(e2.getLocalizedMessage(), e2);
296:                } catch (InterruptedException e2) {
297:                    // Don't know why this exception doesn't do anything.
298:                }
299:
300:                return connection;
301:            }
302:
303:            public void focusGained(FocusEvent e) {
304:                if (e.widget != null) {
305:                    if (e.widget.equals(schema)) {
306:                        super .focusGained(e);
307:                    }
308:                }
309:            }
310:
311:            /**
312:             * TODO summary sentence for dispose ...
313:             * 
314:             * @see org.eclipse.jface.dialogs.IDialogPage#dispose()
315:             * 
316:             */
317:            public void dispose() {
318:                super .dispose();
319:                if (connection != null)
320:                    try {
321:                        connection.close();
322:                    } catch (SQLException e) {
323:                        // it's dead anyhow
324:                    }
325:            }
326:
327:            private Connection connection = null;
328:
329:            public void modifyText(ModifyEvent e) {
330:                if (e.widget != null) {
331:                    if (e.widget.equals(host) || e.widget.equals(port)
332:                            || e.widget.equals(user) || e.widget.equals(pass)) {
333:                        setErrorMessage(null);
334:                    }
335:                }
336:                super .modifyText(e);
337:            }
338:
339:            /**
340:             * TODO summary sentence for isDBCombo ...
341:             * 
342:             * @see net.refractions.udig.catalog.internal.ui.datastore.DataBaseRegistryWizardPage#isDBCombo()
343:             * @return
344:             */
345:            protected boolean isDBCombo() {
346:                return false;
347:            }
348:
349:            protected boolean isHostCombo() {
350:                return false;
351:            }
352:
353:            /**
354:             * TODO summary sentence for hasSchema ...
355:             * 
356:             * @see net.refractions.udig.catalog.internal.ui.datastore.DataBaseRegistryWizardPage#hasSchema()
357:             * @return
358:             */
359:            protected boolean hasSchema() {
360:                return true;
361:            }
362:
363:            protected String getHostText() {
364:                String text = ((Text) host).getText();
365:                if (text.trim().length() == 0)
366:                    text = null;
367:                return host == null ? null : text;
368:            }
369:
370:            protected String getDBText() {
371:                String text = ((Text) database).getText();
372:                if (text.trim().length() == 0)
373:                    text = null;
374:                return database == null ? null : text;
375:            }
376:
377:            private String getSchema() {
378:                String text = schema.getText();
379:                if (text.trim().length() == 0)
380:                    text = null;
381:                return schema == null ? null : text;
382:            }
383:
384:            protected String getUserText() {
385:                String text = user.getText();
386:                if (text.trim().length() == 0)
387:                    text = null;
388:                return user == null ? null : text;
389:            }
390:
391:            protected String getPassText() {
392:                String text = pass.getText();
393:                if (text.trim().length() == 0)
394:                    text = null;
395:                return pass == null ? null : text;
396:            }
397:
398:            @Override
399:            protected boolean doIsPageComplete() {
400:                Map p = getParams();
401:                if (p == null)
402:                    return false;
403:                boolean r = factory.canProcess(p);
404:                return r;
405:            }
406:
407:            public List<IResolve> getResources(IProgressMonitor monitor)
408:                    throws Exception {
409:                if (!isPageComplete())
410:                    return null;
411:
412:                OracleServiceExtension creator = new OracleServiceExtension();
413:                IService service = creator.createService(null, getParams());
414:                service.getInfo(monitor); // load
415:
416:                List<IResolve> servers = new ArrayList<IResolve>();
417:                servers.add(service);
418:                return servers;
419:            }
420:        }
w__w___w___._ja_va2s___._c__o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.