Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / parser / v2 / features / FeatureCollectionBinding.java @ 20663

History | View | Annotate | Download (5.14 KB)

1
package org.gvsig.gpe.gml.parser.v2.features;
2

    
3
import java.io.IOException;
4
import java.util.Map;
5

    
6
import javax.xml.namespace.QName;
7

    
8
import org.gvsig.gpe.gml.parser.GPEDefaultGmlParser;
9
import org.gvsig.gpe.gml.utils.GMLObject;
10
import org.gvsig.gpe.gml.utils.GMLTags;
11
import org.gvsig.gpe.gml.utils.GMLUtilsParser;
12
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
13
import org.gvsig.gpe.xml.stream.XmlStreamException;
14
import org.gvsig.gpe.xml.utils.CompareUtils;
15

    
16
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
17
 *
18
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
19
 *
20
 * This program is free software; you can redistribute it and/or
21
 * modify it under the terms of the GNU General Public License
22
 * as published by the Free Software Foundation; either version 2
23
 * of the License, or (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
33
 *
34
 * For more information, contact:
35
 *
36
 *  Generalitat Valenciana
37
 *   Conselleria d'Infraestructures i Transport
38
 *   Av. Blasco Ib??ez, 50
39
 *   46010 VALENCIA
40
 *   SPAIN
41
 *
42
 *      +34 963862235
43
 *   gvsig@gva.es
44
 *      www.gvsig.gva.es
45
 *
46
 *    or
47
 *
48
 *   IVER T.I. S.A
49
 *   Salamanca 50
50
 *   46005 Valencia
51
 *   Spain
52
 *
53
 *   +34 963163400
54
 *   dac@iver.es
55
 */
56
/* CVS MESSAGES:
57
 *
58
 * $Id: FeatureCollectionBinding.java 350 2008-01-09 12:53:07Z jpiera $
59
 * $Log$
60
 * Revision 1.2  2007/06/29 12:19:34  jorpiell
61
 * The schema validation is made independently of the concrete writer
62
 *
63
 * Revision 1.1  2007/06/07 14:53:30  jorpiell
64
 * Add the schema support
65
 *
66
 *
67
 */
68
/**
69
 * This class parses the gml objects that has a 
70
 * gml:FeatureCollection type. Example:
71
 * <p>
72
 * <pre>
73
 * <code>
74
 * &lt;gml:featureCollection&gt;
75
 * &lt;gml:featureMember&gt; 
76
 * &lt;/gml:featureMember&gt;
77
 * &lt;gml:featureMember&gt; 
78
 * &lt;/gml:featureMember&gt;
79
 * &lt;/gml:featureCollection&gt;
80
 * </code>
81
 * </pre>
82
 * </p>
83
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
84
 */
85
public class FeatureCollectionBinding {
86
        /**
87
         * It parses a feature collection
88
         * @param parser
89
         * The XML parser
90
         * @param handler
91
         * The GPE parser that contains the content handler and
92
         * the error handler
93
         * @return
94
         * A feature
95
         * @throws XmlStreamException
96
         * @throws IOException
97
         */
98
        public Object parse(IXmlStreamReader parser,GPEDefaultGmlParser handler) throws XmlStreamException, IOException {
99
                boolean endCollection = false;
100
                int currentTag;                
101
                Object layer = null;        
102
                //Used to finish to parse the current feature collection
103
                while(parser.getEventType()!= IXmlStreamReader.START_ELEMENT){
104
                        parser.next();
105
                }
106
                QName layerRootType = parser.getName();                
107
                
108
                Map attributes = GMLUtilsParser.getAttributes(parser);                
109
                String fid = handler.getProfile().getFeatureTypeBinding().getID(attributes);
110

    
111
                layer = handler.getContentHandler().startLayer(fid, parser.getName().getNamespaceURI(), null, null, null, null, null);
112

    
113
                QName tag = parser.getName();
114
                currentTag = parser.getEventType();
115

    
116
                while (!endCollection){
117
                        switch(currentTag){
118
                        case IXmlStreamReader.START_ELEMENT:
119
                                if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_NAME)){
120
                                        parser.next();
121
                                        handler.getContentHandler().addNameToLayer(parser.getText(), layer);
122
                                }else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_DESCRIPTION)){
123
                                        parser.next();
124
                                        handler.getContentHandler().addDescriptionToLayer(parser.getText(), layer);
125
                                }else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_BOUNDEDBY)){
126
                                        Object bbox = handler.getProfile().getBoundedByTypeBinding().
127
                                                        parse(parser, handler);
128
                                        handler.getContentHandler().addBboxToLayer(bbox, layer);
129
                                }else if (CompareUtils.compareWithNamespace(tag,GMLTags.GML_FEATUREMEMBER)){
130
                                        GMLObject object = (GMLObject)handler.getProfile().getFeatureMemberTypeBinding().
131
                                                        parse(parser, handler);
132
                                        if (object.getType() == GMLObject.FEATURE){
133
                                                handler.getContentHandler().addFeatureToLayer(object.getObject(), layer);
134
                                        }else{
135
                                                handler.getContentHandler().addParentLayerToLayer(layer, object.getObject());
136
                                        }
137
                                }else{
138
                                        if (!(CompareUtils.compareWithNamespace(layerRootType,tag))){                                                
139
                                                //Feature members
140
                                                GMLObject object =(GMLObject)handler.getProfile().getFeatureTypeBinding().parse(parser, handler);
141
                                                handler.getContentHandler().addFeatureToLayer(object.getObject(), layer);
142
                                        }
143
                                }
144
                                break;
145
                        case IXmlStreamReader.END_ELEMENT:
146
                                if (CompareUtils.compareWithNamespace(tag,layerRootType)){                                                
147
                                        endCollection = true;
148
                                        handler.getContentHandler().endLayer(layer);
149
                                }
150
                                break;
151
                        case IXmlStreamReader.CHARACTERS:                                        
152

    
153
                                break;
154
                        case IXmlStreamReader.END_DOCUMENT:
155
                                endCollection = true;
156
                                break;
157
                        }
158
                        if (!endCollection){                                        
159
                                currentTag = parser.next();
160
                                tag = parser.getName();
161
                        }
162
                }                        
163
                return layer;        
164
        }
165
}