1 | /*
|
---|
2 | * (C) Pharos IP PTy Ltd 1997
|
---|
3 | */
|
---|
4 |
|
---|
5 | package au.com.pharos.dbinterface.vf;
|
---|
6 |
|
---|
7 | import java.util.Date;
|
---|
8 | import java.util.Vector;
|
---|
9 | import java.util.Hashtable;
|
---|
10 | import java.util.Enumeration;
|
---|
11 |
|
---|
12 | import java.text.SimpleDateFormat;
|
---|
13 | import java.text.ParsePosition;
|
---|
14 |
|
---|
15 | import java.text.SimpleDateFormat;
|
---|
16 |
|
---|
17 | public class VFOrder {
|
---|
18 |
|
---|
19 | /* The final date for submission */
|
---|
20 | public Date finalSubmit;
|
---|
21 |
|
---|
22 | /* The date the order was created */
|
---|
23 | public Date orderDate;
|
---|
24 |
|
---|
25 | /* A hash mapping titles requested to numbers of each title*/
|
---|
26 | public Hashtable orderNumbers;
|
---|
27 |
|
---|
28 | /* The name of the ordering store */
|
---|
29 | public String name;
|
---|
30 |
|
---|
31 | public VFOrder(Date newFinal,
|
---|
32 | String newName,
|
---|
33 | Hashtable newOrder)
|
---|
34 | {
|
---|
35 | finalSubmit = newFinal;
|
---|
36 | orderNumbers = newOrder;
|
---|
37 | name = newName;
|
---|
38 | orderDate = new Date(System.currentTimeMillis());
|
---|
39 | if (orderDate.after(finalSubmit)) {
|
---|
40 | throw new IllegalArgumentException("Final submission date is earlier than present date.");
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public VFOrder(Date newFinal,
|
---|
45 | Date newDate,
|
---|
46 | String newName,
|
---|
47 | Hashtable newOrder)
|
---|
48 | {
|
---|
49 | finalSubmit = newFinal;
|
---|
50 | orderDate = newDate;
|
---|
51 | orderNumbers = newOrder;
|
---|
52 | name = newName;
|
---|
53 | orderDate = new Date(System.currentTimeMillis());
|
---|
54 | if (orderDate.after(finalSubmit)) {
|
---|
55 | throw new IllegalArgumentException("Final submission date is earlier than present date.");
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public Vector toVectorString()
|
---|
60 | {
|
---|
61 | Vector result = new Vector();
|
---|
62 | result.addElement(new Long(finalSubmit.getTime()));
|
---|
63 | result.addElement(new Long(orderDate.getTime()));
|
---|
64 | result.addElement(orderNumbers.toString());
|
---|
65 | result.addElement(name);
|
---|
66 | return result;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public VFOrder fromVectorString(Vector input)
|
---|
70 | throws java.text.ParseException
|
---|
71 | {
|
---|
72 | Hashtable data = new Hashtable();
|
---|
73 | SimpleDateFormat form = new SimpleDateFormat();
|
---|
74 | for (Enumeration e = input.elements(); e.hasMoreElements(); ) {
|
---|
75 | System.out.println(e.nextElement());
|
---|
76 | }
|
---|
77 | try {
|
---|
78 | finalSubmit = new Date(((Long) input.elementAt(0)).longValue());
|
---|
79 | } catch (NullPointerException e) {
|
---|
80 | System.err.println("Waaaah!");
|
---|
81 | finalSubmit = new Date();
|
---|
82 | }
|
---|
83 | System.err.println("No 2:" + input.elementAt(1).toString());
|
---|
84 | orderDate = new Date(((Long) input.elementAt(1)).longValue());
|
---|
85 | name = (String) input.elementAt(3);
|
---|
86 | String hashString = (String) input.elementAt(2);
|
---|
87 | StringBuffer key = new StringBuffer();;
|
---|
88 | StringBuffer value = new StringBuffer();
|
---|
89 | String type = new String("key");
|
---|
90 | for (int count = 0; count < hashString.length(); count++) {
|
---|
91 | char i = hashString.charAt(count);
|
---|
92 | if (i == '{' || i == ' ') { ; }
|
---|
93 | else if (i == '}') { data.put(key, value); }
|
---|
94 | else if (i == ',') {data.put(key, value); }
|
---|
95 | else if (i == '=') {
|
---|
96 | if (type.equals("key")) {
|
---|
97 | type = "value";
|
---|
98 | } else {
|
---|
99 | type = "key";
|
---|
100 | }
|
---|
101 | } else {
|
---|
102 | if (type.equals("key")) {
|
---|
103 | key.append(i);
|
---|
104 | } else {
|
---|
105 | value.append(i);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | return new VFOrder(finalSubmit, orderDate, name, data);
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | }
|
---|
116 |
|
---|