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