1   
2   import net.sourceforge.jparam.paramset.ParamSet;
3   import net.sourceforge.jparam.paramset.iParam;
4   import net.sourceforge.jparam.paramset.ioParam;
5   import ducks.Duck;
6   import ducks.DuckRegistrations;
7   
8   public class test2 {
9   	//	int d = 2;
10  
11  	private static boolean DEBUG = false;
12  
13  	public static void main(String[] args) {
14  
15  		DuckRegistrations.registerDucks();
16  		//	 ambiguity in construction
17  		try {
18  
19  			ParamSet ps = new ParamSet();
20  			ps.addParam(new iParam("d"));
21  			String input[] = { "d=duckling(0.5,7)" };
22  			ps.input(input);
23  		} catch (Exception e) {
24  			handleException(e);
25  		}
26  		// tried to output object with no output function
27  		try {
28  			ParamSet ps = new ParamSet();
29  			//			duck duckula;
30  			ps.addParam(new ioParam(/* "duckula, */"d"));
31  			String input[] = { "d=duck(\"Testing output\")" };
32  			//	 this used to work without the escaped double quotes.
33  			ps.input(input);
34  			ps.output(System.out);
35  		} catch (Exception e) {
36  			handleException(e);
37  		}
38  		// impossible conversion
39  		try {
40  			ParamSet ps = new ParamSet();
41  			//	    String s;
42  			ps.addParam(new iParam(/* "s", */"s", new Integer(8)));
43  		} catch (Exception e) {
44  			handleException(e);
45  		}
46  		// more than one user defined conversion is not allowed
47  		try {
48  			ParamSet ps = new ParamSet();
49  			ps
50  					.addParam(new iParam(/* "d", */"d", new String(
51  							"I am a string")));
52  		} catch (Exception e) {
53  			handleException(e);
54  		}
55  		// ambiguity in conversion
56  		try {
57  			ParamSet ps = new ParamSet();
58  			ps.addParam(new iParam("d", new Duck()));
59  		} catch (Exception e) {
60  			handleException(e);
61  		}
62  	}
63  
64  	private static void handleException(Exception e) {
65  		System.out.println("Got following error - ");
66  		System.out.println(e.getMessage());
67  		if (DEBUG) {
68  			e.printStackTrace(System.out);
69  		}
70  	}
71  }