001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
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: */
017: package net.refractions.udig.catalog.memory;
018:
019: import java.io.IOException;
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import net.refractions.udig.catalog.memory.internal.MemoryServiceListener;
024:
025: import org.geotools.data.FeatureReader;
026: import org.geotools.data.memory.MemoryDataStore;
027: import org.geotools.feature.Feature;
028: import org.geotools.feature.FeatureCollection;
029: import org.geotools.feature.FeatureType;
030:
031: /**
032: * This is an extended MemoryDataStore which provides proper event
033: * notification. Clients wishing to supply their own sub-class
034: * of MemoryDataStore for use in the MemoryService extension
035: * should sub-class this class, as that will permit the Catalog
036: * to be notified by events.
037: *
038: * @author mleslie
039: * @author rgould
040: * @since 0.6.0
041: */
042: public class ActiveMemoryDataStore extends MemoryDataStore {
043: List<MemoryServiceListener> list = new ArrayList<MemoryServiceListener>();
044:
045: /**
046: * Construct <code>AnotherMemoryDataStore</code>.
047: *
048: */
049: public ActiveMemoryDataStore() {
050: super ();
051: }
052:
053: /**
054: * Construct <code>AnotherMemoryDataStore</code>.
055: *
056: * @param collection
057: */
058: public ActiveMemoryDataStore(FeatureCollection collection) {
059: super (collection);
060: }
061:
062: /**
063: * Construct <code>AnotherMemoryDataStore</code>.
064: *
065: * @param array
066: */
067: public ActiveMemoryDataStore(Feature[] array) {
068: super (array);
069: }
070:
071: /**
072: * Construct <code>AnotherMemoryDataStore</code>.
073: *
074: * @param reader
075: * @throws IOException
076: */
077: public ActiveMemoryDataStore(FeatureReader reader)
078: throws IOException {
079: super (reader);
080: }
081:
082: /**
083: * TODO summary sentence for addFeatureListener ...
084: *
085: * @param listener
086: */
087: public void addListener(MemoryServiceListener listener) {
088: this .list.add(listener);
089: }
090:
091: /**
092: * TODO summary sentence for removeFeatureListener ...
093: *
094: * @param listener
095: * @return true if removed
096: */
097: public boolean removeListener(MemoryServiceListener listener) {
098: return this .list.remove(listener);
099: }
100:
101: public void createSchema(FeatureType featureType)
102: throws IOException {
103: super .createSchema(featureType);
104: for (MemoryServiceListener listener : this .list) {
105: listener.schemaChanged();
106: }
107: }
108:
109: public void removeSchema(String typeName) {
110: schema.remove(typeName);
111: memory.remove(typeName);
112: for (MemoryServiceListener listener : this.list) {
113: listener.schemaChanged();
114: }
115: }
116:
117: }
|