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: /*
007: * Created on Jan 14, 2004
008: *
009: * To change the template for this generated file go to
010: * Window - Preferences - Java - Code Generation - Code and Comments
011: */
012: package org.vfny.geoserver.config.validation;
013:
014: import org.geotools.validation.dto.TestDTO;
015: import org.geotools.validation.dto.TestSuiteDTO;
016: import java.util.HashMap;
017: import java.util.Iterator;
018: import java.util.Map;
019:
020: /**
021: * TestSuiteConfig purpose.
022: *
023: * <p>
024: * Used to represent a copy of the config information required for the UI.
025: * </p>
026: *
027: * @author dzwiers, Refractions Research, Inc.
028: * @author $Author: dmzwiers $ (last modification)
029: * @version $Id: TestSuiteConfig.java 6326 2007-03-15 18:36:40Z jdeolive $
030: */
031: public class TestSuiteConfig {
032: public static final String CONFIG_KEY = "Validation.TestSuite";
033: public static final String CURRENTLY_SELECTED_KEY = "selectedTestSuite";
034:
035: /** the test suite name */
036: private String name;
037:
038: /** the test suite description */
039: private String description;
040:
041: /** the list of tests - should never be null */
042: private Map tests;
043:
044: /**
045: * TestSuiteConfig constructor.
046: * <p>
047: * Creates a blank HashMap for tests
048: * </p>
049: *
050: */
051: public TestSuiteConfig() {
052: tests = new HashMap();
053: }
054:
055: /**
056: * TestSuiteConfig constructor.
057: *
058: * <p>
059: * Creates a copy of the TestSuiteConfig passed in.
060: * </p>
061: *
062: * @param ts The Test Suite to copy
063: */
064: public TestSuiteConfig(TestSuiteConfig ts) {
065: name = ts.getName();
066: description = ts.getDescription();
067: tests = new HashMap();
068:
069: Iterator i = ts.getTests().keySet().iterator();
070:
071: while (i.hasNext()) {
072: TestConfig t = (TestConfig) ts.getTests().get(i.next());
073: tests.put(t.getName(), new TestConfig(t));
074: }
075: }
076:
077: /**
078: * TestSuiteConfig constructor.
079: *
080: * <p>
081: * Creates a copy of the TestSuiteConfig passed in.
082: * </p>
083: *
084: * @param ts The Test Suite to copy
085: */
086: public TestSuiteConfig(TestSuiteDTO ts, Map plugInConfigs) {
087: name = ts.getName();
088: description = ts.getDescription();
089: tests = new HashMap();
090:
091: Iterator i = ts.getTests().keySet().iterator();
092:
093: while (i.hasNext()) {
094: TestDTO t = (TestDTO) ts.getTests().get(i.next());
095: tests.put(t.getName(), new TestConfig(t, plugInConfigs));
096: }
097: }
098:
099: /**
100: * Implementation of clone.
101: *
102: * @return An instance of TestSuiteConfig.
103: *
104: * @see java.lang.Object#clone()
105: */
106: public Object clone() {
107: return new TestSuiteConfig(this );
108: }
109:
110: public int hashCode() {
111: int r = 1;
112:
113: if (tests != null) {
114: r *= tests.hashCode();
115: }
116:
117: if (name != null) {
118: r *= name.hashCode();
119: }
120:
121: if (description != null) {
122: r *= description.hashCode();
123: }
124:
125: return r;
126: }
127:
128: /**
129: * Implementation of equals.
130: *
131: * @param obj An object to compare for equality.
132: *
133: * @return true when the objects have the same data in the same order.
134: *
135: * @see java.lang.Object#equals(java.lang.Object)
136: */
137: public boolean equals(Object obj) {
138: if ((obj == null) || !(obj instanceof TestSuiteDTO)) {
139: return false;
140: }
141:
142: boolean r = true;
143: TestSuiteDTO ts = (TestSuiteDTO) obj;
144:
145: if (name != null) {
146: r = r && (name.equals(ts.getName()));
147: }
148:
149: if (description != null) {
150: r = r && (description.equals(ts.getDescription()));
151: }
152:
153: if (tests == null) {
154: if (ts.getTests() != null) {
155: return false;
156: }
157: } else {
158: if (ts.getTests() != null) {
159: r = r && tests.equals(ts.getTests());
160: } else {
161: return false;
162: }
163: }
164:
165: return r;
166: }
167:
168: /**
169: * toDTO purpose.
170: * <p>
171: * Clones this config as a DTO.
172: * </p>
173: * @see java.lang.Object#clone()
174: * @param plugIns Map of PlugInDTO objects
175: * @return TestSuiteDTO
176: */
177: public TestSuiteDTO toDTO(Map plugIns) {
178: TestSuiteDTO ts = new TestSuiteDTO();
179: ts.setName(name);
180: ts.setDescription(description);
181:
182: Map myTests = new HashMap();
183:
184: Iterator i = this .tests.keySet().iterator();
185:
186: while (i.hasNext()) {
187: TestConfig t = (TestConfig) this .tests.get(i.next());
188: myTests.put(t.getName(), t.toDTO(plugIns));
189: }
190:
191: ts.setTests(myTests);
192:
193: return ts;
194: }
195:
196: /**
197: * Access description property.
198: *
199: * @return Returns the description.
200: */
201: public String getDescription() {
202: return description;
203: }
204:
205: /**
206: * Set description to description.
207: *
208: * @param description The description to set.
209: */
210: public void setDescription(String description) {
211: this .description = description;
212: }
213:
214: /**
215: * Access name property.
216: *
217: * @return Returns the name.
218: */
219: public String getName() {
220: return name;
221: }
222:
223: /**
224: * Set name to name.
225: *
226: * @param name The name to set.
227: */
228: public void setName(String name) {
229: this .name = name;
230: }
231:
232: /**
233: * Access tests property.
234: *
235: * @return Returns the tests.
236: */
237: public Map getTests() {
238: return tests;
239: }
240:
241: public Object removeTest(String name) {
242: return tests.remove(name);
243: }
244:
245: public void addTest(TestConfig test) {
246: tests.put(test.getName(), test);
247: }
248:
249: /**
250: * Set tests to tests.
251: *
252: * @param tests The tests to set.
253: */
254: public void setTests(Map tests) {
255: this.tests = tests;
256: }
257: }
|