Source Code Cross Referenced for XMLFactory.java in  » GIS » deegree » org » deegree » model » filterencoding » 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 » deegree » org.deegree.model.filterencoding 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $HeadURL:
002:        // /deegreerepository/deegree/src/org/deegree/model/filterencoding/XMLFactory.java,v
003:        // 1.1.1.1 2005/01/05 10:34:46 poth Exp $
004:        /*----------------    FILE HEADER  ------------------------------------------
005:
006:         This file is part of deegree.
007:         Copyright (C) 2001-2008 by:
008:         EXSE, Department of Geography, University of Bonn
009:         http://www.giub.uni-bonn.de/deegree/
010:         lat/lon GmbH
011:         http://www.lat-lon.de
012:
013:         This library is free software; you can redistribute it and/or
014:         modify it under the terms of the GNU Lesser General Public
015:         License as published by the Free Software Foundation; either
016:         version 2.1 of the License, or (at your option) any later version.
017:
018:         This library is distributed in the hope that it will be useful,
019:         but WITHOUT ANY WARRANTY; without even the implied warranty of
020:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
021:         Lesser General Public License for more details.
022:
023:         You should have received a copy of the GNU Lesser General Public
024:         License along with this library; if not, write to the Free Software
025:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026:
027:         Contact:
028:
029:         Andreas Poth
030:         lat/lon GmbH
031:         Aennchenstr. 19
032:         53115 Bonn
033:         Germany
034:         E-Mail: poth@lat-lon.de
035:
036:         Prof. Dr. Klaus Greve
037:         Department of Geography
038:         University of Bonn
039:         Meckenheimer Allee 166
040:         53115 Bonn
041:         Germany
042:         E-Mail: greve@giub.uni-bonn.de
043:        
044:         ---------------------------------------------------------------------------*/
045:        package org.deegree.model.filterencoding;
046:
047:        import java.io.StringReader;
048:        import java.net.URI;
049:
050:        import org.deegree.datatypes.QualifiedName;
051:        import org.deegree.framework.xml.XMLException;
052:        import org.deegree.framework.xml.XMLTools;
053:        import org.deegree.model.filterencoding.capabilities.FilterCapabilities;
054:        import org.deegree.model.filterencoding.capabilities.Function;
055:        import org.deegree.model.filterencoding.capabilities.IdCapabilities;
056:        import org.deegree.model.filterencoding.capabilities.Operator;
057:        import org.deegree.model.filterencoding.capabilities.OperatorFactory100;
058:        import org.deegree.model.filterencoding.capabilities.ScalarCapabilities;
059:        import org.deegree.model.filterencoding.capabilities.SpatialCapabilities;
060:        import org.deegree.model.filterencoding.capabilities.SpatialOperator;
061:        import org.deegree.ogcbase.CommonNamespaces;
062:        import org.w3c.dom.Document;
063:        import org.w3c.dom.Element;
064:
065:        /**
066:         * 
067:         * 
068:         * 
069:         * @version $Revision: 9383 $
070:         * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
071:         * @author last edited by: $Author: apoth $
072:         * 
073:         * @version $Revision: 9383 $, $Date: 2008-01-03 05:29:28 -0800 (Thu, 03 Jan 2008) $
074:         */
075:        public class XMLFactory {
076:
077:            private static URI OGCNS = CommonNamespaces.OGCNS;
078:
079:            /**
080:             * Appends the DOM representation of the <code>FilterCapabilities</code> to the passed
081:             * <code>Element</code>. Generated DOM structure fulfills
082:             * <code>Filter Encoding Specification 1.0.0</code>.
083:             * 
084:             * @param root
085:             * @param filterCapabilities
086:             */
087:            public static void appendFilterCapabilities100(Element root,
088:                    FilterCapabilities filterCapabilities) {
089:
090:                Element filterCapabilitiesNode = XMLTools.appendElement(root,
091:                        OGCNS, "ogc:Filter_Capabilities");
092:                Element spatialCapabilitiesNode = XMLTools.appendElement(
093:                        filterCapabilitiesNode, OGCNS,
094:                        "ogc:Spatial_Capabilities");
095:                Element spatialOperationsNode = XMLTools
096:                        .appendElement(spatialCapabilitiesNode, OGCNS,
097:                                "ogc:Spatial_Operators");
098:                SpatialCapabilities spatialCapabilities = filterCapabilities
099:                        .getSpatialCapabilities();
100:                String[] operators = new String[] {
101:                        OperatorFactory100.OPERATOR_BBOX,
102:                        OperatorFactory100.OPERATOR_EQUALS,
103:                        OperatorFactory100.OPERATOR_DISJOINT,
104:                        OperatorFactory100.OPERATOR_INTERSECT,
105:                        OperatorFactory100.OPERATOR_TOUCHES,
106:                        OperatorFactory100.OPERATOR_CROSSES,
107:                        OperatorFactory100.OPERATOR_WITHIN,
108:                        OperatorFactory100.OPERATOR_CONTAINS,
109:                        OperatorFactory100.OPERATOR_OVERLAPS,
110:                        OperatorFactory100.OPERATOR_BEYOND,
111:                        OperatorFactory100.OPERATOR_DWITHIN };
112:                for (int i = 0; i < operators.length; i++) {
113:                    if (spatialCapabilities.hasOperator(operators[i])) {
114:                        XMLTools.appendElement(spatialOperationsNode, OGCNS,
115:                                "ogc:" + operators[i]);
116:                    }
117:                }
118:                Element scalarCapabilitiesNode = XMLTools.appendElement(
119:                        filterCapabilitiesNode, OGCNS,
120:                        "ogc:Scalar_Capabilities");
121:                ScalarCapabilities scalarCapabilities = filterCapabilities
122:                        .getScalarCapabilities();
123:                if (scalarCapabilities.hasLogicalOperatorsSupport()) {
124:                    XMLTools
125:                            .appendElement(
126:                                    scalarCapabilitiesNode,
127:                                    OGCNS,
128:                                    "ogc:"
129:                                            + OperatorFactory100.OPERATOR_LOGICAL_OPERATORS);
130:                }
131:
132:                if (scalarCapabilities.getComparisonOperators().length > 0) {
133:
134:                    Element operatorsNode = XMLTools.appendElement(
135:                            scalarCapabilitiesNode, OGCNS,
136:                            "ogc:Comparison_Operators");
137:                    operators = new String[] {
138:                            OperatorFactory100.OPERATOR_SIMPLE_COMPARISONS,
139:                            OperatorFactory100.OPERATOR_LIKE,
140:                            OperatorFactory100.OPERATOR_BETWEEN,
141:                            OperatorFactory100.OPERATOR_NULL_CHECK };
142:                    for (int i = 0; i < operators.length; i++) {
143:                        if (scalarCapabilities
144:                                .hasComparisonOperator(operators[i])) {
145:                            XMLTools.appendElement(operatorsNode, OGCNS, "ogc:"
146:                                    + operators[i]);
147:                        }
148:                    }
149:                }
150:                // 'ogc:Arithmetic_Operators'-element
151:                if (scalarCapabilities.getArithmeticOperators().length > 0) {
152:                    Element operatorsNode = XMLTools.appendElement(
153:                            scalarCapabilitiesNode, OGCNS,
154:                            "ogc:Arithmetic_Operators");
155:                    // 'ogc:Simple_Arithmetic'-element
156:                    int hasFunctions = 1;
157:                    if (scalarCapabilities
158:                            .hasArithmeticOperator(OperatorFactory100.OPERATOR_SIMPLE_ARITHMETIC)) {
159:                        XMLTools
160:                                .appendElement(
161:                                        operatorsNode,
162:                                        OGCNS,
163:                                        "ogc:"
164:                                                + OperatorFactory100.OPERATOR_SIMPLE_ARITHMETIC);
165:                        hasFunctions = 2;
166:                    }
167:                    // 'ogc:Functions'-element
168:                    Operator[] arithmeticOperators = scalarCapabilities
169:                            .getArithmeticOperators();
170:                    if (arithmeticOperators.length >= hasFunctions) {
171:                        Element functionsNode = XMLTools.appendElement(
172:                                operatorsNode, OGCNS,
173:                                "ogc:" + OperatorFactory100.OPERATOR_FUNCTIONS,
174:                                null);
175:                        for (int i = 0; i < arithmeticOperators.length; i++) {
176:                            if (arithmeticOperators[i] instanceof  Function) {
177:                                Function function = (Function) arithmeticOperators[i];
178:                                Element functionNode = XMLTools.appendElement(
179:                                        functionsNode, OGCNS,
180:                                        "ogc:Function_Name");
181:                                functionNode.setAttribute("nArgs", ""
182:                                        + function.getArgumentCount());
183:                            }
184:                        }
185:                    }
186:                }
187:            }
188:
189:            /**
190:             * Appends the DOM representation of the <code>FilterCapabilities</code> to the passed
191:             * <code>Element</code>. Generated DOM structure fulfills
192:             * <code>Filter Encoding Specification 1.1.0</code>.
193:             * 
194:             * @param root
195:             * @param filterCapabilities
196:             */
197:            public static void appendFilterCapabilities110(Element root,
198:                    FilterCapabilities filterCapabilities) {
199:                Element filterCapabilitiesNode = XMLTools.appendElement(root,
200:                        OGCNS, "ogc:Filter_Capabilities");
201:                appendSpatialCapabilities110(filterCapabilitiesNode,
202:                        filterCapabilities.getSpatialCapabilities());
203:                appendScalarCapabilities110(filterCapabilitiesNode,
204:                        filterCapabilities.getScalarCapabilities());
205:                appendIdCapabilities110(filterCapabilitiesNode,
206:                        filterCapabilities.getIdCapabilities());
207:            }
208:
209:            /**
210:             * Appends the DOM representation of the <code>SpatialCapabilities</code> to the passed
211:             * <code>Element</code>. Generated DOM structure fulfills
212:             * <code>Filter Encoding Specification 1.1.0</code>.
213:             * 
214:             * @param root
215:             * @param spatialCapabilities
216:             */
217:            public static void appendSpatialCapabilities110(Element root,
218:                    SpatialCapabilities spatialCapabilities) {
219:                Element spatialCapabilitiesNode = XMLTools.appendElement(root,
220:                        OGCNS, "ogc:Spatial_Capabilities");
221:                QualifiedName[] geometryOperands = spatialCapabilities
222:                        .getGeometryOperands();
223:                if (geometryOperands != null && geometryOperands.length > 0) {
224:                    appendGeometryOperands(spatialCapabilitiesNode,
225:                            geometryOperands);
226:                } else {
227:                    // default behavior to ensure that a valid filter capabilities element will be generated
228:                    Element geometryOperandsNode = XMLTools.appendElement(
229:                            spatialCapabilitiesNode, OGCNS,
230:                            "ogc:GeometryOperands");
231:                    XMLTools.appendElement(geometryOperandsNode, OGCNS,
232:                            "ogc:GeometryOperand", "gml:Envelope");
233:
234:                }
235:                SpatialOperator[] spatialOperators = spatialCapabilities
236:                        .getSpatialOperators();
237:                Element spatialOperatorsNode = XMLTools.appendElement(
238:                        spatialCapabilitiesNode, OGCNS, "ogc:SpatialOperators");
239:                for (int i = 0; i < spatialOperators.length; i++) {
240:                    Element spatialOperatorNode = XMLTools.appendElement(
241:                            spatialOperatorsNode, OGCNS, "ogc:SpatialOperator");
242:                    spatialOperatorNode.setAttribute("name",
243:                            spatialOperators[i].getName());
244:                    geometryOperands = spatialOperators[i]
245:                            .getGeometryOperands();
246:                    if (geometryOperands != null && geometryOperands.length > 0) {
247:                        appendGeometryOperands(spatialOperatorsNode,
248:                                geometryOperands);
249:                    }
250:                }
251:            }
252:
253:            /**
254:             * Appends the DOM representation of the <code>SpatialCapabilities</code> to the passed
255:             * <code>Element</code>. Generated DOM structure fulfills
256:             * <code>Filter Encoding Specification 1.1.0</code>.
257:             * 
258:             * @param root
259:             * @param geometryOperands
260:             */
261:            public static void appendGeometryOperands(Element root,
262:                    QualifiedName[] geometryOperands) {
263:                Element geometryOperandsNode = XMLTools.appendElement(root,
264:                        OGCNS, "ogc:GeometryOperands");
265:                for (int i = 0; i < geometryOperands.length; i++) {
266:                    XMLTools.appendElement(geometryOperandsNode, OGCNS,
267:                            "ogc:GeometryOperand", geometryOperands[i]
268:                                    .getPrefixedName());
269:                }
270:            }
271:
272:            /**
273:             * Appends the DOM representation of the <code>ScalarCapabilities</code> to the passed
274:             * <code>Element</code>. Generated DOM structure fulfills
275:             * <code>Filter Encoding Specification 1.1.0</code>.
276:             * 
277:             * @param root
278:             * @param scalarCapabilities
279:             */
280:            public static void appendScalarCapabilities110(Element root,
281:                    ScalarCapabilities scalarCapabilities) {
282:
283:                Element scalarCapabilitiesNode = XMLTools.appendElement(root,
284:                        OGCNS, "ogc:Scalar_Capabilities");
285:                if (scalarCapabilities.hasLogicalOperatorsSupport()) {
286:                    XMLTools.appendElement(scalarCapabilitiesNode, OGCNS,
287:                            "ogc:LogicalOperators");
288:                }
289:                Operator[] comparisonOperators = scalarCapabilities
290:                        .getComparisonOperators();
291:                if (comparisonOperators != null) {
292:                    Element comparisonOperatorsNode = XMLTools.appendElement(
293:                            scalarCapabilitiesNode, OGCNS,
294:                            "ogc:ComparisonOperators");
295:                    for (int i = 0; i < comparisonOperators.length; i++) {
296:                        XMLTools.appendElement(comparisonOperatorsNode, OGCNS,
297:                                "ogc:ComparisonOperator",
298:                                comparisonOperators[i].getName());
299:                    }
300:                }
301:                Operator[] arithmeticOperators = scalarCapabilities
302:                        .getArithmeticOperators();
303:                if (arithmeticOperators != null) {
304:                    Element arithmeticOperatorsNode = XMLTools.appendElement(
305:                            scalarCapabilitiesNode, OGCNS,
306:                            "ogc:ArithmeticOperators");
307:                    XMLTools.appendElement(arithmeticOperatorsNode, OGCNS,
308:                            "ogc:SimpleArithmetic");
309:
310:                    boolean functionAvailable = false;
311:                    for (int i = 0; i < arithmeticOperators.length; i++) {
312:                        if (arithmeticOperators[i] instanceof  Function) {
313:                            functionAvailable = true;
314:                        }
315:                    }
316:
317:                    if (functionAvailable) {
318:                        Element functionsNode = XMLTools
319:                                .appendElement(arithmeticOperatorsNode, OGCNS,
320:                                        "ogc:Functions");
321:                        Element functionNamesNode = XMLTools.appendElement(
322:                                functionsNode, OGCNS, "ogc:FunctionNames");
323:                        for (int i = 0; i < arithmeticOperators.length; i++) {
324:                            if (arithmeticOperators[i] instanceof  Function) {
325:                                Function function = (Function) arithmeticOperators[i];
326:                                Element functionNameNode = XMLTools
327:                                        .appendElement(functionNamesNode,
328:                                                OGCNS, "ogc:FunctionName",
329:                                                function.getName());
330:                                functionNameNode.setAttribute("nArgs", ""
331:                                        + function.getArgumentCount());
332:                            }
333:                        }
334:                    }
335:                }
336:            }
337:
338:            /**
339:             * Appends the DOM representation of the <code>IdCapabilities</code> to the passed
340:             * <code>Element</code>. Generated DOM structure fulfills
341:             * <code>Filter Encoding Specification 1.1.0</code>.
342:             * 
343:             * @param root
344:             * @param idCapabilities
345:             */
346:            public static void appendIdCapabilities110(Element root,
347:                    IdCapabilities idCapabilities) {
348:                Element idCapabilitiesNode = XMLTools.appendElement(root,
349:                        OGCNS, "ogc:Id_Capabilities");
350:                if (idCapabilities != null) {
351:                    Element[] eidElements = idCapabilities.getEidElements();
352:                    for (int i = 0; i < eidElements.length; i++) {
353:                        XMLTools.insertNodeInto(eidElements[i],
354:                                idCapabilitiesNode);
355:                    }
356:                    Element[] fidElements = idCapabilities.getFidElements();
357:                    for (int i = 0; i < fidElements.length; i++) {
358:                        XMLTools.insertNodeInto(fidElements[i],
359:                                idCapabilitiesNode);
360:                    }
361:                } else {
362:                    // default
363:                    XMLTools
364:                            .appendElement(idCapabilitiesNode, OGCNS, "ogc:EID");
365:
366:                }
367:            }
368:
369:            /**
370:             * Appends the DOM representation of the given <code>Filter</code>- section to the passed
371:             * <code>Element</code>.
372:             * 
373:             * TODO: Append the DOM-structure "node by node".
374:             * 
375:             * @param root
376:             * @param filter
377:             *            must not be null
378:             * @throws XMLException
379:             */
380:            public static void appendFilter(Element root, Filter filter)
381:                    throws XMLException {
382:                String filterString = filter.toXML().toString();
383:                try {
384:                    Document doc = XMLTools
385:                            .parse(new StringReader(filterString));
386:                    XMLTools.insertNodeInto(doc.getFirstChild(), root);
387:                } catch (Exception e) {
388:                    e.printStackTrace();
389:                    throw new XMLException(
390:                            "Error appending Filter-expression: "
391:                                    + e.getMessage());
392:                }
393:            }
394:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.