Source Code Cross Referenced for WMSConnectionFactory.java in  » GIS » udig-1.1 » net » refractions » udig » catalog » internal » wms » 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.wms.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.refractions.udig.catalog.internal.wms.ui;
002:
003:        import java.io.IOException;
004:        import java.io.Serializable;
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:        import java.util.Collections;
008:        import java.util.HashMap;
009:        import java.util.List;
010:        import java.util.Map;
011:
012:        import net.refractions.udig.catalog.CatalogPlugin;
013:        import net.refractions.udig.catalog.IResolve;
014:        import net.refractions.udig.catalog.IService;
015:        import net.refractions.udig.catalog.internal.wms.WMSGeoResourceImpl;
016:        import net.refractions.udig.catalog.internal.wms.WMSServiceExtension;
017:        import net.refractions.udig.catalog.internal.wms.WMSServiceImpl;
018:        import net.refractions.udig.catalog.ui.UDIGConnectionFactory;
019:
020:        import org.geotools.data.wms.WebMapServer;
021:
022:        public class WMSConnectionFactory extends UDIGConnectionFactory {
023:
024:            public boolean canProcess(Object context) {
025:                if (context instanceof  IResolve) {
026:                    IResolve resolve = (IResolve) context;
027:                    return resolve.canResolve(WebMapServer.class);
028:                }
029:                return toCapabilitiesURL(context) != null;
030:            }
031:
032:            public Map<String, Serializable> createConnectionParameters(
033:                    Object context) {
034:                if (context instanceof  IResolve) {
035:                    Map params = createParams((IResolve) context);
036:                    if (!params.isEmpty())
037:                        return params;
038:                }
039:                URL url = toCapabilitiesURL(context);
040:                if (url == null) {
041:                    // so we are not sure it is a wms url
042:                    // lets guess
043:                    url = CatalogPlugin.locateURL(context);
044:                }
045:                if (url != null) {
046:                    // well we have a url - lets try it!            
047:                    List<IResolve> list = CatalogPlugin.getDefault()
048:                            .getLocalCatalog().find(url, null);
049:                    for (IResolve resolve : list) {
050:                        Map params = createParams(resolve);
051:                        if (!params.isEmpty())
052:                            return params; // we got the goods!
053:                    }
054:                    return createParams(url);
055:                }
056:                return Collections.EMPTY_MAP;
057:            }
058:
059:            static public Map<String, Serializable> createParams(IResolve handle) {
060:                if (handle instanceof  WMSServiceImpl) {
061:                    // got a hit!
062:                    WMSServiceImpl wms = (WMSServiceImpl) handle;
063:                    return wms.getConnectionParams();
064:                } else if (handle instanceof  WMSGeoResourceImpl) {
065:                    WMSGeoResourceImpl layer = (WMSGeoResourceImpl) handle;
066:                    WMSServiceImpl wms;
067:                    try {
068:                        wms = layer.parent(null);
069:                        return wms.getConnectionParams();
070:                    } catch (IOException e) {
071:                        checkedURL(layer.getIdentifier());
072:                    }
073:                } else if (handle.canResolve(WebMapServer.class)) {
074:                    // must be some kind of handle from a search!
075:                    return createParams(handle.getIdentifier());
076:                }
077:                return Collections.EMPTY_MAP;
078:            }
079:
080:            /** 'Create' params given the provided url, no magic occurs */
081:            static public Map<String, Serializable> createParams(URL url) {
082:                WMSServiceExtension factory = new WMSServiceExtension();
083:                Map params = factory.createParams(url);
084:                if (params != null)
085:                    return params;
086:
087:                Map<String, Serializable> params2 = new HashMap<String, Serializable>();
088:                params2.put(WMSServiceImpl.WMS_URL_KEY, url);
089:                return params2;
090:            }
091:
092:            /**
093:             * Convert "data" to a wms capabilities url
094:             * <p>
095:             * Candidates for conversion are:
096:             * <ul>
097:             * <li>URL - from browser DnD
098:             * <li>URL#layer - from browser DnD
099:             * <li>WMSService - from catalog DnD
100:             * <li>WMSGeoResource - from catalog DnD
101:             * <li>IService - from search DnD
102:             * </ul>
103:             * </p>
104:             * <p>
105:             * No external processing should be required here, it is enough to guess and let
106:             * the ServiceFactory try a real connect.
107:             * </p>
108:             * @param data IService, URL, or something else
109:             * @return URL considered a possibility for a WMS Capabilities, or null
110:             */
111:            static URL toCapabilitiesURL(Object data) {
112:                if (data instanceof  IResolve) {
113:                    return toCapabilitiesURL((IResolve) data);
114:                } else if (data instanceof  URL) {
115:                    return toCapabilitiesURL((URL) data);
116:                } else if (CatalogPlugin.locateURL(data) != null) {
117:                    return toCapabilitiesURL(CatalogPlugin.locateURL(data));
118:                } else {
119:                    return null; // no idea what this should be
120:                }
121:            }
122:
123:            static URL toCapabilitiesURL(IResolve resolve) {
124:                if (resolve instanceof  IService) {
125:                    return toCapabilitiesURL((IService) resolve);
126:                }
127:                return toCapabilitiesURL(resolve.getIdentifier());
128:            }
129:
130:            static URL toCapabilitiesURL(IService resolve) {
131:                if (resolve instanceof  WMSServiceImpl) {
132:                    return toCapabilitiesURL((WMSServiceImpl) resolve);
133:                }
134:                return toCapabilitiesURL(resolve.getIdentifier());
135:            }
136:
137:            /** No further QA checks needed - we know this one works */
138:            static URL toCapabilitiesURL(WMSServiceImpl wms) {
139:                return wms.getIdentifier();
140:            }
141:
142:            /** Quick sanity check to see if url is a WMS url */
143:            static URL toCapabilitiesURL(URL url) {
144:                if (url == null)
145:                    return null;
146:
147:                String path = url.getPath() == null ? null : url.getPath()
148:                        .toLowerCase();
149:                String query = url.getQuery() == null ? null : url.getQuery()
150:                        .toLowerCase();
151:                String protocol = url.getProtocol() == null ? null : url
152:                        .getProtocol().toLowerCase();
153:
154:                if (!"http".equals(protocol) //$NON-NLS-1$
155:                        && !"https".equals(protocol)) { //$NON-NLS-1$ 
156:                    return null;
157:                }
158:                if (query != null && query.indexOf("service=wms") != -1) { //$NON-NLS-1$
159:                    return checkedURL(url);
160:                } else if (query != null
161:                        && query.indexOf("service=") == -1 && query.indexOf("request=getcapabilities") != -1) { //$NON-NLS-1$ //$NON-NLS-2$
162:                    try {
163:                        return new URL(url.toString() + "&SERVICE=WMS"); //$NON-NLS-1$
164:                    } catch (MalformedURLException e) {
165:                        return null;
166:                    }
167:                }
168:
169:                if (path != null
170:                        && path.toUpperCase().indexOf("GEOSERVER/WMS") != -1) { //$NON-NLS-1$
171:                    return checkedURL(url);
172:                }
173:                if (url.toExternalForm().indexOf("WMS") != -1) { //$NON-NLS-1$
174:                    return checkedURL(url);
175:                }
176:                return null;
177:            }
178:
179:            /** Check that any trailing #layer is removed from the url */
180:            static public URL checkedURL(URL url) {
181:                String check = url.toExternalForm();
182:                int hash = check.indexOf('#');
183:                if (hash == -1) {
184:                    return url;
185:                }
186:                try {
187:                    return new URL(check.substring(0, hash));
188:                } catch (MalformedURLException e) {
189:                    return null;
190:                }
191:            }
192:
193:            public URL createConnectionURL(Object context) {
194:                // TODO Auto-generated method stub
195:                return null;
196:            }
197:
198:        }
w__ww__.___j___a_va_2_s_.___co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.