KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > ServerRegistrationID


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.portal.server;
9
10 import org.jboss.portal.common.FQN;
11
12 /**
13  * Abstraction of a unique identifier for registered meta data.
14  *
15  * @author <a HREF="mailto:mholzner@novell.com">Martin Holzner</a>.
16  * @version <tt>$Revision: 1.2 $</tt>
17  */

18 public class ServerRegistrationID extends FQN
19 {
20    private String JavaDoc desc = null;
21
22    public static class Type
23    {
24       private final String JavaDoc type;
25
26       private Type(String JavaDoc type)
27       {
28          this.type = type;
29       }
30
31       public boolean equals(Object JavaDoc o)
32       {
33          if (this == o)
34          {
35             return true;
36          }
37          if (!(o instanceof Type))
38          {
39             return false;
40          }
41
42          final Type type1 = (Type)o;
43
44          if (!type.equals(type1.type))
45          {
46             return false;
47          }
48
49          return true;
50       }
51
52       public int hashCode()
53       {
54          return type.hashCode();
55       }
56
57       public String JavaDoc toString()
58       {
59          return type;
60       }
61    }
62
63    private Type type;
64
65    /**
66     * type for a registered Portal Theme.
67     */

68    public static final Type TYPE_THEME = new Type("theme");
69
70    /**
71     * Type for a registered Portal Layout.
72     */

73    public static final Type TYPE_LAYOUT = new Type("layout");
74
75    /**
76     * @param type
77     * @param names
78     * @throws IllegalArgumentException
79     */

80    private ServerRegistrationID(Type type, String JavaDoc[] names)
81    {
82       super(names);
83       this.type = type;
84    }
85
86    /**
87     * Create a new registration id based on the provided type and names.
88     *
89     * @param type the type of registration to create (TYPE_THEME or TYPE_LAYOUT)
90     * @param names an array of names that together build a unique id
91     * @return a new ServerRegistrationID
92     */

93    public static ServerRegistrationID createID(Type type, String JavaDoc[] names)
94    {
95       return new ServerRegistrationID(type, names);
96    }
97
98    public String JavaDoc toString()
99    {
100       if (desc == null)
101       {
102          StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
103          buffer.append(names[0]);
104          for (int i = 1; i < names.length; i++)
105          {
106             buffer.append('.').append(names[i]);
107          }
108          desc = buffer.toString();
109       }
110       return desc;
111    }
112
113    /**
114     * convenience method to create a new registration id for a theme.
115     *
116     * @param appName the name of the portal web application that contains the theme
117     * @param name the name of the theme
118     * @return a registration id for the meta data of a portal theme with the unique id created from <code>appName</code>
119     * and <code>name</code>
120     * @throws IllegalArgumentException if any of the provided paramter values are null
121     * @see #createID
122     * @see #TYPE_THEME
123     */

124    public static ServerRegistrationID createPortalThemeID(String JavaDoc appName, String JavaDoc name) throws IllegalArgumentException JavaDoc
125    {
126
127       return new ServerRegistrationID(TYPE_THEME, new String JavaDoc[]{appName, name});
128    }
129
130    /**
131     * convenience method to create a new registration id for a layout.
132     *
133     * @param appName the name of the portal web application that contains the layout
134     * @param name the name of the layout
135     * @return a registration id for the meta data of a portal layout with the unique id created from <code>appName</code>
136     * and <code>name</code>
137     * @throws IllegalArgumentException if any of the provided parameter values are null
138     * @see #createID
139     * @see #TYPE_LAYOUT
140     */

141    public static ServerRegistrationID createPortalLayoutID(String JavaDoc appName, String JavaDoc name) throws IllegalArgumentException JavaDoc
142    {
143       return new ServerRegistrationID(TYPE_LAYOUT, new String JavaDoc[]{appName, name});
144    }
145
146    /**
147     * @return the type of this registration data
148     */

149    public Type getType()
150    {
151       return type;
152    }
153
154    public boolean equals(Object JavaDoc obj)
155    {
156       if (obj == this)
157       {
158          return true;
159       }
160       if (!(obj instanceof ServerRegistrationID))
161       {
162          return false;
163       }
164       ServerRegistrationID other = (ServerRegistrationID)obj;
165       if (other.names.length != names.length)
166       {
167          return false;
168       }
169
170       if (other.type != type)
171       {
172          return false;
173       }
174
175       for (int i = 0; i < names.length; i++)
176       {
177          if (!names[i].equals(other.names[i]))
178          {
179             return false;
180          }
181       }
182       return true;
183    }
184
185    public int hashCode()
186    {
187       int tmp = type.hashCode();
188
189       for (int i = 0; i < names.length; i++)
190       {
191          tmp = tmp * 29 + names[i].hashCode();
192       }
193       return tmp;
194    }
195 }
196
Popular Tags