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.wcs.requests;
006:
007: import org.vfny.geoserver.wcs.servlets.WCService;
008: import java.util.ArrayList;
009: import java.util.Iterator;
010: import java.util.List;
011: import java.util.logging.Level;
012: import java.util.logging.Logger;
013:
014: /**
015: * DOCUMENT ME!
016: *
017: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
018: * modification)
019: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
020: * modification)
021: */
022: public class DescribeRequest extends WCSRequest {
023: /** Class logger */
024: private static Logger LOGGER = org.geotools.util.logging.Logging
025: .getLogger("org.vfny.geoserver.requests.wcs");
026:
027: /** Flags whether or not all coverages were requested */
028: protected boolean allRequested = true;
029:
030: /**
031: * Stores all coverages
032: *
033: * @uml.property name="coverages"
034: * @uml.associationEnd elementType="java.lang.String" multiplicity="(0 -1)"
035: */
036: protected List coverages = new ArrayList();
037:
038: /**
039: *
040: * @uml.property name="outputFormat" multiplicity="(0 1)"
041: */
042: protected String outputFormat = "XMLSCHEMA";
043:
044: /**
045: * Empty constructor.
046: */
047: public DescribeRequest(WCService service) {
048: super ("DescribeCoverage", service);
049: }
050:
051: /**
052: * Return request type.
053: *
054: * @return DOCUMENT ME!
055: */
056: public String getRequest() {
057: return "DESCRIBECOVERAGE";
058: }
059:
060: /**
061: * Return boolean for all requested coverages.
062: *
063: * @return DOCUMENT ME!
064: */
065: public boolean allRequested() {
066: return this .allRequested;
067: }
068:
069: /**
070: * Set requested coverages.
071: *
072: * @param coverages
073: * DOCUMENT ME!
074: *
075: * @uml.property name="coverages"
076: */
077: public void setCoverages(List coverages) {
078: this .coverages.clear();
079: this .coverages.addAll(coverages);
080: this .allRequested = false;
081: }
082:
083: /**
084: * Adds a requested coverages to the list.
085: *
086: * @param coverages
087: * DOCUMENT ME!
088: */
089: public void addCoverage(String coverages) {
090: this .coverages.add(coverages);
091: this .allRequested = false;
092: }
093:
094: /**
095: * Return requested coverages.
096: *
097: * @return DOCUMENT ME!
098: *
099: * @uml.property name="coverages"
100: */
101: public List getCoverages() {
102: return this .coverages;
103: }
104:
105: /**
106: * Sets the outputFormat. Right now XMLSCHEMA is the only allowed format.
107: *
108: * @param outputFormat
109: * the new outputFormat
110: *
111: * @uml.property name="outputFormat"
112: */
113: public void setOutputFormat(String outputFormat) {
114: if (!((outputFormat == null) || outputFormat.equals(""))) {
115: this .outputFormat = outputFormat;
116: }
117: }
118:
119: /**
120: * Returns the format for printing the coverage.
121: *
122: * @return DOCUMENT ME!
123: *
124: * @uml.property name="outputFormat"
125: */
126: public String getOutputFormat() {
127: return outputFormat;
128: }
129:
130: /***************************************************************************
131: * OVERRIDES OF toString AND equals METHODS. *
132: **************************************************************************/
133:
134: /**
135: * Returns a string representation of the describe request.
136: *
137: * @return A string of this request.
138: */
139: public String toString() {
140: String returnString = "DescribeCoverage Request [outputFormat: ";
141: returnString = returnString + outputFormat + " [coverages: ";
142:
143: if (LOGGER.isLoggable(Level.FINEST)) {
144: LOGGER.finest("all req: " + allRequested());
145: }
146:
147: if (this .allRequested()) {
148: return returnString + " ALL ]";
149: } else {
150: Iterator i = coverages.listIterator();
151:
152: while (i.hasNext()) {
153: returnString = returnString + i.next();
154:
155: if (i.hasNext()) {
156: returnString = returnString + ", ";
157: }
158: }
159:
160: return returnString + "]";
161: }
162: }
163:
164: /**
165: * Standard over-ride of equals.
166: *
167: * @param o
168: * DOCUMENT ME!
169: *
170: * @return <tt>true</tt> if the object is equal to this.
171: */
172: public boolean equals(Object o) {
173: super .equals(o);
174:
175: if (!(o instanceof DescribeRequest)) {
176: return false;
177: }
178:
179: DescribeRequest request = (DescribeRequest) o;
180: boolean isEqual = true;
181: Iterator internal = coverages.listIterator();
182: Iterator compare = request.getCoverages().listIterator();
183:
184: if (request.allRequested()) {
185: isEqual = this .allRequested() && isEqual;
186:
187: return isEqual;
188: } else {
189: while (internal.hasNext()) {
190: if (compare.hasNext()) {
191: isEqual = internal.next().equals(compare.next())
192: && isEqual;
193: } else {
194: internal.next();
195: isEqual = false;
196: }
197: }
198:
199: if (compare.hasNext()) {
200: return false;
201: } else {
202: return isEqual;
203: }
204: }
205: }
206:
207: public int hashCode() {
208: int result = super .hashCode();
209: result = (23 * result);
210:
211: if (coverages != null) {
212: Iterator internal = coverages.listIterator();
213:
214: while (internal.hasNext()) {
215: result *= internal.next().hashCode();
216: }
217: }
218:
219: return result;
220: }
221: }
|