Source Code Cross Referenced for AbstractDataStoreServiceExtension.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:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.catalog;
016:
017:        import java.io.IOException;
018:        import java.io.Serializable;
019:        import java.net.URL;
020:        import java.util.Map;
021:
022:        import net.refractions.udig.catalog.internal.Messages;
023:
024:        import org.geotools.data.DataStoreFactorySpi;
025:        import org.geotools.data.DataStoreFactorySpi.Param;
026:
027:        /**
028:         * A support class for creating Service Extensions based on Geotools Datastores.  Provides feeback information for when the 
029:         * datastore cannot use the offered parameters
030:         * 
031:         * @author Jesse
032:         * @since 1.1.0
033:         */
034:        public abstract class AbstractDataStoreServiceExtension implements 
035:                ServiceExtension2 {
036:
037:            protected class ParamInfo {
038:
039:                public String the_schema;
040:                public Integer the_port;
041:                public String host;
042:                public String the_database;
043:                public String password;
044:                public String username;
045:                public String protocol;
046:
047:                public ParamInfo(String protocol, String username,
048:                        String password, String host, String the_database,
049:                        Integer the_port, String the_schema) {
050:                    this .protocol = protocol;
051:                    this .username = username;
052:                    this .password = password;
053:                    this .the_database = the_database;
054:                    this .host = host;
055:                    this .the_port = the_port;
056:                    this .the_schema = the_schema;
057:
058:                }
059:
060:            }
061:
062:            public final String reasonForFailure(
063:                    Map<String, Serializable> params) {
064:                String parameterProcessingResult = processParameters(params,
065:                        getDataStoreFactory().getParametersInfo());
066:                if (parameterProcessingResult != null)
067:                    return parameterProcessingResult;
068:
069:                String result = doOtherChecks(params);
070:                if (result != null)
071:                    return result;
072:                return null;
073:            }
074:
075:            /**
076:             * Do any other checks besides a basic parsing of the parameters.
077:             *
078:             * @param params parameters to be used for creating the datastore
079:             * 
080:             * @return null if everything checks out
081:             */
082:            protected abstract String doOtherChecks(
083:                    Map<String, Serializable> params);
084:
085:            /**
086:             * Returns an instance of the datastore factory that can create the datastore.  
087:             *
088:             * @return an instance of the datastore factory that can create the datastore.
089:             */
090:            protected abstract DataStoreFactorySpi getDataStoreFactory();
091:
092:            private String processParameters(Map<String, Serializable> params,
093:                    Param[] arrayParameters) {
094:                if (params == null) {
095:                    return Messages.DataStoreServiceExtension_nullparams;
096:                }
097:                for (int i = 0; i < arrayParameters.length; i++) {
098:                    Param param = arrayParameters[i];
099:                    Object value;
100:                    if (!params.containsKey(param.key)) {
101:                        if (param.required) {
102:                            return param.key
103:                                    + Messages.DataStoreServiceExtension_missingKey
104:                                    + param.description; // missing required key!
105:                        } else {
106:                            continue;
107:                        }
108:                    }
109:                    try {
110:                        value = param.lookUp(params);
111:                    } catch (IOException e) {
112:                        // could not upconvert/parse to expected type!
113:                        // even if this parameter is not required
114:                        // we are going to refuse to process
115:                        // these params
116:                        return Messages.DataStoreServiceExtension_theParam
117:                                + param.key
118:                                + Messages.DataStoreServiceExtension_wrongType
119:                                + param.type
120:                                + Messages.DataStoreServiceExtension_butWas
121:                                + params.get(param.key).getClass();
122:                    }
123:                    if (value == null) {
124:                        if (param.required) {
125:                            return param.key
126:                                    + Messages.DataStoreServiceExtension_nullParam
127:                                    + param.description;
128:                        }
129:                    } else {
130:                        if (!param.type.isInstance(value)) {
131:                            return Messages.DataStoreServiceExtension_theParam
132:                                    + param.key
133:                                    + Messages.DataStoreServiceExtension_wrongType
134:                                    + param.type
135:                                    + Messages.DataStoreServiceExtension_butWas
136:                                    + params.get(param.key).getClass(); // value was not of the required type
137:                        }
138:                    }
139:                }
140:                return null;
141:            }
142:
143:            /**
144:             * For special urls like DB urls.  parses out the required information from the url.  
145:             * Consider:
146:             * jdbc.postgis://username:password@hosr:port/database/schema.  
147:             * it will parse out these paarts from the url.  In cases like oracle the equivalents have to be 
148:             * understood.  
149:             *
150:             * @param url
151:             * @return
152:             */
153:            protected ParamInfo parseParamInfo(URL url) {
154:                String host = url.getHost();
155:                if (host != null && !"".equals(host)) { //$NON-NLS-1$
156:                    if (host.endsWith("postgis.jdbc")) { //$NON-NLS-1$
157:                        host = host.substring(0, host.length() - 12);
158:                    }
159:                }
160:                Integer the_port = url.getPort() == -1 ? new Integer(5432)
161:                        : new Integer(url.getPort());
162:                String path = url.getPath();
163:                String the_database;
164:                String the_schema;
165:                if (path != null) {
166:                    int endDB = path.indexOf('/', 1);
167:                    the_database = path.substring(1, endDB);
168:                    the_schema = path.substring(endDB + 1);
169:                } else {
170:                    the_database = ""; //$NON-NLS-1$
171:                    the_schema = null;
172:                }
173:                if (the_schema == null)
174:                    the_schema = "public"; //$NON-NLS-1$
175:
176:                String userInfo = url.getUserInfo() == null ? "" : url.getUserInfo(); //$NON-NLS-1$
177:                String username;
178:                String password;
179:                if (userInfo.contains(":")) { //$NON-NLS-1$
180:                    int indexOf = userInfo.indexOf(':', 1);
181:                    username = userInfo.substring(0, indexOf);
182:                    password = userInfo.substring(indexOf + 1, userInfo
183:                            .length());
184:                } else {
185:                    username = userInfo;
186:                    password = ""; //$NON-NLS-1$
187:                }
188:                return new ParamInfo(url.getProtocol(), username, password,
189:                        host, the_database, the_port, the_schema);
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.