1 7 8 package org.jboss.portal.server; 9 10 import org.jboss.portal.common.FQN; 11 12 18 public class ServerRegistrationID extends FQN 19 { 20 private String desc = null; 21 22 public static class Type 23 { 24 private final String type; 25 26 private Type(String type) 27 { 28 this.type = type; 29 } 30 31 public boolean equals(Object 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 toString() 58 { 59 return type; 60 } 61 } 62 63 private Type type; 64 65 68 public static final Type TYPE_THEME = new Type("theme"); 69 70 73 public static final Type TYPE_LAYOUT = new Type("layout"); 74 75 80 private ServerRegistrationID(Type type, String [] names) 81 { 82 super(names); 83 this.type = type; 84 } 85 86 93 public static ServerRegistrationID createID(Type type, String [] names) 94 { 95 return new ServerRegistrationID(type, names); 96 } 97 98 public String toString() 99 { 100 if (desc == null) 101 { 102 StringBuffer buffer = new StringBuffer (); 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 124 public static ServerRegistrationID createPortalThemeID(String appName, String name) throws IllegalArgumentException 125 { 126 127 return new ServerRegistrationID(TYPE_THEME, new String []{appName, name}); 128 } 129 130 141 public static ServerRegistrationID createPortalLayoutID(String appName, String name) throws IllegalArgumentException 142 { 143 return new ServerRegistrationID(TYPE_LAYOUT, new String []{appName, name}); 144 } 145 146 149 public Type getType() 150 { 151 return type; 152 } 153 154 public boolean equals(Object 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 |