Java Reference
In-Depth Information
4. public class RunPattern{
5. private static Calendar dateCreator = Calendar.getInstance();
6.
7. public static void main(String [] arguments){
8. Appointment appt = null;
9.
10. System.out.println("Example for the Builder pattern");
11. System.out.println();
12. System.out.println("This example demonstrates the use of the Builder");
13. System.out.println("pattern to create Appointment objects for the PIM.");
14. System.out.println();
15.
16. System.out.println("Creating a Scheduler for the example.");
17. Scheduler pimScheduler = new Scheduler();
18.
19. System.out.println("Creating an AppointmentBuilder for the example.");
20. System.out.println();
21. AppointmentBuilder apptBuilder = new AppointmentBuilder();
22. try{
23. System.out.println("Creating a new Appointment with an AppointmentBuilder");
24. appt = pimScheduler.createAppointment(
25. apptBuilder, createDate(2066, 9, 22, 12, 30),
26. null, "Trek convention", new LocationImpl("Fargo, ND"),
27. createAttendees(4));
28. System.out.println("Successfully created an Appointment.");
29. System.out.println("Appointment information:");
30. System.out.println(appt);
31. System.out.println();
32. }
33. catch (InformationRequiredException exc){
34. printExceptions(exc);
35. }
36.
37. System.out.println("Creating a MeetingBuilder for the example.");
38. MeetingBuilder mtgBuilder = new MeetingBuilder();
39. try{
40. System.out.println("Creating a new Appointment with a MeetingBuilder");
41. System.out.println("(notice that the same create arguments will produce");
42. System.out.println(" an exception, since the MeetingBuilder enforces a");
43. System.out.println(" mandatory end date)");
44. appt = pimScheduler.createAppointment(
45. mtgBuilder, createDate(2066, 9, 22, 12, 30),
46. null, "Trek convention", new LocationImpl("Fargo, ND"),
47. createAttendees(4));
48. System.out.println("Successfully created an Appointment.");
49. System.out.println("Appointment information:");
50. System.out.println(appt);
51. System.out.println();
52. }
53. catch (InformationRequiredException exc){
54. printExceptions(exc);
55. }
56.
57. System.out.println("Creating a new Appointment with a MeetingBuilder");
58. System.out.println("(This time, the MeetingBuilder will provide an end date)");
59. try{
60. appt = pimScheduler.createAppointment(
61. mtgBuilder,
62. createDate(2002, 4, 1, 10, 00),
63. createDate(2002, 4, 1, 11, 30),
64. "OOO Meeting",
65. new LocationImpl("Butte, MT"),
66. createAttendees(2));
67. System.out.println("Successfully created an Appointment.");
68. System.out.println("Appointment information:");
69. System.out.println(appt);
70. System.out.println();
71. }
72. catch (InformationRequiredException exc){
73. printExceptions(exc);
74. }
75. }
76.
77. public static Date createDate(int year, int month, int day, int hour, int minute){
78. dateCreator.set(year, month, day, hour, minute);
79. return dateCreator.getTime();
80. }
81.
Search WWH ::




Custom Search