Source Code Cross Referenced for DefaultMapServers.java in  » GIS » geonetwork » org » wfp » vam » intermap » kernel » map » 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 » geonetwork » org.wfp.vam.intermap.kernel.map 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.wfp.vam.intermap.kernel.map;
025:
026:        import java.util.*;
027:
028:        import org.jdom.*;
029:
030:        import org.wfp.vam.intermap.Constants;
031:
032:        /**
033:         * This class holds informations about map servers listed in the map servers
034:         * configuration file.
035:         */
036:        public class DefaultMapServers {
037:
038:            private static Element mapServers;
039:            private static Element mapContexts;
040:            private static Hashtable htContexts;
041:            private static Element _defaultContext;
042:
043:            /**
044:             * Initializes map servers configuration
045:             *
046:             * @param    config              an Element
047:             *
048:             */
049:            public static void init(Element config) {
050:                // Get map servers from the configuration file
051:                mapServers = getServersEl(config);
052:                mapContexts = getContextsEl(config);
053:                htContexts = getContextsHt(config);
054:
055:                _defaultContext = getDefaultContext(config);
056:                //		mapContexts = elContexts;
057:            }
058:
059:            private static Element getServersEl(Element config) {
060:                Element elServers = (Element) (config
061:                        .getChild(Constants.MAP_SERVERS).detach());
062:                List<Element> servers = elServers.getChildren();
063:
064:                // Set the id attribute for each server
065:                int n = 1;
066:                for (Element elServer : servers)
067:                    elServer.setAttribute(Constants.MAP_SERVER_ID, "" + n++);
068:
069:                return elServers;
070:            }
071:
072:            private static Element getContextsEl(Element config) {
073:                Element elContexts = (Element) config.getChild(
074:                        Constants.MAP_CONTEXTS).clone();
075:                List<Element> contextList = elContexts
076:                        .getChildren(Constants.MAP_CONTEXT);
077:
078:                // Set the id attribute for each server
079:                int n = 1;
080:                for (Element elContext : contextList)
081:                    elContext.setAttribute(Constants.MAP_CONTEXT_ID, "" + n++);
082:
083:                //		System.out.println(Xml.getString(elContexts));
084:                return elContexts;
085:            }
086:
087:            /**
088:             * @author ETj
089:             */
090:            private static Element getDefaultContext(Element config) {
091:                Element elContexts = config.getChild(Constants.MAP_CONTEXTS);
092:                Element defCon = (Element) elContexts.getChild(
093:                        Constants.MAP_DEFAULTCONTEXT).clone();
094:
095:                return defCon;
096:            }
097:
098:            private static Hashtable getContextsHt(Element config) {
099:                Element elContexts = (Element) config.getChild(
100:                        Constants.MAP_CONTEXTS).clone();
101:                List<Element> lContexts = elContexts.getChildren();
102:
103:                // Set the id attribute for each server
104:                Hashtable htContexts = new Hashtable();
105:
106:                int n = 1;
107:                for (Element elContext : lContexts)
108:                    htContexts.put(new Integer(n++), elContext);
109:
110:                return htContexts;
111:            }
112:
113:            /**
114:             * Selects all default map servers
115:             *
116:             * @return   an Element containing all default map servers
117:             *
118:             */
119:            public static Element getServers() {
120:                return (Element) mapServers.clone();
121:            }
122:
123:            /**
124:             * Selects all default map contexts
125:             *
126:             * @return   an Element containing all default contexts
127:             *
128:             */
129:            public static Element getContexts() {
130:                return (Element) mapContexts.clone();
131:            }
132:
133:            public static Element getContext(int id) {
134:                Element context = (Element) htContexts.get(new Integer(id));
135:                return (Element) context.clone();
136:            }
137:
138:            /**
139:             * @author ETj
140:             */
141:            public static Element getDefaultContext() {
142:                return (Element) _defaultContext.clone();
143:            }
144:
145:            /**
146:             * Selects all default map servers having the selected type attribute
147:             *
148:             * @param    type                map server type
149:             *
150:             * @return   an Element containing the selected map servers
151:             *
152:             */
153:            public static Element getServers(String type) {
154:                List servers = mapServers.getChildren();
155:                Element elServers = new Element(Constants.MAP_SERVERS);
156:
157:                // Select map servers having the selected type attribute
158:                for (Iterator i = servers.iterator(); i.hasNext();) {
159:                    Element elServer = (Element) i.next();
160:                    if (elServer.getAttributeValue(Constants.MAP_SERVER_TYPE) == type)
161:                        elServers.addContent(elServer);
162:                }
163:
164:                return elServers;
165:            }
166:
167:            /**
168:             * Returns the type of the selected default map server
169:             *
170:             * @param    id                  a  String
171:             *
172:             * @return   the type of the mapserver identified by id, 0 if no server
173:             * found
174:             *
175:             * @throws   Exception
176:             *
177:             */
178:            public static int getType(String id) throws Exception {
179:                List servers = mapServers.getChildren();
180:
181:                // Look for the mapserver identified by id and return its type
182:                for (Iterator i = servers.iterator(); i.hasNext();) {
183:                    Element server = (Element) i.next();
184:                    if (server.getAttributeValue(Constants.MAP_SERVER_ID)
185:                            .equals(id))
186:                        return Integer.parseInt(server
187:                                .getAttributeValue(Constants.MAP_SERVER_TYPE));
188:                }
189:                // Return 0 if no server found
190:                return 0;
191:            }
192:
193:            /**
194:             * Returns the url of the selected default mapserver
195:             *
196:             * @param    id                  a  String
197:             *
198:             * @return   the url of the mapserver identified by id, null if no server
199:             * found
200:             *
201:             * @throws   Exception
202:             *
203:             */
204:            public static String getUrl(String id) throws Exception {
205:                List servers = mapServers.getChildren();
206:
207:                // Look for the mapserver identified by id and return its url
208:                for (Iterator i = servers.iterator(); i.hasNext();) {
209:                    Element server = (Element) i.next();
210:                    if (server.getAttributeValue(Constants.MAP_SERVER_ID)
211:                            .equals(id))
212:                        return server.getChildText(Constants.MAP_SERVER_URL);
213:                }
214:                // Return null if no server found
215:                return null;
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.