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:
006: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
007: * This code is licensed under the GPL 2.0 license, availible at the root
008: * application directory.
009: */
010: package org.vfny.geoserver.global.dto;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: /**
016: * Data Transfer Object for GeoServer DataStore information.
017: *
018: * <p>
019: * Used to describe a datastore, typically one specified in the catalog.xml
020: * config file.
021: * </p>
022: *
023: * <p>
024: * Data Transfer object are used to communicate between the GeoServer
025: * application and its configuration and persistent layers. As such the class
026: * is final - to allow for its future use as an on-the-wire message.
027: * </p>
028: * Example:<code> DataStoreInfoDTO dsiDto = new DataStoreInfoDTO();
029: * dsiDto.setIde("myDataStore"); dsiDto.setEnabled(true); dsiDto.setTile("My
030: * Data Store"); Map m = new HashMap(); m.put("key","param");
031: * dsiDto.setConnectionParams(m); </code>
032: *
033: * @author dzwiers, Refractions Research, Inc.
034: * @version $Id: DataStoreInfoDTO.java 6326 2007-03-15 18:36:40Z jdeolive $
035: */
036: public final class DataStoreInfoDTO implements DataTransferObject {
037: /** unique datastore identifier */
038: private String id;
039:
040: /** unique namespace to refer to this datastore */
041: private String nameSpaceId;
042:
043: /** true if this data store is enabled */
044: private boolean enabled;
045:
046: /** The title of this data store */
047: private String title;
048:
049: /** a short description about this data store */
050: private String _abstract;
051:
052: /**
053: * Connection parameters to create the DataStoreInfo
054: *
055: * <p>
056: * Limitied to Strings for both Keys and Values.
057: * </p>
058: */
059: private Map connectionParams;
060:
061: /**
062: * DataStoreInfo constructor.
063: *
064: * <p>
065: * does nothing
066: * </p>
067: */
068: public DataStoreInfoDTO() {
069: }
070:
071: /**
072: * DataStoreInfo constructor.
073: *
074: * <p>
075: * Creates a copy of the DataStoreInfo provided. If the DataStoreInfo
076: * provided is null then default values are used. All the datastructures
077: * are cloned.
078: * </p>
079: *
080: * @param dto The datastore to copy.
081: *
082: * @throws NullPointerException DOCUMENT ME!
083: */
084: public DataStoreInfoDTO(DataStoreInfoDTO dto) {
085: if (dto == null) {
086: throw new NullPointerException(
087: "Non-Null DataStoreDTO is requried");
088: }
089:
090: id = dto.getId();
091: nameSpaceId = dto.getNameSpaceId();
092: enabled = dto.isEnabled();
093: _abstract = dto.getAbstract();
094:
095: connectionParams = new HashMap(dto.getConnectionParams());
096:
097: /*
098: try {
099: connectionParams = CloneLibrary.clone(dto.getConnectionParams()); //clone?
100: } catch (Exception e) {
101: connectionParams = new HashMap();
102: }
103: */
104: }
105:
106: /**
107: * Implement clone.
108: *
109: * <p>
110: * creates a clone of this object
111: * </p>
112: *
113: * @return A copy of this DataStoreInfo
114: *
115: * @see java.lang.Object#clone()
116: */
117: public Object clone() {
118: return new DataStoreInfoDTO(this );
119: }
120:
121: /**
122: * Implement equals.
123: *
124: * <p>
125: * recursively tests to determine if the object passed in is a copy of this
126: * object.
127: * </p>
128: *
129: * @param obj The DataStoreInfo object to test.
130: *
131: * @return true when the object passed is the same as this object.
132: *
133: * @see java.lang.Object#equals(java.lang.Object)
134: */
135: public boolean equals(Object obj) {
136: if ((obj == null) || !(obj instanceof DataStoreInfoDTO)) {
137: return false;
138: }
139:
140: DataStoreInfoDTO ds = (DataStoreInfoDTO) obj;
141: boolean r = true;
142: r = r && (id == ds.getId());
143: r = r && (nameSpaceId == ds.getNameSpaceId());
144: r = r && (enabled == ds.isEnabled());
145: r = r && (_abstract == ds.getAbstract());
146:
147: if (connectionParams != null) {
148: r = r && connectionParams.equals(ds.getConnectionParams());
149: } else if (ds.getConnectionParams() != null) {
150: return false;
151: }
152:
153: return r;
154: }
155:
156: /**
157: * Implement hashCode.
158: *
159: * @return Service hashcode or 0
160: *
161: * @see java.lang.Object#hashCode()
162: */
163: public int hashCode() {
164: int r = 1;
165:
166: if (id != null) {
167: r *= id.hashCode();
168: }
169:
170: if (nameSpaceId != null) {
171: r *= nameSpaceId.hashCode();
172: }
173:
174: if (_abstract != null) {
175: r *= _abstract.hashCode();
176: }
177:
178: return r;
179: }
180:
181: /**
182: * Short description of DataStore
183: *
184: * @return Short description
185: */
186: public String getAbstract() {
187: return _abstract;
188: }
189:
190: /**
191: * Map of param:value both of which are represented as text.
192: *
193: * <p>
194: * The map is based on String Keys, and String values.
195: * </p>
196: *
197: * @return Map of Params for DataStoreFactoryAPI use
198: */
199: public Map getConnectionParams() {
200: return connectionParams;
201: }
202:
203: /**
204: * Value is <code>true</code> if the DataStore should be enabled.
205: *
206: * @return ture if DataStore shoudl be enabled
207: */
208: public boolean isEnabled() {
209: return enabled;
210: }
211:
212: /**
213: * Unique identifier representing this DataStore.
214: *
215: * <p>
216: * This value is used to refer to this DataStore by FeatureTypeInfoDTO.
217: * </p>
218: *
219: * @return an identifier, non null
220: */
221: public String getId() {
222: return id;
223: }
224:
225: /**
226: * Namespace <code>prefix</code> for this DataStore.
227: *
228: * @return <code>prefix</code> used for GML encoding
229: */
230: public String getNameSpaceId() {
231: return nameSpaceId;
232: }
233:
234: /**
235: * Title for DataStore, used in error messages & configuration.
236: *
237: * @return Title dor the DataStore
238: */
239: public String getTitle() {
240: return title;
241: }
242:
243: /**
244: * Updates the DataStore abstract.
245: *
246: * @param description
247: */
248: public void setAbstract(String description) {
249: _abstract = description;
250: }
251:
252: /**
253: * Provide DataStore connectin parameters.
254: *
255: * <p>
256: * Map is limited to text based keys and values
257: * </p>
258: *
259: * @param map
260: */
261: public void setConnectionParams(Map map) {
262: if (map != null) {
263: connectionParams = map;
264: }
265: }
266:
267: /**
268: * setEnabled purpose.
269: *
270: * <p>
271: * Description ...
272: * </p>
273: *
274: * @param b
275: */
276: public void setEnabled(boolean b) {
277: enabled = b;
278: }
279:
280: /**
281: * Sets the unique identifier for this DataStoreInfoDTO.
282: *
283: * @param identifier non<code>null</code> identifier for DataStore
284: */
285: public void setId(String identifier) {
286: id = identifier;
287: }
288:
289: /**
290: * Sets the Namespace prefix for the DataStore.
291: *
292: * @param prefix Namespace prefix used by DataStore
293: */
294: public void setNameSpaceId(String prefix) {
295: nameSpaceId = prefix;
296: }
297:
298: /**
299: * Set title used to identify this DataStore to the user.
300: *
301: * @param dataStoreTitle Title used to identify DataStore to user
302: */
303: public void setTitle(String dataStoreTitle) {
304: title = dataStoreTitle;
305: }
306: }
|