Java Reference
In-Depth Information
111. }
112. }
113. catch (TransactionException exc){
114. return false;
115. }
116. }
117. }
118. catch (RemoteException exc){
119. return false;
120. }
121. return true;
122. }
123. private void commitAll(long transactionID,
AppointmentTransactionParticipant[]participants)
124. throws TransactionException, RemoteException{
125. for (int i = 0; i < participants.length; i++){
126. participants[i].commit(transactionID);
127. }
128. }
129. private void cancelAll(long transactionID, AppointmentTransactionParticipant[]
participants)
130. throws RemoteException{
131. for (int i = 0; i < participants.length; i++){
132. participants[i].cancel(transactionID);
133. }
134. }
135. public String toString(){
136. return serviceName + " " + appointments.values().toString();
137. }
138. }
The TransactionException is a signal exception; it has no special content and gets thrown when an invalid
transactionID is supplied to some methods. The receiver might report the exception or ignore it, depending on
its processing needs.
Example A.256 TransactionException.java
1. public class TransactionException extends Exception{
2. public TransactionException(String msg){
3. super(msg);
4. }
5. }
Support classes for this example represent the appointment and its elements, Three interfaces— Appointment ,
Contact , and Location — define the core business behavior. The classes AppointmentImpl , ContactImpl , and
LocationImpl provide implementation for the interface behavior.
Example A.257 Appointment.java
1. import java.util.ArrayList;
2. import java.util.Date;
3. import java.io.Serializable;
4. public interface Appointment extends Serializable{
5. public static final String EOL_STRING = System.getProperty("line.separator");
6.
7. public Date getStartDate();
8. public String getDescription();
9. public ArrayList getAttendees();
10. public Location getLocation();
11.
12. public void setDescription(String newDescription);
13. public void setLocation(Location newLocation);
14. public void setStartDate(Date newStartDate);
15. public void setAttendees(ArrayList newAttendees);
16. public void addAttendee(Contact attendee);
17. public void removeAttendee(Contact attendee);
18. }
Example A.258 AppointmentImpl.java
1. import java.util.ArrayList;
2. import java.util.Date;
3. public class AppointmentImpl implements Appointment{
4. private Date startDate;
5. private String description;
6. private ArrayList attendees = new ArrayList();
7. private Location location;
Search WWH ::




Custom Search