KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > registry > Address


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.arooa.registry;
5
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * A address uniquely identifies a component by its server
10  * and path.
11  */

12 public class Address implements Serializable JavaDoc {
13     private static final long serialVersionUID = 20051117;
14     
15     /** The server */
16     private final ServerId serverId;
17     
18     /** The path */
19     private final Path path;
20     
21     /**
22      * Create a local address.
23      *
24      * @param path The path to the component.
25      */

26     public Address(Path path) {
27         this(ServerId.local(), path);
28     }
29
30     /**
31      * Create an address of an object on a server.
32      *
33      * @param serverId The server id.
34      * @param path The path.
35      */

36     public Address(ServerId serverId, Path path) {
37         if (path == null) {
38             throw new NullPointerException JavaDoc("Path must not be null.");
39         }
40         if (serverId == null) {
41             throw new NullPointerException JavaDoc("URL must not be null.");
42         }
43         this.path = path;
44         this.serverId = serverId;
45     }
46     
47     /**
48      * Get the path.
49      *
50      * @return The path.
51      */

52     public Path getPath() {
53         return path;
54     }
55     
56     /**
57      * Get the ServerId.
58      *
59      * @return The ServerId.
60      */

61     public ServerId getServerId() {
62         return serverId;
63     }
64     
65     /*
66      * (non-Javadoc)
67      * @see java.lang.Object#toString()
68      */

69     public String JavaDoc toString() {
70         return serverId.toString() + ":" + path.toString();
71     }
72     
73     /**
74      * Utility function for debugs.
75      *
76      * @param addresses Array of address.
77      * @return A string.
78      */

79     public static String JavaDoc arrayAsString(Address[] addresses) {
80         if (addresses.length == 0) {
81             return "[No Addresses]";
82         }
83         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
84         for (int i = 0; i < addresses.length; ++i) {
85             buf.append("[");
86             buf.append(addresses[i].toString());
87             buf.append("]");
88         }
89         return buf.toString();
90     }
91 }
92
Popular Tags