001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme;
023:
024: /**
025: * Abstraction of a unique identifier for registered meta data.
026: *
027: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>.
028: * @version <tt>$Revision: 8784 $</tt>
029: */
030: public class ServerRegistrationID extends FQN {
031: /** The serialVersionUID */
032: private static final long serialVersionUID = 8042337046523234207L;
033:
034: private String desc = null;
035:
036: public static class Type {
037: private final String type;
038:
039: private Type(String type) {
040: this .type = type;
041: }
042:
043: public boolean equals(Object o) {
044: if (this == o) {
045: return true;
046: }
047: if (o instanceof Type) {
048: Type that = (Type) o;
049: return this .type.equals(that.type);
050: }
051: return false;
052: }
053:
054: public int hashCode() {
055: return type.hashCode();
056: }
057:
058: public String toString() {
059: return type;
060: }
061: }
062:
063: private Type type;
064:
065: /** type for a registered Portal Theme. */
066: public static final Type TYPE_THEME = new Type("theme");
067:
068: /** Type for a registered Portal Layout. */
069: public static final Type TYPE_LAYOUT = new Type("layout");
070:
071: /** Type for a registered Portal RenderSet. */
072: public static final Type TYPE_RENDERSET = new Type("renderSet");
073:
074: /**
075: * @param type
076: * @param names
077: * @throws IllegalArgumentException
078: */
079: private ServerRegistrationID(Type type, String[] names) {
080: super (names);
081: this .type = type;
082: }
083:
084: /**
085: * Create a new registration id based on the provided type and names.
086: *
087: * @param type the type of registration to create (TYPE_THEME or TYPE_LAYOUT)
088: * @param names an array of names that together build a unique id
089: * @return a new ServerRegistrationID
090: */
091: public static ServerRegistrationID createID(Type type,
092: String[] names) {
093: return new ServerRegistrationID(type, names);
094: }
095:
096: public String toString() {
097: if (desc == null) {
098: StringBuffer buffer = new StringBuffer();
099: buffer.append(names[0]);
100: for (int i = 1; i < names.length; i++) {
101: buffer.append('.').append(names[i]);
102: }
103: desc = buffer.toString();
104: }
105: return desc;
106: }
107:
108: /**
109: * convenience method to create a new registration id for a theme.
110: *
111: * @param appID the name of the portal web application that contains the theme
112: * @param name the name of the theme
113: * @return a registration id for the meta data of a portal theme with the unique id created from <code>appID</code>
114: * and <code>name</code>
115: * @throws IllegalArgumentException if any of the provided paramter values are null
116: * @see #createID
117: * @see #TYPE_THEME
118: */
119: public static ServerRegistrationID createPortalThemeID(
120: String appID, String name) throws IllegalArgumentException {
121:
122: return new ServerRegistrationID(TYPE_THEME, new String[] {
123: appID, name });
124: }
125:
126: /**
127: * convenience method to create a new registration id for a layout.
128: *
129: * @param appID the name of the portal web application that contains the layout
130: * @param name the name of the layout
131: * @return a registration id for the meta data of a portal layout with the unique id created from <code>appID</code>
132: * and <code>name</code>
133: * @throws IllegalArgumentException if any of the provided parameter values are null
134: * @see #createID
135: * @see #TYPE_LAYOUT
136: */
137: public static ServerRegistrationID createPortalLayoutID(
138: String appID, String name) throws IllegalArgumentException {
139: return new ServerRegistrationID(TYPE_LAYOUT, new String[] {
140: appID, name });
141: }
142:
143: /** @return the type of this registration data */
144: public Type getType() {
145: return type;
146: }
147:
148: public boolean equals(Object obj) {
149: if (obj == this ) {
150: return true;
151: }
152: if (!(obj instanceof ServerRegistrationID)) {
153: return false;
154: }
155: ServerRegistrationID other = (ServerRegistrationID) obj;
156: if (other.names.length != names.length) {
157: return false;
158: }
159:
160: if (other.type != type) {
161: return false;
162: }
163:
164: for (int i = 0; i < names.length; i++) {
165: if (!names[i].equals(other.names[i])) {
166: return false;
167: }
168: }
169: return true;
170: }
171:
172: public int hashCode() {
173: int tmp = type.hashCode();
174:
175: for (int i = 0; i < names.length; i++) {
176: tmp = tmp * 29 + names[i].hashCode();
177: }
178: return tmp;
179: }
180: }
|