All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geotools.data.store.EventContentFeatureWriter Maven / Gradle / Ivy

Go to download

The main module contains the GeoTools public interfaces that are used by other GeoTools modules (and GeoTools applications). Where possible we make use industry standard terms as provided by OGC and ISO standards. The formal GeoTools public api consists of gt-metadata, jts and the gt-main module. The main module contains the default implementations that are available provided to other GeoTools modules using our factory system. Factories are obtained from an appropriate FactoryFinder, giving applications a chance configure the factory used using the Factory Hints facilities. FilterFactory ff = CommonFactoryFinder.getFilterFactory(); Expression expr = ff.add( expression1, expression2 ); If you find yourself using implementation specific classes chances are you doing it wrong: Expression expr = new AddImpl( expression1, expressiom2 );

There is a newer version: 24.2-oss84-1
Show newest version
/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2011, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.data.store;

import java.io.IOException;
import org.geotools.data.BatchFeatureEvent;
import org.geotools.data.DiffFeatureWriter;
import org.geotools.data.FeatureWriter;
import org.geotools.data.Transaction;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

/**
 * FeatureWriter wrapper that issues events modifications as required.
 *
 * 

It is the responsibility of a FeatureStore to issue events to interested parties as content is * modified. The {@link ContentState} keeps track of the listeners, while {@link * EventContentFeatureWriter} is willing to fire the events as needed. * *

Event generation happens in two passes: * *

    *
  • As features are modified events are sent out one at a time *
  • When commit() or rollback() is called a "batch" event is sent out *
* * The only trick is the comment() event contains our only indication of the final FeatureIDs * generated for new features. The {@link BatchFeatureEvent} maintains a map of BEFORE/AFTER values * allowing any interested party to update their seleciton. * *

Please note that if you are using {@link DiffFeatureWriter} it sends out events on its own. * * @author Jody Garnett (LISASoft) */ public class EventContentFeatureWriter implements FeatureWriter { ContentState state; SimpleFeature feature; // live value supplied by writer ContentFeatureStore store; FeatureWriter writer; /** EventContentFeatureWriter construction. */ public EventContentFeatureWriter( ContentFeatureStore store, FeatureWriter writer) { this.store = store; this.writer = writer; this.state = store.getState(); @SuppressWarnings("PMD.CloseResource") // not to be closed, not generated Transaction t = state.getTransaction(); if (t != Transaction.AUTO_COMMIT) { // auto commit does not issue batch events t.putState(this, new EventContentTransactionState()); } } /** * Supplys FeatureTypeFrom reader * * @see org.geotools.data.FeatureWriter#getFeatureType() */ public SimpleFeatureType getFeatureType() { return writer.getFeatureType(); } /** * Next Feature from reader or new content. * * @see org.geotools.data.FeatureWriter#next() */ public SimpleFeature next() throws IOException { if (writer == null) { throw new IOException("FeatureWriter has been closed"); } feature = writer.next(); return feature; } /** @see org.geotools.data.FeatureWriter#remove() */ public void remove() throws IOException { if (writer == null) { throw new IOException("FeatureWriter has been closed"); } state.fireFeatureRemoved(store, feature); writer.remove(); } /** * Writes out the current feature. * * @see org.geotools.data.FeatureWriter#write() */ public void write() throws IOException { if (writer == null) { throw new IOException("FeatureWriter has been closed"); } writer.write(); if (feature == null) { throw new IOException("No feature available to write"); } if (writer.hasNext()) { // modify existing feature ReferencedEnvelope bounds = ReferencedEnvelope.reference(feature.getBounds()); state.fireFeatureUpdated(store, feature, bounds); feature = null; } else { // modify a new feature - ie we are adding something state.fireFeatureAdded(store, feature); } } /** * Query for more content. * * @see org.geotools.data.FeatureWriter#hasNext() */ public boolean hasNext() throws IOException { if (writer == null) { return false; } return writer.hasNext(); } /** * Clean up resources associated with this writer. * *

Diff is not clear()ed as it is assumed that it belongs to a Transaction.State object and * may yet be written out. * * @see org.geotools.data.FeatureWriter#close() */ public void close() throws IOException { @SuppressWarnings("PMD.CloseResource") // not to be closed here Transaction t = state.getTransaction(); if (t != Transaction.AUTO_COMMIT) { t.removeState(this); } if (writer != null) { writer.close(); writer = null; } feature = null; } /** * Used to detect commit() and rollback() in order to fire batch feature events. * * @author jody */ class EventContentTransactionState implements Transaction.State { @Override public void commit() throws IOException { store.getState().fireBatchFeatureEvent(true); } @Override public void rollback() throws IOException { store.getState().fireBatchFeatureEvent(false); } @Override public void setTransaction(Transaction transaction) { // not needed to issue batch events (as they pretend to be from AUTO_COMMIT) } @Override public void addAuthorization(String AuthID) throws IOException { // functionality not restricted by lock authorisation } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy