Java Reference
In-Depth Information
35. }
36. }
37. }
38. public void removeAppointment(Appointment appointment){
39. if (appointments.containsValue(appointment)){
40. appointments.remove(appointment.getStartDate());
41. }
42. }
43.
44. public boolean join(long transactionID){
45. if (currentTransaction != 0){
46. return false;
47. } else {
48. currentTransaction = transactionID;
49. return true;
50. }
51. }
52. public void commit(long transactionID) throws TransactionException{
53. if (currentTransaction != transactionID){
54. throw new TransactionException("Invalid TransactionID");
55. } else {
56. removeAppointment(currentAppointment);
57. currentAppointment.setStartDate(updateStartDate);
58. appointments.put(updateStartDate, currentAppointment);
59. }
60. }
61. public void cancel(long transactionID){
62. if (currentTransaction == transactionID){
63. currentTransaction = 0;
64. appointments.remove(updateStartDate);
65. }
66. }
67. public boolean changeDate(long transactionID, Appointment appointment,
68. Date newStartDate) throws TransactionException{
69. if ((appointments.containsValue(appointment)) && (!appointments.
containsKey(newStartDate))){
70. appointments.put(newStartDate, null);
71. updateStartDate = newStartDate;
72. currentAppointment = appointment;
73. return true;
74. }
75. return false;
76. }
77.
78. public boolean changeAppointment(Appointment appointment, Date[] possibleDates,
79. AppointmentTransactionParticipant[] participants, long transactionID){
80. try {
81. for (int i = 0; i < participants.length; i++){
82. if (!participants[i].join(transactionID)){
83. return false;
84. }
85. }
86. for (int i = 0; i < possibleDates.length; i++){
87. if (isDateAvailable(transactionID, appointment, possibleDates[i],
participants)){
88. try {
89. commitAll(transactionID, participants);
90. return true;
91. }
92. catch(TransactionException exc){ }
93. }
94. }
95. }
96. catch (RemoteException exc){ }
97. try{
98. cancelAll(transactionID, participants);
99. }
100. catch (RemoteException exc){}
101. return false;
102. }
103.
104. private boolean isDateAvailable(long transactionID, Appointment appointment,
105. Date date, AppointmentTransactionParticipant[] participants){
106. try{
107. for (int i = 0; i < participants.length; i++){
108. try{
109. if (!participants[i].changeDate(transactionID, appointment, date)){
110. return false;
Search WWH ::




Custom Search