1 50 51 package org.apache.avalon.meta.info; 52 53 import java.util.Properties ; 54 55 import org.apache.avalon.framework.Version; 56 57 77 public final class InfoDescriptor extends Descriptor 78 { 79 83 public static final String TRANSIENT = "transient"; 84 85 public static final String SINGLETON = "singleton"; 86 87 public static final String THREAD = "thread"; 88 89 public static final String POOLED = "pooled"; 90 91 95 100 private final String m_name; 101 102 105 private final String m_classname; 106 107 110 private final Version m_version; 111 112 115 private final String m_lifestyle; 116 117 120 private final String m_schema; 121 122 126 133 public InfoDescriptor( final String classname ) 134 throws IllegalArgumentException 135 { 136 this( null, classname, null, null, null, null ); 137 } 138 139 149 public InfoDescriptor( final String name, 150 final String classname, 151 final Version version, 152 final String lifestyle, 153 final String schema, 154 final Properties attributes ) 155 throws IllegalArgumentException 156 { 157 super( attributes ); 158 159 if ( null == classname ) throw new NullPointerException ( "classname" ); 160 161 if ( classname.indexOf( "/" ) > -1 ) 162 { 163 throw new IllegalArgumentException ( "classname: " + classname ); 164 } 165 166 m_classname = classname; 167 m_version = version; 168 m_schema = schema; 169 170 if ( lifestyle == null ) 171 { 172 m_lifestyle = TRANSIENT; 173 } 174 else 175 { 176 validateLifestyle( lifestyle ); 177 m_lifestyle = lifestyle; 178 } 179 180 if ( name != null ) 181 { 182 m_name = name; 183 } 184 else 185 { 186 m_name = getClassName( classname ); 187 } 188 } 189 190 private void validateLifestyle( String lifestyle ) throws IllegalArgumentException 191 { 192 if ( lifestyle.equals( TRANSIENT ) 193 || lifestyle.equals( SINGLETON ) 194 || lifestyle.equals( THREAD ) 195 || lifestyle.equals( POOLED ) ) 196 { 197 return; 198 } 199 final String error = "Lifestyle policy not recognized: " + lifestyle; 200 throw new IllegalArgumentException ( error ); 201 } 202 203 private String getClassName( String classname ) 204 { 205 int i = classname.lastIndexOf( "." ); 206 if ( i == -1 ) 207 { 208 return classname.toLowerCase(); 209 } 210 else 211 { 212 return classname.substring( i + 1, classname.length() ).toLowerCase(); 213 } 214 } 215 216 221 public String getName() 222 { 223 return m_name; 224 } 225 226 231 public String getConfigurationSchema() 232 { 233 return m_schema; 234 } 235 236 241 public String getClassname() 242 { 243 return m_classname; 244 } 245 246 251 public Version getVersion() 252 { 253 return m_version; 254 } 255 256 261 public String getLifestyle() 262 { 263 return m_lifestyle; 264 } 265 266 270 public String toString() 271 { 272 return "[" + getName() + "] " + getClassname() + ":" + getVersion(); 273 } 274 275 279 public boolean equals(Object other) 280 { 281 boolean isEqual = super.equals(other) && other instanceof InfoDescriptor; 282 283 if (isEqual) 284 { 285 InfoDescriptor info = (InfoDescriptor)other; 286 isEqual = isEqual && m_classname.equals( info.m_classname ); 287 isEqual = isEqual && m_name.equals( info.m_name ); 288 isEqual = isEqual && m_lifestyle.equals( info.m_lifestyle ); 289 290 if ( null == m_version ) 291 { 292 isEqual = isEqual && null == info.m_version; 293 } 294 else 295 { 296 isEqual = isEqual && m_version.equals(info.m_version); 297 } 298 } 299 300 return isEqual; 301 } 302 303 307 public int hashCode() 308 { 309 int hash = super.hashCode(); 310 311 hash >>>= 7; 312 hash ^= m_classname.hashCode(); 313 hash >>>= 7; 314 315 if ( null != m_name ) 316 { 317 hash >>>= 7; 318 hash ^= m_name.hashCode(); 319 } 320 321 if ( null != m_lifestyle ) 322 { 323 hash >>>= 7; 324 hash ^= m_lifestyle.hashCode(); 325 } 326 327 if ( null != m_version ) 328 { 329 hash >>>= 7; 330 hash ^= m_version.hashCode(); 331 } 332 333 return hash; 334 } 335 } 336 | Popular Tags |