Java Reference
In-Depth Information
3. public class ServerDataStoreImpl implements ServerDataStore{
4. private static final String WORKER_SERVER_SERVICE_NAME = "workerThreadServer";
5.
6. public ServerDataStoreImpl(){
7. try {
8. UnicastRemoteObject.exportObject(this);
9. Naming.rebind(WORKER_SERVER_SERVICE_NAME, this);
10. }
11. catch (Exception exc){
12. System.err.println("Error using RMI to register the ServerDataStoreImpl " + exc);
13. }
14. }
15.
16. public Address retrieveAddress(long addressID){
17. if (addressID == 5280L){
18. return new AddressImpl("Fine Dining", "416 Chartres St.", "New Orleans", "LA",
"51720");
19. }
20. else if (addressID == 2010L){
21. return new AddressImpl("Mystic Yacht Club", "19 Imaginary Lane", "Mystic", "CT",
"46802");
22. }
23. else{
24. return new AddressImpl();
25. }
26. }
27. public Contact retrieveContact(long contactID){
28. if (contactID == 5280L){
29. return new ContactImpl("Dwayne", "Dibley", "Accountant", "Virtucon");
30. }
31. else{
32. return new ContactImpl();
33. }
34. }
35.
36. }
The Address and Contact interfaces define the business objects used in this example, and the implementers
AddressImpl and ContactImpl provide underlying functional behavior.
Example A.222 Address.java
1. import java.io.Serializable;
2. public interface Address extends Serializable{
3. public static final String EOL_STRING = System.getProperty("line.separator");
4. public static final String SPACE = " ";
5. public static final String COMMA = ",";
6. public String getType();
7. public String getDescription();
8. public String getStreet();
9. public String getCity();
10. public String getState();
11. public String getZipCode();
12.
13. public void setType(String newType);
14. public void setDescription(String newDescription);
15. public void setStreet(String newStreet);
16. public void setCity(String newCity);
17. public void setState(String newState);
18. public void setZipCode(String newZip);
19. }
Example A.223 AddressImpl.java
1. public class AddressImpl implements Address{
2. private String type;
3. private String description;
4. private String street;
5. private String city;
6. private String state;
7. private String zipCode;
8.
9. public AddressImpl(){ }
10. public AddressImpl(String newDescription, String newStreet,
11. String newCity, String newState, String newZipCode){
12. description = newDescription;
13. street = newStreet;
14. city = newCity;
Search WWH ::




Custom Search