Source Code Cross Referenced for PostGISServiceExtension.java in  » GIS » udig-1.1 » net » refractions » udig » catalog » 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 
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;
018:
019:        import java.io.Serializable;
020:        import java.net.MalformedURLException;
021:        import java.net.URL;
022:        import java.util.HashMap;
023:        import java.util.Map;
024:
025:        import net.refractions.udig.catalog.internal.postgis.PostGISServiceImpl;
026:        import net.refractions.udig.catalog.internal.postgis.PostgisPlugin;
027:        import net.refractions.udig.catalog.postgis.internal.Messages;
028:        import net.refractions.udig.core.internal.CorePlugin;
029:
030:        import org.geotools.data.DataStoreFactorySpi;
031:        import org.geotools.data.postgis.PostgisDataStoreFactory;
032:
033:        /**
034:         * PostGis ServiceExtension
035:         * @author David Zwiers, Refractions Research
036:         * @since 0.6
037:         */
038:        public class PostGISServiceExtension extends
039:                AbstractDataStoreServiceExtension implements  ServiceExtension2 {
040:
041:            /**
042:             * @param id
043:             * @param params
044:             * @return x
045:             */
046:            public IService createService(URL id,
047:                    Map<String, Serializable> params) {
048:                if (params != null
049:                        && params
050:                                .containsKey(getFactory().getParametersInfo()[2].key)
051:                        && params.get(getFactory().getParametersInfo()[2].key) instanceof  String) {
052:                    String val = (String) params.get(getFactory()
053:                            .getParametersInfo()[2].key);
054:                    params.remove(val);
055:                    params.put(getFactory().getParametersInfo()[2].key,
056:                            new Integer(val));
057:                }
058:                if (!getFactory().canProcess(params))
059:                    return null;
060:                if (id == null) {
061:                    try {
062:                        URL toURL = toURL(params);
063:                        return new PostGISServiceImpl(toURL, params);
064:                    } catch (MalformedURLException e) {
065:                        PostgisPlugin.log(
066:                                "Unable to construct proper service URL.", e); //$NON-NLS-1$
067:                        return null;
068:                    }
069:                }
070:                return new PostGISServiceImpl(id, params);
071:            }
072:
073:            public static URL toURL(Map<String, Serializable> params)
074:                    throws MalformedURLException {
075:                String the_host = (String) params.get(PostGISServiceExtension
076:                        .getFactory().getParametersInfo()[1].key);
077:                Integer intPort = (Integer) params.get(PostGISServiceExtension
078:                        .getFactory().getParametersInfo()[2].key);
079:                String the_schema = (String) params.get(PostGISServiceExtension
080:                        .getFactory().getParametersInfo()[3].key);
081:                String the_database = (String) params
082:                        .get(PostGISServiceExtension.getFactory()
083:                                .getParametersInfo()[4].key);
084:                String the_username = (String) params
085:                        .get(PostGISServiceExtension.getFactory()
086:                                .getParametersInfo()[3].key);
087:                String the_password = (String) params
088:                        .get(PostGISServiceExtension.getFactory()
089:                                .getParametersInfo()[4].key);
090:
091:                URL toURL = toURL(the_username, the_password, the_host,
092:                        intPort, the_database, the_schema);
093:                return toURL;
094:            }
095:
096:            /**
097:             * This is a guess ...
098:             * 
099:             * @see net.refractions.udig.catalog.ServiceExtension#createParams(java.net.URL)
100:             * @param url
101:             * @return x
102:             */
103:            public Map<String, Serializable> createParams(URL url) {
104:                if (!isPostGIS(url)) {
105:                    return null;
106:                }
107:
108:                ParamInfo info = parseParamInfo(url);
109:
110:                Map<String, Serializable> params = new HashMap<String, Serializable>();
111:                params.put(getFactory().getParametersInfo()[0].key, "postgis"); // dbtype //$NON-NLS-1$
112:                params.put(getFactory().getParametersInfo()[5].key,
113:                        info.username); // user
114:                params.put(getFactory().getParametersInfo()[6].key,
115:                        info.password); // pass 
116:                params.put(getFactory().getParametersInfo()[1].key, info.host); // host
117:                params.put(getFactory().getParametersInfo()[4].key,
118:                        info.the_database); // database
119:                params.put(getFactory().getParametersInfo()[2].key,
120:                        info.the_port); // port
121:                params.put(getFactory().getParametersInfo()[3].key,
122:                        info.the_schema); // database
123:                return params;
124:            }
125:
126:            private static PostgisDataStoreFactory factory = null;
127:
128:            /**
129:             * @return x
130:             */
131:            public static PostgisDataStoreFactory getFactory() {
132:                if (factory == null) {
133:                    // factory = new PostgisDataStoreFactory();
134:                    factory = new PostgisDataStoreFactory();
135:                }
136:                return factory;
137:            }
138:
139:            /** A couple quick checks on the url */
140:            public static final boolean isPostGIS(URL url) {
141:                if (url == null)
142:                    return false;
143:                return url.getProtocol().toLowerCase().equals("postgis") || url.getProtocol().toLowerCase().equals("postgis.jdbc") || //$NON-NLS-1$ //$NON-NLS-2$
144:                        url.getProtocol().toLowerCase().equals("jdbc.postgis"); //$NON-NLS-1$
145:            }
146:
147:            public static URL toURL(String the_username, String the_password,
148:                    String the_host, Integer intPort, String the_database,
149:                    String the_schema) throws MalformedURLException {
150:                String the_spec = "postgis.jdbc://" + the_username //$NON-NLS-1$
151:                        + ":" + the_password + "@" + the_host //$NON-NLS-1$ //$NON-NLS-2$
152:                        + ":" + intPort + "/" + the_database //$NON-NLS-1$ //$NON-NLS-2$
153:                        + "/" + the_schema; //$NON-NLS-1$
154:                return toURL(the_spec);
155:            }
156:
157:            public static URL toURL(String the_spec)
158:                    throws MalformedURLException {
159:                return new URL(null, the_spec, CorePlugin.RELAXED_HANDLER);
160:            }
161:
162:            @Override
163:            protected String doOtherChecks(Map<String, Serializable> params) {
164:                return null;
165:            }
166:
167:            @Override
168:            protected DataStoreFactorySpi getDataStoreFactory() {
169:                return getFactory();
170:            }
171:
172:            public String reasonForFailure(URL url) {
173:                if (!isPostGIS(url))
174:                    return Messages.PostGISServiceExtension_badURL;
175:                return reasonForFailure(createParams(url));
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.