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: import org.vfny.geoserver.global.MetaDataLink;
008: import java.net.URL;
009: import java.util.ArrayList;
010: import java.util.List;
011:
012: /**
013: * Data Transfer Object representing GeoServer Service information.
014: *
015: * <p>
016: * ServiceConfig is intended to be extended to provide some basic data storage
017: * facilities. This class represents the basic properties of a web service.
018: * </p>
019: *
020: * <p>
021: * Data Transfer object are used to communicate between the GeoServer
022: * application and its configuration and persistent layers. As such the class
023: * is final - to allow for its future use as an on-the-wire message.
024: * </p>
025: *
026: * <p>
027: * It is very tempting to force Web Services to completely define their own DTO
028: * elements (rather than trying for reuse using subclassing or aggregation) -
029: * simply to force each service to document what <b>it</b> means by each of
030: * these peices of information.
031: * </p>
032: *
033: * @author dzwiers, Refractions Research, Inc.
034: * @version $Id: ServiceDTO.java 6326 2007-03-15 18:36:40Z jdeolive $
035: */
036: public final class ServiceDTO implements DataTransferObject {
037: /**
038: * Represents when the Web Service is enabled/disabled.
039: *
040: * <p>
041: * Example: <code>true</code>
042: * </p>
043: */
044: private boolean enabled;
045:
046: /**
047: * Online Reference URL for the web service.
048: *
049: * <p>
050: * A location to look for when additional assistance is required.
051: * </p>
052: *
053: * <p>
054: * Example: <code>new URL("http://www.openplans.org/")</code>
055: * </p>
056: */
057: private URL onlineResource;
058:
059: /**
060: * The name of the service.
061: *
062: * <p>
063: * Example: <code>FreeWFS</code>
064: * </p>
065: *
066: * <p>
067: * It is not clear from the examples if this name allows whitespace?
068: * </p>
069: */
070: private String name;
071:
072: /**
073: * The title of the service.
074: *
075: * <p>
076: * Example: <code>The Open Planning Project Basemap Server</code>
077: * </p>
078: */
079: private String title;
080:
081: /**
082: * A short abstract about the service.
083: *
084: * <p>
085: * Example:
086: * <pre><code>
087: * This is a test server. It contains some basemap data from New York City.
088: * </code></pre>
089: * </p>
090: */
091: private String serverAbstract;
092:
093: /**
094: * A list of keywords associated with the service.
095: *
096: * <p>
097: * Example: <code>new String[]{"WFS","New York"}</code>
098: * </p>
099: */
100: private List keywords = new ArrayList();
101:
102: /**
103: * The fees associated with the service.
104: *
105: * <p>
106: * When there are not any fees, the value "NONE" is used.
107: * </p>
108: *
109: * <p>
110: * Example: <code>NONE</code>
111: * </p>
112: */
113: private String fees;
114:
115: /**
116: * The access constraints associated with the service. When there are not
117: * any, the value "NONE" is used.
118: *
119: * <p>
120: * Example: <code>"NONE"</code>
121: * </p>
122: */
123: private String accessConstraints;
124:
125: /**
126: * Name of the person who maintains the web service. Should ideally be
127: * contact information such as a email address.
128: *
129: * <p>
130: * Example: <code>"The Open Planning Project"</code>
131: * </p>
132: */
133: private String maintainer;
134: private MetaDataLink metadataLink;
135:
136: /**
137: * The output strategy to use when the service is performing a response.
138: * <p>
139: * Examples: SPEED,BUFFER,etc...
140: * </p>
141: */
142: private String strategy;
143:
144: /**
145: * The size of the buffer if the "PARTIAL-BUFFER" strategy is being used.
146: */
147: private int partialBufferSize;
148:
149: /**
150: * ServiceConfig constructor.
151: *
152: * <p>
153: * does nothing
154: * </p>
155: *
156: * @see defaultSettings()
157: */
158: public ServiceDTO() {
159: }
160:
161: /**
162: * ServiceConfig constructor.
163: *
164: * <p>
165: * This is equivalent to calling the clone method. When a null value is
166: * passed in, the default values are used. All non-primary datatypes are
167: * cloned with the exception of Strings (which have a singleton hash
168: * table in memory representation).
169: * </p>
170: *
171: * @param dto The ServiceConfig object to copy into the new ServiceConfig
172: * object.
173: *
174: * @throws NullPointerException If dto is null
175: *
176: * @see defaultSettings()
177: * @see clone()
178: */
179: public ServiceDTO(ServiceDTO dto) {
180: if (dto == null) {
181: throw new NullPointerException("ServiceDTO object required");
182: }
183:
184: enabled = dto.isEnabled();
185: name = dto.getName();
186: title = dto.getTitle();
187: serverAbstract = dto.getAbstract();
188: keywords = new ArrayList(dto.getKeywords());
189: fees = dto.getFees();
190: accessConstraints = dto.getAccessConstraints();
191: maintainer = dto.getMaintainer();
192: onlineResource = dto.getOnlineResource();
193: metadataLink = dto.getMetadataLink();
194: strategy = dto.getStrategy();
195: }
196:
197: /**
198: * Implements clone.
199: *
200: * @return An instance of a ServiceConfig object which represents a copy of
201: * the existing ServiceConfig Object.
202: *
203: * @see java.lang.Object#clone()
204: */
205: public Object clone() {
206: return new ServiceDTO(this );
207: }
208:
209: /**
210: * Implement equals.
211: *
212: * @param other The ServiceConfig object which will be tested.
213: *
214: * @return true when the classes are equal.
215: *
216: * @see java.lang.Object#equals(java.lang.Object)
217: */
218: public boolean equals(Object other) {
219: if ((other == null) || !(other instanceof ServiceDTO)) {
220: return false;
221: }
222:
223: ServiceDTO dto = (ServiceDTO) other;
224:
225: if (enabled != dto.isEnabled()) {
226: return false;
227: }
228:
229: if ((name != null) ? (!name.equals(dto.name))
230: : (dto.name != null)) {
231: return false;
232: }
233:
234: if ((title != null) ? (!title.equals(dto.title))
235: : (dto.title != null)) {
236: return false;
237: }
238:
239: if ((serverAbstract != null) ? (!serverAbstract.equals(dto
240: .getAbstract())) : (dto.serverAbstract != null)) {
241: return false;
242: }
243:
244: if (!keywords.equals(dto.keywords)) {
245: return false;
246: }
247:
248: if ((fees != null) ? (!fees.equals(dto.fees))
249: : (dto.fees != null)) {
250: return false;
251: }
252:
253: if ((accessConstraints != null) ? (!accessConstraints
254: .equals(dto.accessConstraints))
255: : (dto.accessConstraints != null)) {
256: return false;
257: }
258:
259: if ((maintainer != null) ? (!maintainer.equals(dto.maintainer))
260: : (dto.maintainer != null)) {
261: return false;
262: }
263:
264: if ((metadataLink != null) ? (!metadataLink
265: .equals(dto.metadataLink)) : (dto.metadataLink != null)) {
266: return false;
267: }
268:
269: if ((strategy != null) ? (!strategy.equals(dto.strategy))
270: : (dto.strategy != null)) {
271: return false;
272: }
273:
274: return true;
275: }
276:
277: /**
278: * Implement hashCode for ServiceDTO.
279: *
280: * @return Hashcode in agreement with equals method
281: *
282: * @see java.lang.Object#hashCode()
283: */
284: public int hashCode() {
285: return (enabled ? 1 : 0)
286: | ((name != null) ? name.hashCode() : 0)
287: | ((title != null) ? title.hashCode() : 0)
288: | ((serverAbstract != null) ? serverAbstract.hashCode()
289: : 0)
290: | ((keywords != null) ? keywords.hashCode() : 0)
291: | ((fees != null) ? fees.hashCode() : 0)
292: | ((accessConstraints != null) ? accessConstraints
293: .hashCode() : 0)
294: | ((maintainer != null) ? maintainer.hashCode() : 0)
295: | ((metadataLink != null) ? metadataLink.hashCode() : 0)
296: | ((strategy != null) ? strategy.hashCode() : 0);
297: }
298:
299: /**
300: * Name of Service.
301: *
302: * @return
303: */
304: public String getName() {
305: return name;
306: }
307:
308: /**
309: * Online Reference URL for the web service.
310: *
311: * <p>
312: * A location to look for when additional assistance is required.
313: * </p>
314: *
315: * <p>
316: * Example: <code>new URL("http://www.openplans.org/")</code>
317: * </p>
318: *
319: * @return DOCUMENT ME!
320: */
321: public URL getOnlineResource() {
322: return onlineResource;
323: }
324:
325: /**
326: * The title of the service.
327: *
328: * <p>
329: * Example: <code>The Open Planning Project Basemap Server</code>
330: * </p>
331: *
332: * @return DOCUMENT ME!
333: */
334: public String getTitle() {
335: return title;
336: }
337:
338: /**
339: * setName purpose.
340: *
341: * @param string
342: */
343: public void setName(String string) {
344: name = string;
345: }
346:
347: /**
348: * setOnlineResource purpose.
349: *
350: * @param url
351: */
352: public void setOnlineResource(URL url) {
353: onlineResource = url;
354: }
355:
356: /**
357: * Sets the title of the service.
358: *
359: * <p>
360: * Example: <code>The Open Planning Project Basemap Server</code>
361: * </p>
362: *
363: * @param string Title of the Service
364: */
365: public void setTitle(String string) {
366: title = string;
367: }
368:
369: /**
370: * getAbstract purpose.
371: *
372: * @return
373: */
374: public String getAbstract() {
375: return serverAbstract;
376: }
377:
378: /**
379: * The access constraints associated with the service.
380: *
381: * <p>
382: * When there are not any, the value "NONE" is used.
383: * </p>
384: *
385: * <p>
386: * Example: <code>"NONE"</code>
387: * </p>
388: *
389: * @return DOCUMENT ME!
390: */
391: public String getAccessConstraints() {
392: return accessConstraints;
393: }
394:
395: /**
396: * Represents when the Web Service is enabled/disabled.
397: *
398: * @return <code>true</code> is service is enabled
399: */
400: public boolean isEnabled() {
401: return enabled;
402: }
403:
404: /**
405: * The fees associated with the service.
406: *
407: * <p>
408: * When there are not any fees, the value "NONE" is used.
409: * </p>
410: *
411: * <p>
412: * Example: <code>NONE</code>
413: * </p>
414: *
415: * @return DOCUMENT ME!
416: */
417: public String getFees() {
418: return fees;
419: }
420:
421: /**
422: * Keywords associated with the service.
423: *
424: * <p>
425: * Example: <code>new String[]{"WFS","New York"}</code>
426: * </p>
427: *
428: * @return DOCUMENT ME!
429: */
430: public List getKeywords() {
431: return keywords;
432: }
433:
434: /**
435: * Name of the party who maintains the web service.
436: *
437: * <p>
438: * Should ideally be contact information such as a email address.
439: * </p>
440: *
441: * <p>
442: * Example: <code>"The Open Planning Project"</code>
443: * </p>
444: *
445: * @return The maintainer of this Service
446: */
447: public String getMaintainer() {
448: return maintainer;
449: }
450:
451: /**
452: * Provides a short abstract about the service.
453: *
454: * <p>
455: * Example:
456: * <pre><code>
457: * This is a test server. It contains some basemap data from New York City.
458: * </code></pre>
459: * </p>
460: *
461: * @param serviceAbstract Abstract describing service
462: */
463: public void setAbstract(String serviceAbstract) {
464: serverAbstract = serviceAbstract;
465: }
466:
467: /**
468: * Provide the access constraints associated with the service.
469: *
470: * <p>
471: * When there are not any, use the value "NONE".
472: * </p>
473: *
474: * <p>
475: * Example: <code>"NONE"</code>
476: * </p>
477: *
478: * @param constraints DOCUMENT ME!
479: */
480: public void setAccessConstraints(String constraints) {
481: accessConstraints = constraints;
482: }
483:
484: /**
485: * setEnabled purpose.
486: *
487: * @param b
488: */
489: public void setEnabled(boolean b) {
490: enabled = b;
491: }
492:
493: /**
494: * Provide the fees associated with the service.
495: *
496: * <p>
497: * When there are not any fees, use the value "NONE".
498: * </p>
499: *
500: * <p>
501: * Example: <code>NONE</code>
502: * </p>
503: *
504: * @param string DOCUMENT ME!
505: */
506: public void setFees(String string) {
507: fees = string;
508: }
509:
510: /**
511: * Provide keywords associated with the service.
512: *
513: * <p>
514: * Example: <code>new String[]{"WFS","New York"}</code>
515: * </p>
516: *
517: * @param array DOCUMENT ME!
518: */
519: public void setKeywords(List array) {
520: keywords = array;
521: }
522:
523: /**
524: * Provide the party that maintains the web service.
525: *
526: * <p>
527: * Should ideally be contact information such as a email address.
528: * </p>
529: *
530: * <p>
531: * Example: <code>"The Open Planning Project"</code>
532: * </p>
533: *
534: * @param string DOCUMENT ME!
535: */
536: public void setMaintainer(String string) {
537: maintainer = string;
538: }
539:
540: /**
541: * @return Returns the metadataLink.
542: *
543: */
544: public MetaDataLink getMetadataLink() {
545: return metadataLink;
546: }
547:
548: /**
549: * @param metadataLink The metadataLink to set.
550: *
551: */
552: public void setMetadataLink(MetaDataLink metadataLink) {
553: this .metadataLink = metadataLink;
554: }
555:
556: /**
557: * Sets the strategy used by the service when performing a response.
558: *
559: */
560: public void setStrategy(String strategy) {
561: this .strategy = strategy;
562: }
563:
564: /**
565: * @return The strategy used by the service when performing a response.
566: */
567: public String getStrategy() {
568: return strategy;
569: }
570:
571: /**
572: * @return The size of the buffer used by the PARTIAL-BUFFER strategy.
573: * TODO: this should be factored out when config is splittable among modules.
574: */
575: public int getPartialBufferSize() {
576: return partialBufferSize;
577: }
578:
579: /**
580: * Sets the size of the buffer used by the PARTIAL-BUFFER strategy.
581: * TODO: this should be factored out when config is splittable among modules.
582: */
583: public void setPartialBufferSize(int partialBufferSize) {
584: this.partialBufferSize = partialBufferSize;
585: }
586: }
|