1 50 51 package org.apache.avalon.meta.info; 52 53 import java.io.Serializable ; 54 55 import org.apache.avalon.framework.configuration.Configuration; 56 57 77 public class Type implements Serializable 78 { 79 private final InfoDescriptor m_descriptor; 80 private final ContextDescriptor m_context; 81 private final Configuration m_configuration; 82 private final ServiceDescriptor[] m_services; 83 private final DependencyDescriptor[] m_dependencies; 84 private final CategoryDescriptor[] m_loggers; 85 private final StageDescriptor[] m_stages; 86 private final ExtensionDescriptor[] m_extensions; 87 88 109 public Type( final InfoDescriptor descriptor, 110 final CategoryDescriptor[] loggers, 111 final ContextDescriptor context, 112 final ServiceDescriptor[] services, 113 final DependencyDescriptor[] dependencies, 114 final StageDescriptor[] stages, 115 final ExtensionDescriptor[] extensions ) 116 throws NullPointerException 117 { 118 this( descriptor, loggers, context, services, dependencies, stages, extensions, null ); 119 } 120 121 142 public Type( final InfoDescriptor descriptor, 143 final CategoryDescriptor[] loggers, 144 final ContextDescriptor context, 145 final ServiceDescriptor[] services, 146 final DependencyDescriptor[] dependencies, 147 final StageDescriptor[] stages, 148 final ExtensionDescriptor[] extensions, 149 final Configuration defaults ) 150 throws NullPointerException 151 { 152 if ( null == descriptor ) 153 { 154 throw new NullPointerException ( "descriptor" ); 155 } 156 if ( null == loggers ) 157 { 158 throw new NullPointerException ( "loggers" ); 159 } 160 if ( null == context ) 161 { 162 throw new NullPointerException ( "context" ); 163 } 164 if ( null == services ) 165 { 166 throw new NullPointerException ( "services" ); 167 } 168 if ( null == dependencies ) 169 { 170 throw new NullPointerException ( "dependencies" ); 171 } 172 if ( null == stages ) 173 { 174 throw new NullPointerException ( "stages" ); 175 } 176 if ( null == extensions ) 177 { 178 throw new NullPointerException ( "extensions" ); 179 } 180 181 m_descriptor = descriptor; 182 m_loggers = loggers; 183 m_context = context; 184 m_services = services; 185 m_dependencies = dependencies; 186 m_stages = stages; 187 m_extensions = extensions; 188 m_configuration = defaults; 189 } 190 191 196 public InfoDescriptor getInfo() 197 { 198 return m_descriptor; 199 } 200 201 206 public CategoryDescriptor[] getCategories() 207 { 208 return m_loggers; 209 } 210 211 217 public boolean isaCategory( String name ) 218 { 219 CategoryDescriptor[] loggers = getCategories(); 220 for( int i = 0; i < loggers.length; i++ ) 221 { 222 CategoryDescriptor logger = loggers[ i ]; 223 if( logger.getName().equals( name ) ) 224 { 225 return true; 226 } 227 } 228 return false; 229 } 230 231 237 public ContextDescriptor getContext() 238 { 239 return m_context; 240 } 241 242 247 public ServiceDescriptor[] getServices() 248 { 249 return m_services; 250 } 251 252 258 public ServiceDescriptor getService( final ReferenceDescriptor reference ) 259 { 260 for ( int i = 0; i < m_services.length; i++ ) 261 { 262 final ServiceDescriptor service = m_services[i]; 263 if ( service.getReference().matches( reference ) ) 264 { 265 return service; 266 } 267 } 268 return null; 269 } 270 271 277 public ServiceDescriptor getService( final String classname ) 278 { 279 for ( int i = 0; i < m_services.length; i++ ) 280 { 281 final ServiceDescriptor service = m_services[i]; 282 if ( service.getReference().getClassname().equals( classname ) ) 283 { 284 return service; 285 } 286 } 287 return null; 288 } 289 290 295 public DependencyDescriptor[] getDependencies() 296 { 297 return m_dependencies; 298 } 299 300 306 public DependencyDescriptor getDependency( final String key ) 307 { 308 for ( int i = 0; i < m_dependencies.length; i++ ) 309 { 310 if ( m_dependencies[i].getKey().equals( key ) ) 311 { 312 return m_dependencies[i]; 313 } 314 } 315 return null; 316 } 317 318 323 public Configuration getConfiguration() 324 { 325 return m_configuration; 326 } 327 328 333 public StageDescriptor[] getStages() 334 { 335 return m_stages; 336 } 337 338 343 public ExtensionDescriptor[] getExtensions() 344 { 345 return m_extensions; 346 } 347 348 354 public ExtensionDescriptor getExtension( StageDescriptor stage ) 355 { 356 return getExtension( stage.getKey() ); 357 } 358 359 365 public ExtensionDescriptor getExtension( String key ) 366 { 367 ExtensionDescriptor[] extensions = getExtensions(); 368 for ( int i = 0; i < extensions.length; i++ ) 369 { 370 ExtensionDescriptor extension = extensions[i]; 371 String ref = extension.getKey(); 372 if ( key.equals( ref ) ) 373 { 374 return extension; 375 } 376 } 377 return null; 378 } 379 380 384 public String toString() 385 { 386 return getInfo().toString(); 387 } 388 389 393 public boolean equals(Object other) 394 { 395 boolean isEqual = other instanceof Type; 396 isEqual = isEqual && m_descriptor.equals(((Type)other).m_descriptor); 397 isEqual = isEqual && m_configuration.equals(((Type)other).m_configuration); 398 isEqual = isEqual && m_context.equals(((Type)other).m_context); 399 for( int i=0; i<m_loggers.length; i++ ) 400 { 401 isEqual = isEqual && m_loggers[i].equals(((Type)other).m_loggers[i]); 402 } 403 for( int i=0; i<m_services.length; i++ ) 404 { 405 isEqual = isEqual && m_services[i].equals(((Type)other).m_services[i]); 406 } 407 for( int i=0; i<m_dependencies.length; i++ ) 408 { 409 isEqual = isEqual && m_dependencies[i].equals(((Type)other).m_dependencies[i]); 410 } 411 for( int i=0; i<m_stages.length; i++ ) 412 { 413 isEqual = isEqual && m_stages[i].equals(((Type)other).m_stages[i]); 414 } 415 for( int i=0; i<m_extensions.length; i++ ) 416 { 417 isEqual = isEqual && m_extensions[i].equals(((Type)other).m_extensions[i]); 418 } 419 return isEqual; 420 } 421 422 426 public int hashCode() 427 { 428 int hash = m_descriptor.hashCode(); 429 hash >>>= 13; 430 hash ^= m_context.hashCode(); 431 hash >>>= 13; 432 if( m_configuration != null ) 433 { 434 hash ^= m_context.hashCode(); 435 hash >>>= 13; 436 } 437 hash >>>= 13; 438 for( int i=0; i<m_services.length; i++ ) 439 { 440 hash ^= m_services[i].hashCode(); 441 hash >>>= 13; 442 } 443 for( int i=0; i<m_dependencies.length; i++ ) 444 { 445 hash ^= m_dependencies[i].hashCode(); 446 hash >>>= 13; 447 } 448 for( int i=0; i<m_loggers.length; i++ ) 449 { 450 hash ^= m_loggers[i].hashCode(); 451 hash >>>= 13; 452 } 453 for( int i=0; i<m_stages.length; i++ ) 454 { 455 hash ^= m_stages[i].hashCode(); 456 hash >>>= 13; 457 } 458 for( int i=0; i<m_extensions.length; i++ ) 459 { 460 hash ^= m_extensions[i].hashCode(); 461 hash >>>= 13; 462 } 463 return hash; 464 } 465 } 466 | Popular Tags |