01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.validation;
16:
17: import java.util.Iterator;
18: import java.util.Map;
19:
20: import net.refractions.udig.validation.internal.Messages;
21:
22: import org.eclipse.swt.SWT;
23: import org.eclipse.swt.widgets.Display;
24: import org.eclipse.swt.widgets.MessageBox;
25: import org.geotools.validation.dto.ArgumentDTO;
26: import org.geotools.validation.dto.TestDTO;
27: import org.geotools.validation.dto.TestSuiteDTO;
28:
29: /**
30: * TODO Purpose of
31: * <p>
32: *
33: * </p>
34: * @author chorner
35: * @since 1.0.1
36: */
37: public class DTOUtils {
38: /**
39: * Checks an individual test to determine if all of the arguments are non-null.
40: *
41: * @param test
42: * @return
43: */
44: public static boolean noNullArguments(TestDTO test) {
45: Map args = test.getArgs();
46: for (Iterator i = args.keySet().iterator(); i.hasNext();) {
47: ArgumentDTO arg = (ArgumentDTO) args.get(i.next());
48: if (arg.getValue() == null)
49: return false;
50: }
51: return true;
52: }
53:
54: /**
55: * Ensures that each test in the testSuite does not contain any null
56: * arguments. Tests that contain "errors" are selected in red and a dialog
57: * complains to the user.
58: *
59: * @param testSuite
60: * @return
61: */
62: public static boolean noNullArguments(TestSuiteDTO testSuite) {
63: Map tests = testSuite.getTests();
64: boolean badTests = false;
65: for (Iterator i = tests.keySet().iterator(); i.hasNext();) {
66: TestDTO currentTest = (TestDTO) tests.get(i.next());
67: if (!noNullArguments(currentTest)) {
68: //the test contains a null argument!
69: badTests = true;
70: break;
71: }
72: }
73: if (badTests) {
74: //yell at the user
75: MessageBox mb = new MessageBox(Display.getCurrent()
76: .getActiveShell(), SWT.ICON_ERROR | SWT.OK);
77: mb.setMessage(Messages.DTOUtils_nullArg);
78: mb.open();
79: return false;
80: }
81: return true;
82: }
83:
84: }
|