Source Code Cross Referenced for ElementHandlerFactory.java in  » GIS » GeoTools-2.4.1 » org » geotools » xml » handlers » 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 » GeoTools 2.4.1 » org.geotools.xml.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
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:        package org.geotools.xml.handlers;
017:
018:        import java.net.URI;
019:        import java.net.URISyntaxException;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import java.util.logging.Logger;
023:
024:        import org.geotools.xml.SchemaFactory;
025:        import org.geotools.xml.XMLElementHandler;
026:        import org.geotools.xml.schema.ComplexType;
027:        import org.geotools.xml.schema.Element;
028:        import org.geotools.xml.schema.Schema;
029:        import org.geotools.xml.schema.SimpleType;
030:        import org.geotools.xml.schema.Type;
031:        import org.xml.sax.SAXException;
032:
033:        /**
034:         * <p>
035:         * This class is used to create handlers for child elements based on the
036:         * currently defined namespaces. This class is called by the XMLSAXHandler  to
037:         * help act as a library of prefix -> Schema mappings.
038:         * </p>
039:         *
040:         * @author dzwiers www.refractions.net
041:         *
042:         * @see org.geotools.xml.XMLSAXHandler
043:         * @see Schema
044:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/handlers/ElementHandlerFactory.java $
045:         */
046:        public class ElementHandlerFactory {
047:            public static final String KEY = "org.geotools.xml.handlers.ElementHandlerFactory_KEY";
048:            private Logger logger;
049:            private Map targSchemas = new HashMap(); // maps prefix -->> Schema
050:            private Map prefixURIs = new HashMap(); // maps prefix -->> URI
051:            protected URI defaultNS = null;
052:
053:            /**
054:             * Creates a new ElementHandlerFactory object.
055:             *
056:             * @param l Logger
057:             */
058:            public ElementHandlerFactory(Logger l) {
059:                logger = l;
060:            }
061:
062:            /**
063:             * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
064:             */
065:            public void endPrefixMapping(String prefix) {
066:                URI s = (URI) prefixURIs.remove(prefix);
067:
068:                if (s != null) {
069:                    targSchemas.remove(s);
070:                }
071:            }
072:
073:            /**
074:             * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
075:             *      java.lang.String)
076:             */
077:            public void startPrefixMapping(String prefix, String targ, URI uri)
078:                    throws SAXException {
079:                logger.finest("Target == '" + targ + "'");
080:                logger.finest("URI == '" + uri + "'");
081:
082:                try {
083:                    URI tns = new URI(targ);
084:                    Schema s = SchemaFactory.getInstance(tns, uri, logger
085:                            .getLevel());
086:
087:                    if (s != null) {
088:                        if ((prefix == null) || "".equalsIgnoreCase(prefix)) {
089:                            defaultNS = s.getTargetNamespace();
090:                        }
091:
092:                        targSchemas.put(s.getTargetNamespace(), s);
093:                        prefixURIs.put(prefix, tns);
094:                    } else {
095:                        prefixURIs.put(prefix, tns);
096:                    }
097:                } catch (URISyntaxException e) {
098:                    logger.warning(e.toString());
099:                    throw new SAXException(e);
100:                }
101:            }
102:
103:            /**
104:             * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
105:             *      java.lang.String)
106:             */
107:            public void startPrefixMapping(String prefix, String targ)
108:                    throws SAXException {
109:                logger.finest("Target == '" + targ + "'");
110:
111:                try {
112:                    URI tns = new URI(targ);
113:                    Schema s = SchemaFactory.getInstance(tns);
114:
115:                    if (s == null) {
116:                        prefixURIs.put(prefix, tns);
117:                        return;
118:                    }
119:
120:                    if ((prefix == null) || "".equalsIgnoreCase(prefix)) {
121:                        defaultNS = s.getTargetNamespace();
122:                    }
123:
124:                    targSchemas.put(s.getTargetNamespace(), s);
125:                    prefixURIs.put(prefix, tns);
126:                } catch (URISyntaxException e) {
127:                    logger.warning(e.toString());
128:                    throw new SAXException(e);
129:                }
130:            }
131:
132:            /**
133:             * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
134:             *      java.lang.String)
135:             */
136:            protected void startPrefixMapping(String prefix, Schema targ) {
137:                logger.finest("Target == '" + targ + "'");
138:                if ((prefix == null) || "".equalsIgnoreCase(prefix)) {
139:                    defaultNS = targ.getTargetNamespace();
140:                }
141:                targSchemas.put(targ.getTargetNamespace(), targ);
142:                prefixURIs.put(prefix, targ.getTargetNamespace());
143:            }
144:
145:            /**
146:             * Creates an element handler for the element specified by name and
147:             * namespace. Will return null if a suitable handler is not found.
148:             *
149:             * @param namespaceURI
150:             * @param localName
151:             *
152:             *
153:             * @throws SAXException
154:             *
155:             * @see ElementHandlerFactory#createElementHandler(Element)
156:             */
157:            public XMLElementHandler createElementHandler(URI namespaceURI,
158:                    String localName) throws SAXException {
159:
160:                if (localName == null) {
161:                    return null;
162:                }
163:
164:                if (namespaceURI == null || "".equals(namespaceURI.toString())) {
165:                    namespaceURI = defaultNS;
166:                }
167:
168:                logger.finest("Trying to create an element handler for "
169:                        + localName + " :: " + namespaceURI);
170:
171:                Schema s = (Schema) targSchemas.get(namespaceURI);
172:
173:                if (s == null) {
174:                    logger.finest("Could not find Schema " + namespaceURI);
175:
176:                    return null;
177:                }
178:
179:                logger.finest("Found Schema " + s.getTargetNamespace());
180:
181:                Element[] eth = s.getElements();
182:
183:                if (eth == null) {
184:                    return null;
185:                }
186:
187:                for (int i = 0; i < eth.length; i++) {
188:                    String name = eth[i].getName();
189:                    if (localName.equalsIgnoreCase(name)
190:                            || name.equals(IgnoreHandler.NAME)) {
191:                        return createElementHandler(eth[i]);
192:                    }
193:                }
194:
195:                //TODO search the nesting import stuff
196:                return null;
197:            }
198:
199:            /**
200:             * Creates an element handler based on the element provided.
201:             *
202:             * @param eth Element
203:             *
204:             *
205:             * @throws SAXException
206:             */
207:            public XMLElementHandler createElementHandler(Element eth)
208:                    throws SAXException {
209:                Type type = eth.getType();
210:
211:                if (type == null) {
212:                    throw new SAXException("Type not found for "
213:                            + eth.getName() + " ");
214:                }
215:
216:                if (type instanceof  SimpleType) {
217:                    return new SimpleElementHandler(eth);
218:                }
219:                if (type instanceof  ComplexType) {
220:                    return new ComplexElementHandler(this , eth);
221:                }
222:
223:                return new IgnoreHandler(eth);
224:            }
225:
226:            public URI getNamespace(String prefix) {
227:                URI s = (URI) prefixURIs.get(prefix);
228:                return s;
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.