Package net.opengis.wfs

Examples of net.opengis.wfs.InsertElementType


       
        AttributeDescriptor ad = ftf.createAttributeDescriptor(XSSchema.STRING_TYPE, new NameImpl("dummyAttribute"), 0, 1, true, null);
        SimpleFeatureType ft = ftf.createSimpleFeatureType(new NameImpl("dummyFeatureType"), Collections.singletonList(ad), null, false, null, null, null);
        SimpleFeature feature = ff.createSimpleFeature(new Object[] {"dummyValue"}, ft, "dummyId");
       
        InsertElementType insert = wfsfac.createInsertElementType();
        insert.getFeature().add(feature);       
       
        Encoder encoder = new Encoder(new WFSConfiguration());
        //System.out.println(encoder.encodeAsString(insert, WFS.Insert));
        Document doc = encoder.encodeAsDOM(insert, WFS.Insert);
        XMLAssert.assertXpathEvaluatesTo("dummyId", "//wfs:Insert/wfs:dummyFeatureType/@fid", doc);
View Full Code Here


       
        AttributeDescriptor ad = ftf.createAttributeDescriptor(XSSchema.STRING_TYPE, new NameImpl("dummyAttribute"), 0, 1, true, null);
        SimpleFeatureType ft = ftf.createSimpleFeatureType(new NameImpl("dummyFeatureType"), Collections.singletonList(ad), null, false, null, null, null);
        SimpleFeature feature = ff.createSimpleFeature(new Object[] {"dummyValue"}, ft, "dummyId");
       
        InsertElementType insert = wfsfac.createInsertElementType();
        insert.getFeature().add(feature);       
       
        Encoder encoder = new Encoder(new WFSConfiguration());
        //System.out.println(encoder.encodeAsString(insert, WFS.Insert));
        Document doc = encoder.encodeAsDOM(insert, WFS.Insert);
        XMLAssert.assertXpathEvaluatesTo("dummyId", "//wfs:Insert/wfs:dummyFeatureType/@gml:id", doc);
View Full Code Here

     * @generated modifiable
     */
    @SuppressWarnings("unchecked")
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        InsertElementType insertElement = wfsfactory.createInsertElementType();

        //<xsd:choice>
        //   <xsd:element ref="gml:_FeatureCollection"/>
        //   <xsd:sequence>
        //       <xsd:element maxOccurs="unbounded" ref="gml:_Feature"/>
        //   </xsd:sequence>
        //</xsd:choice>
        if (node.hasChild(FeatureCollection.class)) {
            SimpleFeatureCollection fc = (SimpleFeatureCollection) node.getChildValue(FeatureCollection.class);
            insertElement.getFeature().addAll(DataUtilities.list(fc));
        } else if (node.hasChild(SimpleFeature.class)) {
            insertElement.getFeature().addAll(node.getChildValues(SimpleFeature.class));
        }

        //<xsd:attribute default="GenerateNew" name="idgen"
        //              type="wfs:IdentifierGenerationOptionType" use="optional">
        if (node.hasAttribute("idgen")) {
            insertElement.setIdgen((IdentifierGenerationOptionType) node.getAttributeValue("idgen"));
        }

        //<xsd:attribute name="handle" type="xsd:string" use="optional">
        if (node.hasAttribute("handle")) {
            insertElement.setHandle((String) node.getAttributeValue("handle"));
        }

        //<xsd:attribute default="text/xml; subtype=gml/3.1.1"
        //               name="inputFormat" type="xsd:string" use="optional">
        if (node.hasAttribute("inputFormat")) {
            insertElement.setInputFormat((String) node.getAttributeValue("inputFormat"));
        }

        //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
        if (node.hasAttribute("srsName")) {
            insertElement.setSrsName((URI) node.getAttributeValue("srsName"));
        }

        return insertElement;
    }
