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.vfny.geoserver.global.dto.StyleDTO;
008: import java.io.File;
009:
010: /**
011: * StyleConfig purpose.
012: *
013: * <p>
014: * Defines the style ids to be used by the wms.
015: * The files must be contained in geoserver/misc/wms/styles.
016: * We're working on finding a better place for them,
017: * but for now that's where you must put them if you want them
018: * on the server.
019: * </p>
020: *
021: * @author dzwiers, Refractions Research, Inc.
022: * @version $Id: StyleConfig.java 6326 2007-03-15 18:36:40Z jdeolive $
023: */
024: public class StyleConfig {
025: /** The syle id. */
026: private String id = "";
027:
028: /** The file which contains more information about the style. */
029: private File filename = null;
030:
031: /** whether this is the system's default style. */
032: private boolean _default = false;
033:
034: /**
035: * StyleConfig constructor.
036: *
037: * <p>
038: * Creates a StyleConfig to represent an instance with default data.
039: * </p>
040: *
041: * @see defaultSettings()
042: */
043: public StyleConfig() {
044: id = "";
045: filename = null;
046: _default = false;
047: }
048:
049: /**
050: * Simple copy constructor.
051: * <p>
052: * Used to duplicate a StyleConfig during editing.
053: * </p>
054: * @param style StyleConfig to copy
055: */
056: public StyleConfig(StyleConfig style) {
057: if (style == null) {
058: throw new NullPointerException(
059: "Non null StyleConfig required");
060: }
061:
062: id = style.getId();
063: filename = new File(style.getFilename().toString());
064: _default = style.isDefault();
065: }
066:
067: /**
068: * StyleConfig constructor.
069: *
070: * <p>
071: * Creates a copy of the StyleDTO provided. All the data structures are
072: * cloned.
073: * </p>
074: *
075: * @param style The style to copy.
076: *
077: * @throws NullPointerException DOCUMENT ME!
078: */
079: public StyleConfig(StyleDTO style) {
080: if (style == null) {
081: throw new NullPointerException("Non null StyleDTO required");
082: }
083:
084: id = style.getId();
085: filename = new File(style.getFilename().toString());
086: _default = style.isDefault();
087: }
088:
089: /**
090: * Implement loadDTO.
091: *
092: * <p>
093: * Stores the data provided for the specified StyleDTO object
094: * </p>
095: *
096: * @param obj a StyleDTO object
097: *
098: * @throws NullPointerException DOCUMENT ME!
099: *
100: * @see org.vfny.geoserver.config.DataStructure#loadDTO(java.lang.Object)
101: */
102: public void update(StyleDTO obj) {
103: if (obj == null) {
104: throw new NullPointerException(
105: "Style Data Transfer Object required");
106: }
107:
108: StyleDTO sDto = (StyleDTO) obj;
109: id = sDto.getId();
110: filename = new File(sDto.getFilename().toString());
111: _default = sDto.isDefault();
112: }
113:
114: /**
115: * Implement toDTO.
116: *
117: * <p>
118: * Creates a StyleDTO which represents the data in this config object.
119: * </p>
120: *
121: * @return a copy of this classes data in a StyleDTO object.
122: *
123: * @see org.vfny.geoserver.config.DataStructure#toDTO()
124: */
125: public StyleDTO toDTO() {
126: StyleDTO sDto = new StyleDTO();
127: sDto.setDefault(_default);
128: sDto.setFilename(new File(filename.toString()));
129: sDto.setId(id);
130:
131: return sDto;
132: }
133:
134: /**
135: * isDefault purpose.
136: *
137: * <p>
138: * Description ...
139: * </p>
140: *
141: * @return
142: */
143: public boolean isDefault() {
144: return _default;
145: }
146:
147: /**
148: * getFilename purpose.
149: *
150: * <p>
151: * Description ...
152: * </p>
153: *
154: * @return
155: */
156: public File getFilename() {
157: return filename;
158: }
159:
160: /**
161: * getId purpose.
162: *
163: * <p>
164: * Description ...
165: * </p>
166: *
167: * @return
168: */
169: public String getId() {
170: return id;
171: }
172:
173: /**
174: * setDefault purpose.
175: *
176: * <p>
177: * Description ...
178: * </p>
179: *
180: * @param b
181: */
182: public void setDefault(boolean b) {
183: _default = b;
184: }
185:
186: /**
187: * setFilename purpose.
188: *
189: * <p>
190: * Description ...
191: * </p>
192: *
193: * @param file
194: */
195: public void setFilename(File file) {
196: filename = file;
197: }
198:
199: /**
200: * setId purpose.
201: *
202: * <p>
203: * Description ...
204: * </p>
205: *
206: * @param string
207: */
208: public void setId(String string) {
209: id = string;
210: }
211: }
|