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.config;
006:
007: import org.opengis.coverage.grid.Format;
008: import org.vfny.geoserver.global.dto.CoverageStoreInfoDTO;
009: import org.vfny.geoserver.util.CoverageStoreUtils;
010: import java.io.IOException;
011: import javax.servlet.ServletContext;
012:
013: /**
014: * DataFormatInfo purpose.
015: *
016: * <p>
017: * Used to describe a coverage format, typically one specified in the
018: * catalog.xml config file.
019: * </p>
020: *
021: * <p>
022: * </p>
023: *
024: * @author dzwiers, Refractions Research, Inc.
025: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
026: * modification)
027: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
028: * modification)
029: */
030: public class CoverageStoreConfig {
031: /**
032: * unique datasore identifier
033: */
034: private String id;
035:
036: /**
037: * unique namespace to refer to this format
038: *
039: * @uml.property name="nameSpaceId" multiplicity="(0 1)"
040: */
041: private String nameSpaceId;
042: private String type;
043: private String url;
044:
045: /**
046: * wether this format is enabled
047: */
048: private boolean enabled = true;
049:
050: /**
051: * a short description about this format
052: */
053: private String title;
054:
055: /** a short description about this format */
056: private String _abstract;
057:
058: /**
059: * Config ONLY!
060: */
061: private Format factory;
062:
063: /**
064: * Create a new CoverageStoreConfig from a dataFormatId and factoryDescription
065: *
066: * <p>
067: * Creates a DataFormatInfo to represent an instance with default data.
068: * </p>
069: *
070: * @param dataFormatId
071: * Description of Format (see CoverageStoreUtils)
072: * @param factoryDescription
073: * DOCUMENT ME!
074: *
075: * @see defaultSettings()
076: */
077: public CoverageStoreConfig(String dataFormatId,
078: String factoryDescription) {
079: this (dataFormatId, CoverageStoreUtils
080: .aquireFactory(factoryDescription));
081: }
082:
083: /** Creates a new CoverageStoreConfig for the provided factory (Format). */
084: public CoverageStoreConfig(String dataFormatId, Format factory) {
085: this .factory = factory;
086: id = dataFormatId;
087: nameSpaceId = "";
088: type = factory.getName();
089: url = "file:coverages/";
090: enabled = true;
091: title = "";
092: _abstract = "";
093: }
094:
095: /**
096: * DataFormatInfo constructor.
097: *
098: * <p>
099: * Creates a copy of the DataFormatInfoDTO provided. All the datastructures
100: * are cloned.
101: * </p>
102: *
103: * @param dto
104: * The format to copy.
105: */
106: public CoverageStoreConfig(CoverageStoreInfoDTO dto) {
107: reset(dto);
108: }
109:
110: /**
111: * Called to update Config class based on DTO information
112: *
113: * @param dto
114: * DOCUMENT ME!
115: *
116: * @throws NullPointerException
117: * DOCUMENT ME!
118: */
119: public void reset(CoverageStoreInfoDTO dto) {
120: if (dto == null) {
121: throw new NullPointerException(
122: "Non null CoverageStoreInfoDTO required");
123: }
124:
125: factory = CoverageStoreUtils.aquireFactoryByType(dto.getType());
126:
127: id = dto.getId();
128: nameSpaceId = dto.getNameSpaceId();
129: type = dto.getType();
130: url = dto.getUrl();
131: enabled = dto.isEnabled();
132: _abstract = dto.getAbstract();
133: }
134:
135: /**
136: * Implement loadDTO.
137: *
138: * <p>
139: * Populates the data fields with the DataFormatInfoDTO provided.
140: * </p>
141: *
142: * @param df
143: * the DataFormatInfoDTO to use.
144: *
145: * @throws NullPointerException
146: * DOCUMENT ME!
147: *
148: * @see org.vfny.geoserver.config.DataStructure#loadDTO(java.lang.Object)
149: */
150: public void update(CoverageStoreInfoDTO df) {
151: if (df == null) {
152: throw new NullPointerException(
153: "CoverageStoreInfo Data Transfer Object required");
154: }
155:
156: id = df.getId();
157: nameSpaceId = df.getNameSpaceId();
158: type = df.getType();
159: url = df.getUrl();
160: enabled = df.isEnabled();
161: _abstract = df.getAbstract();
162: }
163:
164: /**
165: * Implement toDTO.
166: *
167: * <p>
168: * Create a DataFormatInfoDTO from the current config object.
169: * </p>
170: *
171: * @return The data represented as a DataFormatInfoDTO
172: *
173: * @see org.vfny.geoserver.config.DataStructure#toDTO()
174: */
175: public CoverageStoreInfoDTO toDTO() {
176: CoverageStoreInfoDTO ds = new CoverageStoreInfoDTO();
177: ds.setId(id);
178: ds.setNameSpaceId(nameSpaceId);
179: ds.setType(type);
180: ds.setUrl(url);
181: ds.setEnabled(enabled);
182: ds.setAbstract(_abstract);
183:
184: return ds;
185: }
186:
187: /**
188: * getAbstract purpose.
189: *
190: * <p>
191: * Description ...
192: * </p>
193: *
194: * @return
195: */
196: public String getAbstract() {
197: return _abstract;
198: }
199:
200: /**
201: * isEnabled purpose.
202: *
203: * <p>
204: * Description ...
205: * </p>
206: *
207: * @return
208: */
209: public boolean isEnabled() {
210: return enabled;
211: }
212:
213: /**
214: * This is the Format ID
215: *
216: * <p>
217: *
218: * </p>
219: *
220: * @return
221: */
222: public String getId() {
223: return id;
224: }
225:
226: /**
227: * getTitle purpose.
228: *
229: * <p>
230: * Description ...
231: * </p>
232: *
233: * @return
234: */
235: public String getTitle() {
236: return title;
237: }
238:
239: /**
240: * setAbstract purpose.
241: *
242: * <p>
243: * Description ...
244: * </p>
245: *
246: * @param string
247: */
248: public void setAbstract(String string) {
249: if (string != null) {
250: _abstract = string;
251: }
252: }
253:
254: /**
255: * setEnabled purpose.
256: *
257: * <p>
258: * Description ...
259: * </p>
260: *
261: * @param b
262: */
263: public void setEnabled(boolean b) {
264: enabled = b;
265: }
266:
267: /**
268: * setTitle purpose.
269: *
270: * <p>
271: * Description ...
272: * </p>
273: *
274: * @param string
275: *
276: * @uml.property name="title"
277: */
278: public void setTitle(String string) {
279: if (string != null) {
280: title = string;
281: }
282: }
283:
284: // Access to Dyanmic Content
285:
286: /**
287: * It would be nice if we did not throw this away - but life is too short
288: *
289: * @return Real Format generated by this CoverageStoreConfig
290: *
291: * @throws IOException
292: * If Format could not be aquired
293: */
294: public Format findDataFormat(ServletContext sc) throws IOException {
295: return CoverageStoreUtils.acquireFormat(type, sc);
296: }
297:
298: /**
299: * @return Returns the factory.
300: */
301: public Format getFactory() {
302: return factory;
303: }
304:
305: /**
306: * @param factory
307: * The factory to set.
308: */
309: public void setFactory(Format factory) {
310: this .factory = factory;
311: }
312:
313: /**
314: * @return Returns the type.
315: */
316: public String getType() {
317: return type;
318: }
319:
320: /**
321: * @param type
322: * The type to set.
323: */
324: public void setType(String type) {
325: this .type = type;
326: }
327:
328: /**
329: * @return Returns the url.
330: */
331: public String getUrl() {
332: return url;
333: }
334:
335: /**
336: * @param url
337: * The url to set.
338: */
339: public void setUrl(String url) {
340: this .url = url;
341: }
342:
343: public String getNameSpaceId() {
344: return nameSpaceId;
345: }
346:
347: public void setNameSpaceId(String nameSpaceId) {
348: this.nameSpaceId = nameSpaceId;
349: }
350: }
|