View Full Code Here

        return insertElement;
    }

    public Object getProperty(Object object, QName name)
        throws Exception {
        InsertElementType insert = (InsertElementType) object;

        if (GML._Feature.equals(name)) {
            return insert.getFeature();
        }

        return super.getProperty(object, name);
    }}
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        InsertElementType insertElement = wfsfactory.createInsertElementType();

        //features
        insertElement.getFeature().addAll(node.getChildValues(SimpleFeature.class));

        //handle
        if (node.hasAttribute("handle")) {
            insertElement.setHandle((String) node.getAttributeValue("handle"));
        }

        //NOTE: officially this is not supported for wfs 1.0, but we support it
        // here as an extension to wfs 1.0, also since its not actualy in the
        // schema it comes to us as a string, not a uri
        //<xsd:attribute name="srsName" type="xsd:anyURI" use="optional">
        if (node.hasAttribute("srsName")) {
            String srsName = (String) node.getAttributeValue("srsName");
            insertElement.setSrsName(new URI(srsName));
        }
        return insertElement;
    }
View Full Code Here

        return insertElement;
    }
   
    public Object getProperty(Object object, QName name)
        throws Exception {
        InsertElementType insert = (InsertElementType) object;
   
        if (GML._Feature.equals(name)) {
            return insert.getFeature();
        }
   
        return super.getProperty(object, name);
    }
View Full Code Here

        // build the transaction
        QName restricted = new QName(SF_NAMESPACE, "restricted");
        WfsFactory wfs = WfsFactory.eINSTANCE;
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
       
        InsertElementType insert = wfs.createInsertElementType();
        SimpleFeatureType ft = DataUtilities.createType("restricted", "cat:java.lang.Long,the_geom:Polygon");
        Geometry polygon = new WKTReader().read("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))");
        SimpleFeature f = SimpleFeatureBuilder.build(ft, new Object[] {123, polygon}, "restricted.105");
        insert.getFeature().add(f);
       
        DeleteElementType delete = wfs.createDeleteElementType();
        delete.setTypeName(restricted);
        delete.setFilter(ff.id(Collections.singleton(ff.featureId("restricted.23"))));
       
View Full Code Here

        // build the transaction
        QName restricted = new QName(SF_NAMESPACE, "restricted");
        WfsFactory wfs = WfsFactory.eINSTANCE;
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

        InsertElementType insert = wfs.createInsertElementType();
        SimpleFeatureType ft = DataUtilities.createType("restricted",
                "cat:java.lang.Long,the_geom:Polygon");
        Geometry polygon = new WKTReader().read("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))");
        SimpleFeature f = SimpleFeatureBuilder.build(ft, new Object[] { 123, polygon },
                "restricted.105");
        insert.getFeature().add(f);

        DeleteElementType delete = wfs.createDeleteElementType();
        delete.setTypeName(restricted);
        delete.setFilter(ff.id(Collections.singleton(ff.featureId("restricted.23"))));
