/** * Returns a configured {@link GMLFeatureReader} instance for calling specific feature parsing methods. * * @return a configured {@link GMLFeatureReader} instance, never <code>null</code> */ public GMLFeatureReader getFeatureReader() { if ( featureReader == null ) { featureReader = new GMLFeatureReader( this ); } return featureReader; }
/** * Returns the object representation for the feature (or feature collection) element event that the cursor of the * given <code>XMLStreamReader</code> points at. * * @param xmlStream * cursor must point at the <code>START_ELEMENT</code> event of the feature element, afterwards points at * the next event after the <code>END_ELEMENT</code> event of the feature element * @param crs * default CRS for all descendant geometry properties, can be <code>null</code> * @return object representation for the given feature element * @throws XMLStreamException * @throws UnknownCRSException * @throws XMLParsingException */ public Feature parseFeature( XMLStreamReaderWrapper xmlStream, ICRS crs ) throws XMLStreamException, XMLParsingException, UnknownCRSException { if ( schema == null ) { schema = buildAppSchema( xmlStream ); gmlStreamReader.setApplicationSchema( schema ); } if ( schema instanceof DynamicAppSchema ) { return parseFeatureDynamic( xmlStream, crs, (DynamicAppSchema) schema ); } return parseFeatureStatic( xmlStream, crs ); }
/** * Returns a {@link StreamFeatureCollection} that allows stream-based access to the members of the feature * collection that the cursor of the given <code>XMLStreamReader</code> points at. * <p> * This method does not automatically consume all events from the underlying XML stream. Instead, it allows the * caller to control the consumption by iterating over the features in the returned collection. * </p> * * @return deegree model representation for the current GML feature collection element, never <code>null</code> * @throws XMLStreamException * @throws XMLParsingException * @throws UnknownCRSException */ public StreamFeatureCollection readFeatureCollectionStream() throws XMLStreamException, XMLParsingException, UnknownCRSException { return getFeatureReader().getFeatureStream( xmlStream, defaultCRS ); }
/** * Returns a {@link StreamFeatureCollection} that allows stream-based access to the members of the feature * collection that the cursor of the given <code>XMLStreamReader</code> points at. * * @param xmlStream * cursor must point at the <code>START_ELEMENT</code> event of a feature collection element * @param crs * default CRS for all descendant geometry properties, can be <code>null</code> * @return * @throws XMLStreamException */ public StreamFeatureCollection getFeatureStream( XMLStreamReaderWrapper xmlStream, ICRS crs ) throws XMLStreamException { if ( schema == null ) { schema = buildAppSchema( xmlStream ); gmlStreamReader.setApplicationSchema( schema ); } String fid = parseFeatureId( xmlStream ); QName featureName = xmlStream.getName(); FeatureCollectionType ft = (FeatureCollectionType) lookupFeatureType( xmlStream, featureName, true ); return new StreamFeatureCollection( fid, ft, this, xmlStream, crs ); }
private Feature parseFeatureDynamic( XMLStreamReaderWrapper xmlStream, ICRS crs, DynamicAppSchema appSchema ) throws XMLStreamException, XMLParsingException, UnknownCRSException { String fid = parseFeatureId( xmlStream ); FeatureType ft = lookupFeatureType( xmlStream, featureName, false ); if ( ft == null ) { LOG.debug( "- adding feature type '" + featureName + "'" ); PropertyType propDecl = ft.getPropertyDeclaration( propName ); if ( propDecl == null ) { property = parsePropertyDynamic( propName, xmlStream, activeCRS, ft, lastPropDecl, appSchema ); propDecl = property.getType(); } else { property = parseProperty( xmlStream, propDecl, activeCRS );
pt = new SimplePropertyType( propName, 1, 1, STRING, null, null ); Property prop = parseProperty( xmlStream, pt, activeCRS ); propertyList.add( prop ); xmlStream.nextTag(); if ( findConcretePropertyType( propName, activeDecl ) != null ) { while ( declIter.hasNext() && findConcretePropertyType( propName, activeDecl ) == null ) { if ( !gmlStreamReader.getLaxMode() && propOccurences < activeDecl.getMinOccurs() ) { String msg = null; propOccurences = 0; if ( findConcretePropertyType( propName, activeDecl ) == null ) { String msg = Messages.getMessage( "ERROR_PROPERTY_UNEXPECTED", propName, type.getName() ); throw new XMLParsingException( xmlStream, msg ); Property property = parseProperty( xmlStream, findConcretePropertyType( propName, activeDecl ), activeCRS ); if ( property != null ) {
private Property recreatePropertyFromGml( final PropertyType pt, final GenericXMLElement particle ) { try { final GMLSchemaInfoSet gmlSchema = ft.getSchema().getGMLSchema(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( bos ); final GMLVersion version = ft.getSchema().getGMLSchema().getVersion(); final GMLStreamWriter gmlWriter = GMLOutputFactory.createGMLStreamWriter( version, xmlWriter ); gmlWriter.setNamespaceBindings( gmlSchema.getNamespacePrefixes() ); final GmlXlinkOptions resolveState = new GmlXlinkOptions(); gmlWriter.getFeatureWriter().export( particle, resolveState ); gmlWriter.close(); xmlWriter.close(); bos.close(); final InputStream is = new ByteArrayInputStream( bos.toByteArray() ); final XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader( is ); final GMLStreamReader gmlReader = GMLInputFactory.createGMLStreamReader( version, xmlReader ); gmlReader.setApplicationSchema( ft.getSchema() ); gmlReader.setLaxMode( true ); final Property property = gmlReader.getFeatureReader().parseProperty( new XMLStreamReaderWrapper( xmlReader, null ), pt, null ); return property; } catch ( final Exception e ) { LOG.error( e.getMessage(), e ); } return new GenericProperty( pt, particle.getName(), null, particle.getAttributes(), particle.getChildren() ); }
String fid = parseFeatureId( xmlStream ); FeatureType ft = lookupFeatureType( xmlStream, featureName, true ); List<Property> propertyList = parseProperties( xmlStream, crs, ft ); if ( LOG.isDebugEnabled() ) { LOG.debug( " - parsing feature (end): " + xmlStream.getCurrentEventInfo() );
/** * Returns the deegree model representation for the GML feature element event that the cursor of the underlying xml * stream points to. * * @return deegree model representation for the current GML feature element, never <code>null</code> * @throws XMLStreamException * @throws XMLParsingException * @throws UnknownCRSException */ public Feature readFeature() throws XMLStreamException, XMLParsingException, UnknownCRSException { return getFeatureReader().parseFeature( xmlStream, defaultCRS ); }
value = refFeature; } else { value = parseFeatureDynamic( xmlStream, activeCRS, appSchema ); XMLStreamUtils.nextElement( xmlStream );
LOG.debug( "- property '" + propName + "'" ); if ( featureReader.findConcretePropertyType( propName, activeDecl ) != null ) { while ( declIter.hasNext() && featureReader.findConcretePropertyType( propName, activeDecl ) == null ) { if ( propOccurences < activeDecl.getMinOccurs() ) { String msg = null; propOccurences = 0; if ( featureReader.findConcretePropertyType( propName, activeDecl ) == null ) { String msg = Messages.getMessage( "ERROR_PROPERTY_UNEXPECTED", propName, ft.getName() ); throw new XMLParsingException( xmlStream, msg ); PropertyType pt = featureReader.findConcretePropertyType( propName, activeDecl ); if ( pt instanceof FeaturePropertyType ) { Property property = featureReader.parseProperty( xmlStream, pt, activeCRS ); if ( property != null ) { feature = (Feature) property.getValue(); featureArrayMode = true; } else { Property property = featureReader.parseProperty( xmlStream, pt, activeCRS ); if ( property != null ) {
Property prop = featureReader.parseProperty( new XMLStreamReaderWrapper( xmlStream, null ), pt, crs );
/** * Returns the deegree model representation for the GML feature collection element event that the cursor of the * underlying xml stream points to. * <p> * Please note that {@link #readFeatureCollectionStream()} should be preferred (especially for large feature * collections), because it does not build and store all features in memory at once. * </p> * * @return deegree model representation for the current GML feature collection element, never <code>null</code> * @throws XMLStreamException * @throws XMLParsingException * @throws UnknownCRSException */ public FeatureCollection readFeatureCollection() throws XMLStreamException, XMLParsingException, UnknownCRSException { return (FeatureCollection) getFeatureReader().parseFeature( xmlStream, defaultCRS ); }
private Feature readFeatureArray() throws XMLParsingException, XMLStreamException, UnknownCRSException { Feature feature = null; if ( xmlStream.getEventType() == START_ELEMENT ) { feature = featureReader.parseFeature( xmlStream, activeCRS ); } if ( xmlStream.next() == END_ELEMENT ) { LOG.debug( "End of feature array property encountered." ); featureArrayMode = false; propOccurences++; } return feature; }
private Property parseArrayProperty( XMLStreamReaderWrapper xmlStream, ArrayPropertyType propDecl, ICRS crs ) throws NoSuchElementException, XMLStreamException, XMLParsingException, UnknownCRSException { List<Feature> elems = new ArrayList<Feature>(); QName propName = xmlStream.getName(); Map<QName, PrimitiveValue> attrs = parseAttributes( xmlStream, propDecl.getElementDecl() ); boolean isNilled = attrs.containsKey( XSI_NIL ) && (Boolean) attrs.get( XSI_NIL ).getValue(); XMLStreamUtils.nextElement( xmlStream ); while ( !xmlStream.isEndElement() ) { Feature elem = gmlStreamReader.getFeatureReader().parseFeature( xmlStream, crs ); elems.add( elem ); XMLStreamUtils.nextElement( xmlStream ); } Feature[] elemArray = elems.toArray( new Feature[elems.size()] ); TypedObjectNodeArray<Feature> value = new TypedObjectNodeArray<Feature>( elemArray ); return new GenericProperty( propDecl, propName, value, isNilled ); }
private TypedObjectNode parseComplexXMLElement( XMLStreamReaderWrapper xmlStream, ICRS crs ) throws NoSuchElementException, XMLStreamException, XMLParsingException, UnknownCRSException { QName elName = xmlStream.getName(); LOG.debug( "Parsing complex XML element " + elName + " (without schema information)" ); if ( gmlStreamReader.getGeometryReader().isGeometryElement( xmlStream ) ) { return gmlStreamReader.getGeometryReader().parse( xmlStream ); } else if ( schema.getFeatureType( elName ) != null ) { return gmlStreamReader.getFeatureReader().parseFeature( xmlStream, crs ); } Map<QName, PrimitiveValue> attrs = parseAttributes( xmlStream ); List<TypedObjectNode> children = new ArrayList<TypedObjectNode>(); int eventType = 0; while ( ( eventType = xmlStream.next() ) != END_ELEMENT ) { if ( eventType == START_ELEMENT ) { TypedObjectNode child = parseGenericXMLElement( xmlStream, null, crs ); children.add( child ); } else if ( eventType == CDATA || eventType == CHARACTERS ) { // mixed content -> use string as primitive type String s = xmlStream.getText(); if ( !s.trim().isEmpty() ) { children.add( new PrimitiveValue( s ) ); } } } return new GenericXMLElement( xmlStream.getName(), null, attrs, children ); }
return gmlStreamReader.getGeometryReader().parse( xmlStream ); } else if ( schema.getFeatureType( elName ) != null ) { return gmlStreamReader.getFeatureReader().parseFeature( xmlStream, crs );
Feature subFeature = gmlStreamReader.getFeatureReader().parseFeature( xmlStream, crs ); List<TypedObjectNode> values = new ArrayList<TypedObjectNode>(); values.add( subFeature );