001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.global.dto;
006:
007: /**
008: * Data Transfer Object for communication with GeoServer's Web Feature Service.
009: *
010: * <p>
011: * Data Transfer object are used to communicate between the GeoServer
012: * application and its configuration and persistent layers. As such the class
013: * is final - to allow for its future use as an on-the-wire message.
014: * </p>
015: *
016: * @author dzwiers, Refractions Research, Inc.
017: * @version $Id: WFSDTO.java 6326 2007-03-15 18:36:40Z jdeolive $
018: */
019: public final class WFSDTO implements DataTransferObject {
020: /** ServiceLevel bit used to indicate Basic support */
021: public static final int SERVICE_BASIC = 1;
022:
023: /** ServiceLevel bit used to indicate Transaction Insert support */
024: public static final int SERVICE_INSERT = 2;
025:
026: /** ServiceLevel bit used to indicate Transaction Update support */
027: public static final int SERVICE_UPDATE = 4;
028:
029: /** ServiceLevel bit used to indicate Transaction Delete support */
030: public static final int SERVICE_DELETE = 8;
031:
032: /** ServiceLevel bit used to indicate Locking support */
033: public static final int SERVICE_LOCKING = 16;
034:
035: /** ServiceLevel mask equivilent to basic WFS conformance */
036: public static final int BASIC = 1;
037:
038: /** ServiceLevel mask for transactional WFS conformance. */
039: public static final int TRANSACTIONAL = SERVICE_BASIC
040: | SERVICE_INSERT | SERVICE_UPDATE | SERVICE_DELETE;
041:
042: /** ServiceLevel mask equivilent to complete WFS conformance */
043: public static final int COMPLETE = TRANSACTIONAL | SERVICE_LOCKING;
044:
045: /** The service parameters for this instance. */
046: private ServiceDTO service;
047: private boolean srsXmlStyle = true;
048: private int serviceLevel = COMPLETE; //if not set then it should be complete
049: private boolean featureBounding = true;
050:
051: /**
052: * ie. citeConformanceHacks value equals true
053: *
054: * <p>
055: * Currently there are certain legal things in the Geoserver WFS
056: * GetCapabilities response that the CITE tests throw error if it finds.
057: * An example of this is the supported GetFeature output formats. CITE
058: * only allows GML2, GML2-ZIP, and SHAPE-ZIP. We support GML2, GML2-GZIP,
059: * GML2-ZIP, and SHAPE-ZIP, so CITE tests will complain that we're not
060: * allowed to support GML2-GZIP! By setting this option to "true" the
061: * GetCapabilities response will NOT show we support those extra
062: * dataformats. In the future we may find other "silly" things.
063: * </p>
064: */
065: private boolean citeConformanceHacks = false; //default to normal operations
066:
067: /**
068: * WFS Data Transfer Object constructor. does nothing
069: */
070: public WFSDTO() {
071: }
072:
073: /**
074: * WFS constructor.
075: *
076: * <p>
077: * Creates a copy of the WFS provided. If the WFS provided is null then
078: * default values are used. All the data structures are cloned.
079: * </p>
080: *
081: * @param other The WFS to copy.
082: *
083: * @throws NullPointerException DOCUMENT ME!
084: */
085: public WFSDTO(WFSDTO other) {
086: if (other == null) {
087: throw new NullPointerException(
088: "Data Transfer Object required");
089: }
090:
091: service = (ServiceDTO) new ServiceDTO(other.getService());
092: featureBounding = other.isFeatureBounding();
093: serviceLevel = other.getServiceLevel();
094: citeConformanceHacks = other.getCiteConformanceHacks();
095: }
096:
097: /**
098: * Implement clone as a DeepCopy.
099: *
100: * @return A Deep Copy of this WFSDTO
101: *
102: * @see java.lang.Object#clone()
103: */
104: public Object clone() {
105: return new WFSDTO(this );
106: }
107:
108: /**
109: * Implement equals.
110: *
111: * @param other Other object to test for equality
112: *
113: * @return true when the object passed is equal to this object.
114: *
115: * @see java.lang.Object#equals(java.lang.Object)
116: */
117: public boolean equals(Object other) {
118: if ((other == null) || !(other instanceof WFSDTO)) {
119: return false;
120: }
121:
122: WFSDTO dto = (WFSDTO) other;
123:
124: if (citeConformanceHacks != dto.getCiteConformanceHacks()) {
125: return false;
126: }
127:
128: if (featureBounding != dto.isFeatureBounding()) {
129: return false;
130: }
131:
132: return (((serviceLevel == dto.getServiceLevel()) && (service == null)) ? (dto
133: .getService() == null)
134: : service.equals(dto.getService()));
135: }
136:
137: /**
138: * Implement hashCode.
139: *
140: * @return Service hashcode or 0
141: *
142: * @see java.lang.Object#hashCode()
143: */
144: public int hashCode() {
145: return (service == null) ? 0 : service.hashCode();
146: }
147:
148: /**
149: * Provides access to the Service DTO object.
150: *
151: * <p>
152: * Note well that this is the internal ServiceDTO object used by the WFSDTO
153: * - any changes made to the result of this method will change the state
154: * of this WFSDTO object.
155: * </p>
156: *
157: * @return ServericeDTO used by this WFSDTO
158: */
159: public ServiceDTO getService() {
160: return service;
161: }
162:
163: /**
164: * Set this WFS Data Tranfer Object to use the provided Service DTO.
165: *
166: * <p>
167: * A copy of the provided dto is made.
168: * </p>
169: *
170: * @param dto ServiceDTO used to configure this WFSDTO
171: *
172: * @throws NullPointerException DOCUMENT ME!
173: */
174: public void setService(ServiceDTO dto) {
175: if (dto == null) {
176: throw new NullPointerException("ServiceDTO requrired");
177: }
178:
179: service = dto;
180: }
181:
182: /**
183: * Whether the srs xml attribute should be in the EPSG:4326 (non-xml)
184: * style, or in the http://www.opengis.net/gml/srs/epsg.xml#4326 style.
185: *
186: * @return <tt>true</tt> if the srs is reported with the xml style
187: */
188: public boolean isSrsXmlStyle() {
189: return srsXmlStyle;
190: }
191:
192: /**
193: * Sets whether the srs xml attribute should be in the EPSG:4326 (non-xml)
194: * style, or in the http://www.opengis.net/gml/srs/epsg.xml#4326 style.
195: *
196: * @param doXmlStyle whether the srs style should be xml or not.
197: */
198: public void setSrsXmlStyle(boolean doXmlStyle) {
199: this .srsXmlStyle = doXmlStyle;
200: }
201:
202: /**
203: * Access serviceLevel property.
204: *
205: * @return Returns the serviceLevel.
206: */
207: public int getServiceLevel() {
208: return serviceLevel;
209: }
210:
211: /**
212: * Set serviceLevel to serviceLevel.
213: *
214: * @param serviceLevel The serviceLevel to set.
215: */
216: public void setServiceLevel(int serviceLevel) {
217: this .serviceLevel = serviceLevel;
218: }
219:
220: /**
221: * turn on/off the citeConformanceHacks option.
222: *
223: * @param on
224: */
225: public void setCiteConformanceHacks(boolean on) {
226: citeConformanceHacks = on;
227: }
228:
229: /**
230: * get the current value of the citeConformanceHacks
231: *
232: * @return
233: */
234: public boolean getCiteConformanceHacks() {
235: return (citeConformanceHacks);
236: }
237:
238: /**
239: * Returns whether the gml returned by getFeature includes an
240: * auto-calculated bounds element on each feature or not.
241: *
242: * @return <tt>true</tt> if the gml features will have boundedBy
243: * automatically generated.
244: */
245: public boolean isFeatureBounding() {
246: return featureBounding;
247: }
248:
249: /**
250: * Sets whether the gml returned by getFeature includes an auto-calculated
251: * bounds element on each feature or not.
252: *
253: * @param featureBounding <tt>true</tt> if gml features should have
254: * boundedBy automatically generated.
255: */
256: public void setFeatureBounding(boolean featureBounding) {
257: this.featureBounding = featureBounding;
258: }
259: }
|