001: /*
002: * Created on 22.09.2005 for PIROL
003: *
004: * SVN header information:
005: * $Author: javamap $
006: * $Rev: 856 $
007: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
008: * $Id: PirolFeatureCollection.java 856 2007-06-19 04:15:27Z javamap $
009: */
010: package de.fho.jump.pirol.utilities.FeatureCollection;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014: import java.util.Iterator;
015: import java.util.List;
016:
017: import com.vividsolutions.jts.geom.Envelope;
018: import com.vividsolutions.jump.feature.Feature;
019: import com.vividsolutions.jump.feature.FeatureCollection;
020: import com.vividsolutions.jump.feature.FeatureDataset;
021: import com.vividsolutions.jump.feature.FeatureSchema;
022:
023: import de.fho.jump.pirol.utilities.apiTools.CollectionsTools;
024: import de.fho.jump.pirol.utilities.apiTools.FeatureCollectionTools;
025: import de.fho.jump.pirol.utilities.metaData.MetaDataMap;
026: import de.fho.jump.pirol.utilities.metaData.ObjectContainingMetaInformation;
027:
028: /**
029: *
030: * Class that wraps a FeatureDataset and adds methods to get and set meta information objects.
031: *
032: * @author Ole Rahn
033: * <br>
034: * <br>FH Osnabrück - University of Applied Sciences Osnabrück,
035: * <br>Project: PIROL (2005),
036: * <br>Subproject: Daten- und Wissensmanagement
037: *
038: * @version $Rev: 856 $
039: * @see de.fhOsnabrueck.jump.pirol.utilities.metaData.MetaInformationHandler#createPirolFeatureCollection(FeatureCollection)
040: *
041: */
042: public class PirolFeatureCollection implements FeatureCollection,
043: ObjectContainingMetaInformation {
044:
045: private static final long serialVersionUID = 1997134887214940597L;
046:
047: protected FeatureCollection featureDataSet = null;
048: protected MetaDataMap metaInformation = null;
049:
050: protected PirolFeatureCollectionRole[] roles = null;
051:
052: public PirolFeatureCollection(FeatureCollection featureDataSet,
053: PirolFeatureCollectionRole initRole) {
054: this .featureDataSet = featureDataSet;
055:
056: this .roles = new PirolFeatureCollectionRole[PirolFeatureCollectionRole.numOfExistentRoles];
057: this .roles[0] = initRole;
058: }
059:
060: /**
061: * Constructor - for java2xml, only!!
062: *
063: */
064: public PirolFeatureCollection() {
065: }
066:
067: /**
068: * for java2xml
069: */
070: public Collection getXmlRoles() {
071: ArrayList rolesForXml = new ArrayList();
072: CollectionsTools.addArrayToList(rolesForXml, this .roles);
073: return rolesForXml;
074: }
075:
076: /**
077: * for java2xml
078: */
079: public void addXmlRole(PirolFeatureCollectionRole role) {
080: this .addRole(role);
081: }
082:
083: /**
084: * for java2xml
085: */
086: public FeatureCollection getFeatureDataSet() {
087: return featureDataSet;
088: }
089:
090: /**
091: * for java2xml
092: */
093: public void setFeatureDataSet(FeatureCollection featureDataSet) {
094: this .featureDataSet = featureDataSet;
095: }
096:
097: public void addRole(PirolFeatureCollectionRole role) {
098: for (int i = 0; i < this .roles.length; i++) {
099: if (this .roles[i] == null) {
100: this .roles[i] = role;
101: return;
102: } else if (this .roles[i].equalsRole(role)) {
103: return;
104: }
105: }
106: }
107:
108: public void removeRole(PirolFeatureCollectionRole role) {
109: int removedRoleIndex = -1;
110: for (int i = 0; i < this .roles.length; i++) {
111: if (this .roles[i] == null) {
112: return;
113: } else if (this .roles[i].equalsRole(role)) {
114: this .roles[i] = null;
115: removedRoleIndex = i;
116: return;
117: } else {
118: if (removedRoleIndex > -1 && i > removedRoleIndex) {
119: this .roles[i - 1] = this .roles[i];
120: this .roles[i] = null;
121: }
122: }
123: }
124: }
125:
126: public PirolFeatureCollectionRole[] getRoles() {
127: return roles;
128: }
129:
130: /**
131: * Check if this FeatureCollection has a role like the given one
132: *@param role the role to check for
133: *@return the role if this FeatureCollection has a role like the given one, else null
134: *
135: *@see PirolFeatureCollectionRoleTypes
136: */
137: public PirolFeatureCollectionRole getRole(
138: PirolFeatureCollectionRole role) {
139: for (int i = 0; i < this .roles.length && this .roles[i] != null; i++) {
140: if (this .roles[i].equalsRole(role)) {
141: return this .roles[i];
142: }
143: }
144: return null;
145: }
146:
147: /**
148: * Check if this FeatureCollection has a role like the given one
149: *@param role the role to check for
150: *@return the role if this FeatureCollection has a role like the given one, else null
151: *
152: *@see PirolFeatureCollectionRoleTypes
153: */
154: public PirolFeatureCollectionRole getRole(
155: PirolFeatureCollectionRoleTypes role) {
156: for (int i = 0; i < this .roles.length && this .roles[i] != null; i++) {
157: if (this .roles[i].equalsRole(role)) {
158: return this .roles[i];
159: }
160: }
161: return null;
162: }
163:
164: /**
165: * Check if this FeatureCollection has a role with the given ID
166: *@param roleId id of the role type to check for
167: *@return the role if this FeatureCollection has a role with the given ID, else null
168: *
169: *@see PirolFeatureCollectionRoleTypes
170: */
171: public PirolFeatureCollectionRole getRole(int roleId) {
172: for (int i = 0; i < this .roles.length && this .roles[i] != null; i++) {
173: if (this .roles[i].equalsRole(roleId)) {
174: return this .roles[i];
175: }
176: }
177: return null;
178: }
179:
180: public MetaDataMap getMetaInformation() {
181: return metaInformation;
182: }
183:
184: public void setMetaInformation(MetaDataMap metaInformation) {
185: this .metaInformation = metaInformation;
186: }
187:
188: public void invalidateEnvelope(boolean simpleInvalidation) {
189:
190: if (FeatureDataset.class.isInstance(featureDataSet)) {
191: ((FeatureDataset) featureDataSet).invalidateEnvelope();
192: }
193:
194: if (simpleInvalidation)
195: return;
196:
197: this .featureDataSet.getEnvelope().setToNull();
198:
199: Feature[] features = FeatureCollectionTools
200: .FeatureCollection2FeatureArray(this .featureDataSet);
201: for (int i = 0; i < features.length; i++) {
202: features[i].getGeometry().geometryChanged();
203: }
204:
205: // throw new UnsupportedOperationException("the wrapped FeatureCollection does not support this operation: " + this.featureDataSet.getClass().getName());
206: }
207:
208: public void add(Feature feature) {
209: this .invalidateEnvelope(true);
210: featureDataSet.add(feature);
211: }
212:
213: public void addAll(Collection features) {
214: this .invalidateEnvelope(true);
215: featureDataSet.addAll(features);
216: }
217:
218: public void clear() {
219: this .invalidateEnvelope(true);
220: featureDataSet.clear();
221: }
222:
223: public boolean equals(Object arg0) {
224: return featureDataSet.equals(arg0);
225: }
226:
227: public Envelope getEnvelope() {
228: this .invalidateEnvelope(true);
229: return featureDataSet.getEnvelope();
230: }
231:
232: public List getFeatures() {
233: this .invalidateEnvelope(true);
234: return featureDataSet.getFeatures();
235: }
236:
237: public FeatureSchema getFeatureSchema() {
238: return featureDataSet.getFeatureSchema();
239: }
240:
241: public int hashCode() {
242: return featureDataSet.hashCode();
243: }
244:
245: public boolean isEmpty() {
246: return featureDataSet.isEmpty();
247: }
248:
249: public Iterator iterator() {
250: this .invalidateEnvelope(true);
251: return featureDataSet.iterator();
252: }
253:
254: public List query(Envelope envelope) {
255: return featureDataSet.query(envelope);
256: }
257:
258: public Collection remove(Envelope env) {
259: this .invalidateEnvelope(true);
260: return featureDataSet.remove(env);
261: }
262:
263: public void remove(Feature feature) {
264: this .invalidateEnvelope(true);
265: featureDataSet.remove(feature);
266: }
267:
268: public void removeAll(Collection features) {
269: this .invalidateEnvelope(true);
270: featureDataSet.removeAll(features);
271: }
272:
273: public int size() {
274: return featureDataSet.size();
275: }
276:
277: public String toString() {
278: return featureDataSet.toString();
279: }
280:
281: public Feature[] toArray() {
282: return FeatureCollectionTools
283: .FeatureCollection2FeatureArray(this .featureDataSet);
284: }
285:
286: protected void finalize() throws Throwable {
287: super .finalize();
288:
289: for (int i = 0; i < this .roles.length && this .roles[i] != null; i++) {
290: this .roles[i].clearRam();
291: }
292: }
293:
294: /**
295: * the PirolFeatureCollection is a wrapper for other feature collections
296: * in some cases one might want to work with the original FC. Therefor you can use this method.
297: *@return the feature collection wrapped by this PirolFeatureCollection
298: */
299: public FeatureCollection getWrappee() {
300: return this.featureDataSet;
301: }
302:
303: }
|