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: * Created on November 3, 2003, 12:00 PM
017: */
018:
019: package org.geotools.styling;
020:
021: import java.util.ArrayList;
022: import java.util.Arrays;
023:
024: import org.geotools.data.DataStore;
025: import org.geotools.event.GTList;
026: import org.geotools.feature.FeatureType;
027: import org.geotools.resources.Utilities;
028:
029: /**
030: * DJB: on inlinefeature support:
031: * The inline features also lets you "sort of" make your WMS into a WFS-T.
032: *
033: *I was going to implement this after SLD POST on monday, but I was
034: *expecting the definition in the spec to be a bit "nicer". Right now
035: *its just:
036: *
037: *<element name=�InlineFeature�>
038: * <complexType>
039: * <sequence>
040: * <element ref="gml:_Feature"
041: * maxOccurs="unbounded"/>
042: * </sequence>
043: * </complexType>
044: *
045: *
046: * (the spec hasnt been finalized)
047: *
048: * I guess if we make some assumptions about the data coming in - ie. every
049: * feature is the same type, and its simple (no nesting, no <choices>, and
050: * no attributes), then we can parse ones that look like:
051: *
052: * <Feature>
053: * <Name>David Blasby</Name>
054: * <Location> ... GML ... </Location>
055: * </Feature>
056: *
057: *
058: *I'm not the best at reading .xsd, but I think that means you can stick
059: *in ANY GML Feature. If so, its way too general.
060: *
061: *My plan was to parse the first Feature (or, the given schema if there is
062: *one) to find out all the property names (and which one(s) are the
063: *geometry) and make a FeatureType. (I'd assume all the properties were
064: *strings)
065: *
066: *Then, make a MemoryDataStore and put the features in it. I can pass
067: *this off to the lite renderer as normal.
068: *
069: * @author jamesm
070: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/UserLayerImpl.java $
071: */
072: public class UserLayerImpl extends StyledLayerImpl implements UserLayer {
073: /**
074: * the (memory) datastore that will contain the inline features.
075: * The initial implementation has this as a MemoryDataStore with one FeatureType in it.
076: * You should ensure that you dont keep references to it around so it can be GCed.
077: */
078: private DataStore inlineFeatureDatastore = null;
079: private FeatureType inlineFeatureType = null;
080:
081: RemoteOWS remoteOWS;
082: ArrayList styles = new GTList(this , "styles");
083: FeatureTypeConstraint[] constraints = new FeatureTypeConstraint[0];
084:
085: public RemoteOWS getRemoteOWS() {
086: return remoteOWS;
087: }
088:
089: public DataStore getInlineFeatureDatastore() {
090: return inlineFeatureDatastore;
091: }
092:
093: public FeatureType getInlineFeatureType() {
094: return inlineFeatureType;
095: }
096:
097: public void setInlineFeatureDatastore(DataStore store) {
098: inlineFeatureDatastore = store;
099: fireChanged();
100: }
101:
102: public void setInlineFeatureType(FeatureType ft) {
103: inlineFeatureType = ft;
104: fireChanged();
105: }
106:
107: public void setRemoteOWS(RemoteOWS service) {
108: RemoteOWS old = this .remoteOWS;
109: this .remoteOWS = service;
110:
111: fireChildChanged("remoteOWS", this .remoteOWS, old);
112: }
113:
114: public FeatureTypeConstraint[] getLayerFeatureConstraints() {
115: return constraints;
116: }
117:
118: public void setLayerFeatureConstraints(
119: FeatureTypeConstraint[] constraints) {
120: this .constraints = constraints;
121: fireChanged();
122: }
123:
124: public Style[] getUserStyles() {
125: return (Style[]) styles.toArray(new Style[0]);
126: }
127:
128: public void setUserStyles(Style[] styles) {
129: this .styles.clear();
130: this .styles.addAll(Arrays.asList(styles));
131: fireChanged();
132: }
133:
134: public void addUserStyle(Style style) {
135: styles.add(style);
136: fireChanged();
137: }
138:
139: public void accept(StyleVisitor visitor) {
140: visitor.visit(this );
141: }
142:
143: public boolean equals(Object oth) {
144: if (this == oth) {
145: return true;
146: }
147:
148: if (oth instanceof UserLayerImpl) {
149: UserLayerImpl other = (UserLayerImpl) oth;
150:
151: if (!(Utilities.equals(inlineFeatureDatastore,
152: other.inlineFeatureDatastore)
153: && Utilities.equals(inlineFeatureType,
154: other.inlineFeatureType)
155: && Utilities.equals(remoteOWS, other.remoteOWS) && Utilities
156: .equals(styles, other.styles))) {
157: return false;
158: }
159:
160: final int length = constraints.length;
161: if (length != other.constraints.length)
162: return false;
163: for (int i = 0; i < length; i++) {
164: if (!Utilities.equals(constraints[i],
165: other.constraints[i]))
166: return false;
167: }
168: return true;
169: }
170:
171: return false;
172: }
173: }
|