001: /*
002: * Created on Jan 23, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.config.validation;
008:
009: import org.geotools.validation.dto.PlugInDTO;
010: import org.geotools.validation.dto.TestSuiteDTO;
011: import org.vfny.geoserver.global.GeoValidator;
012: import java.util.HashMap;
013: import java.util.Iterator;
014: import java.util.Map;
015: import java.util.Set;
016:
017: /**
018: * ValidationConfig purpose.
019: * <p>
020: * Description of ValidationConfig ...
021: * </p>
022: *
023: * @author dzwiers, Refractions Research, Inc.
024: * @author $Author: dmzwiers $ (last modification)
025: * @version $Id: ValidationConfig.java 6177 2007-02-19 10:11:27Z aaime $
026: */
027: public class ValidationConfig {
028: public static final String CONFIG_KEY = "Validation.Config";
029: private Map plugIns;
030: private Map testSuites;
031:
032: /**
033: * ValidationConfig constructor.
034: * <p>
035: * Description
036: * </p>
037: *
038: */
039: public ValidationConfig() {
040: super ();
041: plugIns = new HashMap();
042: testSuites = new HashMap();
043: }
044:
045: /**
046: * ValidationConfig constructor.
047: * <p>
048: * Description
049: * </p>
050: * @param validator GeoValidator
051: */
052: public ValidationConfig(GeoValidator validator) {
053: this (validator.getPlugIns(), validator.getTestSuites());
054: }
055:
056: /**
057: * ValidationConfig constructor.
058: * <p>
059: * Description
060: * </p>
061: * @param plugIns a List of PlugInDTO objects
062: * @param testSuites a List of TestSuiteDTO objects
063: */
064: public ValidationConfig(Map plugIns, Map testSuites) {
065: this .plugIns = new HashMap();
066: this .testSuites = new HashMap();
067:
068: Iterator i = null;
069: i = plugIns.keySet().iterator();
070:
071: while (i.hasNext()) {
072: PlugInDTO dto = (PlugInDTO) plugIns.get(i.next());
073: PlugInConfig config = new PlugInConfig(dto);
074: this .plugIns.put(config.getName(), config);
075: }
076:
077: i = testSuites.keySet().iterator();
078:
079: while (i.hasNext()) {
080: TestSuiteDTO dto = (TestSuiteDTO) testSuites.get(i.next());
081: TestSuiteConfig config = new TestSuiteConfig(dto,
082: this .plugIns);
083: this .testSuites.put(config.getName(), config);
084: }
085: }
086:
087: /**
088: *
089: * getPlugIn purpose.
090: * <p>
091: * Gets a PlugInConfig
092: * </p>
093: * @param name
094: * @return PlugInConfig or null if one does not exist
095: */
096: public PlugInConfig getPlugIn(String name) {
097: if (name == null) {
098: return null;
099: }
100:
101: return (PlugInConfig) plugIns.get(name);
102: }
103:
104: /**
105: *
106: * getTestSuite purpose.
107: * <p>
108: * Gets a TestSuiteConfig
109: * </p>
110: * @param name
111: * @return TestSuiteConfig or null if one does not exist
112: */
113: public TestSuiteConfig getTestSuite(String name) {
114: if (name == null) {
115: return null;
116: }
117:
118: return (TestSuiteConfig) testSuites.get(name);
119: }
120:
121: /**
122: *
123: * getTest purpose.
124: * <p>
125: * Gets a TestConfig
126: * </p>
127: * @param name
128: * @param testSuite
129: * @return TestSuiteConfig or null if one does not exist
130: */
131: public TestConfig getTest(String name, String testSuite) {
132: if ((name == null) || (testSuite == null)) {
133: return null;
134: }
135:
136: TestSuiteConfig tcn = getTestSuite(testSuite);
137:
138: if (tcn == null) {
139: return null;
140: }
141:
142: return (TestConfig) tcn.getTests().get(name);
143: }
144:
145: /**
146: *
147: * addPlugIn purpose.
148: * <p>
149: * Adds the plugin.
150: * </p>
151: * @param plugIn
152: * @return true
153: */
154: public boolean addPlugIn(PlugInConfig plugIn) {
155: plugIns.put(plugIn.getName(), plugIn);
156:
157: return true;
158: }
159:
160: /**
161: *
162: * addTest purpose.
163: * <p>
164: * Adds the test to the specified testSuite.
165: * </p>
166: * @param test
167: * @param testSuite
168: * @return true on sucess (requires specified plugin to exist), false otherwise.
169: */
170: public boolean addTest(TestConfig test, String testSuite) {
171: TestSuiteConfig tsc = (TestSuiteConfig) testSuites
172: .get(testSuite);
173:
174: if ((tsc != null)
175: && plugIns.containsKey(test.getPlugIn().getName())) {
176: tsc.getTests().put(test.getName(), test);
177:
178: return true;
179: }
180:
181: return false;
182: }
183:
184: public boolean addTestSuite(TestSuiteConfig testSuite) {
185: Iterator i = testSuite.getTests().keySet().iterator();
186:
187: while (i.hasNext()) {
188: TestConfig test = (TestConfig) testSuite.getTests().get(
189: i.next());
190:
191: if (!plugIns.containsKey(test.getPlugIn().getName())) {
192: return false;
193: }
194: }
195:
196: // plug ins all exist
197: testSuites.put(testSuite.getName(), testSuite);
198:
199: return true;
200: }
201:
202: public Object removeTestSuite(String name) {
203: return testSuites.remove(name);
204: }
205:
206: public Object removePlugIn(String name) {
207: return plugIns.remove(name);
208: }
209:
210: public Object removeTest(String testSuite, String name) {
211: return ((TestSuiteConfig) testSuites.get(testSuite)).getTests()
212: .remove(name);
213: }
214:
215: /**
216: * toDTO purpose.
217: * <p>
218: * Creates a representation as DTOs
219: * </p>
220: * @param plugIns List an empty list to store the resulting plugInDTOs
221: * @param testSuites List an empty list to store the resulting TestSuiteDTOs
222: * @return true if the lists contain the data, false otherwise.
223: */
224: public boolean toDTO(Map plugIns, Map testSuites) {
225: if ((plugIns == null) || (testSuites == null)) {
226: return false;
227: }
228:
229: if ((plugIns.size() != 0) || (testSuites.size() != 0)) {
230: return false;
231: }
232:
233: // list are empty, and exist.
234: Iterator i = null;
235: i = this .plugIns.keySet().iterator();
236:
237: while (i.hasNext()) {
238: PlugInDTO dto = ((PlugInConfig) this .plugIns.get(i.next()))
239: .toDTO();
240: plugIns.put(dto.getName(), dto);
241: }
242:
243: i = this .testSuites.keySet().iterator();
244:
245: while (i.hasNext()) {
246: TestSuiteDTO dto = ((TestSuiteConfig) this .testSuites.get(i
247: .next())).toDTO(plugIns);
248: testSuites.put(dto.getName(), dto);
249: }
250:
251: return true;
252: }
253:
254: /**
255: * Access plugIns property.
256: *
257: * @return Returns the plugIns.
258: */
259: public Map getPlugIns() {
260: return plugIns;
261: }
262:
263: /**
264: * Access plugIns property.
265: *
266: * @return Returns the plugIns.
267: */
268: public Set getPlugInNames() {
269: return plugIns.keySet();
270: }
271:
272: /**
273: * Set plugIns to plugIns.
274: *
275: * @param plugIns The plugIns to set.
276: */
277: public void setPlugIns(Map plugIns) {
278: this .plugIns = plugIns;
279: }
280:
281: /**
282: * Access testSuites property.
283: *
284: * @return Returns the testSuites.
285: */
286: public Map getTestSuites() {
287: return testSuites;
288: }
289:
290: /**
291: * Access testSuites property.
292: *
293: * @return Returns the testSuites.
294: */
295: public Set getTestSuiteNames() {
296: return testSuites.keySet();
297: }
298:
299: /**
300: * Set testSuites to testSuites.
301: *
302: * @param testSuites The testSuites to set.
303: */
304: public void setTestSuites(Map testSuites) {
305: this.testSuites = testSuites;
306: }
307: }
|