View Full Code Here

    public void execute(EObject element, TransactionType request, Map featureStores,
        TransactionResponseType response, TransactionListener listener)
        throws WFSTransactionException {
        LOGGER.finer("Transasction Insert:" + element);

        InsertElementType insert = (InsertElementType) element;
        long inserted = response.getTransactionSummary().getTotalInserted().longValue();

        try {
            // group features by their schema
            HashMap /* <SimpleFeatureType,FeatureCollection> */ schema2features = new HashMap();

            for (Iterator f = insert.getFeature().iterator(); f.hasNext();) {
                SimpleFeature feature = (SimpleFeature) f.next();
                SimpleFeatureType schema = feature.getFeatureType();
                SimpleFeatureCollection collection;
                collection = (SimpleFeatureCollection) schema2features.get(schema);

                if (collection == null) {
                    collection = new DefaultFeatureCollection(null, schema);
                    schema2features.put(schema, collection);
                }

                collection.add(feature);
            }

            // JD: change from set fo list because if inserting
            // features into different feature stores, they could very well
            // get given the same id
            // JD: change from list to map so that the map can later be
            // processed and we can report the fids back in the same order
            // as they were supplied
            HashMap schema2fids = new HashMap();

            for (Iterator c = schema2features.values().iterator(); c.hasNext();) {
                SimpleFeatureCollection collection = (SimpleFeatureCollection) c.next();
                SimpleFeatureType schema = collection.getSchema();

                final QName elementName = new QName(schema.getName().getNamespaceURI(), schema.getTypeName());
                SimpleFeatureStore store;
                store = DataUtilities.simple((FeatureStore) featureStores.get(elementName));

                if (store == null) {
                    throw new WFSException("Could not locate FeatureStore for '" + elementName
                        + "'");
                }

                if (collection != null) {
                    // if we really need to, make sure we are inserting coordinates that do
                    // match the CRS area of validity
                    if(getInfo().isCiteCompliant()) {
                        checkFeatureCoordinatesRange(collection);
                    }
                   
                    // reprojection
                    final GeometryDescriptor defaultGeometry = store.getSchema().getGeometryDescriptor();
                    if(defaultGeometry != null) {
                        CoordinateReferenceSystem target = defaultGeometry.getCoordinateReferenceSystem();
                        if (target != null) {
                            collection = new ReprojectingFeatureCollection(collection, target);
                        }
                    }
                   
                    // Need to use the namespace here for the
                    // lookup, due to our weird
                    // prefixed internal typenames. see
                    // http://jira.codehaus.org/secure/ViewIssue.jspa?key=GEOS-143

                    // Once we get our datastores making features
                    // with the correct namespaces
                    // we can do something like this:
                    // FeatureTypeInfo typeInfo =
                    // catalog.getFeatureTypeInfo(schema.getTypeName(),
                    // schema.getNamespace());
                    // until then (when geos-144 is resolved) we're
                    // stuck with:
                    // QName qName = (QName) typeNames.get( i );
                    // FeatureTypeInfo typeInfo =
                    // catalog.featureType( qName.getPrefix(),
                    // qName.getLocalPart() );

                    // this is possible with the insert hack above.
                    LOGGER.finer("Use featureValidation to check contents of insert");

                    // featureValidation(
                    // typeInfo.getDataStore().getId(), schema,
                    // collection );
                    List fids = (List) schema2fids.get(schema.getTypeName());

                    if (fids == null) {
                        fids = new LinkedList();
                        schema2fids.put(schema.getTypeName(), fids);
                    }

                    //fire pre insert event
                    TransactionEvent event = new TransactionEvent(TransactionEventType.PRE_INSERT,
                            elementName, collection);
                    event.setSource( insert );
                   
                    listener.dataStoreChange( event );
                    fids.addAll(store.addFeatures(collection));
                   
                    //fire post insert event
                    //event = new TransactionEvent(TransactionEventType.POST_INSERT, elementName, collection, insert );
                    //listener.dataStoreChange( event );
                }
            }

            // report back fids, we need to keep the same order the
            // fids were reported in the original feature collection
            InsertedFeatureType insertedFeature = null;

            for (Iterator f = insert.getFeature().iterator(); f.hasNext();) {
                SimpleFeature feature = (SimpleFeature) f.next();
                SimpleFeatureType schema = feature.getFeatureType();

                // get the next fid
                LinkedList fids = (LinkedList) schema2fids.get(schema.getTypeName());
                String fid = ((FeatureId) fids.removeFirst()).getID();

                insertedFeature = WfsFactory.eINSTANCE.createInsertedFeatureType();
                insertedFeature.setHandle(insert.getHandle());
                insertedFeature.getFeatureId().add(filterFactory.featureId(fid));

                response.getInsertResults().getFeature().add(insertedFeature);
            }

            // update the insert counter
            inserted += insert.getFeature().size();
        } catch (Exception e) {
            String msg = "Error performing insert: " + e.getMessage();
            throw new WFSTransactionException(msg, e, insert.getHandle());
        }

        // update transaction summary
        response.getTransactionSummary().setTotalInserted(BigInteger.valueOf(inserted));
    }
View Full Code Here

    public Class getElementClass() {
        return InsertElementType.class;
    }

    public QName[] getTypeNames(EObject element) throws WFSTransactionException {
        InsertElementType insert = (InsertElementType) element;
        List typeNames = new ArrayList();

        if (!insert.getFeature().isEmpty()) {
            for (Iterator f = insert.getFeature().iterator(); f.hasNext();) {
                SimpleFeature feature = (SimpleFeature) f.next();

                String name = feature.getFeatureType().getTypeName();
                String namespaceURI = feature.getFeatureType().getName().getNamespaceURI();
View Full Code Here

TOP

Related Classes of net.opengis.wfs.InsertElementType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.