Java Reference
In-Depth Information
7. public ContactImpl(){}
8. public ContactImpl(String newFirstName, String newLastName,
9. String newTitle, String newOrganization){
10. firstName = newFirstName;
11. lastName = newLastName;
12. title = newTitle;
13. organization = newOrganization;
14. }
15.
16. public String getFirstName(){ return firstName; }
17. public String getLastName(){ return lastName; }
18. public String getTitle(){ return title; }
19. public String getOrganization(){ return organization; }
20.
21. public void setFirstName(String newFirstName){ firstName = newFirstName; }
22. public void setLastName(String newLastName){ lastName = newLastName; }
23. public void setTitle(String newTitle){ title = newTitle; }
24. public void setOrganization(String newOrganization){ organization = newOrganization; }
25.
26. public String toString(){
27. return firstName + SPACE + lastName;
28. }
29. }
Example A.261
Location.java
1. import java.io.Serializable;
2. public interface Location extends Serializable{
3. public String getLocation();
4. public void setLocation(String newLocation);
5. }
Example A.262
LocationImpl.java
1. public class LocationImpl implements Location{
2. private String location;
3.
4. public LocationImpl(){ }
5. public LocationImpl(String newLocation){
6. location = newLocation;
7. }
8.
9. public String getLocation(){ return location; }
10.
11. public void setLocation(String newLocation){ location = newLocation; }
12.
13. public String toString(){ return location; }
14. }
RunPattern
demonstrates coordination among the
AddressBook
objects to reschedule an appointment. It creates
three
AddressBooks
, setting up conflict-ing appointments in two of them. Next, it instructs an
AddressBook
to
update the appointment. This results in an appointment in the address books with the first start time available to
all three
AddressBooks
: 12 noon.
Example A.263
RunPattern.java
1. import java.io.IOException;
2. import java.rmi.Naming;
3. import java.util.Date;
4. import java.util.Calendar;
5. import java.util.ArrayList;
6. public class RunPattern{
7. private static Calendar dateCreator = Calendar.getInstance();
8.
9. public static void main(String [] arguments){
10. System.out.println("Example for the Transaction pattern");
11. System.out.println("This code example shows how a Transaction can");
12. System.out.println(" be applied to support change across a distributed");
13. System.out.println(" system. In ths case, a distributed transaction");
14. System.out.println(" is used to coordinate the change of dates in");
15. System.out.println(" appointment books.");
16.
17. System.out.println("Running the RMI compiler (rmic)");
18. System.out.println();
19. try{
20. Process p1 = Runtime.getRuntime().exec("rmic AppointmentBook");
21. p1.waitFor();