001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data;
017:
018: import java.util.EventObject;
019: import com.vividsolutions.jts.geom.Envelope;
020:
021: /**
022: * A simple event object to represent all events triggered by DataStore
023: * instances (typically change events).
024: *
025: * <p>
026: * The "Source" FeatureEvents is taken to be a <code>FeatureSource</code>,
027: * rather than <code>DataStore</code>. The is due to FeatureSource having a a
028: * hold of Transaction information.
029: * </p>
030: *
031: * <p>
032: * DataStore implementations will actually keep the list listeners by
033: * DataSource, and can report FeatureWriter modifications as required (by
034: * filtering the Listener list by typeName and Transaction).
035: * </p>
036: *
037: * <p>
038: * The commit opperation will also need to provide notification.
039: * </p>
040: *
041: * @since GeoTools 2.0
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/api/src/main/java/org/geotools/data/FeatureEvent.java $
043: */
044: public class FeatureEvent extends EventObject {
045: private static final long serialVersionUID = 3154238322369916485L;
046:
047: /**
048: * Event type constant denoting the adding of a feature.
049: *
050: * <p>
051: * This EventType is used when FeatureWriter.write() is called when
052: * <code>FeatureWriter.hasNext()</code> has previously returned
053: * <code>false</code>. This action represents a newly create Feature being
054: * passed to the DataStore.
055: * </p>
056: *
057: * <p>
058: * The FeatureWriter making the modification will need to check that
059: * <code>typeName</code> it is modifing matches the
060: * <code>FeatureSource.getSchema().getTypeName()</code> before sending
061: * notification to any listeners on the FeatureSource.
062: * </p>
063: *
064: * <p>
065: * If the FeatureWriter is opperating against a Transaction it will need
066: * ensure that to check the FeatureSource.getTransaction() for a match
067: * before sending notification to any listeners on the FeatureSource.
068: * </p>
069: *
070: * <p>
071: * FeatureEvent.getBounds() should reflect the the Bounding Box of the
072: * newly created Features.
073: * </p>
074: */
075: public static final int FEATURES_ADDED = 1;
076:
077: /**
078: * Event type constant denoting that features in the collection has been
079: * modified.
080: *
081: * <p>
082: * This EventType is used when a FeatureWriter.write() is called when
083: * <code>FeatureWriter.hasNext()</code> returns <code>true</code> and the
084: * current Feature has been changed. This EventType is also used when a
085: * Transaction <code>commit()</code> or <code>rolledback</code> is called.
086: * </p>
087: *
088: * <p>
089: * The FeatureWriter making the modification will need to check that
090: * <code>typeName</code> it is modifing matches the
091: * <code>FeatureSource.getSchema().getTypeName()</code> before sending
092: * notification to any listeners on the FeatureSource.
093: * </p>
094: *
095: * <p>
096: * If the FeatureWriter is opperating against a Transaction it will need
097: * ensure that to check the FeatureSource.getTransaction() for a match
098: * before sending notification to any listeners on the FeatureSource. All
099: * FeatureSources of the same typename will need to be informed of a
100: * <code>commit</code>, except ones in the same Transaction, and only
101: * FeatureSources in the same Transaction will need to be informed of a
102: * rollback.
103: * </p>
104: *
105: * <p>
106: * FeatureEvent.getBounds() should reflect the the BoundingBox of the
107: * FeatureWriter modified Features. This may not be possible during a
108: * <code>commit()</code> or <code>rollback()</code> opperation.
109: * </p>
110: */
111: public static final int FEATURES_CHANGED = 0;
112:
113: /**
114: * Event type constant denoting the removal of a feature.
115: *
116: * <p>
117: * This EventType is used when FeatureWriter.remove() is called. This
118: * action represents a Feature being removed from the DataStore.
119: * </p>
120: *
121: * <p>
122: * The FeatureWriter making the modification will need to check that
123: * <code>typeName</code> it is modifing matches the
124: * <code>FeatureSource.getSchema().getTypeName()</code> before sending
125: * notification to any listeners on the FeatureSource.
126: * </p>
127: *
128: * <p>
129: * If the FeatureWriter is opperating against a Transaction it will need
130: * ensure that to check the FeatureSource.getTransaction() for a match
131: * before sending notification to any listeners on the FeatureSource.
132: * </p>
133: *
134: * <p>
135: * FeatureEvent.getBounds() should reflect the the Bounding Box of the
136: * removed Features.
137: * </p>
138: */
139: public static final int FEATURES_REMOVED = -1;
140:
141: /** Indicates one of FEATURES_ADDED, FEATURES_REMOVED, FEATURES_CHANGED */
142: private int type;
143:
144: /**
145: * Indicates the bounds in which the modification occured.
146: *
147: * <p>
148: * This value is allowed to by <code>null</code> if this information is not
149: * known.
150: * </p>
151: */
152: private Envelope bounds;
153:
154: /**
155: * Constructs a new FeatureEvent.
156: *
157: * @param featureSource The DataStore that fired the event
158: * @param eventType One of FEATURE_CHANGED, FEATURE_REMOVED or
159: * FEATURE_ADDED
160: * @param bounds The area modified by this change
161: */
162: public FeatureEvent(FeatureSource featureSource, int eventType,
163: Envelope bounds) {
164: super (featureSource);
165: this .type = eventType;
166: this .bounds = bounds;
167: }
168:
169: /**
170: * Provides access to the FeatureSource which fired the event.
171: *
172: * @return The FeatureSource which was the event's source.
173: */
174: public FeatureSource getFeatureSource() {
175: return (FeatureSource) source;
176: }
177:
178: /**
179: * Provides information on the type of change that has occured. Possible
180: * types are: add, remove, change
181: *
182: * @return an int which must be one of FEATURES_ADDED, FEATURES_REMOVED,
183: * FEATURES_CHANGED
184: */
185: public int getEventType() {
186: return type;
187: }
188:
189: /**
190: * Provides access to the area modified (if known).
191: *
192: * @return A bounding box of the modifications or <code>null</code> if
193: * unknown.
194: */
195: public Envelope getBounds() {
196: return bounds;
197: }
198: }
|